@schoolbelle/common
Version:
Demo library to showcase Angular packaging format
1,249 lines (1,225 loc) • 622 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@schoolbelle/common/tokens'), require('@angular/common/http'), require('@schoolbelle/common/services/storage'), require('rxjs/add/operator/toPromise'), require('rxjs/BehaviorSubject'), require('@schoolbelle/common/services/user'), require('@schoolbelle/common/services/user-to-group'), require('lodash'), require('ngx-bootstrap/modal/bs-modal-ref.service'), require('ngx-bootstrap/modal'), require('rxjs/add/operator/take'), require('@angular/common'), require('@schoolbelle/common/services/group'), require('@schoolbelle/common/services/socket'), require('rxjs'), require('jwt-decode'), require('@schoolbelle/common/services/translation'), require('@schoolbelle/common/services/file'), require('@schoolbelle/common/services/letter-to-group'), require('@schoolbelle/common/services/sms'), require('@schoolbelle/common/services/pubsub'), require('@schoolbelle/common/services/infinite-scroll-list'), require('rxjs/Subscription'), require('@angular/animations'), require('rxjs/Subject'), require('immutable'), require('socket.io-client'), require('@schoolbelle/common/services/window'), require('@schoolbelle/common/services/object-change-tracker'), require('@schoolbelle/common/services/member')) :
typeof define === 'function' && define.amd ? define('@schoolbelle/common/services', ['exports', '@angular/core', '@schoolbelle/common/tokens', '@angular/common/http', '@schoolbelle/common/services/storage', 'rxjs/add/operator/toPromise', 'rxjs/BehaviorSubject', '@schoolbelle/common/services/user', '@schoolbelle/common/services/user-to-group', 'lodash', 'ngx-bootstrap/modal/bs-modal-ref.service', 'ngx-bootstrap/modal', 'rxjs/add/operator/take', '@angular/common', '@schoolbelle/common/services/group', '@schoolbelle/common/services/socket', 'rxjs', 'jwt-decode', '@schoolbelle/common/services/translation', '@schoolbelle/common/services/file', '@schoolbelle/common/services/letter-to-group', '@schoolbelle/common/services/sms', '@schoolbelle/common/services/pubsub', '@schoolbelle/common/services/infinite-scroll-list', 'rxjs/Subscription', '@angular/animations', 'rxjs/Subject', 'immutable', 'socket.io-client', '@schoolbelle/common/services/window', '@schoolbelle/common/services/object-change-tracker', '@schoolbelle/common/services/member'], factory) :
(factory((global.schoolbelle = global.schoolbelle || {}, global.schoolbelle.common = global.schoolbelle.common || {}, global.schoolbelle.common.services = {}),global.ng.core,global.schoolbelle.common.tokens,global.ng.common.http,global.schoolbelle.common.services.storage,global.rxjs['add/operator/toPromise'],global.rxjs.BehaviorSubject,global.schoolbelle.common.services.user,global.schoolbelle.common.services['user-to-group'],null,null,null,global.rxjs['add/operator/take'],global.ng.common,global.schoolbelle.common.services.group,global.schoolbelle.common.services.socket,global.rxjs,null,global.schoolbelle.common.services.translation,global.schoolbelle.common.services.file,global.schoolbelle.common.services['letter-to-group'],global.schoolbelle.common.services.sms,global.schoolbelle.common.services.pubsub,global.schoolbelle.common.services['infinite-scroll-list'],global.rxjs.Subscription,global.ng.animations,global.rxjs.Subject,null,null,global.schoolbelle.common.services.window,global.schoolbelle.common.services['object-change-tracker'],global.schoolbelle.common.services.member));
}(this, (function (exports,core,tokens,http,storage,toPromise,BehaviorSubject,user,userToGroup,_,bsModalRef_service,modal,take,common,group,socket,rxjs,jwt_decode,translation,file,letterToGroup,sms,pubsub,infiniteScrollList,Subscription,animations,Subject,Immutable,io,window$1,objectChangeTracker,member) { 'use strict';
jwt_decode = jwt_decode && jwt_decode.hasOwnProperty('default') ? jwt_decode['default'] : jwt_decode;
io = io && io.hasOwnProperty('default') ? io['default'] : io;
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var AuthService = (function () {
function AuthService(http$$1, storageService, serverHost) {
this.http = http$$1;
this.storageService = storageService;
this.serverHost = serverHost;
var /** @type {?} */ type = (this.storageService.get('sbe-auth.session.type', 'session'));
var /** @type {?} */ intltel = this.storageService.get('sbe-auth.session.intltel', 'session');
var /** @type {?} */ verificationCode = this.storageService.get('sbe-auth.session.verificationCode', 'session');
if (type)
this.type = type;
if (intltel)
this.intltel = intltel;
if (verificationCode)
this.verificationCode = verificationCode;
}
Object.defineProperty(AuthService.prototype, "type", {
get: /**
* @return {?}
*/ function () {
return this._type;
},
set: /**
* @param {?} v
* @return {?}
*/ function (v) {
this._type = v;
if (v) {
this.storageService.set('sbe-auth.session.type', v, 'session');
}
else {
this.storageService.remove('sbe-auth.session.type', 'session');
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(AuthService.prototype, "intltel", {
get: /**
* @return {?}
*/ function () {
return this._intltel;
},
set: /**
* @param {?} v
* @return {?}
*/ function (v) {
this._intltel = v;
if (v) {
this.storageService.set('sbe-auth.session.intltel', v, 'session');
}
else {
this.storageService.remove('sbe-auth.session.intltel', 'session');
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(AuthService.prototype, "verificationCode", {
get: /**
* @return {?}
*/ function () {
return this._verificationCode;
},
set: /**
* @param {?} v
* @return {?}
*/ function (v) {
this._verificationCode = v;
if (v) {
this.storageService.set('sbe-auth.session.verificationCode', v, 'session');
}
else {
this.storageService.remove('sbe-auth.session.verificationCode', 'session');
}
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
AuthService.prototype.clear = /**
* @return {?}
*/
function () {
this.type = undefined;
this.intltel = undefined;
this.verificationCode = undefined;
};
/**
* @param {?} idtoken
* @return {?}
*/
AuthService.prototype.saveToken = /**
* @param {?} idtoken
* @return {?}
*/
function (idtoken) {
if (idtoken) {
this.storageService.set(AuthService.localStorageIdTokenKey, idtoken, 'local');
}
else {
this.storageService.remove(AuthService.localStorageIdTokenKey, 'local');
}
};
/**
* @param {?=} type
* @param {?=} countryDialCode
* @param {?=} tel
* @return {?}
*/
AuthService.prototype.requestCode = /**
* @param {?=} type
* @param {?=} countryDialCode
* @param {?=} tel
* @return {?}
*/
function (type, countryDialCode, tel) {
if (type === void 0) {
type = 'register';
}
var /** @type {?} */ url = this.serverHost + "/verification/request_code";
return this.http
.post(url, { type: type, countryDialCode: countryDialCode, tel: tel }, { responseType: 'text' })
.toPromise();
};
/**
* @param {?=} type
* @param {?=} countryDialCode
* @param {?=} tel
* @param {?=} verificationCode
* @param {?=} callback_url
* @return {?}
*/
AuthService.prototype.verifyCode = /**
* @param {?=} type
* @param {?=} countryDialCode
* @param {?=} tel
* @param {?=} verificationCode
* @param {?=} callback_url
* @return {?}
*/
function (type, countryDialCode, tel, verificationCode, callback_url) {
var _this = this;
if (type === void 0) {
type = 'register';
}
if (callback_url === void 0) {
callback_url = undefined;
}
var /** @type {?} */ url = this.serverHost + "/verification/verify_code";
return this.http
.post(url, {
type: type,
countryDialCode: countryDialCode,
tel: tel,
code: verificationCode,
callback_url: callback_url
}, { responseType: 'text' })
.toPromise()
.then(function (token) {
if (type === 'tmp' && token) {
_this.saveToken(token);
}
return token;
});
};
/**
* @param {?} countryDialCode
* @param {?} tel
* @param {?} password
* @param {?=} callback_url
* @return {?}
*/
AuthService.prototype.login = /**
* @param {?} countryDialCode
* @param {?} tel
* @param {?} password
* @param {?=} callback_url
* @return {?}
*/
function (countryDialCode, tel, password, callback_url) {
var _this = this;
if (callback_url === void 0) {
callback_url = undefined;
}
var /** @type {?} */ url = this.serverHost + "/login";
return this.http
.post(url, {
countryDialCode: countryDialCode,
tel: tel,
password: password,
callback_url: callback_url
}, { responseType: 'text' })
.toPromise()
.then(function (token) {
_this.saveToken(token);
return token;
});
};
/**
* @param {?} countryDialCode
* @param {?} tel
* @param {?} verificationCode
* @param {?} name
* @param {?} password
* @param {?=} callback_url
* @return {?}
*/
AuthService.prototype.register = /**
* @param {?} countryDialCode
* @param {?} tel
* @param {?} verificationCode
* @param {?} name
* @param {?} password
* @param {?=} callback_url
* @return {?}
*/
function (countryDialCode, tel, verificationCode, name, password, callback_url) {
var _this = this;
if (callback_url === void 0) {
callback_url = undefined;
}
var /** @type {?} */ url = this.serverHost + "/register";
return this.http
.post(url, {
countryDialCode: countryDialCode,
tel: tel,
code: verificationCode,
name: name,
password: password
})
.toPromise()
.then(function () { return _this.login(countryDialCode, tel, password, callback_url); });
};
/**
* @return {?}
*/
AuthService.prototype.getTermsOfUse = /**
* @return {?}
*/
function () {
var /** @type {?} */ url = this.serverHost + "/legal/user_agreement";
return this.http.get(url, { responseType: 'text' }).toPromise();
};
/**
* @return {?}
*/
AuthService.prototype.getPrivacyPolicy = /**
* @return {?}
*/
function () {
var /** @type {?} */ url = this.serverHost + "/legal/privacy_policy";
return this.http.get(url, { responseType: 'text' }).toPromise();
};
/**
* @param {?} countryDialCode
* @param {?} tel
* @param {?} password
* @return {?}
*/
AuthService.prototype.agreeToTerms = /**
* @param {?} countryDialCode
* @param {?} tel
* @param {?} password
* @return {?}
*/
function (countryDialCode, tel, password) {
var /** @type {?} */ url = this.serverHost + "/legal/agree_to_terms";
return this.http
.post(url, {
countryDialCode: countryDialCode,
tel: tel,
password: password
})
.toPromise();
};
AuthService.localStorageIdTokenKey = 'sbe-auth.idToken';
AuthService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
AuthService.ctorParameters = function () {
return [
{ type: http.HttpClient, },
{ type: storage.StorageService, },
{ type: undefined, decorators: [{ type: core.Inject, args: [tokens.REST_SERVER_HOST,] },] },
];
};
return AuthService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var AuthServiceModule = (function () {
function AuthServiceModule() {
}
/**
* @return {?}
*/
AuthServiceModule.forRoot = /**
* @return {?}
*/
function () {
return {
ngModule: AuthServiceModule,
providers: [AuthService]
};
};
AuthServiceModule.decorators = [
{ type: core.NgModule, args: [{
imports: [http.HttpClientModule, storage.StorageServiceModule]
},] },
];
return AuthServiceModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var BadgeService = (function () {
function BadgeService(http$$1, userService, utgService, serverHost) {
this.http = http$$1;
this.userService = userService;
this.utgService = utgService;
this.serverHost = serverHost;
this.list = [];
this.badges = {
total: 0
};
this.changeEvent = new BehaviorSubject.BehaviorSubject(this.badges);
}
Object.defineProperty(BadgeService.prototype, "onChange", {
get: /**
* @return {?}
*/ function () {
return this.changeEvent.asObservable();
},
enumerable: true,
configurable: true
});
/**
* @param {?=} path
* @return {?}
*/
BadgeService.prototype.get = /**
* @param {?=} path
* @return {?}
*/
function (path) {
if (path === void 0) {
path = undefined;
}
return path ? _.get(this.badges, path) : this.badges;
};
/**
* @return {?}
*/
BadgeService.prototype.refresh = /**
* @return {?}
*/
function () {
var _this = this;
var /** @type {?} */ url = this.serverHost + "/user/notification/list";
return this.http
.get(url, {
headers: { Authorization: 'Bearer ' + this.userService.token },
responseType: 'json'
})
.toPromise()
.then(function (list) {
_this.list.splice(0, _this.list.length);
_.forEach(Object.keys(_this.badges), function (key) { return delete _this.badges[key]; });
_this.badges.total = 0;
list.forEach(function (li) {
if (!_.find(_this.list, { notification_id: li.notification_id })) {
_this.list.push(li);
_this.addToBadges(li);
}
});
_this.changeEvent.next(_this.badges);
});
};
/**
* @return {?}
*/
BadgeService.prototype.fetch = /**
* @return {?}
*/
function () {
var _this = this;
var /** @type {?} */ last_id = (_.maxBy(this.list, 'notification_id') || {}).notification_id;
var /** @type {?} */ url = this.serverHost + "/user/notification/list";
var /** @type {?} */ params = new http.HttpParams().set('last_id', last_id);
return this.http
.get(url, {
params: params,
headers: { Authorization: 'Bearer ' + this.userService.token },
responseType: 'json'
})
.toPromise()
.then(function (list) {
list.forEach(function (li) {
if (!_.find(_this.list, { notification_id: li.notification_id })) {
_this.list.push(li);
_this.addToBadges(li);
}
});
_this.changeEvent.next(_this.badges);
});
};
/**
* @param {?} params
* @return {?}
*/
BadgeService.prototype.find = /**
* @param {?} params
* @return {?}
*/
function (params) {
return _.find(this.list, function (li) {
for (var /** @type {?} */ path in params) {
var /** @type {?} */ value = params[path];
if (_.get(li, path) !== value)
return false;
}
return true;
});
};
/**
* @param {?} params
* @return {?}
*/
BadgeService.prototype.read = /**
* @param {?} params
* @return {?}
*/
function (params) {
var _this = this;
// path-value pairs
var /** @type {?} */ li = this.find(params);
if (!li)
return Promise.resolve();
var /** @type {?} */ url = this.serverHost + "/user/notification/read";
var /** @type {?} */ httpParams = new http.HttpParams().set('notification_id', '' + params.notification_id);
return this.http
.post(url, {
params: httpParams,
headers: { Authorization: 'Bearer ' + this.userService.token }
})
.toPromise()
.then(function () {
_this.removeFromBadges(li);
var /** @type {?} */ index = _.findIndex(_this.list, {
notification_id: li.notification_id
});
if (index !== -1)
_this.list.splice(index, 1);
_this.changeEvent.next(_this.badges);
});
};
/**
* @param {?} li
* @return {?}
*/
BadgeService.prototype.addToBadges = /**
* @param {?} li
* @return {?}
*/
function (li) {
var /** @type {?} */ group$$1 = _.find(this.utgService.list, { group_id: li.group_id });
if (!group$$1)
return;
if (BadgeService.notificationToRecord.indexOf(li.table + '.*') !== -1 ||
BadgeService.notificationToRecord.indexOf(li.table + '.' + li.type) === -1)
return;
if (!li.new || !li.new.ltg_id)
return;
if (li.new.type && group$$1.type && group$$1.type.match(/school/))
return;
if (li.new.type) {
var /** @type {?} */ value_o = _.get(this.badges, [li.group_id, li.new.type]) || 0;
var /** @type {?} */ total_o = _.get(this.badges, [li.group_id, 'total']) || 0;
var /** @type {?} */ grand_total_o = _.get(this.badges, ['total']) || 0;
_.set(this.badges, [li.group_id, li.new.type], value_o + 1);
_.set(this.badges, [li.group_id, 'total'], total_o + 1);
_.set(this.badges, ['total'], grand_total_o + 1);
}
};
/**
* @param {?} li
* @return {?}
*/
BadgeService.prototype.removeFromBadges = /**
* @param {?} li
* @return {?}
*/
function (li) {
var /** @type {?} */ group$$1 = _.find(this.utgService.list, { group_id: li.group_id });
if (!group$$1)
return;
if (li.group_id && li.old && li.old.type) {
if (group$$1.type && group$$1.type.match(/school/))
return;
var /** @type {?} */ value_o = _.get(this.badges, [li.group_id, li.old.type]) || 1;
var /** @type {?} */ total_o = _.get(this.badges, [li.group_id, 'total']) || 1;
var /** @type {?} */ grand_total_o = _.get(this.badges, ['total']) || 1;
if (value_o <= 0)
value_o = 1;
if (total_o <= 0)
value_o = 1;
_.set(this.badges, [li.group_id, li.old.type], value_o - 1);
_.set(this.badges, [li.group_id, 'total'], total_o - 1);
_.set(this.badges, ['total'], grand_total_o - 1);
}
};
BadgeService.notificationToRecord = ['letter_to_group.insert', 'utgRequest.insert'];
BadgeService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
BadgeService.ctorParameters = function () {
return [
{ type: http.HttpClient, },
{ type: user.UserService, },
{ type: userToGroup.UserToGroupService, },
{ type: undefined, decorators: [{ type: core.Inject, args: [tokens.REST_SERVER_HOST,] },] },
];
};
return BadgeService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var BadgeServiceModule = (function () {
function BadgeServiceModule() {
}
/**
* @return {?}
*/
BadgeServiceModule.forRoot = /**
* @return {?}
*/
function () {
return {
NgModule: BadgeService,
providers: [BadgeService]
};
};
BadgeServiceModule.decorators = [
{ type: core.NgModule, args: [{},] },
];
return BadgeServiceModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
function __values(o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m)
return m.call(o);
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var DialogAbstractComponent = (function () {
function DialogAbstractComponent(modalRef) {
this.modalRef = modalRef;
this.action = new core.EventEmitter();
}
/**
* @param {?=} result
* @return {?}
*/
DialogAbstractComponent.prototype.ok = /**
* @param {?=} result
* @return {?}
*/
function (result) {
if (result === void 0) {
result = true;
}
this.modalRef.hide();
this.action.emit(result);
};
/**
* @return {?}
*/
DialogAbstractComponent.prototype.cancel = /**
* @return {?}
*/
function () {
this.modalRef.hide();
this.action.emit(false);
};
DialogAbstractComponent.decorators = [
{ type: core.Component, args: [{
template: ''
},] },
];
/** @nocollapse */
DialogAbstractComponent.ctorParameters = function () {
return [
{ type: bsModalRef_service.BsModalRef, },
];
};
DialogAbstractComponent.propDecorators = {
"title": [{ type: core.Input },],
"message": [{ type: core.Input },],
};
return DialogAbstractComponent;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var DialogConfirmComponent = (function (_super) {
__extends(DialogConfirmComponent, _super);
function DialogConfirmComponent() {
return _super !== null && _super.apply(this, arguments) || this;
}
DialogConfirmComponent.decorators = [
{ type: core.Component, args: [{
selector: 'dialog-confirm',
template: "<div *ngIf=\"title\" class=\"card-header\" [innerHTML]=\"title\"></div>\n<div *ngIf=\"message\" class=\"card-body\" [innerHTML]=\"message\"></div>\n<div class=\"modal-footer\">\n <button type=\"button\" class=\"btn btn-outline-danger\" (click)=\"modalRef.hide(); action.emit(false)\" i18n>Cancel</button>\n <button type=\"button\" class=\"btn btn-outline-primary\" (click)=\"modalRef.hide(); action.emit(true)\" i18n>Confirm</button>\n</div>\n"
},] },
];
return DialogConfirmComponent;
}(DialogAbstractComponent));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var DialogAlertComponent = (function (_super) {
__extends(DialogAlertComponent, _super);
function DialogAlertComponent() {
return _super !== null && _super.apply(this, arguments) || this;
}
DialogAlertComponent.decorators = [
{ type: core.Component, args: [{
selector: 'dialog-alert',
template: "<div class=\"card\">\n <div *ngIf=\"title\" class=\"card-header\" [innerHTML]=\"title\"></div>\n <div *ngIf=\"message\" class=\"card-body\" [innerHTML]=\"message\"></div>\n <div class=\"card-footer text-right\">\n <button type=\"button\" class=\"btn btn-outline-danger\" (click)=\"modalRef.hide(); action.emit(true)\" i18n>Close</button>\n </div>\n</div> \n"
},] },
];
return DialogAlertComponent;
}(DialogAbstractComponent));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var DialogSelectComponent = (function (_super) {
__extends(DialogSelectComponent, _super);
function DialogSelectComponent() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.selections = [];
return _this;
}
/**
* @param {?} i
* @return {?}
*/
DialogSelectComponent.prototype.select = /**
* @param {?} i
* @return {?}
*/
function (i) {
this.modalRef.hide();
this.action.emit(i);
};
DialogSelectComponent.decorators = [
{ type: core.Component, args: [{
selector: 'dialog-select',
template: "<div *ngIf=\"title\" class=\"card-header\" [innerHTML]=\"title\"></div>\n<div class=\"card-body\">\n <button class=\"btn btn-block btn-outline-dark\" *ngFor=\"let selection of selections; index as i\" (click)=\"select(i)\" [innerHTML]=\"selection.html\" [ngClass]=\"selection.class\"></button>\n <button type=\"button\" class=\"btn btn-block btn-outline-danger\" (click)=\"cancel()\" i18n>Cancel</button>\n</div>\n"
},] },
];
/** @nocollapse */
DialogSelectComponent.propDecorators = {
"selections": [{ type: core.Input },],
};
return DialogSelectComponent;
}(DialogAbstractComponent));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var DialogService = (function () {
function DialogService(modalService) {
this.modalService = modalService;
}
/**
* @param {?=} title
* @param {?=} message
* @param {?=} options
* @return {?}
*/
DialogService.prototype.confirm = /**
* @param {?=} title
* @param {?=} message
* @param {?=} options
* @return {?}
*/
function (title, message, options) {
var _this = this;
if (title === void 0) {
title = '';
}
if (message === void 0) {
message = '';
}
if (options === void 0) {
options = {};
}
return new Promise(function (resolve, reject) {
var /** @type {?} */ modalRef = _this.modalService.show(DialogConfirmComponent, Object.assign({}, options, { backdrop: 'static' }));
modalRef.content.title = title;
modalRef.content.message = message;
modalRef.content.action.take(1).subscribe(function (result) {
if (result !== false)
resolve(result);
else
reject(result);
});
});
};
/**
* @param {?=} title
* @param {?=} message
* @param {?=} options
* @return {?}
*/
DialogService.prototype.alert = /**
* @param {?=} title
* @param {?=} message
* @param {?=} options
* @return {?}
*/
function (title, message, options) {
var _this = this;
if (title === void 0) {
title = '';
}
if (message === void 0) {
message = '';
}
if (options === void 0) {
options = {};
}
return new Promise(function (resolve, reject) {
var /** @type {?} */ modalRef = _this.modalService.show(DialogAlertComponent, Object.assign({}, options, { backdrop: 'static' }));
modalRef.content.title = title;
modalRef.content.message = message;
modalRef.content.action.take(1).subscribe(function (result) {
if (result !== false)
resolve(result);
else
reject(result);
});
});
};
/**
* @param {?=} title
* @param {?=} selections
* @param {?=} options
* @return {?}
*/
DialogService.prototype.select = /**
* @param {?=} title
* @param {?=} selections
* @param {?=} options
* @return {?}
*/
function (title, selections, options) {
var _this = this;
if (title === void 0) {
title = '';
}
if (options === void 0) {
options = {};
}
return new Promise(function (resolve, reject) {
var /** @type {?} */ modalRef = _this.modalService.show(DialogSelectComponent, Object.assign({}, options, { backdrop: 'static' }));
modalRef.content.title = title;
modalRef.content.selections = selections;
modalRef.content.action.take(1).subscribe(function (result) {
if (result !== false)
resolve(result);
else
reject(result);
});
});
};
DialogService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
DialogService.ctorParameters = function () {
return [
{ type: modal.BsModalService, },
];
};
return DialogService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var DialogModule = (function () {
function DialogModule() {
}
DialogModule.decorators = [
{ type: core.NgModule, args: [{
imports: [common.CommonModule, modal.ModalModule.forRoot()],
entryComponents: [
DialogConfirmComponent,
DialogAlertComponent,
DialogSelectComponent
],
declarations: [
DialogAbstractComponent,
DialogConfirmComponent,
DialogAlertComponent,
DialogSelectComponent
],
providers: [DialogService]
},] },
];
return DialogModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var FileService = (function () {
function FileService(http$$1, groupService, socketService, serverHost) {
this.http = http$$1;
this.groupService = groupService;
this.socketService = socketService;
this.serverHost = serverHost;
this.uploadStatusChangeEvent = new rxjs.Subject();
this.uploadStatus = new Map();
}
Object.defineProperty(FileService.prototype, "onUploadStatusChange", {
get: /**
* @return {?}
*/ function () {
return this.uploadStatusChangeEvent.asObservable();
},
enumerable: true,
configurable: true
});
/**
* @param {?} key
* @param {?} data
* @return {?}
*/
FileService.prototype.setUploadStatus = /**
* @param {?} key
* @param {?} data
* @return {?}
*/
function (key, data) {
this.uploadStatus.set(key, data);
this.uploadStatusChangeEvent.next(this.caculatePercent());
};
/**
* @param {?} key
* @param {?} data
* @return {?}
*/
FileService.prototype.updateUploadStatus = /**
* @param {?} key
* @param {?} data
* @return {?}
*/
function (key, data) {
var /** @type {?} */ found = this.uploadStatus.get(key);
if (found) {
Object.assign(found, data);
this.uploadStatusChangeEvent.next(this.caculatePercent());
}
};
/**
* @return {?}
*/
FileService.prototype.caculatePercent = /**
* @return {?}
*/
function () {
var _this = this;
var /** @type {?} */ perc = 0;
this.uploadStatus.forEach(function (uploadState, key) {
perc +=
(uploadState.upload * 0.5 +
(typeof uploadState.process === 'undefined'
? 1
: uploadState.process) *
0.5) /
_this.uploadStatus.size;
});
return perc;
};
/**
* @param {?} file
* @param {?} opts
* @return {?}
*/
FileService.prototype.getUrl = /**
* @param {?} file
* @param {?} opts
* @return {?}
*/
function (file$$1, opts) {
return this.http
.post(this.serverHost + '/group/file/sign_url', {
sign_for: 'upload',
name: file$$1.name,
type: file$$1.type,
size: file$$1.size,
process: opts.process
}, {
headers: { Authorization: "Bearer " + this.groupService.token }
})
.toPromise();
};
/**
* @param {?} file
* @param {?=} opts
* @return {?}
*/
FileService.prototype.upload = /**
* @param {?} file
* @param {?=} opts
* @return {?}
*/
function (file$$1, opts) {
var _this = this;
if (opts === void 0) {
opts = { process: false };
}
return new Promise(function (resolve, reject) {
_this.getUrl(file$$1, opts)
.then(function (data) {
_this.setUploadStatus(data.file_id, {
name: file$$1.name,
size: file$$1.size,
type: file$$1.type,
upload: 0,
process: opts.process ? 0 : undefined
});
_this.http
.put(data.signedUrl, file$$1, { reportProgress: true })
.subscribe(function (event) {
console.log(event);
// let perc = Math.round(progressEvent.loaded / progressEvent.total * 100);
// let info = this.uploadStatus.get(data.file_id);
// if (info) info.upload = perc;
// observer.next(perc);
}, reject, function () {
_this.updateUploadStatus(data.file_id, { upload: 100 });
if (opts.process === true)
_this.observeProgress(data.file_id).subscribe(null, reject, function () { return resolve(data.file_id); });
else
resolve(data.file_id);
});
})
.catch(reject);
}).then(function (sbe_file_id) { return _this.register(sbe_file_id); });
};
/**
* @param {?} sbe_file_id
* @return {?}
*/
FileService.prototype.register = /**
* @param {?} sbe_file_id
* @return {?}
*/
function (sbe_file_id) {
return this.http
.post(this.serverHost + '/group/file/register', { file_id: sbe_file_id }, { headers: { Authorization: "Bearer " + this.groupService.token } })
.toPromise();
// .then(response=>response.json());
};
/**
* @param {?} file_id
* @return {?}
*/
FileService.prototype.observeProgress = /**
* @param {?} file_id
* @return {?}
*/
function (file_id) {
var _this = this;
return new rxjs.Observable(function (observer) {
var /** @type {?} */ uploadStatus = _this.uploadStatus.get(file_id);
var /** @type {?} */ process = uploadStatus ? uploadStatus.process : undefined;
if (process === undefined)
observer.error('no processing found');
else if (process === 100)
observer.complete();
else {
_this.socketService.listen('f' + file_id);
var /** @type {?} */ subscription_1 = _this.socketService
.getObservable('f' + file_id)
.subscribe(function (event) {
var /** @type {?} */ data = event.data;
if (data.match(/download \d+/))
process = Math.round(FileService.Weights.download * parseInt(data.replace(/\D/g, '')));
else if (data.match(/convert.low \d+/))
process = Math.round(FileService.Weights.download * 100 +
FileService.Weights.convert *
parseInt(data.replace(/\D/g, '')));
else if (data.match(/upload.low \d+/))
process = Math.round((FileService.Weights.download + FileService.Weights.convert) *
100 +
FileService.Weights.upload * parseInt(data.replace(/\D/g, '')));
_this.updateUploadStatus(file_id, { process: process });
if (process === 100 || data.match('job is done')) {
observer.complete();
_this.socketService.unlisten('f' + file_id);
subscription_1.unsubscribe();
}
else if (data.match('timeout')) {
observer.error('timeout');
subscription_1.unsubscribe();
}
else {
observer.next(process);
}
});
}
});
};
/**
* @param {?} letterFiles
* @param {?=} process
* @return {?}
*/
FileService.prototype.multipleUpload = /**
* @param {?} letterFiles
* @param {?=} process
* @return {?}
*/
function (letterFiles, process) {
var _this = this;
if (process === void 0) {
process = true;
}
this.uploadStatus.clear();
if (process)
this.socketService.connect(true);
var /** @type {?} */ promises = [];
_.forEach(letterFiles, function (file$$1, index) {
if (file$$1 instanceof File) {
promises.push(_this.upload(file$$1, { process: process }).then(function (fileInfo) {
letterFiles.splice(index, 1, fileInfo);
}));
}
});
return Promise.all(promises).then(function () { return (letterFiles); });
};
/**
* @param {?} uri
* @param {?} name
* @return {?}
*/
FileService.prototype.download = /**
* @param {?} uri
* @param {?} name
* @return {?}
*/
function (uri, name) { };
FileService.Weights = {
download: 0.1,
convert: 0.8,
upload: 0.1
};
FileService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
FileService.ctorParameters = function () {
return [
{ type: http.HttpClient, },
{ type: group.GroupService, },
{ type: socket.SocketService, },
{ type: undefined, decorators: [{ type: core.Inject, args: [tokens.REST_SERVER_HOST,] },] },
];
};
return FileService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var FileServiceModule = (function () {
function FileServiceModule() {
}
/**
* @return {?}
*/
FileServiceModule.forRoot = /**
* @return {?}
*/
function () {
return {
ngModule: FileServiceModule,
providers: [FileService]
};
};
FileServiceModule.decorators = [
{ type: core.NgModule, args: [{
imports: [http.HttpClientModule]
},] },
];
return FileServiceModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var GroupInfo = (function () {
function GroupInfo(params) {
this.type = params.type;
this.group_name = params.group_name;
this.school_name = params.school_name;
}
return GroupInfo;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var Group = (function () {
function Group(params) {
this.uid = params.uid;
this.gid = params.gid;
this.sid = params.sid;
this.scopes = params.scopes;
this.tabs = params.tabs;
this.info = new GroupInfo(params.info);
this.groupIdToken = params.groupIdToken;
}
return Group;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var GroupTranslationComponent = (function () {
function GroupTranslationComponent() {
}
GroupTranslationComponent.decorators = [
{ type: core.Component, args: [{
selector: 'translation-group',
template: "<div hidden id=\"fetching-group\"\ni18n-translation-text=\"@@fetchingGroup\"\ntranslation-text=\"\uD559\uAE09\uC815\uBCF4\uB97C \uBD88\uB7EC\uC624\uB294 \uC911\uC785\uB2C8\uB2E4...\"></div>\n"
},] },
];
return GroupTranslationComponent;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var GroupService = (function () {
function GroupService(http$