@bnsights/bbsf-utilities 1.0.37 → 1.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,23 @@
1
- import * as i1$1 from '@angular/common';
2
- import { DOCUMENT, CommonModule } from '@angular/common';
3
1
  import * as i0 from '@angular/core';
4
- import { Injectable, Inject, Injector, NgModule } from '@angular/core';
5
- import * as i1$2 from '@angular/router';
2
+ import { Injectable, Injector, Inject, NgModule } from '@angular/core';
3
+ import * as i4 from '@angular/router';
6
4
  import { Router, RouterModule } from '@angular/router';
7
5
  import * as i1 from '@ngx-translate/core';
8
6
  import { TranslateService } from '@ngx-translate/core';
9
7
  import { BlockUI, BlockUIModule } from 'ng-block-ui';
10
8
  import { ToastrService, ToastrModule } from 'ngx-toastr';
11
9
  import { HttpModule } from '@angular/http';
12
- import { __awaiter, __decorate, __rest } from 'tslib';
13
- import * as i1$3 from '@angular/common/http';
10
+ import { __decorate, __awaiter, __rest } from 'tslib';
11
+ import * as i1$1 from '@angular/common/http';
14
12
  import { HttpHeaders, HttpClient, HttpParams } from '@angular/common/http';
15
- import { UserManager, WebStorageStateStore } from 'oidc-client';
16
- import { Subject, Observable, throwError, BehaviorSubject } from 'rxjs';
13
+ import { BehaviorSubject, Subject, Observable, throwError } from 'rxjs';
14
+ import { JwtHelperService } from '@auth0/angular-jwt';
15
+ import * as i5 from 'ngx-cookie-service';
16
+ import { CookieService } from 'ngx-cookie-service';
17
17
  import { takeUntil, tap, map } from 'rxjs/operators';
18
18
  import { plainToClass } from 'class-transformer';
19
+ import * as i1$2 from '@angular/common';
20
+ import { DOCUMENT, CommonModule } from '@angular/common';
19
21
  import JSZip from 'jszip';
20
22
  import { fragment, create } from 'xmlbuilder2';
21
23
  import VNode from 'virtual-dom/vnode/vnode';
@@ -31,6 +33,15 @@ import imageToBase64 from 'image-to-base64';
31
33
  import mimeTypes from 'mime-types';
32
34
  import colorNames from 'color-name';
33
35
 
36
+ class BBSFTranslateService extends TranslateService {
37
+ }
38
+ BBSFTranslateService.ɵprov = i0.ɵɵdefineInjectable({ factory: function BBSFTranslateService_Factory() { return new BBSFTranslateService(i0.ɵɵinject(i1.TranslateStore), i0.ɵɵinject(i1.TranslateLoader), i0.ɵɵinject(i1.TranslateCompiler), i0.ɵɵinject(i1.TranslateParser), i0.ɵɵinject(i1.MissingTranslationHandler), i0.ɵɵinject(i1.USE_DEFAULT_LANG), i0.ɵɵinject(i1.USE_STORE), i0.ɵɵinject(i1.USE_EXTEND), i0.ɵɵinject(i1.DEFAULT_LANGUAGE)); }, token: BBSFTranslateService, providedIn: "root" });
39
+ BBSFTranslateService.decorators = [
40
+ { type: Injectable, args: [{
41
+ providedIn: 'root'
42
+ },] }
43
+ ];
44
+
34
45
  // This file can be replaced during build by using the `fileReplacements` array.
35
46
  // `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`.
36
47
  // The list of file replacements can be found in `angular.json`.
@@ -88,13 +99,270 @@ EnvironmentService.decorators = [
88
99
  },] }
89
100
  ];
90
101
 
