air-lib
Version:
This is Air's angular component library
1,224 lines (1,212 loc) • 300 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('ngx-cookie-service'), require('ngx-cookie-service/cookie-service/cookie.service'), require('@angular/common/http'), require('rxjs/operators'), require('rxjs'), require('@ngx-translate/core'), require('@angular/router'), require('ngx-moment'), require('moment'), require('lodash'), require('@angular/common'), require('@angular/platform-browser'), require('rxjs/Subject'), require('rxjs/add/operator/filter'), require('rxjs/add/operator/map'), require('@angular/forms'), require('@angular/core')) :
typeof define === 'function' && define.amd ? define('air-lib', ['exports', 'ngx-cookie-service', 'ngx-cookie-service/cookie-service/cookie.service', '@angular/common/http', 'rxjs/operators', 'rxjs', '@ngx-translate/core', '@angular/router', 'ngx-moment', 'moment', 'lodash', '@angular/common', '@angular/platform-browser', 'rxjs/Subject', 'rxjs/add/operator/filter', 'rxjs/add/operator/map', '@angular/forms', '@angular/core'], factory) :
(factory((global['air-lib'] = {}),global.ngxCookieService,global.i1,global.ng.common.http,global.rxjs.operators,global.rxjs,global.i1$2,global.ng.router,global.ngxMoment,global.moment_,global._,global.ng.common,global.ng.platformBrowser,global.rxjs.Subject,global.rxjs['add/operator/filter'],global.rxjs['add/operator/map'],global.ng.forms,global.ng.core));
}(this, (function (exports,ngxCookieService,i1,i1$1,operators,rxjs,i1$2,i5,ngxMoment,moment_,_,common,i2,Subject,filter,map,forms,i0) { 'use strict';
/**
* @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: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */ SessionContext.ngInjectableDef = i0.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 i0.EventEmitter();
}
return CommunicationService.emitters;
};
/**
* @return {?}
*/
CommunicationService.getMessageBus = /**
* @return {?}
*/
function () {
if (!CommunicationService.emittersBus) {
CommunicationService.emittersBus = new i0.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 i0.EventEmitter();
CommunicationService.emittersBus = new i0.EventEmitter();
// tslint:disable-next-line:no-inferrable-types
CommunicationService.activeTab = '';
CommunicationService.decorators = [
{ type: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
CommunicationService.ctorParameters = function () { return []; };
/** @nocollapse */ CommunicationService.ngInjectableDef = i0.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 () {
moment_.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: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
SessionService.ctorParameters = function () {
return [
{ type: ngxCookieService.CookieService },
{ type: i5.Router },
{ type: SessionContext }
];
};
/** @nocollapse */ SessionService.ngInjectableDef = i0.defineInjectable({ factory: function SessionService_Factory() { return new SessionService(i0.inject(i1.CookieService), i0.inject(i5.Router), i0.inject(SessionContext)); }, token: SessionService, providedIn: "root" });
return SessionService;
}());
/*! *****************************************************************************
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 __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _$$1 = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_$$1)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_$$1.label++;
return { value: op[1], done: false };
case 5:
_$$1.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _$$1.ops.pop();
_$$1.trys.pop();
continue;
default:
if (!(t = _$$1.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_$$1 = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_$$1.label = op[1];
break;
}
if (op[0] === 6 && _$$1.label < t[1]) {
_$$1.label = t[1];
t = op;
break;
}
if (t && _$$1.label < t[2]) {
_$$1.label = t[2];
_$$1.ops.push(op);
break;
}
if (t[2])
_$$1.ops.pop();
_$$1.trys.pop();
continue;
}
op = body.call(thisArg, _$$1);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
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 };
}
};
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/**
* @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: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
AuthService.ctorParameters = function () {
return [
{ type: SessionService }
];
};
/** @nocollapse */ AuthService.ngInjectableDef = i0.defineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0.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 i1$1.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 i1$1.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 i1$1.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 i1$1.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: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
HttpService.ctorParameters = function () {
return [
{ type: i1$1.HttpClient },
{ type: SessionContext }
];
};
/** @nocollapse */ HttpService.ngInjectableDef = i0.defineInjectable({ factory: function HttpService_Factory() { return new HttpService(i0.inject(i1$1.HttpClient), i0.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) {
this.translater.addLangs([locale]);
this.translater.setDefaultLang(locale);
this.translater.use(locale);
};
/**
* @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: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
TranslationService.ctorParameters = function () {
return [
{ type: i1$2.TranslateService },
{ type: HttpService }
];
};
/** @nocollapse */ TranslationService.ngInjectableDef = i0.defineInjectable({ factory: function TranslationService_Factory() { return new TranslationService(i0.inject(i1$2.TranslateService), i0.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: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
CanActivateService.ctorParameters = function () {