@bnsights/bbsf-utilities 1.0.26 → 1.0.28

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,8 @@
1
- import * as i1$2 from '@angular/common';
1
+ import * as i1$1 from '@angular/common';
2
2
  import { DOCUMENT, CommonModule } from '@angular/common';
3
3
  import * as i0 from '@angular/core';
4
- import { Injectable, Inject, NgModule, Injector } from '@angular/core';
5
- import * as i4 from '@angular/router';
4
+ import { Injectable, Inject, Injector, NgModule } from '@angular/core';
5
+ import * as i1$2 from '@angular/router';
6
6
  import { Router, RouterModule } from '@angular/router';
7
7
  import * as i1 from '@ngx-translate/core';
8
8
  import { TranslateService } from '@ngx-translate/core';
@@ -10,10 +10,10 @@ import { BlockUI, BlockUIModule } from 'ng-block-ui';
10
10
  import { ToastrService, ToastrModule } from 'ngx-toastr';
11
11
  import { HttpModule } from '@angular/http';
12
12
  import { __awaiter, __decorate } from 'tslib';
13
- import * as i1$1 from '@angular/common/http';
13
+ import * as i1$3 from '@angular/common/http';
14
14
  import { HttpHeaders, HttpClient, HttpParams } from '@angular/common/http';
15
15
  import { UserManager, WebStorageStateStore } from 'oidc-client';
16
- import { BehaviorSubject, Subject, Observable, throwError } from 'rxjs';
16
+ import { Subject, Observable, throwError, BehaviorSubject } from 'rxjs';
17
17
  import { takeUntil, tap, map } from 'rxjs/operators';
18
18
  import { plainToClass } from 'class-transformer';
19
19
 
@@ -53,6 +53,18 @@ class EnvironmentService {
53
53
  let Url = environment["BBSF_IdentityServerUrl"];
54
54
  return Url;
55
55
  }
56
+ getIsIdentityServerExternal() {
57
+ let Mode = environment["BBSF_IsExternalIdentityServer"];
58
+ return Mode;
59
+ }
60
+ getIsIdentityServerClientId() {
61
+ let Mode = environment["BBSF_IdentityServer_Client_Id"];
62
+ return Mode;
63
+ }
64
+ getIsIdentityServerClientSecret() {
65
+ let Mode = environment["BBSF_IdentityServer_Client_Secret"];
66
+ return Mode;
67
+ }
56
68
  }
57
69
  EnvironmentService.AreaList = [];
58
70
  EnvironmentService.ɵprov = i0.ɵɵdefineInjectable({ factory: function EnvironmentService_Factory() { return new EnvironmentService(); }, token: EnvironmentService, providedIn: "root" });
@@ -71,241 +83,6 @@ BBSFTranslateService.decorators = [
71
83
  },] }
72
84
  ];
73
85
 