91
- class BBSFTranslateService extends TranslateService {
102
+ class UtilityService {
103
+ constructor(translator, environmentService) {
104
+ this.translator = translator;
105
+ this.environmentService = environmentService;
106
+ this.isCreatedBefore = false;
107
+ }
108
+ getResourceValue(Key) {
109
+ let ResourceValue = this.translator.instant(Key);
110
+ return ResourceValue;
111
+ }
112
+ getCurrentLanguage() {
113
+ let currentLanguage = this.environmentService.getDefaultLanguage();
114
+ let lang = localStorage.getItem('language');
115
+ if (lang)
116
+ currentLanguage = lang;
117
+ else
118
+ localStorage.setItem('language', currentLanguage);
119
+ return currentLanguage;
120
+ }
121
+ isCurrentLanguageEnglish() {
122
+ return this.getCurrentLanguage() == "en";
123
+ }
124
+ isCurrentLanguageArabic() {
125
+ return this.getCurrentLanguage() == "ar";
126
+ }
127
+ notifySuccessMessage(Message, title, time, showHeader = true) {
128
+ let MessageTemplate = this.getResourceValue("SuccessMessage");
129
+ let titleTemplate;
130
+ if (Message) {
131
+ MessageTemplate = Message;
132
+ }
133
+ if (title) {
134
+ titleTemplate = title;
135
+ }
136
+ let toaster = AppInjector.get(ToastrService);
137
+ showHeader ? toaster.success(MessageTemplate, titleTemplate) : toaster.success(MessageTemplate);
138
+ }
139
+ notifyErrorMessage(Message, title, time, showHeader = true) {
140
+ let MessageTemplate = this.getResourceValue("ErrorMessage");
141
+ let titleTemplate = this.getResourceValue("Error");
142
+ if (Message) {
143
+ MessageTemplate = Message;
144
+ }
145
+ if (title) {
146
+ titleTemplate = title;
147
+ }
148
+ const toaster = AppInjector.get(ToastrService);
149
+ showHeader ? toaster.error(MessageTemplate, titleTemplate) : toaster.error(MessageTemplate);
150
+ }
151
+ notifyWarningMessage(Message, title, time, showHeader = true) {
152
+ let MessageTemplate = this.getResourceValue("WarningMessage");
153
+ let titleTemplate = this.getResourceValue("Warning");
154
+ if (Message) {
155
+ MessageTemplate = Message;
156
+ }
157
+ if (title) {
158
+ titleTemplate = title;
159
+ }
160
+ const toaster = AppInjector.get(ToastrService);
161
+ showHeader ? toaster.warning(MessageTemplate, titleTemplate) : toaster.warning(MessageTemplate);
162
+ }
163
+ startBlockUI() {
164
+ this.blockUI.start();
165
+ }
166
+ stopBlockUI() {
167
+ this.blockUI.stop();
168
+ }
92
169
  }
93
- BBSFTranslateService.ɵprov = i0.ɵɵdefineInjectable({ factory: function BBSFTranslateService_Factory() { return new BBSFTranslateService(i0.ɵɵinject(i1.TranslateStore), i0.ɵɵinject(i1.TranslateLoader), i0.ɵɵinject(i1.TranslateCompiler), i0.ɵɵinject(i1.TranslateParser), i0.ɵɵinject(i1.MissingTranslationHandler), i0.ɵɵinject(i1.USE_DEFAULT_LANG), i0.ɵɵinject(i1.USE_STORE), i0.ɵɵinject(i1.USE_EXTEND), i0.ɵɵinject(i1.DEFAULT_LANGUAGE)); }, token: BBSFTranslateService, providedIn: "root" });
94
- BBSFTranslateService.decorators = [
170
+ UtilityService.ɵprov = i0.ɵɵdefineInjectable({ factory: function UtilityService_Factory() { return new UtilityService(i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(EnvironmentService)); }, token: UtilityService, providedIn: "root" });
171
+ UtilityService.decorators = [
95
172
  { type: Injectable, args: [{
96
173
  providedIn: 'root'
97
174
  },] }
175
+ ];
176
+ UtilityService.ctorParameters = () => [
177
+ { type: BBSFTranslateService },
178
+ { type: EnvironmentService }
179
+ ];
180
+ __decorate([
181
+ BlockUI()
182
+ ], UtilityService.prototype, "blockUI", void 0);
183
+
184
+ class User {
185
+ }
186
+
187
+ const TOKEN_KEY = 'access_token';
188
+ class AuthService {
189
+ constructor(injector, http, environmentService, translateService, router, cookieService, utilityService) {
190
+ this.injector = injector;
191
+ this.http = http;
192
+ this.environmentService = environmentService;
193
+ this.translateService = translateService;
194
+ this.router = router;
195
+ this.cookieService = cookieService;
196
+ this.utilityService = utilityService;
197
+ this.redirectUrl = '';
198
+ this.jwtHelper = new JwtHelperService();
199
+ this.isAuthenticatedSubject = new BehaviorSubject(this.hasToken());
200
+ this.isAuthenticate$ = this.isAuthenticatedSubject.asObservable();
201
+ this.user = this.getUserManager();
202
+ }
203
+ hasToken() {
204
+ const token = this.cookieService.get(TOKEN_KEY);
205
+ return token && !this.jwtHelper.isTokenExpired(token);
206
+ }
207
+ getUserManager() {
208
+ const token = this.cookieService.get(TOKEN_KEY);
209
+ if (token)
210
+ this.handleAccessTokenWithoutLanguage(token);
211
+ return AuthService.user;
212
+ }
213
+ getUser() {
214
+ this.user = AuthService.user;
215
+ }
216
+ storUser(User) {
217
+ AuthService.user = this.user = this.user;
218
+ }
219
+ getCurrentUser() {
220
+ return AuthService.user;
221
+ }
222
+ isAuthenticated() {
223
+ return __awaiter(this, void 0, void 0, function* () {
224
+ return AuthService.user != null && !this.jwtHelper.isTokenExpired(AuthService.user.access_token);
225
+ });
226
+ }
227
+ isUserInRole(allowedPermission) {
228
+ let selectedPermissionSetID = Number.parseInt(this.user.profile['selectedpermissionsetid']);
229
+ return allowedPermission.includes(selectedPermissionSetID);
230
+ }
231
+ authorizationHeaderValue() {
232
+ return AuthService.user
233
+ ? `${AuthService.user.token_type} ${AuthService.user.access_token}`
234
+ : '';
235
+ }
236
+ name() {
237
+ return AuthService.user != null ? AuthService.user.profile.given_name : '';
238
+ }
239
+ setUrl(url) {
240
+ localStorage.setItem('redirectUrl', url);
241
+ }
242
+ getUrl() {
243
+ var _a;
244
+ return (_a = localStorage.getItem('redirectUrl')) !== null && _a !== void 0 ? _a : "/";
245
+ }
246
+ signout() {
247
+ AuthService.timers.map(t => clearInterval(t));
248
+ AuthService.timers = [];
249
+ if (!this.isAuthenticated()) {
250
+ this.cookieService.delete(TOKEN_KEY);
251
+ this.router.navigate(['/Admin/account/login']);
252
+ }
253
+ this.logout().subscribe(res => {
254
+ this.cookieService.delete(TOKEN_KEY);
255
+ this.router.navigate(['/Admin/account/login']);
256
+ });
257
+ }
258
+ logout() {
259
+ const httpOptions = {
260
+ headers: new HttpHeaders({
261
+ 'Content-Type': 'application/json',
262
+ }),
263
+ };
264
+ let ApiUrl = '/Account/';
265
+ return this.http.get(this.environmentService.getApiUrl() + ApiUrl + 'Logout', httpOptions);
266
+ }
267
+ clearUserSessionClaims() {
268
+ const httpOptions = {
269
+ headers: new HttpHeaders({
270
+ 'Content-Type': 'application/json',
271
+ }),
272
+ };
273
+ let ApiUrl = '/api/Home/';
274
+ return this.http.get(this.environmentService.getBaseUrl() + ApiUrl + 'ClearCurrentUserSession', httpOptions);
275
+ }
276
+ handleAccessToken(response) {
277
+ return __awaiter(this, void 0, void 0, function* () {
278
+ const token = response;
279
+ AuthService.user = new User();
280
+ AuthService.user.token_type = "Bearer";
281
+ AuthService.user.access_token = token;
282
+ AuthService.user.profile = this.jwtHelper.decodeToken(token);
283
+ AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
284
+ AuthService.timers.map(t => clearInterval(t));
285
+ AuthService.timers = [];
286
+ this.setTokenSeconds();
287
+ AuthService.timers.push(this.checkRefreshToken());
288
+ this.user = AuthService.user;
289
+ yield this.updateLanguage();
290
+ this.cookieService.set(TOKEN_KEY, token, null, null, null, true, 'Strict');
291
+ this.isAuthenticatedSubject.next(true);
292
+ });
293
+ }
294
+ handleAccessTokenWithoutLanguage(response) {
295
+ const token = response;
296
+ AuthService.user = new User();
297
+ AuthService.user.token_type = "Bearer";
298
+ AuthService.user.access_token = token;
299
+ AuthService.user.profile = this.jwtHelper.decodeToken(token);
300
+ AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
301
+ this.setTokenSeconds();
302
+ this.user = AuthService.user;
303
+ this.cookieService.set(TOKEN_KEY, token, null, null, null, true, 'Strict');
304
+ this.isAuthenticatedSubject.next(true);
305
+ }
306
+ updateLanguage() {
307
+ return __awaiter(this, void 0, void 0, function* () {
308
+ if (!localStorage.getItem('language') ||
309
+ localStorage.getItem('language') == this.user.profile.locale)
310
+ localStorage.setItem('language', this.user.profile.locale);
311
+ if (this.translateService.currentLang != localStorage.getItem('language')) {
312
+ this.translateService.resetLang(this.translateService.currentLang);
313
+ yield this.translateService
314
+ .reloadLang(localStorage.getItem('language'))
315
+ .subscribe((res) => {
316
+ console.log(res);
317
+ });
318
+ }
319
+ });
320
+ }
321
+ checkRefreshToken() {
322
+ let date = new Date();
323
+ return setInterval(() => {
324
+ if (Math.floor(AuthService.seconds) < 120 && this.isAuthenticated())
325
+ this.refresh();
326
+ AuthService.seconds--;
327
+ }, 1000);
328
+ }
329
+ setTokenSeconds() {
330
+ let date = new Date();
331
+ AuthService.seconds = (AuthService.user.expires_at - date) / 1000;
332
+ }
333
+ refresh() {
334
+ const httpOptions = {
335
+ headers: new HttpHeaders({
336
+ 'Content-Type': 'application/json',
337
+ 'Authorization': this.authorizationHeaderValue(),
338
+ }),
339
+ };
340
+ let ApiUrl = '/api/Home/';
341
+ this.http.get(this.environmentService.getApiUrl() + ApiUrl + 'RefreshAccessToken', httpOptions).subscribe((res) => {
342
+ this.cookieService.delete(TOKEN_KEY);
343
+ this.handleAccessTokenWithoutLanguage(res.val);
344
+ });
345
+ }
346
+ }
347
+ AuthService.user = null;
348
+ AuthService.UserClaims = null;
349
+ //refresh
350
+ AuthService.timers = [];
351
+ AuthService.seconds = 0;
352
+ AuthService.ɵprov = i0.ɵɵdefineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(i1$1.HttpClient), i0.ɵɵinject(EnvironmentService), i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(i4.Router), i0.ɵɵinject(i5.CookieService), i0.ɵɵinject(UtilityService)); }, token: AuthService, providedIn: "root" });
353
+ AuthService.decorators = [
354
+ { type: Injectable, args: [{
355
+ providedIn: 'root',
356
+ },] }
357
+ ];
358
+ AuthService.ctorParameters = () => [
359
+ { type: Injector },
360
+ { type: HttpClient },
361
+ { type: EnvironmentService },
362
+ { type: BBSFTranslateService },
363
+ { type: Router },
364
+ { type: CookieService },
365
+ { type: UtilityService }
98
366
  ];
