@bnsights/bbsf-utilities 1.0.37 → 1.0.38

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,8 +1,6 @@
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';
@@ -10,12 +8,16 @@ import { BlockUI, BlockUIModule } from 'ng-block-ui';
10
8
  import { ToastrService, ToastrModule } from 'ngx-toastr';
11
9
  import { HttpModule } from '@angular/http';
12
10
  import { __awaiter, __decorate, __rest } from 'tslib';
13
- import * as i1$3 from '@angular/common/http';
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';
@@ -97,6 +99,281 @@ BBSFTranslateService.decorators = [
97
99
  },] }
98
100
  ];
99
101
 
102
+ class User {
103
+ }
104
+
105
+ const TOKEN_KEY = 'access_token';
106
+ class AuthService {
107
+ constructor(injector, http, environmentService, translateService, router, cookieService) {
108
+ this.injector = injector;
109
+ this.http = http;
110
+ this.environmentService = environmentService;
111
+ this.translateService = translateService;
112
+ this.router = router;
113
+ this.cookieService = cookieService;
114
+ this.redirectUrl = '';
115
+ this.jwtHelper = new JwtHelperService();
116
+ this.isAuthenticatedSubject = new BehaviorSubject(this.hasToken());
117
+ this.isAuthenticate$ = this.isAuthenticatedSubject.asObservable();
118
+ this.user = this.getUserManager();
119
+ }
120
+ hasToken() {
121
+ const token = this.cookieService.get(TOKEN_KEY);
122
+ return token && !this.jwtHelper.isTokenExpired(token);
123
+ }
124
+ getUserManager() {
125
+ const token = this.cookieService.get(TOKEN_KEY);
126
+ if (token)
127
+ this.handleAccessTokenWithoutLanguage(token);
128
+ return AuthService.user;
129
+ }
130
+ getUser() {
131
+ this.user = AuthService.user;
132
+ }
133
+ storUser(User) {
134
+ AuthService.user = this.user = this.user;
135
+ }
136
+ getCurrentUser() {
137
+ return AuthService.user;
138
+ }
139
+ isAuthenticated() {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ return AuthService.user != null && !this.jwtHelper.isTokenExpired(AuthService.user.access_token);
142
+ });
143
+ }
144
+ isUserInRole(allowedPermission) {
145
+ let selectedPermissionSetID = Number.parseInt(this.user.profile['selectedpermissionsetid']);
146
+ return allowedPermission.includes(selectedPermissionSetID);
147
+ }
148
+ authorizationHeaderValue() {
149
+ return AuthService.user
150
+ ? `${AuthService.user.token_type} ${AuthService.user.access_token}`
151
+ : '';
152
+ }
153
+ name() {
154
+ return AuthService.user != null ? AuthService.user.profile.given_name : '';
155
+ }
156
+ setUrl(url) {
157
+ localStorage.setItem('redirectUrl', url);
158
+ }
159
+ getUrl() {
160
+ var _a;
161
+ return (_a = localStorage.getItem('redirectUrl')) !== null && _a !== void 0 ? _a : "/";
162
+ }
163
+ signout() {
164
+ AuthService.timers.map(t => clearInterval(t));
165
+ AuthService.timers = [];
166
+ if (!this.isAuthenticated()) {
167
+ this.cookieService.delete(TOKEN_KEY);
168
+ this.router.navigate(['/Admin/account/login']);
169
+ }
170
+ this.logout().subscribe(res => {
171
+ this.cookieService.delete(TOKEN_KEY);
172
+ this.router.navigate(['/Admin/account/login']);
173
+ });
174
+ }
175
+ logout() {
176
+ const httpOptions = {
177
+ headers: new HttpHeaders({
178
+ 'Content-Type': 'application/json',
179
+ }),
180
+ };
181
+ let ApiUrl = '/Account/';
182
+ return this.http.get(this.environmentService.getApiUrl() + ApiUrl + 'Logout', httpOptions);
183
+ }
184
+ clearUserSessionClaims() {
185
+ const httpOptions = {
186
+ headers: new HttpHeaders({
187
+ 'Content-Type': 'application/json',
188
+ }),
189
+ };
190
+ let ApiUrl = '/api/Home/';
191
+ return this.http.get(this.environmentService.getBaseUrl() + ApiUrl + 'ClearCurrentUserSession', httpOptions);
192
+ }
193
+ loginForm(model) {
194
+ const httpOptions = {
195
+ headers: new HttpHeaders({
196
+ 'Content-Type': 'application/json',
197
+ }),
198
+ };
199
+ let ApiUrl = '/Account/';
200
+ return this.http.post(this.environmentService.getApiUrl() + ApiUrl + 'Authenticate', model, httpOptions);
201
+ }
202
+ handleAccessToken(response) {
203
+ return __awaiter(this, void 0, void 0, function* () {
204
+ const token = response;
205
+ AuthService.user = new User();
206
+ AuthService.user.token_type = "Bearer";
207
+ AuthService.user.access_token = token;
208
+ AuthService.user.profile = this.jwtHelper.decodeToken(token);
209
+ AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
210
+ AuthService.timers.map(t => clearInterval(t));
211
+ AuthService.timers = [];
212
+ this.setTokenSeconds();
213
+ AuthService.timers.push(this.checkRefreshToken());
214
+ this.user = AuthService.user;
215
+ yield this.updateLanguage();
216
+ this.cookieService.set(TOKEN_KEY, token, null, null, null, true, 'Strict');
217
+ this.isAuthenticatedSubject.next(true);
218
+ });
219
+ }
220
+ handleAccessTokenWithoutLanguage(response) {
221
+ const token = response;
222
+ AuthService.user = new User();
223
+ AuthService.user.token_type = "Bearer";
224
+ AuthService.user.access_token = token;
225
+ AuthService.user.profile = this.jwtHelper.decodeToken(token);
226
+ AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
227
+ this.setTokenSeconds();
228
+ this.user = AuthService.user;
229
+ this.cookieService.set(TOKEN_KEY, token, null, null, null, true, 'Strict');
230
+ this.isAuthenticatedSubject.next(true);
231
+ }
232
+ updateLanguage() {
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ if (!localStorage.getItem('language') ||
235
+ localStorage.getItem('language') == this.user.profile.locale)
236
+ localStorage.setItem('language', this.user.profile.locale);
237
+ if (this.translateService.currentLang != localStorage.getItem('language')) {
238
+ this.translateService.resetLang(this.translateService.currentLang);
239
+ yield this.translateService
240
+ .reloadLang(localStorage.getItem('language'))
241
+ .subscribe((res) => {
242
+ console.log(res);
243
+ });
244
+ }
245
+ });
246
+ }
247
+ checkRefreshToken() {
248
+ let date = new Date();
249
+ return setInterval(() => {
250
+ if (Math.floor(AuthService.seconds) < 120 && this.isAuthenticated())
251
+ this.refresh();
252
+ AuthService.seconds--;
253
+ }, 1000);
254
+ }
255
+ setTokenSeconds() {
256
+ let date = new Date();
257
+ AuthService.seconds = (AuthService.user.expires_at - date) / 1000;
258
+ }
259
+ refresh() {
260
+ const httpOptions = {
261
+ headers: new HttpHeaders({
262
+ 'Content-Type': 'application/json',
263
+ 'Authorization': this.authorizationHeaderValue(),
264
+ }),
265
+ };
266
+ let ApiUrl = '/api/Home/';
267
+ this.http.get(this.environmentService.getApiUrl() + ApiUrl + 'RefreshAccessToken', httpOptions).subscribe((res) => {
268
+ this.cookieService.delete(TOKEN_KEY);
269
+ this.handleAccessTokenWithoutLanguage(res);
270
+ });
271
+ }
272
+ }
273
+ AuthService.user = null;
274
+ AuthService.UserClaims = null;
275
+ //refresh
276
+ AuthService.timers = [];
277
+ AuthService.seconds = 0;
278
+ 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)); }, token: AuthService, providedIn: "root" });
279
+ AuthService.decorators = [
280
+ { type: Injectable, args: [{
281
+ providedIn: 'root',
282
+ },] }
283
+ ];
284
+ AuthService.ctorParameters = () => [
285
+ { type: Injector },
286
+ { type: HttpClient },
287
+ { type: EnvironmentService },
288
+ { type: BBSFTranslateService },
289
+ { type: Router },
290
+ { type: CookieService }
291
+ ];
292
+
293
+ class UtilityService {
294
+ constructor(translator, authService, environmentService) {
295
+ this.translator = translator;
296
+ this.authService = authService;
297
+ this.environmentService = environmentService;
298
+ this.isCreatedBefore = false;
299
+ }
300
+ getResourceValue(Key) {
301
+ let ResourceValue = this.translator.instant(Key);
302
+ return ResourceValue;
303
+ }
304
+ getCurrentLanguage() {
305
+ let currentLanguage = this.environmentService.getDefaultLanguage();
306
+ let lang = localStorage.getItem('language');
307
+ if (lang)
308
+ currentLanguage = lang;
309
+ else
310
+ localStorage.setItem('language', currentLanguage);
311
+ return currentLanguage;
312
+ }
313
+ isCurrentLanguageEnglish() {
314
+ return this.getCurrentLanguage() == "en";
315
+ }
316
+ isCurrentLanguageArabic() {
317
+ return this.getCurrentLanguage() == "ar";
318
+ }
319
+ notifySuccessMessage(Message, title, time, showHeader = true) {
320
+ let MessageTemplate = this.getResourceValue("SuccessMessage");
321
+ let titleTemplate;
322
+ if (Message) {
323
+ MessageTemplate = Message;
324
+ }
325
+ if (title) {
326
+ titleTemplate = title;
327
+ }
328
+ let toaster = AppInjector.get(ToastrService);
329
+ showHeader ? toaster.success(MessageTemplate, titleTemplate) : toaster.success(MessageTemplate);
330
+ }
331
+ notifyErrorMessage(Message, title, time, showHeader = true) {
332
+ let MessageTemplate = this.getResourceValue("ErrorMessage");
333
+ let titleTemplate = this.getResourceValue("Error");
334
+ if (Message) {
335
+ MessageTemplate = Message;
336
+ }
337
+ if (title) {
338
+ titleTemplate = title;
339
+ }
340
+ const toaster = AppInjector.get(ToastrService);
341
+ showHeader ? toaster.error(MessageTemplate, titleTemplate) : toaster.error(MessageTemplate);
342
+ }
343
+ notifyWarningMessage(Message, title, time, showHeader = true) {
344
+ let MessageTemplate = this.getResourceValue("WarningMessage");
345
+ let titleTemplate = this.getResourceValue("Warning");
346
+ if (Message) {
347
+ MessageTemplate = Message;
348
+ }
349
+ if (title) {
350
+ titleTemplate = title;
351
+ }
352
+ const toaster = AppInjector.get(ToastrService);
353
+ showHeader ? toaster.warning(MessageTemplate, titleTemplate) : toaster.warning(MessageTemplate);
354
+ }
355
+ startBlockUI() {
356
+ this.blockUI.start();
357
+ }
358
+ stopBlockUI() {
359
+ this.blockUI.stop();
360
+ }
361
+ }
362
+ UtilityService.ɵprov = i0.ɵɵdefineInjectable({ factory: function UtilityService_Factory() { return new UtilityService(i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(AuthService), i0.ɵɵinject(EnvironmentService)); }, token: UtilityService, providedIn: "root" });
363
+ UtilityService.decorators = [
364
+ { type: Injectable, args: [{
365
+ providedIn: 'root'
366
+ },] }
367
+ ];
368
+ UtilityService.ctorParameters = () => [
369
+ { type: BBSFTranslateService },
370
+ { type: AuthService },
371
+ { type: EnvironmentService }
372
+ ];
373
+ __decorate([
374
+ BlockUI()
375
+ ], UtilityService.prototype, "blockUI", void 0);
376
+
100
377
  class RequestOptionsModel {
101
378
  constructor() {
102
379
  this.disableSuccessNotification = false;
@@ -342,7 +619,7 @@ class StylesBundleService {
342
619
  head.appendChild(style);
343
620
  }
344
621
  }
345
- StylesBundleService.ɵprov = i0.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0.ɵɵinject(i1$1.DOCUMENT), i0.ɵɵinject(BBSFTranslateService)); }, token: StylesBundleService, providedIn: "root" });
622
+ StylesBundleService.ɵprov = i0.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0.ɵɵinject(i1$2.DOCUMENT), i0.ɵɵinject(BBSFTranslateService)); }, token: StylesBundleService, providedIn: "root" });
346
623
  StylesBundleService.decorators = [
347
624
  { type: Injectable, args: [{
348
625
  providedIn: 'root'
@@ -353,396 +630,11 @@ StylesBundleService.ctorParameters = () => [
353
630
  { type: BBSFTranslateService }
354
631
  ];
355
632
 
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;
633
+ class ControlValidationService {
634
+ constructor(utilityService) {
635
+ this.utilityService = utilityService;
636
+ this.requestOptions = new RequestOptionsModel();
637
+ this.isCreatedBefor = false;
746
638
  }
747
639
  showGlobalError(errorMessage, formId, deleteOld) {
748
640
  let globalErorrElement = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
@@ -906,6 +798,80 @@ __decorate([
906
798
  BlockUI()
907
799
  ], ControlValidationService.prototype, "blockUI", void 0);
908
800
 
801
+ class MasterLayoutService {
802
+ constructor(router, http, authService, stylesBundleService, translate, environmentService) {
803
+ this.router = router;
804
+ this.http = http;
805
+ this.authService = authService;
806
+ this.stylesBundleService = stylesBundleService;
807
+ this.translate = translate;
808
+ this.environmentService = environmentService;
809
+ this.ApiUrl = '/api/Home/';
810
+ }
811
+ switchLang(lang, bundleEnglishName, bundleArabicName) {
812
+ this.changeLanguage(lang).subscribe((result) => {
813
+ this.updateUserInfo().subscribe((Value) => {
814
+ let UserInfoObject = Value;
815
+ this.authService.handleAccessToken(UserInfoObject.token);
816
+ this.stylesBundleService.loadThemes(lang, bundleEnglishName, bundleArabicName);
817
+ localStorage.setItem('language', lang);
818
+ this.translate.use(lang);
819
+ });
820
+ });
821
+ }
822
+ reloadComponent() {
823
+ let currentUrl = this.router.url;
824
+ this.router.routeReuseStrategy.shouldReuseRoute = () => false;
825
+ this.router.onSameUrlNavigation = 'reload';
826
+ this.router.navigate([currentUrl]);
827
+ }
828
+ changeLanguage(key) {
829
+ let params = new HttpParams();
830
+ params = params.append('UserId', this.authService.user.profile.id);
831
+ params = params.append('LanguageKey', key);
832
+ return this.http.post(this.ApiUrl + 'UpdateLanguage', null, null, params);
833
+ }
834
+ getUserClaims() {
835
+ return this.http.get(this.ApiUrl + 'GetUserClaims', null, null);
836
+ }
837
+ logError(error) {
838
+ let params = new HttpParams();
839
+ params = params.append('error', error);
840
+ return this.http.post(this.ApiUrl + 'LogError', null, null, params);
841
+ }
842
+ updateUserInfo() {
843
+ return this.http.get(this.ApiUrl + 'UpdateUserInfo', null, null);
844
+ }
845
+ switchRole(permissionSetID) {
846
+ this.updateRole(permissionSetID).subscribe((result) => {
847
+ this.updateUserInfo().subscribe((Value) => {
848
+ let UserInfoObject = Value;
849
+ this.authService.handleAccessToken(UserInfoObject.token);
850
+ });
851
+ });
852
+ }
853
+ updateRole(permissionSetID) {
854
+ let params = new HttpParams();
855
+ params = params.append('UserId', this.authService.user.profile.id);
856
+ params = params.append('RoleID', permissionSetID);
857
+ return this.http.post(this.ApiUrl + 'SwitchRole', null, null, params);
858
+ }
859
+ }
860
+ 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" });
861
+ MasterLayoutService.decorators = [
862
+ { type: Injectable, args: [{
863
+ providedIn: 'root',
864
+ },] }
865
+ ];
866
+ MasterLayoutService.ctorParameters = () => [
867
+ { type: Router },
868
+ { type: RequestHandlerService },
869
+ { type: AuthService },
870
+ { type: StylesBundleService },
871
+ { type: TranslateService },
872
+ { type: EnvironmentService }
873
+ ];
874
+
909
875
  class ConfigurationService {
910
876
  constructor(httpClient) {
911
877
  this.httpClient = httpClient;
@@ -918,7 +884,7 @@ class ConfigurationService {
918
884
  }
919
885
  }
920
886
  ConfigurationService.JsonData = [];
921
- ConfigurationService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ConfigurationService_Factory() { return new ConfigurationService(i0.ɵɵinject(i1$3.HttpClient)); }, token: ConfigurationService, providedIn: "root" });
887
+ ConfigurationService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ConfigurationService_Factory() { return new ConfigurationService(i0.ɵɵinject(i1$1.HttpClient)); }, token: ConfigurationService, providedIn: "root" });
922
888
  ConfigurationService.decorators = [
923
889
  { type: Injectable, args: [{
924
890
  providedIn: 'root'
@@ -956,7 +922,8 @@ BBSFUtilitiesModule.decorators = [
956
922
  BBSFTranslateService,
957
923
  ControlValidationService,
958
924
  MasterLayoutService,
959
- ConfigurationService
925
+ ConfigurationService,
926
+ CookieService
960
927
  ]
961
928
  },] }
962
929
  ];