74
- class AuthService {
75
- constructor(http, environmentService, translateService, router) {
76
- this.http = http;
77
- this.environmentService = environmentService;
78
- this.translateService = translateService;
79
- this.router = router;
80
- // Observable navItem source
81
- this._authNavStatusSource = new BehaviorSubject(false);
82
- // Observable navItem stream
83
- this.authNavStatus$ = this._authNavStatusSource.asObservable();
84
- // Observable navItem source
85
- this._userSource = new Subject();
86
- this.UserStatus$ = this._userSource.asObservable();
87
- this.manager = new UserManager({
88
- authority: this.environmentService.getIdentityServerUrl(),
89
- client_id: 'angular_spa',
90
- redirect_uri: this.environmentService.getIdentityServerUrl() + '/Admin/authentication/auth-callback',
91
- post_logout_redirect_uri: this.environmentService.getBaseUrl(),
92
- response_type: "id_token token",
93
- scope: "openid profile email IdentityServerApi",
94
- filterProtocolClaims: true,
95
- loadUserInfo: true,
96
- automaticSilentRenew: true,
97
- silent_redirect_uri: this.environmentService.getIdentityServerUrl() + '/assets/silent-callback.html',
98
- userStore: new WebStorageStateStore({ store: window.localStorage })
99
- });
100
- this.redirectUrl = "";
101
- this.manager.getUser().then((user) => __awaiter(this, void 0, void 0, function* () {
102
- this.manager.storeUser(user);
103
- AuthService.user = user;
104
- this.user = user;
105
- this._authNavStatusSource.next(yield this.isAuthenticated());
106
- }));
107
- this.manager.events.addAccessTokenExpired(_ => {
108
- this._authNavStatusSource.next(false);
109
- });
110
- }
111
- login() {
112
- return this.manager.signinRedirect();
113
- }
114
- getUser() {
115
- this.manager.getUser().then((user) => __awaiter(this, void 0, void 0, function* () {
116
- ;
117
- AuthService.user = user;
118
- this.user = user;
119
- this._authNavStatusSource.next(yield this.isAuthenticated());
120
- }));
121
- }
122
- storUser(User) {
123
- this.manager.storeUser(User);
124
- }
125
- revokeAccessToken() {
126
- this.manager.revokeAccessToken();
127
- }
128
- signinSilent() {
129
- let x = this.manager.signinSilentCallback();
130
- x.then(s => {
131
- //console.log(s)
132
- });
133
- }
134
- completeAuthentication() {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- this.user = yield this.manager.signinRedirectCallback();
137
- AuthService.user = this.user;
138
- if (!localStorage.getItem("language") || localStorage.getItem("language") == this.user.profile.locale)
139
- localStorage.setItem("language", this.user.profile.locale);
140
- if (this.translateService.currentLang != localStorage.getItem("language")) {
141
- this.translateService.resetLang(this.translateService.currentLang);
142
- yield this.translateService.reloadLang(localStorage.getItem("language")).subscribe((res) => {
143
- console.log(res);
144
- });
145
- }
146
- this._userSource.next(AuthService.user);
147
- this._authNavStatusSource.next(yield this.isAuthenticated());
148
- });
149
- }
150
- refreshToken(token) {
151
- return __awaiter(this, void 0, void 0, function* () {
152
- const httpOptions = {
153
- headers: new HttpHeaders({
154
- 'Content-Type': 'application/json',
155
- 'Authorization': token
156
- })
157
- };
158
- this.manager.revokeAccessToken();
159
- return yield this.http.post(`${this.environmentService.getIdentityServerUrl()}/users/refresh-token`, httpOptions, { withCredentials: true }).subscribe((user) => {
160
- this._userSource.next(user);
161
- AuthService.user = user;
162
- this.user = user;
163
- });
164
- });
165
- }
166
- getCurrentUser() {
167
- return this.manager.getUser();
168
- }
169
- isAuthenticated() {
170
- return __awaiter(this, void 0, void 0, function* () {
171
- let user = yield this.manager.getUser().then(user => {
172
- return user;
173
- });
174
- return this.user != null && !this.user.expired;
175
- });
176
- }
177
- isUserInRole(allowedPermission) {
178
- let selectedPermissionSetID = Number.parseInt(this.user.profile["selectedpermissionsetid"]);
179
- return allowedPermission.includes(selectedPermissionSetID);
180
- }
181
- authorizationHeaderValue() {
182
- return AuthService.user ? `${AuthService.user.token_type} ${AuthService.user.access_token}` : "";
183
- }
184
- name() {
185
- return AuthService.user != null ? AuthService.user.profile.given_name : '';
186
- }
187
- setUrl(url) {
188
- localStorage.setItem("redirectUrl", url);
189
- }
190
- getUrl() {
191
- return localStorage.getItem("redirectUrl");
192
- }
193
- signinSilentCallback() {
194
- return __awaiter(this, void 0, void 0, function* () {
195
- let user = yield this.manager.signinSilentCallback();
196
- //await this.manager.storeUser(user);
197
- AuthService.user = user;
198
- console.log("Token from signinSilentCallback :" + AuthService.user);
199
- this.user = user;
200
- });
201
- }
202
- signout() {
203
- return __awaiter(this, void 0, void 0, function* () {
204
- if (yield !this.isAuthenticated())
205
- this.router.navigate(['/Admin/account/login']),
206
- localStorage.clear();
207
- yield this.manager.signoutRedirect();
208
- });
209
- }
210
- }
211
- AuthService.user = null;
212
- AuthService.ɵprov = i0.ɵɵdefineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0.ɵɵinject(i1$1.HttpClient), i0.ɵɵinject(EnvironmentService), i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(i4.Router)); }, token: AuthService, providedIn: "root" });
213
- AuthService.decorators = [
214
- { type: Injectable, args: [{
215
- providedIn: 'root'
216
- },] }
217
- ];
218
- AuthService.ctorParameters = () => [
219
- { type: HttpClient },
220
- { type: EnvironmentService },
221
- { type: BBSFTranslateService },
222
- { type: Router }
223
- ];
224
-
225
- class UtilityService {
226
- constructor(translator, authService, environmentService) {
227
- this.translator = translator;
228
- this.authService = authService;
229
- this.environmentService = environmentService;
230
- this.isCreatedBefore = false;
231
- }
232
- getResourceValue(Key) {
233
- let ResourceValue = this.translator.instant(Key);
234
- return ResourceValue;
235
- }
236
- getCurrentLanguage() {
237
- let currentLanguage = this.environmentService.getDefaultLanguage();
238
- let lang = localStorage.getItem('language');
239
- if (lang)
240
- currentLanguage = lang;
241
- else
242
- localStorage.setItem('language', currentLanguage);
243
- return currentLanguage;
244
- }
245
- isCurrentLanguageEnglish() {
246
- return this.getCurrentLanguage() == "en";
247
- }
248
- isCurrentLanguageArabic() {
249
- return this.getCurrentLanguage() == "ar";
250
- }
251
- notifySuccessMessage(Message, title, time, showHeader = true) {
252
- let MessageTemplate = this.getResourceValue("SuccessMessage");
253
- let titleTemplate;
254
- if (Message) {
255
- MessageTemplate = Message;
256
- }
257
- if (title) {
258
- titleTemplate = title;
259
- }
260
- let toaster = AppInjector.get(ToastrService);
261
- showHeader ? toaster.success(MessageTemplate, titleTemplate) : toaster.success(MessageTemplate);
262
- }
263
- notifyErrorMessage(Message, title, time, showHeader = true) {
264
- let MessageTemplate = this.getResourceValue("ErrorMessage");
265
- let titleTemplate = this.getResourceValue("Error");
266
- if (Message) {
267
- MessageTemplate = Message;
268
- }
269
- if (title) {
270
- titleTemplate = title;
271
- }
272
- const toaster = AppInjector.get(ToastrService);
273
- showHeader ? toaster.error(MessageTemplate, titleTemplate) : toaster.error(MessageTemplate);
274
- }
275
- notifyWarningMessage(Message, title, time, showHeader = true) {
276
- let MessageTemplate = this.getResourceValue("WarningMessage");
277
- let titleTemplate = this.getResourceValue("Warning");
278
- if (Message) {
279
- MessageTemplate = Message;
280
- }
281
- if (title) {
282
- titleTemplate = title;
283
- }
284
- const toaster = AppInjector.get(ToastrService);
285
- showHeader ? toaster.warning(MessageTemplate, titleTemplate) : toaster.warning(MessageTemplate);
286
- }
287
- startBlockUI() {
288
- this.blockUI.start();
289
- }
290
- stopBlockUI() {
291
- this.blockUI.stop();
292
- }
293
- }
294
- UtilityService.ɵprov = i0.ɵɵdefineInjectable({ factory: function UtilityService_Factory() { return new UtilityService(i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(AuthService), i0.ɵɵinject(EnvironmentService)); }, token: UtilityService, providedIn: "root" });
295
- UtilityService.decorators = [
296
- { type: Injectable, args: [{
297
- providedIn: 'root'
298
- },] }
299
- ];
300
- UtilityService.ctorParameters = () => [
301
- { type: BBSFTranslateService },
302
- { type: AuthService },
303
- { type: EnvironmentService }
304
- ];
305
- __decorate([
306
- BlockUI()
307
- ], UtilityService.prototype, "blockUI", void 0);
308
-
309
86
  class RequestOptionsModel {
310
87
  constructor() {
311
88
  this.disableSuccessNotification = false;
@@ -474,15 +251,19 @@ class RequestHandlerService {
474
251
  }
475
252
  else {
476
253
  if (err.status == 400)
477
- throwError(err); //error 400 is thrown to be catch by the Form component to handle Fluent validation errors
254
+ throwError(err); //error 400 is thrown to be catch by the Form component to handle Fluent validation errors
478
255
  else if (err.status == 401)
479
256
  this.router.navigate(["/Admin/account/login"]);
480
257
  else if (err.status == 403)
481
258
  this.utilityService.notifyErrorMessage(isEnglish ? "Sorry, You're not authorized to access this action" : "عذرا ليس لديك الصلاحيه لهذا الطلب");
482
259
  else if (err.status == 510)
483
260
  this.utilityService.notifyErrorMessage(isEnglish ? "Can not delete this item as it is related to others" : "لا يمكن حذف هذا العنصر لأنه مرتبط بعناصر أخرى");
484
- else
485
- this.utilityService.notifyErrorMessage(`error message is: ${err.error ? err.error.Message : err.message}`);
261
+ else if (err.status == 515)
262
+ this.utilityService.notifyErrorMessage((err.error ? err.error.Message : err.message));
263
+ else {
264
+ console.log(`error message is: ${err.error ? err.error.Message : err.message}`);
265
+ this.utilityService.notifyErrorMessage(this.utilityService.getResourceValue("ErrorMassage"));
266
+ }
486
267
  }
487
268
  this.utilityService.stopBlockUI();
488
269
  }
@@ -547,7 +328,7 @@ class StylesBundleService {
547
328
  head.appendChild(style);
548
329
  }
549
330
  }
