air-lib
Version:
This is Air's angular component library
1,480 lines (1,466 loc) • 254 kB
JavaScript
import { CookieService } from 'ngx-cookie-service';
import { CookieService as CookieService$1 } from 'ngx-cookie-service/cookie-service/cookie.service';
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
import { finalize, tap } from 'rxjs/operators';
import { BehaviorSubject } from 'rxjs';
import { TranslateService, TranslateModule } from '@ngx-translate/core';
import { Router, RouterModule, ActivatedRoute, NavigationEnd } from '@angular/router';
import { MomentModule } from 'ngx-moment';
import * as moment_ from 'moment';
import { locale } from 'moment';
import { findIndex } from 'lodash';
import { CommonModule } from '@angular/common';
import { DomSanitizer } from '@angular/platform-browser';
import { Subject } from 'rxjs/Subject';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';
import { NG_VALUE_ACCESSOR, ReactiveFormsModule, FormsModule } from '@angular/forms';
import { Injectable, NgModule, Pipe, Directive, HostListener, Input, EventEmitter, Output, Component, ViewChild, ViewContainerRef, ComponentFactoryResolver, ViewEncapsulation, forwardRef, ElementRef, defineInjectable, inject } from '@angular/core';
import { __awaiter, __generator, __extends, __values, __spread } from 'tslib';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var User = /** @class */ (function () {
function User() {
}
return User;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var BusMessageType = /** @class */ (function () {
function BusMessageType() {
}
BusMessageType.NewUserLogin = 'newuserlogin';
return BusMessageType;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var SessionContext = /** @class */ (function () {
function SessionContext() {
}
Object.defineProperty(SessionContext.prototype, "accessToken", {
get: /**
* @return {?}
*/
function () {
return '';
},
enumerable: true,
configurable: true
});
SessionContext.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */ SessionContext.ngInjectableDef = defineInjectable({ factory: function SessionContext_Factory() { return new SessionContext(); }, token: SessionContext, providedIn: "root" });
return SessionContext;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var CommunicationService = /** @class */ (function () {
function CommunicationService() {
}
/**
* @return {?}
*/
CommunicationService.get = /**
* @return {?}
*/
function () {
if (!CommunicationService.emitters) {
CommunicationService.emitters = new EventEmitter();
}
return CommunicationService.emitters;
};
/**
* @return {?}
*/
CommunicationService.getMessageBus = /**
* @return {?}
*/
function () {
if (!CommunicationService.emittersBus) {
CommunicationService.emittersBus = new EventEmitter();
}
return CommunicationService.emittersBus;
};
/**
* @return {?}
*/
CommunicationService.getCurrentActiveTab = /**
* @return {?}
*/
function () {
return CommunicationService.activeTab;
};
/**
* @param {?} value
* @return {?}
*/
CommunicationService.setCurrentActiveTab = /**
* @param {?} value
* @return {?}
*/
function (value) {
if (value) {
CommunicationService.activeTab = value;
}
};
CommunicationService.emitters = new EventEmitter();
CommunicationService.emittersBus = new EventEmitter();
// tslint:disable-next-line:no-inferrable-types
CommunicationService.activeTab = '';
CommunicationService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
CommunicationService.ctorParameters = function () { return []; };
/** @nocollapse */ CommunicationService.ngInjectableDef = defineInjectable({ factory: function CommunicationService_Factory() { return new CommunicationService(); }, token: CommunicationService, providedIn: "root" });
return CommunicationService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var SessionService = /** @class */ (function () {
function SessionService(cookiesService, router, sessionContext) {
var _this = this;
this.cookiesService = cookiesService;
this.router = router;
this.sessionContext = sessionContext;
this.userKey = 'AirUser';
this.adminAccessTokenKey = 'AirAdminToken';
this.adminReturnUrlKey = 'AirAdminReturnUrl';
this.isImpersonatedKey = 'AirIsImpersonated';
this.apiServer = sessionContext.apiServer;
/** @type {?} */
var userJson = localStorage.getItem(this.userKey);
this.user = userJson ? JSON.parse(userJson) : new User();
this.InitComponent();
this.isAuthenticated = false;
this.accessToken = '' + localStorage.getItem(SessionService.AccessTokenKey);
this.activities = new Array();
this.subscribeMessageBus = CommunicationService.getMessageBus()
.subscribe(function (msg) {
if (msg.name === BusMessageType.NewUserLogin) {
_this.referralTree = null;
}
});
}
/**
* @return {?}
*/
SessionService.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
if (this.subscribeMessageBus) {
this.subscribeMessageBus.unsubscribe();
}
};
/**
* @param {?} activity
* @return {?}
*/
SessionService.prototype.hasActivity = /**
* @param {?} activity
* @return {?}
*/
function (activity) {
if (this.isAuthenticated && !this.activities.length) {
this.getActivitiesFromCookie();
}
if (!this.activities || !activity || !this.isAuthenticated) {
return false;
}
return this.activities.indexOf(activity) !== -1;
};
/**
* @param {?} userData
* @return {?}
*/
SessionService.prototype.setUser = /**
* @param {?} userData
* @return {?}
*/
function (userData) {
this.user = userData;
/** @type {?} */
var userJson = JSON.stringify(this.user);
localStorage.setItem(this.userKey, userJson);
this.InitComponent();
};
/**
* @param {?} userProfileData
* @return {?}
*/
SessionService.prototype.setUserProfile = /**
* @param {?} userProfileData
* @return {?}
*/
function (userProfileData) {
this.userProfile = userProfileData;
CommunicationService.get().emit(this.userProfile);
};
/**
* @param {?} referralTree
* @return {?}
*/
SessionService.prototype.setReferralTree = /**
* @param {?} referralTree
* @return {?}
*/
function (referralTree) {
this.referralTree = referralTree;
CommunicationService.get().emit(this.referralTree);
};
/**
* @private
* @return {?}
*/
SessionService.prototype.InitComponent = /**
* @private
* @return {?}
*/
function () {
locale(this.user.locale ? this.user.locale : 'ru');
};
/**
* @private
* @return {?}
*/
SessionService.prototype.getActivitiesFromCookie = /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var activities = this.cookiesService.get('Activities');
this.activities = activities ? JSON.parse(activities) : [];
};
/**
* @return {?}
*/
SessionService.prototype.isImpersonated = /**
* @return {?}
*/
function () {
return Boolean(localStorage.getItem(this.isImpersonatedKey) === 'true'
? localStorage.getItem(this.isImpersonatedKey)
: false);
};
SessionService.AccessTokenKey = 'AirToken';
SessionService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
SessionService.ctorParameters = function () { return [
{ type: CookieService },
{ type: Router },
{ type: SessionContext }
]; };
/** @nocollapse */ SessionService.ngInjectableDef = defineInjectable({ factory: function SessionService_Factory() { return new SessionService(inject(CookieService$1), inject(Router), inject(SessionContext)); }, token: SessionService, providedIn: "root" });
return SessionService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var AuthService = /** @class */ (function () {
function AuthService(sessionService) {
this.sessionService = sessionService;
this.allowedList = new Array();
this.allowedList[0] = '/account/login';
this.allowedList[1] = '/account/recovery-password';
this.allowedList[2] = '/account/registration';
this.allowedList[3] = '/account/impersonation';
}
/**
* @param {?} state
* @return {?}
*/
AuthService.prototype.isAllowed = /**
* @param {?} state
* @return {?}
*/
function (state) {
/** @type {?} */
var isAllowed = false;
for (var i = 0; i < this.allowedList.length; i++) {
if (state.url.indexOf(this.allowedList[i]) !== -1) {
isAllowed = true;
break;
}
}
if (isAllowed) {
return true;
}
/** @type {?} */
var localStorageInfo = JSON.parse('' + localStorage.getItem('isAuthenticated'));
this.sessionService.isAuthenticated = (localStorageInfo === true) ? true : false;
return this.sessionService.isAuthenticated;
};
AuthService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
AuthService.ctorParameters = function () { return [
{ type: SessionService }
]; };
/** @nocollapse */ AuthService.ngInjectableDef = defineInjectable({ factory: function AuthService_Factory() { return new AuthService(inject(SessionService)); }, token: AuthService, providedIn: "root" });
return AuthService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var HttpService = /** @class */ (function () {
function HttpService(http, sessionContext) {
this.http = http;
this.sessionContext = sessionContext;
if (!sessionContext) {
throw new Error('SessionContext is null');
}
}
/**
* @param {?} url
* @param {?=} useAuthorizationHeader
* @return {?}
*/
HttpService.prototype.httpGet = /**
* @param {?} url
* @param {?=} useAuthorizationHeader
* @return {?}
*/
function (url, useAuthorizationHeader) {
if (useAuthorizationHeader === void 0) { useAuthorizationHeader = true; }
/** @type {?} */
var headers = this.getHeaders(this.sessionContext, useAuthorizationHeader);
if (this.sessionContext.apiServer) {
url = this.sessionContext.apiServer + url;
}
return this.http.get(url, { headers: headers, responseType: 'json' });
};
/**
* @param {?} url
* @param {?=} useAuthorizationHeader
* @return {?}
*/
HttpService.prototype.get = /**
* @param {?} url
* @param {?=} useAuthorizationHeader
* @return {?}
*/
function (url, useAuthorizationHeader) {
if (useAuthorizationHeader === void 0) { useAuthorizationHeader = true; }
/** @type {?} */
var headers = this.getHeaders(this.sessionContext, useAuthorizationHeader);
if (this.sessionContext.apiServer) {
url = this.sessionContext.apiServer + url;
}
return this.http.get(url, { headers: headers, observe: 'response' });
};
/**
* @param {?} url
* @param {?=} useAuthorizationHeader
* @param {?=} useApiServer
* @param {?=} userequestOption
* @return {?}
*/
HttpService.prototype.httpGetFile = /**
* @param {?} url
* @param {?=} useAuthorizationHeader
* @param {?=} useApiServer
* @param {?=} userequestOption
* @return {?}
*/
function (url, useAuthorizationHeader, useApiServer, userequestOption) {
if (useAuthorizationHeader === void 0) { useAuthorizationHeader = true; }
if (useApiServer === void 0) { useApiServer = false; }
if (userequestOption === void 0) { userequestOption = false; }
/** @type {?} */
var headers = new HttpHeaders();
if (useAuthorizationHeader) {
headers = headers.append('Authorization', 'Bearer ' + this.sessionContext.accessToken);
}
if (useApiServer) {
url = this.sessionContext.apiServer + url;
}
if (userequestOption) {
return this.http.get(url, { headers: headers, responseType: 'blob' });
}
else {
return this.http.get(url, { headers: headers });
}
};
/**
* @param {?} method
* @param {?} url
* @param {?} object
* @param {?=} reportProgressCallback
* @return {?}
*/
HttpService.prototype.getChunkedResponse = /**
* @param {?} method
* @param {?} url
* @param {?} object
* @param {?=} reportProgressCallback
* @return {?}
*/
function (method, url, object, reportProgressCallback) {
var _this = this;
if (reportProgressCallback === void 0) { reportProgressCallback = null; }
return new Promise(function (resolve, reject) {
/** @type {?} */
var _xhr = new XMLHttpRequest();
/** @type {?} */
var previousLen = 0;
/** @type {?} */
var data = JSON.stringify(object);
/** @type {?} */
var total = 0;
/**
* @return {?}
*/
function complete() {
console.log('Complete. Chunks received: ', total);
resolve(true);
}
/**
* @param {?} count
* @return {?}
*/
function reportProgress(count) {
if (!reportProgressCallback) {
return;
}
reportProgressCallback(count);
}
_xhr.onreadystatechange = function () {
/** @type {?} */
var text = _xhr.responseText;
if (!text || text.length === 0) {
return;
}
text = text.substring(previousLen);
if (text.length === 0) {
complete();
return;
}
/** @type {?} */
var items = text.split('\n-- values separator --').map(function (x) { return x.trim(); });
if (items.length > 0) {
/** @type {?} */
var lastItem = items[items.length - 1];
/** @type {?} */
var trimmedValue = lastItem.length > 0 ? lastItem[lastItem.length - 1].trim() : lastItem.trim();
if (trimmedValue !== '') {
items.pop();
}
}
if (items.length > 0) {
/** @type {?} */
var dataItem = __spread(items).filter(function (x) { return x !== ''; });
total += data.length;
reportProgress(total);
// console.log('chunk data:', data);
if (dataItem.length === 0) {
complete();
return;
}
// console.log('Working. Chunks received:', total);
}
previousLen += text.length;
if (_xhr.readyState === 4) {
if (_xhr.status === 200) {
complete();
return;
}
reject(false);
return;
}
};
_xhr.open(method, _this.sessionContext.apiServer + url, true);
_xhr.setRequestHeader('Content-Type', 'application/json');
_xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
_xhr.setRequestHeader('X-Disable-Compression', 'true');
_xhr.setRequestHeader('Authorization', 'Bearer ' + _this.sessionContext.accessToken);
_xhr.send(data);
});
};
/**
* @param {?} url
* @param {?} object
* @param {?=} useAuthorizationHeader
* @param {?=} requestType
* @return {?}
*/
HttpService.prototype.httpPost = /**
* @param {?} url
* @param {?} object
* @param {?=} useAuthorizationHeader
* @param {?=} requestType
* @return {?}
*/
function (url, object, useAuthorizationHeader, requestType) {
if (useAuthorizationHeader === void 0) { useAuthorizationHeader = true; }
if (requestType === void 0) { requestType = 'json'; }
/** @type {?} */
var body = requestType === 'json' ? JSON.stringify(object) : object;
/** @type {?} */
var headers = new HttpHeaders();
if (requestType === 'json') {
headers = this.getHeaders(this.sessionContext, useAuthorizationHeader);
}
else {
headers = this.getHeaders(this.sessionContext, useAuthorizationHeader, 'application/x-www-form-urlencoded');
}
if (this.sessionContext.apiServer) {
url = this.sessionContext.apiServer + url;
}
return this.http.post(url, body, { headers: headers, responseType: 'json', withCredentials: true });
};
// tslint:disable-next-line:max-line-length
// tslint:disable-next-line:max-line-length
/**
* @param {?} url
* @param {?} object
* @param {?=} useAuthorizationHeader
* @param {?=} requestType
* @param {?=} customHeaders
* @return {?}
*/
HttpService.prototype.post =
// tslint:disable-next-line:max-line-length
/**
* @param {?} url
* @param {?} object
* @param {?=} useAuthorizationHeader
* @param {?=} requestType
* @param {?=} customHeaders
* @return {?}
*/
function (url, object, useAuthorizationHeader, requestType, customHeaders) {
if (useAuthorizationHeader === void 0) { useAuthorizationHeader = true; }
if (requestType === void 0) { requestType = 'json'; }
if (customHeaders === void 0) { customHeaders = null; }
/** @type {?} */
var body = requestType === 'json' ? JSON.stringify(object) : object;
/** @type {?} */
var headers = new HttpHeaders();
if (requestType === 'json') {
headers = this.getHeaders(this.sessionContext, useAuthorizationHeader);
}
else {
headers = this.getHeaders(this.sessionContext, useAuthorizationHeader, 'application/x-www-form-urlencoded');
}
if (this.sessionContext) {
url = this.sessionContext.apiServer + url;
}
if (customHeaders) {
headers = this.appendCustomHeaders(headers, customHeaders);
}
return this.http.post(url, body, {
headers: headers,
responseType: 'json',
withCredentials: true,
observe: 'response'
});
};
/**
* @param {?} url
* @param {?} object
* @param {?=} useAuthorizationHeader
* @return {?}
*/
HttpService.prototype.httpPut = /**
* @param {?} url
* @param {?} object
* @param {?=} useAuthorizationHeader
* @return {?}
*/
function (url, object, useAuthorizationHeader) {
if (useAuthorizationHeader === void 0) { useAuthorizationHeader = true; }
/** @type {?} */
var body = JSON.stringify(object);
/** @type {?} */
var headers = this.getHeaders(this.sessionContext, useAuthorizationHeader);
if (this.sessionContext) {
url = this.sessionContext.apiServer + url;
}
return this.http.put(url, body, { headers: headers, responseType: 'json' });
};
// tslint:disable-next-line:max-line-length
// tslint:disable-next-line:max-line-length
/**
* @param {?} url
* @param {?} object
* @param {?=} useAuthorizationHeader
* @param {?=} customHeaders
* @return {?}
*/
HttpService.prototype.put =
// tslint:disable-next-line:max-line-length
/**
* @param {?} url
* @param {?} object
* @param {?=} useAuthorizationHeader
* @param {?=} customHeaders
* @return {?}
*/
function (url, object, useAuthorizationHeader, customHeaders) {
if (useAuthorizationHeader === void 0) { useAuthorizationHeader = true; }
if (customHeaders === void 0) { customHeaders = null; }
/** @type {?} */
var body = JSON.stringify(object);
/** @type {?} */
var headers = this.getHeaders(this.sessionContext, useAuthorizationHeader);
if (this.sessionContext) {
url = this.sessionContext.apiServer + url;
}
if (customHeaders) {
headers = this.appendCustomHeaders(headers, customHeaders);
}
return this.http.put(url, body, {
headers: headers,
responseType: 'json',
withCredentials: true,
observe: 'response'
});
};
// tslint:disable-next-line:max-line-length
// tslint:disable-next-line:max-line-length
/**
* @param {?} url
* @param {?=} useAuthorizationHeader
* @param {?=} customHeaders
* @return {?}
*/
HttpService.prototype.delete =
// tslint:disable-next-line:max-line-length
/**
* @param {?} url
* @param {?=} useAuthorizationHeader
* @param {?=} customHeaders
* @return {?}
*/
function (url, useAuthorizationHeader, customHeaders) {
if (useAuthorizationHeader === void 0) { useAuthorizationHeader = true; }
if (customHeaders === void 0) { customHeaders = null; }
/** @type {?} */
var headers = this.getHeaders(this.sessionContext, useAuthorizationHeader);
if (customHeaders) {
headers = this.appendCustomHeaders(headers, customHeaders);
}
return this.http.delete(this.sessionContext.apiServer + url, {
headers: headers,
responseType: 'json',
withCredentials: true,
observe: 'response'
});
};
/**
* @param {?} url
* @param {?=} useAuthorizationHeader
* @return {?}
*/
HttpService.prototype.httpDelete = /**
* @param {?} url
* @param {?=} useAuthorizationHeader
* @return {?}
*/
function (url, useAuthorizationHeader) {
if (useAuthorizationHeader === void 0) { useAuthorizationHeader = true; }
/** @type {?} */
var headers = this.getHeaders(this.sessionContext, useAuthorizationHeader);
return this.http.delete(this.sessionContext.apiServer + url, { headers: headers, responseType: 'json' });
};
/**
* @param {?} url
* @param {?} file
* @param {?=} useAuthorizationHeader
* @return {?}
*/
HttpService.prototype.httpPostAttachment = /**
* @param {?} url
* @param {?} file
* @param {?=} useAuthorizationHeader
* @return {?}
*/
function (url, file, useAuthorizationHeader) {
var _this = this;
if (useAuthorizationHeader === void 0) { useAuthorizationHeader = true; }
return new Promise(function (resolve, reject) {
/** @type {?} */
var xhr = new XMLHttpRequest();
/** @type {?} */
var formData = new FormData();
formData.append('file', file, file.name);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
resolve(xhr.response);
}
else {
reject(xhr.response);
}
}
};
xhr.open('POST', _this.sessionContext.apiServer + url, true);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
if (useAuthorizationHeader) {
xhr.setRequestHeader('Authorization', 'Bearer ' + _this.sessionContext.accessToken);
}
xhr.send(formData);
});
};
// tslint:disable-next-line:max-line-length
// tslint:disable-next-line:max-line-length
/**
* @param {?} sessionContext
* @param {?} useAuthorizationHeader
* @param {?=} contentTypeHeader
* @return {?}
*/
HttpService.prototype.getHeaders =
// tslint:disable-next-line:max-line-length
/**
* @param {?} sessionContext
* @param {?} useAuthorizationHeader
* @param {?=} contentTypeHeader
* @return {?}
*/
function (sessionContext, useAuthorizationHeader, contentTypeHeader) {
if (contentTypeHeader === void 0) { contentTypeHeader = 'application/json'; }
/** @type {?} */
var headers = new HttpHeaders();
headers = headers.append('Accept', 'application/json');
headers = headers.append('Content-Type', contentTypeHeader);
if (useAuthorizationHeader && sessionContext.accessToken) {
headers = headers.append('Authorization', 'Bearer ' + this.sessionContext.accessToken);
}
return headers;
};
/**
* @param {?} name
* @return {?}
*/
HttpService.prototype.getStateByName = /**
* @param {?} name
* @return {?}
*/
function (name) {
/** @type {?} */
var result = this.httpGet(Const.urlGetStateByName + name);
return result.map(function (data) {
if (data) {
return JSON.parse(data);
}
return null;
});
};
/**
* @param {?} name
* @param {?} state
* @return {?}
*/
HttpService.prototype.setStateByName = /**
* @param {?} name
* @param {?} state
* @return {?}
*/
function (name, state) {
/** @type {?} */
var strState = JSON.stringify(state);
this.httpPut(Const.urlSetState + name, strState)
.subscribe(function () { }, function (err) { return console.log(err); });
};
/**
* @private
* @param {?} headers
* @param {?} customHeaders
* @return {?}
*/
HttpService.prototype.appendCustomHeaders = /**
* @private
* @param {?} headers
* @param {?} customHeaders
* @return {?}
*/
function (headers, customHeaders) {
if (customHeaders) {
customHeaders.forEach(function (key, value) {
headers = headers.append(key, value);
});
}
return headers;
};
HttpService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
HttpService.ctorParameters = function () { return [
{ type: HttpClient },
{ type: SessionContext }
]; };
/** @nocollapse */ HttpService.ngInjectableDef = defineInjectable({ factory: function HttpService_Factory() { return new HttpService(inject(HttpClient), inject(SessionContext)); }, token: HttpService, providedIn: "root" });
return HttpService;
}());
var Const = /** @class */ (function () {
function Const() {
}
Const.urlSetState = 'api/State/SetState/';
Const.urlGetStateByName = 'api/State/GetStateByName?name=';
return Const;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var TranslationService = /** @class */ (function () {
function TranslationService(translateService, http) {
this.http = http;
this.defaultLang = 'ru-RU';
this.englishLang = 'en-US';
this.ukraineLang = 'uk-UA';
this.localizationStorage = new Array();
this.translater = translateService;
/** @type {?} */
var userLang = this.defaultLocale();
this.setLanguage(userLang);
}
/**
* @param {?} locale
* @return {?}
*/
TranslationService.prototype.setLanguage = /**
* @param {?} locale
* @return {?}
*/
function (locale$$1) {
this.translater.addLangs([locale$$1]);
this.translater.setDefaultLang(locale$$1);
this.translater.use(locale$$1);
};
/**
* @param {?} parts
* @return {?}
*/
TranslationService.prototype.loadTranslation = /**
* @param {?} parts
* @return {?}
*/
function (parts) {
var _this = this;
/** @type {?} */
var userLocalLanguage = localStorage.getItem('language');
/** @type {?} */
var lang;
if (userLocalLanguage) {
lang = userLocalLanguage;
}
else {
lang = this.translater.currentLang ? this.translater.currentLang : this.defaultLang;
}
/** @type {?} */
var notLoadedParts = parts.filter(function (part) {
return _this.localizationStorage.indexOf(part) < 0;
});
if (notLoadedParts.length > 0) {
/** @type {?} */
var partUrl_1 = notLoadedParts.join(',');
return new Promise(function (resolve, reject) {
_this.http.httpGet('api/Localizations/' + lang + '?parts=' + partUrl_1, false)
.subscribe(function (data) {
notLoadedParts.forEach(function (part) {
if (data[part]) {
_this.translater.setTranslation(_this.translater.currentLang, data[part], true);
_this.localizationStorage.push(part);
}
});
resolve(true);
}, function (err) {
console.log(err);
reject(false);
});
});
}
else {
return true;
}
};
/**
* @private
* @return {?}
*/
TranslationService.prototype.defaultLocale = /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var browserLocale = navigator.language || navigator['userLanguage'];
if (/ru/gmi.test(browserLocale)) {
browserLocale = this.defaultLang;
}
else if (/uk/gmi.test(browserLocale)) {
browserLocale = this.ukraineLang;
}
else if (/en/gmi.test(browserLocale)) {
browserLocale = this.englishLang;
}
return browserLocale;
};
/**
* @param {?} key
* @param {?=} interpolateParams
* @return {?}
*/
TranslationService.prototype.translate = /**
* @param {?} key
* @param {?=} interpolateParams
* @return {?}
*/
function (key, interpolateParams) {
return this.translater.get(key, interpolateParams);
};
/**
* @param {?} key
* @param {?=} interpolateParams
* @return {?}
*/
TranslationService.prototype.translateInstant = /**
* @param {?} key
* @param {?=} interpolateParams
* @return {?}
*/
function (key, interpolateParams) {
return this.translater.instant(key, interpolateParams);
};
/**
* @param {?} key
* @return {?}
*/
TranslationService.prototype.translateSync = /**
* @param {?} key
* @return {?}
*/
function (key) {
return this.translater.instant(key);
};
TranslationService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
TranslationService.ctorParameters = function () { return [
{ type: TranslateService },
{ type: HttpService }
]; };
/** @nocollapse */ TranslationService.ngInjectableDef = defineInjectable({ factory: function TranslationService_Factory() { return new TranslationService(inject(TranslateService), inject(HttpService)); }, token: TranslationService, providedIn: "root" });
return TranslationService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var CanActivateService = /** @class */ (function () {
function CanActivateService(translator, authService, sessionService, http, router) {
this.translator = translator;
this.authService = authService;
this.sessionService = sessionService;
this.http = http;
this.router = router;
}
/**
* @param {?} route
* @param {?} state
* @return {?}
*/
CanActivateService.prototype.canActivate = /**
* @param {?} route
* @param {?} state
* @return {?}
*/
function (route, state) {
return __awaiter(this, void 0, void 0, function () {
var parts, isAllowed;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!route.data) return [3 /*break*/, 2];
parts = Object.keys(route.data).map(function (key) { return route.data[key]; });
if (!(parts.length > 0)) return [3 /*break*/, 2];
return [4 /*yield*/, this.translator.loadTranslation(parts)];
case 1:
_a.sent();
_a.label = 2;
case 2:
isAllowed = this.authService.isAllowed(state);
if (!isAllowed) {
this.router.navigateByUrl('/account');
}
return [2 /*return*/, isAllowed];
}
});
});
};
CanActivateService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
CanActivateService.ctorParameters = function () { return [
{ type: TranslationService },
{ type: AuthService },
{ type: SessionService },
{ type: HttpService },
{ type: Router }
]; };
/** @nocollapse */ CanActivateService.ngInjectableDef = defineInjectable({ factory: function CanActivateService_Factory() { return new CanActivateService(inject(TranslationService), inject(AuthService), inject(SessionService), inject(HttpService), inject(Router)); }, token: CanActivateService, providedIn: "root" });
return CanActivateService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var BusMessage = /** @class */ (function () {
function BusMessage(name, data) {
if (name === void 0) { name = ''; }
if (data === void 0) { data = null; }
this.name = name;
this.data = data;
}
return BusMessage;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var HttpInterceptorService = /** @class */ (function () {
function HttpInterceptorService() {
this.count = 0;
this.interceptorDto = new BusMessage();
}
/**
* @param {?} req
* @param {?} next
* @return {?}
*/
HttpInterceptorService.prototype.intercept = /**
* @param {?} req
* @param {?} next
* @return {?}
*/
function (req, next) {
var _this = this;
/** @type {?} */
var started = Date.now();
/** @type {?} */
var ok;
if (this.count === 0) {
this.interceptorDto.name = 'http started';
CommunicationService.get().emit(this.interceptorDto);
}
this.count++;
// extend server response observable with logging
return next.handle(req)
.pipe(tap(
// Succeeds when there is a response; ignore other events
function (event) { return ok = event instanceof HttpResponse ? 'succeeded' : ''; },
// Operation failed; error is an HttpErrorResponse
function (error) { return ok = 'failed'; }),
// Log when response observable either completes or errors
finalize(function () {
_this.count--;
if (_this.count === 0) {
_this.interceptorDto.name = 'http finished';
CommunicationService.get().emit(_this.interceptorDto);
}
/** @type {?} */
var elapsed = Date.now() - started;
/** @type {?} */
var msg = req.method + " \"" + req.urlWithParams + "\"\n " + ok + " in " + elapsed + " ms.";
console.log(msg);
}));
};
HttpInterceptorService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
HttpInterceptorService.ctorParameters = function () { return []; };
/** @nocollapse */ HttpInterceptorService.ngInjectableDef = defineInjectable({ factory: function HttpInterceptorService_Factory() { return new HttpInterceptorService(); }, token: HttpInterceptorService, providedIn: "root" });
return HttpInterceptorService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var PagingEvent = /** @class */ (function () {
function PagingEvent(hash) {
this.targetUrl = '';
this.hash = hash;
}
return PagingEvent;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var PagingService = /** @class */ (function () {
function PagingService() {
PagingService.currentMessage = PagingService.messageSource.asObservable();
}
/**
* @param {?} hash
* @param {?} context
* @param {?} currentIndex
* @param {?} itemsOnPage
* @return {?}
*/
PagingService.fireHashChangedEvent = /**
* @param {?} hash
* @param {?} context
* @param {?} currentIndex
* @param {?} itemsOnPage
* @return {?}
*/
function (hash, context, currentIndex, itemsOnPage) {
/** @type {?} */
var hashIndex = Math.floor(currentIndex / itemsOnPage);
if (!PagingService.isExistsHash(context, hashIndex)) {
PagingService.addHash(context, hashIndex, hash);
}
};
/**
* @param {?} event
* @return {?}
*/
PagingService.firePagingEvent = /**
* @param {?} event
* @return {?}
*/
function (event) {
PagingService.saveToLocalStorage(event);
PagingService.messageSource.next(event);
};
/**
* @param {?} event
* @return {?}
*/
PagingService.fireClosingContextEvent = /**
* @param {?} event
* @return {?}
*/
function (event) {
PagingService.messageSource.next(event);
};
/**
* @param {?} pagingEvent
* @return {?}
*/
PagingService.saveToLocalStorage = /**
* @param {?} pagingEvent
* @return {?}
*/
function (pagingEvent) {
/** @type {?} */
var key = pagingEvent.hash + '_' + pagingEvent.currentId + '_' + pagingEvent.currentIndex;
localStorage.setItem(key, JSON.stringify(pagingEvent));
};
/**
* @param {?} snapshot
* @return {?}
*/
PagingService.readFromLocalStorage = /**
* @param {?} snapshot
* @return {?}
*/
function (snapshot) {
/** @type {?} */
var key = PagingService.buildKey(snapshot);
/** @type {?} */
var json = localStorage.getItem(key);
if (!json) {
return null;
}
/** @type {?} */
var result = (/** @type {?} */ (JSON.parse(json)));
return result;
};
/**
* @param {?} route
* @param {?} name
* @return {?}
*/
PagingService.readSegmentByName = /**
* @param {?} route
* @param {?} name
* @return {?}
*/
function (route, name) {
/** @type {?} */
var snapshot = route.snapshot;
return snapshot.params[name];
};
/**
* @param {?} pagingEvent
* @return {?}
*/
PagingService.buildRedirectUrl = /**
* @param {?} pagingEvent
* @return {?}
*/
function (pagingEvent) {
return pagingEvent.detailsUrl + pagingEvent.currentId + '/' + pagingEvent.hash + '/' + pagingEvent.currentIndex;
};
/**
* @param {?} snapshot
* @return {?}
*/
PagingService.buildKey = /**
* @param {?} snapshot
* @return {?}
*/
function (snapshot) {
/** @type {?} */
var id = snapshot.paramMap.get('id');
/** @type {?} */
var hash = snapshot.paramMap.get('hash');
/** @type {?} */
var pageIndex = snapshot.paramMap.get('page');
/** @type {?} */
var result = hash + '_' + id + '_' + pageIndex;
console.log('buildKey=' + result);
return result;
};
/**
* @param {?} context
* @param {?} index
* @return {?}
*/
PagingService.isExistsHash = /**
* @param {?} context
* @param {?} index
* @return {?}
*/
function (context, index) {
/** @type {?} */
var key = this.buildMapKey(context, index);
return PagingService.cache.has(key);
};
/**
* @param {?} context
* @param {?} index
* @return {?}
*/
PagingService.getHash = /**
* @param {?} context
* @param {?} index
* @return {?}
*/
function (context, index) {
/** @type {?} */
var key = this.buildMapKey(context, index);
/** @type {?} */
var result = PagingService.cache.get(key);
if (result === undefined) {
throw new Error('Key does not exists.');
}
return result;
};
/**
* @param {?} context
* @param {?} index
* @param {?} hash
* @return {?}
*/
PagingService.addHash = /**
* @param {?} context
* @param {?} index
* @param {?} hash
* @return {?}
*/
function (context, index, hash) {
/** @type {?} */
var key = this.buildMapKey(context, index);
PagingService.cache.set(key, hash);
};
/**
* @param {?} context
* @param {?} index
* @return {?}
*/
PagingService.buildMapKey = /**
* @param {?} context
* @param {?} index
* @return {?}
*/
function (context, index) {
/** @type {?} */
var splitter = '_';
return context + splitter + index;
};
PagingService.cache = new Map();
PagingService.emptyPagingEvent = new PagingEvent('empty');
PagingService.messageSource = new BehaviorSubject(PagingService.emptyPagingEvent);
PagingService.currentMessage = PagingService.messageSource.asObservable();
PagingService.decorators = [
{ type: Injectable, args: [{
providedIn: 'root'
},] }
];
PagingService.ctorParameters = function () { return []; };
/** @nocollapse */ PagingService.ngInjectableDef = defineInjectable({ factory: function PagingService_Factory() { return new PagingService(); }, token: PagingService, providedIn: "root" });
return PagingService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DetailsPagingComponent = /** @class */ (function () {
function DetailsPagingComponent(route) {
this.route = route;
}
/**
* @return {?}
*/
DetailsPagingComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
/** @type {?} */
var self = this;
self.setOptions();
};
/**
* @return {?}
*/
DetailsPagingComponent.prototype.setOptions = /**
* @return {?}
*/
function () {
/** @type {?} */
var self = this;
/** @type {?} */
var firstLevelActivatedRoute = self.route.children[0];
if (firstLevelActivatedRoute) {
/** @type {?} */
var localStorageValue = PagingService.readFromLocalStorage(firstLevelActivatedRoute.snapshot);
if (localStorageValue) {
self.options = localStorageValue;
}
}
if (!self.options || self.options == null || self.options.hash === 'empty') {
return;
}
self.init(self.options);
};
/**
* @param {?} options
* @return {?}
*/
DetailsPagingComponent.prototype.init = /**
* @param {?} options
* @return {?}
*/
function (options) {
/** @type {?} */
var self = this;
self.options = options;
if (!self.options || self.options == null) {
return;
}
self.options.backUrl = decodeURIComponent(self.options.backUrl);
self.isVisible = self.options
&& self.options.currentIndex !== undefined
&& self.options.startIndex !== undefined
&& self.options.total !== undefined;
if (self.isVisible) {
self.links = self.getLinks(self.options.currentIndex + 1, self.lastIndex + 1);
}
};
Object.defineProperty(DetailsPagingComponent.prototype, "lastIndex", {
get: /**
* @return {?}
*/
function () {
return this.options.startIndex + this.options.total - 1;
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
DetailsPagingComponent.prototype.first = /**
* @return {?}
*/
function () {
this.options.currentIndex = this.options.startIndex;
this.go(this.options.currentIndex);
};
/**
* @return {?}
*/
DetailsPagingComponent.prototype.previous = /**
* @return {?}
*/
function () {
if (this.options && this.options.currentIndex === this.options.startIndex) {
return;
}
this.options.currentIndex = this.options.currentIndex - 1;
this.go(this.options.currentIndex);
};
/**
* @param {?} index
* @return {?}
*/
DetailsPagingComponent.prototype.goTo = /**
* @param {?} index
* @return {?}
*/
function (index) {
if (index < this.options.startIndex || index > this.lastIndex) {
throw Error('Out of range, should be between ' + this.options.startIndex + ' and ' + this.lastIndex);
}
this.options.previousIndex = this.options.currentIndex;
this.options.currentIndex = index;
console.log('Current index is ' + this.options.currentIndex + ', last index is ' + this.lastIndex);
this.go(this.options.currentIndex);
};
/**
* @return {?}
*/
DetailsPagingComponent.prototype.next = /**
* @return {?}
*/
function () {
if (this.options && this.options.currentIndex === this.lastIndex) {
return;
}
this.options.currentIndex++;
this.go(this.options.currentIndex);
};
/**
* @return {?}
*/
DetailsPagingComponent.prototype.last = /**
* @return {?}
*/
function () {
this.options.curr