99
367
 
100
368
  class RequestOptionsModel {
@@ -342,7 +610,7 @@ class StylesBundleService {
342
610
  head.appendChild(style);
343
611
  }
344
612
  }
345
- StylesBundleService.ɵprov = i0.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0.ɵɵinject(i1$1.DOCUMENT), i0.ɵɵinject(BBSFTranslateService)); }, token: StylesBundleService, providedIn: "root" });
613
+ StylesBundleService.ɵprov = i0.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0.ɵɵinject(i1$2.DOCUMENT), i0.ɵɵinject(BBSFTranslateService)); }, token: StylesBundleService, providedIn: "root" });
346
614
  StylesBundleService.decorators = [
347
615
  { type: Injectable, args: [{
348
616
  providedIn: 'root'
@@ -353,396 +621,11 @@ StylesBundleService.ctorParameters = () => [
353
621
  { type: BBSFTranslateService }
354
622
  ];
355
623
 
356
- class MasterLayoutService {
357
- constructor(router, http, authService, stylesBundleService, translate, environmentService) {
358
- this.router = router;
359
- this.http = http;
360
- this.authService = authService;
361
- this.stylesBundleService = stylesBundleService;
362
- this.translate = translate;
363
- this.environmentService = environmentService;
364
- this.ApiUrl = '/api/Home/';
365
- }
366
- switchLang(lang, bundleEnglishName, bundleArabicName) {
367
- this.changeLanguage(lang).subscribe((result) => {
368
- this.updateUserInfo().subscribe((Value) => {
369
- let UserInfoObject = Value;
370
- this.authService.getUser();
371
- this.authService.user.profile = Object.assign(this.authService.user.profile, UserInfoObject);
372
- this.authService.storUser(this.authService.user);
373
- this.stylesBundleService.loadThemes(lang, bundleEnglishName, bundleArabicName);
374
- localStorage.setItem('language', lang);
375
- this.translate.use(lang);
376
- });
377
- });
378
- }
379
- reloadComponent() {
380
- let currentUrl = this.router.url;
381
- this.router.routeReuseStrategy.shouldReuseRoute = () => false;
382
- this.router.onSameUrlNavigation = 'reload';
383
- this.router.navigate([currentUrl]);
384
- }
385
- changeLanguage(key) {
386
- let params = new HttpParams();
387
- params = params.append('UserId', this.authService.user.profile.id);
388
- params = params.append('LanguageKey', key);
389
- return this.http.post(this.ApiUrl + 'UpdateLanguage', null, null, params);
390
- }
391
- getUserClaims() {
392
- return this.http.get(this.ApiUrl + 'GetUserClaims', null, null);
393
- }
394
- logError(error) {
395
- let params = new HttpParams();
396
- params = params.append('error', error);
397
- return this.http.post(this.ApiUrl + 'LogError', null, null, params);
398
- }
399
- updateUserInfo() {
400
- let isExternal = this.environmentService.getIsIdentityServerExternal().toLowerCase() == 'true';
401
- if (isExternal)
402
- return this.getUserClaims();
403
- return this.http.get('/connect/userinfo');
404
- }
405
- switchRole(permissionSetID) {
406
- this.updateRole(permissionSetID).subscribe((result) => {
407
- this.updateUserInfo().subscribe((Value) => {
408
- let UserInfoObject = Value;
409
- this.authService.getUser();
410
- this.authService.user.profile = Object.assign(this.authService.user.profile, UserInfoObject);
411
- this.authService.storUser(this.authService.user);
412
- });
413
- });
414
- }
415
- updateRole(permissionSetID) {
416
- let params = new HttpParams();
417
- params = params.append('UserId', this.authService.user.profile.id);
418
- params = params.append('RoleID', permissionSetID);
419
- return this.http.post(this.ApiUrl + 'SwitchRole', null, null, params);
420
- }
421
- }
422
- MasterLayoutService.ɵprov = i0.ɵɵdefineInjectable({ factory: function MasterLayoutService_Factory() { return new MasterLayoutService(i0.ɵɵinject(i1$2.Router), i0.ɵɵinject(RequestHandlerService), i0.ɵɵinject(AuthService), i0.ɵɵinject(StylesBundleService), i0.ɵɵinject(i1.TranslateService), i0.ɵɵinject(EnvironmentService)); }, token: MasterLayoutService, providedIn: "root" });
423
- MasterLayoutService.decorators = [
424
- { type: Injectable, args: [{
425
- providedIn: 'root',
426
- },] }
427
- ];
428
- MasterLayoutService.ctorParameters = () => [
429
- { type: Router },
430
- { type: RequestHandlerService },
431
- { type: AuthService },
432
- { type: StylesBundleService },
433
- { type: TranslateService },
434
- { type: EnvironmentService }
435
- ];
436
-
437
- class AuthService {
438
- constructor(injector, http, environmentService, translateService, router) {
439
- this.injector = injector;
440
- this.http = http;
441
- this.environmentService = environmentService;
442
- this.translateService = translateService;
443
- this.router = router;
444
- // Observable navItem source
445
- this._authNavStatusSource = new BehaviorSubject(false);
446
- // Observable navItem stream
447
- this.authNavStatus$ = this._authNavStatusSource.asObservable();
448
- // Observable navItem source
449
- this._userSource = new Subject();
450
- this.UserStatus$ = this._userSource.asObservable();
451
- this.manager = this.getUserManager();
452
- this.redirectUrl = '';
453
- this.manager.getUser().then((user) => __awaiter(this, void 0, void 0, function* () {
454
- this.manager.storeUser(user);
455
- AuthService.user = user;
456
- this.user = user;
457
- this._authNavStatusSource.next(yield this.isAuthenticated());
458
- }));
459
- this.manager.events.addAccessTokenExpired((_) => {
460
- this._authNavStatusSource.next(false);
461
- });
462
- }
463
- getUserManager() {
464
- let user = null;
465
- let isExternal = this.environmentService.getIsIdentityServerExternal().toLowerCase() ==
466
- 'true';
467
- if (isExternal) {
468
- user = new UserManager({
469
- authority: this.environmentService.getIdentityServerUrl(),
470
- client_id: this.environmentService.getIsIdentityServerClientId(),
471
- client_secret: this.environmentService.getIsIdentityServerClientSecret(),
472
- redirect_uri: this.environmentService.getBaseUrl() +
473
- '/Admin/authentication/auth-callback',
474
- post_logout_redirect_uri: this.environmentService.getBaseUrl(),
475
- response_type: 'code',
476
- scope: 'openid profile email',
477
- filterProtocolClaims: true,
478
- loadUserInfo: true,
479
- automaticSilentRenew: true,
480
- silent_redirect_uri: this.environmentService.getBaseUrl() + '/assets/silent-callback.html',
481
- userStore: new WebStorageStateStore({ store: window.localStorage }),
482
- });
483
- }
484
- else {
485
- user = new UserManager({
486
- authority: this.environmentService.getIdentityServerUrl(),
487
- client_id: 'angular_spa',
488
- redirect_uri: this.environmentService.getBaseUrl() +
489
- '/Admin/authentication/auth-callback',
490
- post_logout_redirect_uri: this.environmentService.getBaseUrl(),
491
- response_type: 'id_token token',
492
- scope: 'openid profile email IdentityServerApi',
493
- filterProtocolClaims: true,
494
- loadUserInfo: true,
495
- automaticSilentRenew: true,
496
- silent_redirect_uri: this.environmentService.getBaseUrl() + '/assets/silent-callback.html',
497
- userStore: new WebStorageStateStore({ store: window.localStorage }),
498
- });
499
- }
500
- return user;
501
- }
502
- login() {
503
- return this.manager.signinRedirect();
504
- }
505
- getUser() {
506
- this.manager.getUser().then((user) => __awaiter(this, void 0, void 0, function* () {
507
- AuthService.user = user;
508
- this.user = user;
509
- this._authNavStatusSource.next(yield this.isAuthenticated());
510
- }));
511
- }
512
- storUser(User) {
513
- this.manager.storeUser(User);
514
- }
515
- revokeAccessToken() {
516
- this.manager.revokeAccessToken();
517
- }
518
- signinSilent() {
519
- let x = this.manager.signinSilentCallback();
520
- x.then((s) => {
521
- //console.log(s)
522
- });
523
- }
524
- completeAuthentication() {
525
- return __awaiter(this, void 0, void 0, function* () {
526
- this.user = yield this.manager.signinRedirectCallback();
527
- AuthService.user = this.user;
528
- this._userSource.next(AuthService.user);
529
- this._authNavStatusSource.next(yield this.isAuthenticated());
530
- let isExternal = this.environmentService.getIsIdentityServerExternal().toLowerCase() ==
531
- 'true';
532
- if (isExternal) {
533
- const masterLayoutService = this.injector.get(MasterLayoutService);
534
- let userClaims = yield masterLayoutService.getUserClaims().toPromise()
535
- .then((e) => {
536
- AuthService.UserClaims = e;
537
- }, (error) => {
538
- console.log(error);
539
- });
540
- AuthService.user.profile = Object.assign(AuthService.user.profile, AuthService.UserClaims);
541
- }
542
- this.storUser(AuthService.user);
543
- if (!localStorage.getItem('language') ||
544
- localStorage.getItem('language') == this.user.profile.locale)
545
- localStorage.setItem('language', this.user.profile.locale);
546
- if (this.translateService.currentLang != localStorage.getItem('language')) {
547
- this.translateService.resetLang(this.translateService.currentLang);
548
- yield this.translateService
549
- .reloadLang(localStorage.getItem('language'))
550
- .subscribe((res) => {
551
- console.log(res);
552
- });
553
- }
554
- this._userSource.next(AuthService.user);
555
- this._authNavStatusSource.next(yield this.isAuthenticated());
556
- this.user = AuthService.user;
557
- });
558
- }
559
- refreshToken(token) {
560
- return __awaiter(this, void 0, void 0, function* () {
561
- const httpOptions = {
562
- headers: new HttpHeaders({
563
- 'Content-Type': 'application/json',
564
- Authorization: token,
565
- }),
566
- };
567
- this.manager.revokeAccessToken();
568
- return yield this.http
569
- .post(`${this.environmentService.getIdentityServerUrl()}/users/refresh-token`, httpOptions, { withCredentials: true })
570
- .subscribe((user) => {
571
- this._userSource.next(user);
572
- AuthService.user = user;
573
- this.user = user;
574
- });
575
- });
576
- }
577
- getCurrentUser() {
578
- return this.manager.getUser();
579
- }
580
- isAuthenticated() {
581
- return __awaiter(this, void 0, void 0, function* () {
582
- let user = yield this.manager.getUser().then((user) => {
583
- return user;
584
- });
585
- return this.user != null && !this.user.expired;
586
- });
587
- }
588
- isUserInRole(allowedPermission) {
589
- let selectedPermissionSetID = Number.parseInt(this.user.profile['selectedpermissionsetid']);
590
- return allowedPermission.includes(selectedPermissionSetID);
591
- }
592
- authorizationHeaderValue() {
593
- return AuthService.user
594
- ? `${AuthService.user.token_type} ${AuthService.user.access_token}`
595
- : '';
596
- }
597
- name() {
598
- return AuthService.user != null ? AuthService.user.profile.given_name : '';
599
- }
600
- setUrl(url) {
601
- localStorage.setItem('redirectUrl', url);
602
- }
603
- getUrl() {
604
- return localStorage.getItem('redirectUrl');
605
- }
606
- signinSilentCallback() {
607
- return __awaiter(this, void 0, void 0, function* () {
608
- let user = yield this.manager.signinSilentCallback();
609
- //await this.manager.storeUser(user);
610
- AuthService.user = user;
611
- console.log('Token from signinSilentCallback :' + AuthService.user);
612
- this.user = user;
613
- });
614
- }
615
- signout() {
616
- return __awaiter(this, void 0, void 0, function* () {
617
- if (yield !this.isAuthenticated())
618
- this.router.navigate(['/Admin/account/login']), localStorage.clear();
619
- let isExternal = this.environmentService.getIsIdentityServerExternal().toLowerCase() ==
620
- 'true';
621
- if (isExternal) {
622
- yield this.clearUserSessionClaims()
623
- .toPromise()
624
- .then((res) => {
625
- let result = res;
626
- });
627
- }
628
- yield this.manager.signoutRedirect();
629
- });
630
- }
631
- clearUserSessionClaims() {
632
- const httpOptions = {
633
- headers: new HttpHeaders({
634
- 'Content-Type': 'application/json',
635
- }),
636
- };
637
- let ApiUrl = '/api/Home/';
638
- return this.http.get(this.environmentService.getBaseUrl() + ApiUrl + 'ClearCurrentUserSession', httpOptions);
639
- }
640
- }
641
- AuthService.user = null;
642
- AuthService.UserClaims = null;
643
- AuthService.ɵprov = i0.ɵɵdefineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(i1$3.HttpClient), i0.ɵɵinject(EnvironmentService), i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(i1$2.Router)); }, token: AuthService, providedIn: "root" });
644
- AuthService.decorators = [
645
- { type: Injectable, args: [{
646
- providedIn: 'root',
647
- },] }
648
- ];
649
- AuthService.ctorParameters = () => [
650
- { type: Injector },
651
- { type: HttpClient },
652
- { type: EnvironmentService },
653
- { type: BBSFTranslateService },
654
- { type: Router }
655
- ];
656
-
657
- class UtilityService {
658
- constructor(translator, authService, environmentService) {
659
- this.translator = translator;
660
- this.authService = authService;
661
- this.environmentService = environmentService;
662
- this.isCreatedBefore = false;
663
- }
664
- getResourceValue(Key) {
665
- let ResourceValue = this.translator.instant(Key);
666
- return ResourceValue;
667
- }
668
- getCurrentLanguage() {
669
- let currentLanguage = this.environmentService.getDefaultLanguage();
670
- let lang = localStorage.getItem('language');
671
- if (lang)
672
- currentLanguage = lang;
673
- else
674
- localStorage.setItem('language', currentLanguage);
675
- return currentLanguage;
676
- }
677
- isCurrentLanguageEnglish() {
678
- return this.getCurrentLanguage() == "en";
679
- }
680
- isCurrentLanguageArabic() {
681
- return this.getCurrentLanguage() == "ar";
682
- }
683
- notifySuccessMessage(Message, title, time, showHeader = true) {
684
- let MessageTemplate = this.getResourceValue("SuccessMessage");
685
- let titleTemplate;
686
- if (Message) {
687
- MessageTemplate = Message;
688
- }
689
- if (title) {
690
- titleTemplate = title;
691
- }
692
- let toaster = AppInjector.get(ToastrService);
693
- showHeader ? toaster.success(MessageTemplate, titleTemplate) : toaster.success(MessageTemplate);
694
- }
695
- notifyErrorMessage(Message, title, time, showHeader = true) {
696
- let MessageTemplate = this.getResourceValue("ErrorMessage");
697
- let titleTemplate = this.getResourceValue("Error");
698
- if (Message) {
699
- MessageTemplate = Message;
700
- }
701
- if (title) {
702
- titleTemplate = title;
703
- }
704
- const toaster = AppInjector.get(ToastrService);
705
- showHeader ? toaster.error(MessageTemplate, titleTemplate) : toaster.error(MessageTemplate);
706
- }
707
- notifyWarningMessage(Message, title, time, showHeader = true) {
708
- let MessageTemplate = this.getResourceValue("WarningMessage");
709
- let titleTemplate = this.getResourceValue("Warning");
710
- if (Message) {
711
- MessageTemplate = Message;
712
- }
713
- if (title) {
714
- titleTemplate = title;
715
- }
716
- const toaster = AppInjector.get(ToastrService);
717
- showHeader ? toaster.warning(MessageTemplate, titleTemplate) : toaster.warning(MessageTemplate);
718
- }
719
- startBlockUI() {
720
- this.blockUI.start();
721
- }
722
- stopBlockUI() {
723
- this.blockUI.stop();
724
- }
725
- }
726
- UtilityService.ɵprov = i0.ɵɵdefineInjectable({ factory: function UtilityService_Factory() { return new UtilityService(i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(AuthService), i0.ɵɵinject(EnvironmentService)); }, token: UtilityService, providedIn: "root" });
727
- UtilityService.decorators = [
728
- { type: Injectable, args: [{
729
- providedIn: 'root'
730
- },] }
731
- ];
732
- UtilityService.ctorParameters = () => [
733
- { type: BBSFTranslateService },
734
- { type: AuthService },
735
- { type: EnvironmentService }
736
- ];
737
- __decorate([
738
- BlockUI()
739
- ], UtilityService.prototype, "blockUI", void 0);
740
-
741
- class ControlValidationService {
742
- constructor(utilityService) {
743
- this.utilityService = utilityService;
744
- this.requestOptions = new RequestOptionsModel();
745
- this.isCreatedBefor = false;
624
+ class ControlValidationService {
625
+ constructor(utilityService) {
626
+ this.utilityService = utilityService;
627
+ this.requestOptions = new RequestOptionsModel();
628
+ this.isCreatedBefor = false;
746
629
  }
747
630
  showGlobalError(errorMessage, formId, deleteOld) {
748
631
  let globalErorrElement = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
@@ -906,6 +789,80 @@ __decorate([
906
789
  BlockUI()
907
790
  ], ControlValidationService.prototype, "blockUI", void 0);
908
791
 
792
+ class MasterLayoutService {
793
+ constructor(router, http, authService, stylesBundleService, translate, environmentService) {
794
+ this.router = router;
795
+ this.http = http;
796
+ this.authService = authService;
797
+ this.stylesBundleService = stylesBundleService;
798
+ this.translate = translate;
799
+ this.environmentService = environmentService;
800
+ this.ApiUrl = '/api/Home/';
801
+ }
802
+ switchLang(lang, bundleEnglishName, bundleArabicName) {
803
+ this.changeLanguage(lang).subscribe((result) => {
804
+ this.updateUserInfo().subscribe((Value) => {
805
+ let UserInfoObject = Value;
806
+ this.authService.handleAccessToken(UserInfoObject.token);
807
+ this.stylesBundleService.loadThemes(lang, bundleEnglishName, bundleArabicName);
808
+ localStorage.setItem('language', lang);
809
+ this.translate.use(lang);
810
+ });
811
+ });
812
+ }
813
+ reloadComponent() {
814
+ let currentUrl = this.router.url;
815
+ this.router.routeReuseStrategy.shouldReuseRoute = () => false;
816
+ this.router.onSameUrlNavigation = 'reload';
817
+ this.router.navigate([currentUrl]);
818
+ }
819
+ changeLanguage(key) {
820
+ let params = new HttpParams();
821
+ params = params.append('UserId', this.authService.user.profile.id);
822
+ params = params.append('LanguageKey', key);
823
+ return this.http.post(this.ApiUrl + 'UpdateLanguage', null, null, params);
824
+ }
825
+ getUserClaims() {
826
+ return this.http.get(this.ApiUrl + 'GetUserClaims', null, null);
827
+ }
828
+ logError(error) {
829
+ let params = new HttpParams();
830
+ params = params.append('error', error);
831
+ return this.http.post(this.ApiUrl + 'LogError', null, null, params);
832
+ }
833
+ updateUserInfo() {
834
+ return this.http.get(this.ApiUrl + 'UpdateUserInfo', null, null);
835
+ }
836
+ switchRole(permissionSetID) {
837
+ this.updateRole(permissionSetID).subscribe((result) => {
838
+ this.updateUserInfo().subscribe((Value) => {
839
+ let UserInfoObject = Value;
840
+ this.authService.handleAccessToken(UserInfoObject.token);
841
+ });
842
+ });
843
+ }
844
+ updateRole(permissionSetID) {
845
+ let params = new HttpParams();
846
+ params = params.append('UserId', this.authService.user.profile.id);
847
+ params = params.append('RoleID', permissionSetID);
848
+ return this.http.post(this.ApiUrl + 'SwitchRole', null, null, params);
849
+ }
850
+ }
851
+ MasterLayoutService.ɵprov = i0.ɵɵdefineInjectable({ factory: function MasterLayoutService_Factory() { return new MasterLayoutService(i0.ɵɵinject(i4.Router), i0.ɵɵinject(RequestHandlerService), i0.ɵɵinject(AuthService), i0.ɵɵinject(StylesBundleService), i0.ɵɵinject(i1.TranslateService), i0.ɵɵinject(EnvironmentService)); }, token: MasterLayoutService, providedIn: "root" });
852
+ MasterLayoutService.decorators = [
853
+ { type: Injectable, args: [{
854
+ providedIn: 'root',
855
+ },] }
856
+ ];
857
+ MasterLayoutService.ctorParameters = () => [
858
+ { type: Router },
859
+ { type: RequestHandlerService },
860
+ { type: AuthService },
861
+ { type: StylesBundleService },
862
+ { type: TranslateService },
863
+ { type: EnvironmentService }
864
+ ];
865
+
909
866
  class ConfigurationService {
910
867
  constructor(httpClient) {
911
868
  this.httpClient = httpClient;
@@ -918,7 +875,7 @@ class ConfigurationService {
918
875
  }
919
876
  }
920
877
  ConfigurationService.JsonData = [];
921
- ConfigurationService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ConfigurationService_Factory() { return new ConfigurationService(i0.ɵɵinject(i1$3.HttpClient)); }, token: ConfigurationService, providedIn: "root" });
878
+ ConfigurationService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ConfigurationService_Factory() { return new ConfigurationService(i0.ɵɵinject(i1$1.HttpClient)); }, token: ConfigurationService, providedIn: "root" });
922
879
  ConfigurationService.decorators = [
923
880
  { type: Injectable, args: [{
924
881
  providedIn: 'root'
@@ -956,7 +913,8 @@ BBSFUtilitiesModule.decorators = [
956
913
  BBSFTranslateService,
957
914
  ControlValidationService,
958
915
  MasterLayoutService,
959
- ConfigurationService
916
+ ConfigurationService,
917
+ CookieService
960
918
  ]
961
919
  },] }
962
920
  ];