550
- StylesBundleService.ɵprov = i0.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0.ɵɵinject(i1$2.DOCUMENT), i0.ɵɵinject(BBSFTranslateService)); }, token: StylesBundleService, providedIn: "root" });
331
+ StylesBundleService.ɵprov = i0.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0.ɵɵinject(i1$1.DOCUMENT), i0.ɵɵinject(BBSFTranslateService)); }, token: StylesBundleService, providedIn: "root" });
551
332
  StylesBundleService.decorators = [
552
333
  { type: Injectable, args: [{
553
334
  providedIn: 'root'
@@ -558,45 +339,409 @@ StylesBundleService.ctorParameters = () => [
558
339
  { type: BBSFTranslateService }
559
340
  ];
560
341
 
561
- class ControlValidationService {
562
- constructor(utilityService) {
563
- this.utilityService = utilityService;
564
- this.requestOptions = new RequestOptionsModel();
565
- this.isCreatedBefor = false;
342
+ class MasterLayoutService {
343
+ constructor(router, http, authService, stylesBundleService, translate, environmentService) {
344
+ this.router = router;
345
+ this.http = http;
346
+ this.authService = authService;
347
+ this.stylesBundleService = stylesBundleService;
348
+ this.translate = translate;
349
+ this.environmentService = environmentService;
350
+ this.ApiUrl = '/api/Home/';
566
351
  }
567
- showGlobalError(errorMessage, formId, deleteOld) {
568
- let globalErorrElement = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
569
- if (globalErorrElement.length > 0) {
570
- this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
571
- }
572
- if (this.isCreatedBefor == true) {
573
- this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
574
- }
575
- // tslint:disable-next-line: prefer-const
576
- if (!formId)
577
- formId = "currentForm";
578
- var object = document.getElementById(formId);
579
- const tagName = 'div';
580
- // tslint:disable-next-line: prefer-const
581
- var elementToAppend = document.createElement(tagName); // Your tag name here
582
- let message = "";
583
- if (!errorMessage || (typeof errorMessage == "string")) {
584
- if (localStorage.getItem('language') == "ar")
585
- message = errorMessage ? errorMessage : "لديك بعص الأخطاء . من فضلك قم بالمراجعه ";
586
- else
587
- message = errorMessage ? errorMessage : "You have some validation errors. Please check below";
588
- elementToAppend.innerHTML = "<ul class='list-unstyled m-0 py-3 d-flex align-items-center fs-6'><li><i class='fa fa-times-circle text-danger me-3 fs-2'></i>" + message + "</li></ul>";
589
- elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
590
- elementToAppend.id += 'errorId';
591
- // tslint:disable-next-line: prefer-for-of
592
- const elementToAppen = elementToAppend.cloneNode(true);
593
- // let targetElement = object.getElementsByClassName("b-control")[0];
594
- object.insertBefore(elementToAppen, object.firstChild);
595
- }
596
- else {
597
- elementToAppend.innerHTML = "<ul>";
598
- for (const iterator of errorMessage) {
599
- elementToAppend.innerHTML = "<li>" + iterator + "</li>";
352
+ switchLang(lang, bundleEnglishName, bundleArabicName) {
353
+ this.changeLanguage(lang).subscribe((result) => {
354
+ this.updateUserInfo().subscribe((Value) => {
355
+ let UserInfoObject = Value;
356
+ this.authService.getUser();
357
+ this.authService.user.profile = Object.assign(this.authService.user.profile, UserInfoObject);
358
+ this.authService.storUser(this.authService.user);
359
+ this.stylesBundleService.loadThemes(lang, bundleEnglishName, bundleArabicName);
360
+ localStorage.setItem('language', lang);
361
+ this.translate.use(lang);
362
+ });
363
+ });
364
+ }
365
+ reloadComponent() {
366
+ let currentUrl = this.router.url;
367
+ this.router.routeReuseStrategy.shouldReuseRoute = () => false;
368
+ this.router.onSameUrlNavigation = 'reload';
369
+ this.router.navigate([currentUrl]);
370
+ }
371
+ changeLanguage(key) {
372
+ let params = new HttpParams();
373
+ params = params.append('UserId', this.authService.user.profile.id);
374
+ params = params.append('LanguageKey', key);
375
+ return this.http.post(this.ApiUrl + 'UpdateLanguage', null, null, params);
376
+ }
377
+ getUserClaims() {
378
+ return this.http.get(this.ApiUrl + 'GetUserClaims', null, null);
379
+ }
380
+ logError(error) {
381
+ let params = new HttpParams();
382
+ params = params.append('error', error);
383
+ return this.http.post(this.ApiUrl + 'LogError', null, null, params);
384
+ }
385
+ updateUserInfo() {
386
+ if (this.environmentService.getIsIdentityServerExternal())
387
+ return this.getUserClaims();
388
+ return this.http.get('/connect/userinfo');
389
+ }
390
+ switchRole(permissionSetID) {
391
+ this.updateRole(permissionSetID).subscribe((result) => {
392
+ this.updateUserInfo().subscribe((Value) => {
393
+ let UserInfoObject = Value;
394
+ this.authService.getUser();
395
+ this.authService.user.profile = Object.assign(this.authService.user.profile, UserInfoObject);
396
+ this.authService.storUser(this.authService.user);
397
+ });
398
+ });
399
+ }
400
+ updateRole(permissionSetID) {
401
+ let params = new HttpParams();
402
+ params = params.append('UserId', this.authService.user.profile.id);
403
+ params = params.append('RoleID', permissionSetID);
404
+ return this.http.post(this.ApiUrl + 'SwitchRole', null, null, params);
405
+ }
406
+ }
407
+ 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" });
408
+ MasterLayoutService.decorators = [
409
+ { type: Injectable, args: [{
410
+ providedIn: 'root',
411
+ },] }
412
+ ];
413
+ MasterLayoutService.ctorParameters = () => [
414
+ { type: Router },
415
+ { type: RequestHandlerService },
416
+ { type: AuthService },
417
+ { type: StylesBundleService },
418
+ { type: TranslateService },
419
+ { type: EnvironmentService }
420
+ ];
421
+
422
+ class AuthService {
423
+ constructor(injector, http, environmentService, translateService, router) {
424
+ this.injector = injector;
425
+ this.http = http;
426
+ this.environmentService = environmentService;
427
+ this.translateService = translateService;
428
+ this.router = router;
429
+ // Observable navItem source
430
+ this._authNavStatusSource = new BehaviorSubject(false);
431
+ // Observable navItem stream
432
+ this.authNavStatus$ = this._authNavStatusSource.asObservable();
433
+ // Observable navItem source
434
+ this._userSource = new Subject();
435
+ this.UserStatus$ = this._userSource.asObservable();
436
+ this.manager = this.getUserManager();
437
+ this.redirectUrl = '';
438
+ this.manager.getUser().then((user) => __awaiter(this, void 0, void 0, function* () {
439
+ this.manager.storeUser(user);
440
+ AuthService.user = user;
441
+ this.user = user;
442
+ this._authNavStatusSource.next(yield this.isAuthenticated());
443
+ }));
444
+ this.manager.events.addAccessTokenExpired((_) => {
445
+ this._authNavStatusSource.next(false);
446
+ });
447
+ }
448
+ getUserManager() {
449
+ let user = null;
450
+ let isExternal = this.environmentService.getIsIdentityServerExternal().toLowerCase() == "true";
451
+ if (isExternal) {
452
+ user = new UserManager({
453
+ authority: this.environmentService.getIdentityServerUrl(),
454
+ client_id: this.environmentService.getIsIdentityServerClientId(),
455
+ client_secret: this.environmentService.getIsIdentityServerClientSecret(),
456
+ redirect_uri: this.environmentService.getBaseUrl() +
457
+ '/Admin/authentication/auth-callback',
458
+ post_logout_redirect_uri: this.environmentService.getBaseUrl(),
459
+ response_type: 'code',
460
+ scope: 'openid profile email',
461
+ filterProtocolClaims: true,
462
+ loadUserInfo: true,
463
+ automaticSilentRenew: true,
464
+ silent_redirect_uri: this.environmentService.getBaseUrl() + '/assets/silent-callback.html',
465
+ userStore: new WebStorageStateStore({ store: window.localStorage }),
466
+ });
467
+ }
468
+ else {
469
+ user = new UserManager({
470
+ authority: this.environmentService.getIdentityServerUrl(),
471
+ client_id: 'angular_spa',
472
+ redirect_uri: this.environmentService.getBaseUrl() +
473
+ '/Admin/authentication/auth-callback',
474
+ post_logout_redirect_uri: this.environmentService.getBaseUrl(),
475
+ response_type: 'id_token token',
476
+ scope: 'openid profile email IdentityServerApi',
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
+ return user;
485
+ }
486
+ login() {
487
+ return this.manager.signinRedirect();
488
+ }
489
+ getUser() {
490
+ this.manager.getUser().then((user) => __awaiter(this, void 0, void 0, function* () {
491
+ AuthService.user = user;
492
+ this.user = user;
493
+ this._authNavStatusSource.next(yield this.isAuthenticated());
494
+ }));
495
+ }
496
+ storUser(User) {
497
+ this.manager.storeUser(User);
498
+ }
499
+ revokeAccessToken() {
500
+ this.manager.revokeAccessToken();
501
+ }
502
+ signinSilent() {
503
+ let x = this.manager.signinSilentCallback();
504
+ x.then((s) => {
505
+ //console.log(s)
506
+ });
507
+ }
508
+ completeAuthentication() {
509
+ return __awaiter(this, void 0, void 0, function* () {
510
+ this.user = yield this.manager.signinRedirectCallback();
511
+ AuthService.user = this.user;
512
+ this._userSource.next(AuthService.user);
513
+ this._authNavStatusSource.next(yield this.isAuthenticated());
514
+ let isExternal = this.environmentService.getIsIdentityServerExternal().toLowerCase() == "true";
515
+ if (isExternal) {
516
+ const masterLayoutService = this.injector.get(MasterLayoutService);
517
+ let userClaims = yield masterLayoutService
518
+ .getUserClaims()
519
+ .toPromise()
520
+ .then((e) => {
521
+ AuthService.UserClaims = e;
522
+ });
523
+ AuthService.user.profile = Object.assign(AuthService.user.profile, AuthService.UserClaims);
524
+ }
525
+ this.storUser(AuthService.user);
526
+ if (!localStorage.getItem('language') ||
527
+ localStorage.getItem('language') == this.user.profile.locale)
528
+ localStorage.setItem('language', this.user.profile.locale);
529
+ if (this.translateService.currentLang != localStorage.getItem('language')) {
530
+ this.translateService.resetLang(this.translateService.currentLang);
531
+ yield this.translateService
532
+ .reloadLang(localStorage.getItem('language'))
533
+ .subscribe((res) => {
534
+ console.log(res);
535
+ });
536
+ }
537
+ this._userSource.next(AuthService.user);
538
+ this._authNavStatusSource.next(yield this.isAuthenticated());
539
+ this.user = AuthService.user;
540
+ });
541
+ }
542
+ refreshToken(token) {
543
+ return __awaiter(this, void 0, void 0, function* () {
544
+ const httpOptions = {
545
+ headers: new HttpHeaders({
546
+ 'Content-Type': 'application/json',
547
+ Authorization: token,
548
+ }),
549
+ };
550
+ this.manager.revokeAccessToken();
551
+ return yield this.http
552
+ .post(`${this.environmentService.getIdentityServerUrl()}/users/refresh-token`, httpOptions, { withCredentials: true })
553
+ .subscribe((user) => {
554
+ this._userSource.next(user);
555
+ AuthService.user = user;
556
+ this.user = user;
557
+ });
558
+ });
559
+ }
560
+ getCurrentUser() {
561
+ return this.manager.getUser();
562
+ }
563
+ isAuthenticated() {
564
+ return __awaiter(this, void 0, void 0, function* () {
565
+ let user = yield this.manager.getUser().then((user) => {
566
+ return user;
567
+ });
568
+ return this.user != null && !this.user.expired;
569
+ });
570
+ }
571
+ isUserInRole(allowedPermission) {
572
+ let selectedPermissionSetID = Number.parseInt(this.user.profile['selectedpermissionsetid']);
573
+ return allowedPermission.includes(selectedPermissionSetID);
574
+ }
575
+ authorizationHeaderValue() {
576
+ return AuthService.user
577
+ ? `${AuthService.user.token_type} ${AuthService.user.access_token}`
578
+ : '';
579
+ }
580
+ name() {
581
+ return AuthService.user != null ? AuthService.user.profile.given_name : '';
582
+ }
583
+ setUrl(url) {
584
+ localStorage.setItem('redirectUrl', url);
585
+ }
586
+ getUrl() {
587
+ return localStorage.getItem('redirectUrl');
588
+ }
589
+ signinSilentCallback() {
590
+ return __awaiter(this, void 0, void 0, function* () {
591
+ let user = yield this.manager.signinSilentCallback();
592
+ //await this.manager.storeUser(user);
593
+ AuthService.user = user;
594
+ console.log('Token from signinSilentCallback :' + AuthService.user);
595
+ this.user = user;
596
+ });
597
+ }
598
+ signout() {
599
+ return __awaiter(this, void 0, void 0, function* () {
600
+ if (yield !this.isAuthenticated())
601
+ this.router.navigate(['/Admin/account/login']), localStorage.clear();
602
+ yield this.manager.signoutRedirect();
603
+ });
604
+ }
605
+ }
606
+ AuthService.user = null;
607
+ AuthService.UserClaims = null;
608
+ 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" });
609
+ AuthService.decorators = [
610
+ { type: Injectable, args: [{
611
+ providedIn: 'root',
612
+ },] }
613
+ ];
614
+ AuthService.ctorParameters = () => [
615
+ { type: Injector },
616
+ { type: HttpClient },
617
+ { type: EnvironmentService },
618
+ { type: BBSFTranslateService },
619
+ { type: Router }
620
+ ];
621
+
622
+ class UtilityService {
623
+ constructor(translator, authService, environmentService) {
624
+ this.translator = translator;
625
+ this.authService = authService;
626
+ this.environmentService = environmentService;
627
+ this.isCreatedBefore = false;
628
+ }
629
+ getResourceValue(Key) {
630
+ let ResourceValue = this.translator.instant(Key);
631
+ return ResourceValue;
632
+ }
633
+ getCurrentLanguage() {
634
+ let currentLanguage = this.environmentService.getDefaultLanguage();
635
+ let lang = localStorage.getItem('language');
636
+ if (lang)
637
+ currentLanguage = lang;
638
+ else
639
+ localStorage.setItem('language', currentLanguage);
640
+ return currentLanguage;
641
+ }
642
+ isCurrentLanguageEnglish() {
643
+ return this.getCurrentLanguage() == "en";
644
+ }
645
+ isCurrentLanguageArabic() {
646
+ return this.getCurrentLanguage() == "ar";
647
+ }
648
+ notifySuccessMessage(Message, title, time, showHeader = true) {
649
+ let MessageTemplate = this.getResourceValue("SuccessMessage");
650
+ let titleTemplate;
651
+ if (Message) {
652
+ MessageTemplate = Message;
653
+ }
654
+ if (title) {
655
+ titleTemplate = title;
656
+ }
657
+ let toaster = AppInjector.get(ToastrService);
658
+ showHeader ? toaster.success(MessageTemplate, titleTemplate) : toaster.success(MessageTemplate);
659
+ }
660
+ notifyErrorMessage(Message, title, time, showHeader = true) {
661
+ let MessageTemplate = this.getResourceValue("ErrorMessage");
662
+ let titleTemplate = this.getResourceValue("Error");
663
+ if (Message) {
664
+ MessageTemplate = Message;
665
+ }
666
+ if (title) {
667
+ titleTemplate = title;
668
+ }
669
+ const toaster = AppInjector.get(ToastrService);
670
+ showHeader ? toaster.error(MessageTemplate, titleTemplate) : toaster.error(MessageTemplate);
671
+ }
672
+ notifyWarningMessage(Message, title, time, showHeader = true) {
673
+ let MessageTemplate = this.getResourceValue("WarningMessage");
674
+ let titleTemplate = this.getResourceValue("Warning");
675
+ if (Message) {
676
+ MessageTemplate = Message;
677
+ }
678
+ if (title) {
679
+ titleTemplate = title;
680
+ }
681
+ const toaster = AppInjector.get(ToastrService);
682
+ showHeader ? toaster.warning(MessageTemplate, titleTemplate) : toaster.warning(MessageTemplate);
683
+ }
684
+ startBlockUI() {
685
+ this.blockUI.start();
686
+ }
687
+ stopBlockUI() {
688
+ this.blockUI.stop();
689
+ }
690
+ }
691
+ UtilityService.ɵprov = i0.ɵɵdefineInjectable({ factory: function UtilityService_Factory() { return new UtilityService(i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(AuthService), i0.ɵɵinject(EnvironmentService)); }, token: UtilityService, providedIn: "root" });
692
+ UtilityService.decorators = [
693
+ { type: Injectable, args: [{
694
+ providedIn: 'root'
695
+ },] }
696
+ ];
697
+ UtilityService.ctorParameters = () => [
698
+ { type: BBSFTranslateService },
699
+ { type: AuthService },
700
+ { type: EnvironmentService }
701
+ ];
702
+ __decorate([
703
+ BlockUI()
704
+ ], UtilityService.prototype, "blockUI", void 0);
705
+
706
+ class ControlValidationService {
707
+ constructor(utilityService) {
708
+ this.utilityService = utilityService;
709
+ this.requestOptions = new RequestOptionsModel();
710
+ this.isCreatedBefor = false;
711
+ }
712
+ showGlobalError(errorMessage, formId, deleteOld) {
713
+ let globalErorrElement = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
714
+ if (globalErorrElement.length > 0) {
715
+ this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
716
+ }
717
+ if (this.isCreatedBefor == true) {
718
+ this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
719
+ }
720
+ // tslint:disable-next-line: prefer-const
721
+ if (!formId)
722
+ formId = "currentForm";
723
+ var object = document.getElementById(formId);
724
+ const tagName = 'div';
725
+ // tslint:disable-next-line: prefer-const
726
+ var elementToAppend = document.createElement(tagName); // Your tag name here
727
+ let message = "";
728
+ if (!errorMessage || (typeof errorMessage == "string")) {
729
+ if (localStorage.getItem('language') == "ar")
730
+ message = errorMessage ? errorMessage : "لديك بعص الأخطاء . من فضلك قم بالمراجعه ";
731
+ else
732
+ message = errorMessage ? errorMessage : "You have some validation errors. Please check below";
733
+ elementToAppend.innerHTML = "<ul class='list-unstyled m-0 py-3 d-flex align-items-center fs-6'><li><i class='fa fa-times-circle text-danger me-3 fs-2'></i>" + message + "</li></ul>";
734
+ elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
735
+ elementToAppend.id += 'errorId';
736
+ // tslint:disable-next-line: prefer-for-of
737
+ const elementToAppen = elementToAppend.cloneNode(true);
738
+ // let targetElement = object.getElementsByClassName("b-control")[0];
739
+ object.insertBefore(elementToAppen, object.firstChild);
740
+ }
741
+ else {
742
+ elementToAppend.innerHTML = "<ul>";
743
+ for (const iterator of errorMessage) {
744
+ elementToAppend.innerHTML = "<li>" + iterator + "</li>";
600
745
  }
601
746
  elementToAppend.innerHTML = "</ul>";
602
747
  elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
@@ -719,93 +864,19 @@ __decorate([
719
864
  BlockUI()
720
865
  ], ControlValidationService.prototype, "blockUI", void 0);
721
866
 
722
- class MasterLayoutService {
723
- constructor(router, http, authService, stylesBundleService, translate) {
724
- this.router = router;
725
- this.http = http;
726
- this.authService = authService;
727
- this.stylesBundleService = stylesBundleService;
728
- this.translate = translate;
729
- this.ApiUrl = "/api/Home/";
730
- }
731
- switchLang(lang, bundleEnglishName, bundleArabicName) {
732
- this.changeLanguage(lang).subscribe((result) => {
733
- this.updateUserInfo().subscribe((Value) => {
734
- let UserInfoObject = Value;
735
- this.authService.getUser();
736
- this.authService.user.profile = Object.assign(this.authService.user.profile, UserInfoObject);
737
- this.authService.storUser(this.authService.user);
738
- this.stylesBundleService.loadThemes(lang, bundleEnglishName, bundleArabicName);
739
- localStorage.setItem('language', lang);
740
- this.translate.use(lang);
741
- });
742
- });
743
- }
744
- reloadComponent() {
745
- let currentUrl = this.router.url;
746
- this.router.routeReuseStrategy.shouldReuseRoute = () => false;
747
- this.router.onSameUrlNavigation = 'reload';
748
- this.router.navigate([currentUrl]);
749
- }
750
- changeLanguage(key) {
751
- let params = new HttpParams();
752
- params = params.append("UserId", this.authService.user.profile.id);
753
- params = params.append("LanguageKey", key);
754
- return this.http.post(this.ApiUrl + 'UpdateLanguage', null, null, params);
755
- }
756
- logError(error) {
757
- let params = new HttpParams();
758
- params = params.append("error", error);
759
- return this.http.post(this.ApiUrl + 'LogError', null, null, params);
760
- }
761
- updateUserInfo() {
762
- return this.http.get('/connect/userinfo');
763
- }
764
- switchRole(permissionSetID) {
765
- this.updateRole(permissionSetID).subscribe((result) => {
766
- this.updateUserInfo().subscribe((Value) => {
767
- let UserInfoObject = Value;
768
- this.authService.getUser();
769
- this.authService.user.profile = Object.assign(this.authService.user.profile, UserInfoObject);
770
- this.authService.storUser(this.authService.user);
771
- });
772
- });
773
- }
774
- updateRole(permissionSetID) {
775
- let params = new HttpParams();
776
- params = params.append("UserId", this.authService.user.profile.id);
777
- params = params.append("RoleID", permissionSetID);
778
- return this.http.post(this.ApiUrl + 'SwitchRole', null, null, params);
779
- }
780
- }
781
- 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)); }, token: MasterLayoutService, providedIn: "root" });
782
- MasterLayoutService.decorators = [
783
- { type: Injectable, args: [{
784
- providedIn: 'root'
785
- },] }
786
- ];
787
- MasterLayoutService.ctorParameters = () => [
788
- { type: Router },
789
- { type: RequestHandlerService },
790
- { type: AuthService },
791
- { type: StylesBundleService },
792
- { type: TranslateService }
793
- ];
794
-
795
867
  class ConfigurationService {
796
868
  constructor(httpClient) {
797
869
  this.httpClient = httpClient;
798
- this.jsonData = [];
799
870
  this.httpClient.get("./assets/config/configurations.json").subscribe(data => {
800
- console.log(data);
801
- this.jsonData = data;
871
+ ConfigurationService.JsonData = data;
802
872
  });
803
873
  }
804
874
  getConfigurationValue(key) {
805
- return this.jsonData[key];
875
+ return ConfigurationService.JsonData[key];
806
876
  }
807
877
  }
808
- ConfigurationService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ConfigurationService_Factory() { return new ConfigurationService(i0.ɵɵinject(i1$1.HttpClient)); }, token: ConfigurationService, providedIn: "root" });
878
+ ConfigurationService.JsonData = [];
879
+ ConfigurationService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ConfigurationService_Factory() { return new ConfigurationService(i0.ɵɵinject(i1$3.HttpClient)); }, token: ConfigurationService, providedIn: "root" });
809
880
  ConfigurationService.decorators = [
810
881
  { type: Injectable, args: [{
811
882
  providedIn: 'root'