@bnsights/bbsf-utilities 1.0.60 → 1.0.65

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,19 @@
1
- import { DOCUMENT, CommonModule } from '@angular/common';
1
+ import { CommonModule, DOCUMENT } from '@angular/common';
2
+ import * as i1$1 from '@angular/common/http';
3
+ import { HttpClientModule, HttpHeaders, HttpParams, HttpErrorResponse } from '@angular/common/http';
2
4
  import * as i0 from '@angular/core';
3
- import { Injectable, Inject, inject, NgModule } from '@angular/core';
4
- import * as i1$1 from '@angular/router';
5
- import { RouterModule } from '@angular/router';
6
- import * as i4 from '@ngx-translate/core';
7
- import { TranslateService } from '@ngx-translate/core';
8
- import * as i1$2 from 'ng-block-ui';
9
- import { BlockUI, BlockUIModule } from 'ng-block-ui';
10
- import * as i2 from 'ngx-toastr';
11
- import { ToastrService, ToastrModule } from 'ngx-toastr';
12
- import * as i4$1 from 'ngx-cookie-service';
13
- import { CookieService } from 'ngx-cookie-service';
14
- import * as i1 from '@angular/common/http';
15
- import { HttpParams, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
16
- import { Subject, throwError, Observable, lastValueFrom, BehaviorSubject } from 'rxjs';
17
- import { JwtHelperService } from '@auth0/angular-jwt';
5
+ import { NgModule, Injectable, inject, Inject } from '@angular/core';
6
+ import * as i3 from '@angular/router';
7
+ import { RouterModule, Router } from '@angular/router';
8
+ import * as i1 from 'ng-block-ui';
9
+ import { BlockUIModule, BlockUI } from 'ng-block-ui';
10
+ import { provideToastr, ToastrService } from 'ngx-toastr';
18
11
  import { __decorate } from 'tslib';
12
+ import { BehaviorSubject, Subject, throwError, Observable, lastValueFrom } from 'rxjs';
13
+ import { JwtHelperService } from '@auth0/angular-jwt';
14
+ import * as i4 from 'ngx-cookie-service';
15
+ import * as i4$1 from '@ngx-translate/core';
16
+ import { TranslateService } from '@ngx-translate/core';
19
17
  import { plainToClass } from 'class-transformer';
20
18
  import { takeUntil, tap, map } from 'rxjs/operators';
21
19
  import JSZip from 'jszip';
@@ -33,16 +31,33 @@ import imageToBase64 from 'image-to-base64';
33
31
  import mimeTypes from 'mime-types';
34
32
  import sizeOf from 'image-size';
35
33
 
36
- class User {
34
+ class BBSFUtilitiesModule {
35
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: BBSFUtilitiesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
36
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.6", ngImport: i0, type: BBSFUtilitiesModule, imports: [CommonModule,
37
+ RouterModule, i1.BlockUIModule, HttpClientModule] }); }
38
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: BBSFUtilitiesModule, providers: [
39
+ provideToastr(),
40
+ ], imports: [CommonModule,
41
+ RouterModule,
42
+ BlockUIModule.forRoot(),
43
+ HttpClientModule] }); }
37
44
  }
38
-
39
- var AuthenticationModes;
40
- (function (AuthenticationModes) {
41
- AuthenticationModes["Forms"] = "Forms";
42
- AuthenticationModes["UAEPass"] = "UAEPass";
43
- AuthenticationModes["WindowsAD"] = "WindowsAD";
44
- AuthenticationModes["AzureAD"] = "AzureAD";
45
- })(AuthenticationModes || (AuthenticationModes = {}));
45
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: BBSFUtilitiesModule, decorators: [{
46
+ type: NgModule,
47
+ args: [{
48
+ declarations: [],
49
+ imports: [
50
+ CommonModule,
51
+ RouterModule,
52
+ BlockUIModule.forRoot(),
53
+ HttpClientModule
54
+ ],
55
+ exports: [],
56
+ providers: [
57
+ provideToastr(),
58
+ ]
59
+ }]
60
+ }] });
46
61
 
47
62
  class AppearanceConfigurationService {
48
63
  constructor(configService) {
@@ -76,193 +91,428 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImpor
76
91
  }]
77
92
  }], ctorParameters: () => [{ type: ConfigurationService }] });
78
93
 
79
- class ConfigurationService {
80
- static { this.JsonData = []; }
81
- constructor(httpClient, authService) {
82
- this.httpClient = httpClient;
83
- this.authService = authService;
84
- this.httpClient.get("./assets/config/configurations.json")
85
- .subscribe(data => {
86
- ConfigurationService.JsonData = data;
87
- });
88
- this.currentUserProfile = this.authService.getCurrentUser()?.profile;
89
- }
90
- getConfigurationValue(key) {
91
- var selectedKey = ConfigurationService.JsonData[key];
92
- if (selectedKey && typeof selectedKey === 'object') {
93
- if (selectedKey.OrganizationConfigurations) {
94
- if (this.currentUserProfile && this.currentUserProfile.organizationGUID_ID) {
95
- let organizationValue = Array(selectedKey.OrganizationConfigurations).find(o => o.OrganizationID_GUID == this.currentUserProfile.organizationGUID_ID);
96
- return organizationValue;
97
- }
98
- }
99
- else {
100
- return selectedKey.Value;
101
- }
102
- }
103
- else {
104
- return selectedKey;
105
- }
106
- }
107
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: ConfigurationService, deps: [{ token: i1.HttpClient }, { token: AuthService }], target: i0.ɵɵFactoryTarget.Injectable }); }
108
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: ConfigurationService, providedIn: 'root' }); }
109
- }
110
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: ConfigurationService, decorators: [{
111
- type: Injectable,
112
- args: [{
113
- providedIn: 'root'
114
- }]
115
- }], ctorParameters: () => [{ type: i1.HttpClient }, { type: AuthService }] });
116
-
117
- class AreaModel {
118
- }
119
-
120
- class ErrorModel {
121
- }
122
-
123
- class RequestOptionsModel {
124
- constructor() {
125
- this.disableSuccessNotification = false;
126
- this.disableBlockUI = false;
127
- this.disableErrorHandler = false;
128
- this.responseType = "";
129
- this.formGroup = null;
130
- this.castResponsetoClass = true;
131
- }
132
- }
133
-
134
- class WordDocumentModel {
135
- constructor() {
136
- this.options = new DocumentOptionsModel();
137
- }
138
- }
139
- class DocumentOptionsModel {
94
+ class User {
140
95
  }
141
96
 
142
- class LanguageDTO {
143
- }
97
+ var AuthenticationModes;
98
+ (function (AuthenticationModes) {
99
+ AuthenticationModes["Forms"] = "Forms";
100
+ AuthenticationModes["UAEPass"] = "UAEPass";
101
+ AuthenticationModes["WindowsAD"] = "WindowsAD";
102
+ AuthenticationModes["AzureAD"] = "AzureAD";
103
+ })(AuthenticationModes || (AuthenticationModes = {}));
144
104
 
145
- class ControlValidationService {
146
- constructor(utilityService) {
105
+ const TOKEN_KEY = 'access_token';
106
+ class AuthService {
107
+ static { this.user = null; }
108
+ static { this.UserClaims = null; }
109
+ //refresh
110
+ static { this.timers = []; }
111
+ static { this.seconds = 0; }
112
+ constructor(injector, http, environmentService, translateService, router, cookieService, utilityService) {
113
+ this.injector = injector;
114
+ this.http = http;
115
+ this.environmentService = environmentService;
116
+ this.translateService = translateService;
117
+ this.router = router;
118
+ this.cookieService = cookieService;
147
119
  this.utilityService = utilityService;
148
- this.requestOptions = new RequestOptionsModel();
149
- this.isCreatedBefor = false;
120
+ this.redirectUrl = '';
121
+ this.jwtHelper = new JwtHelperService();
122
+ this.isAuthenticatedSubject = new BehaviorSubject(this.hasToken());
123
+ this.isAuthenticate$ = this.isAuthenticatedSubject.asObservable();
124
+ this.user = this.getUserManager();
150
125
  }
151
- showGlobalError(errorMessage, formId, deleteOld) {
152
- let globalErorrElement = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
153
- if (globalErorrElement.length > 0) {
154
- this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
155
- }
156
- if (this.isCreatedBefor == true) {
157
- this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
158
- }
159
- // tslint:disable-next-line: prefer-const
160
- if (!formId)
161
- formId = "currentForm";
162
- var object = document.getElementById(formId);
163
- const tagName = 'div';
164
- // tslint:disable-next-line: prefer-const
165
- var elementToAppend = document.createElement(tagName); // Your tag name here
166
- let message = "";
167
- if (!errorMessage || (typeof errorMessage == "string")) {
168
- if (localStorage.getItem('language') == "ar")
169
- message = errorMessage ? errorMessage : "لديك بعص الأخطاء . من فضلك قم بالمراجعه ";
126
+ hasToken() {
127
+ const token = this.cookieService.get(TOKEN_KEY);
128
+ return token && !this.jwtHelper.isTokenExpired(token);
129
+ }
130
+ getUserManager() {
131
+ const token = this.cookieService.get(TOKEN_KEY);
132
+ if (token) {
133
+ if (!this.jwtHelper.isTokenExpired(token))
134
+ this.handleAccessTokenWithoutLanguage(token);
170
135
  else
171
- message = errorMessage ? errorMessage : "You have some validation errors. Please check below";
172
- 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>";
173
- elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
174
- elementToAppend.id += 'errorId';
175
- // tslint:disable-next-line: prefer-for-of
176
- const elementToAppen = elementToAppend.cloneNode(true);
177
- // let targetElement = object.getElementsByClassName("b-control")[0];
178
- object.insertBefore(elementToAppen, object.firstChild);
136
+ this.cookieService.delete(TOKEN_KEY, '/');
179
137
  }
180
138
  else {
181
- let ul = document.createElement("ul");
182
- elementToAppend.appendChild(ul);
183
- for (const iterator of errorMessage) {
184
- let li = document.createElement("li");
185
- li.innerHTML = iterator;
186
- ul.appendChild(li);
187
- }
188
- elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
189
- elementToAppend.id += 'errorId';
190
- // tslint:disable-next-line: prefer-for-of
191
- const elementToAppen = elementToAppend.cloneNode(true);
192
- // let targetElement = object.getElementsByClassName("b-control")[0];
193
- object.insertBefore(elementToAppen, object.firstChild);
194
- }
195
- this.isCreatedBefor = true;
196
- }
197
- removeGlobalError() {
198
- const removedList = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
199
- // tslint:disable-next-line: prefer-for-of
200
- for (let index = 0; index < removedList.length; index++) {
201
- const element = removedList[index];
202
- element.remove();
139
+ AuthService.timers.map(t => clearInterval(t));
140
+ AuthService.timers = [];
141
+ AuthService.user = null;
142
+ this.user = null;
203
143
  }
204
- this.isCreatedBefor = false;
144
+ return AuthService.user;
205
145
  }
206
- showInputErro(errors) {
207
- // show error on top of form
208
- this.showGlobalError();
209
- // remove old error from server
210
- this.removeElementsByClass('errortemplet');
211
- // Looping in error Object
212
- for (const key in errors) {
213
- if (errors.hasOwnProperty(key)) {
214
- for (const iterator of errors[key]) {
215
- const input = document.querySelectorAll('[ng-reflect-name=' + key + ']')[0];
216
- if (input.attributes['ng-reflect-name'].value === key) {
217
- this.removeElementsByClass('erroclass-' + key);
218
- const tagName = 'p';
219
- const elementToAppend = document.createElement(tagName); // Your tag name here
220
- elementToAppend.innerHTML = iterator;
221
- elementToAppend.style.color = 'red';
222
- elementToAppend.className += 'errortemplet erroclass-' + key;
223
- const elementToappen = elementToAppend.cloneNode(true);
224
- input.parentNode.insertBefore(elementToappen, input.lastChild);
225
- break;
226
- }
227
- }
228
- }
229
- }
146
+ getUser() {
147
+ this.user = AuthService.user;
230
148
  }
231
- removeElementsByClass(className) {
232
- const elements = document.getElementsByClassName(className);
233
- while (elements.length > 0) {
234
- elements[0].parentNode.removeChild(elements[0]);
235
- }
149
+ storUser(User) {
150
+ AuthService.user = this.user = this.user;
236
151
  }
237
- renderServerErrors(form, err, requestOptions, formId) {
238
- if (err.error == null) {
239
- return;
240
- }
241
- let errorsArray = [];
242
- this.requestOptions = requestOptions;
243
- if (err.error.validation_errors) {
244
- err.error.validation_errors.forEach((element) => {
245
- let fieldName = element.field;
246
- let controlName = element.controlName;
247
- let message = element.message;
248
- if (form == null) {
249
- this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(`${message}`);
250
- }
251
- else if (controlName && !this.hasControlName(form, controlName)) {
252
- errorsArray.push(`${fieldName}: ${message}`);
253
- }
254
- else {
255
- this.setFieldError(form, controlName, fieldName, message);
256
- this.showGlobalError(null, formId);
257
- }
258
- });
259
- if (errorsArray.length > 0)
260
- this.showGlobalError(errorsArray, formId);
261
- }
152
+ getCurrentUser() {
153
+ return AuthService.user;
262
154
  }
263
- hasControlName(form, controlName) {
264
- let control = form.get(controlName);
265
- return control != null;
155
+ isAuthenticated() {
156
+ return AuthService.user != null && !this.jwtHelper.isTokenExpired(AuthService.user.access_token);
157
+ }
158
+ isUserInRole(allowedPermission) {
159
+ let selectedPermissionSetID = Number.parseInt(AuthService.user.profile['selectedpermissionsetid']);
160
+ return allowedPermission.includes(selectedPermissionSetID);
161
+ }
162
+ authorizationHeaderValue() {
163
+ return AuthService.user
164
+ ? `${AuthService.user.token_type} ${AuthService.user.access_token}`
165
+ : '';
166
+ }
167
+ name() {
168
+ return AuthService.user != null ? AuthService.user.profile.given_name : '';
169
+ }
170
+ setUrl(url) {
171
+ localStorage.setItem('redirectUrl', url);
172
+ }
173
+ getUrl() {
174
+ return localStorage.getItem('redirectUrl') ?? "/";
175
+ }
176
+ signOut() {
177
+ let isAuthenticated = this.isAuthenticated();
178
+ this.cookieService.delete(TOKEN_KEY, '/');
179
+ AuthService.timers.map(t => clearInterval(t));
180
+ AuthService.timers = [];
181
+ AuthService.user = null;
182
+ this.user = null;
183
+ localStorage.removeItem("redirectUrl");
184
+ if (isAuthenticated) {
185
+ this.logout().subscribe(res => {
186
+ if (this.environmentService.getBBSFAuthenticationMode() == AuthenticationModes.UAEPass)
187
+ this.logoutFromUAEPass();
188
+ else
189
+ this.router.navigate(['/Admin/account/login']);
190
+ });
191
+ }
192
+ else {
193
+ if (this.environmentService.getBBSFAuthenticationMode() == AuthenticationModes.UAEPass)
194
+ this.logoutFromUAEPass();
195
+ else
196
+ this.router.navigate(['/Admin/account/login']);
197
+ }
198
+ }
199
+ logout() {
200
+ const httpOptions = {
201
+ headers: new HttpHeaders({
202
+ 'Content-Type': 'application/json',
203
+ }),
204
+ };
205
+ let ApiUrl = '/Account/';
206
+ return this.http.get(this.environmentService.getApiUrl() + ApiUrl + 'Logout', httpOptions);
207
+ }
208
+ clearUserSessionClaims() {
209
+ const httpOptions = {
210
+ headers: new HttpHeaders({
211
+ 'Content-Type': 'application/json',
212
+ }),
213
+ };
214
+ let ApiUrl = '/api/Home/';
215
+ return this.http.get(this.environmentService.getBaseUrl() + ApiUrl + 'ClearCurrentUserSession', httpOptions);
216
+ }
217
+ async handleAccessToken(response) {
218
+ this.cookieService.delete(TOKEN_KEY, '/');
219
+ const token = response;
220
+ AuthService.user = null;
221
+ AuthService.user = new User();
222
+ AuthService.user.token_type = "Bearer";
223
+ AuthService.user.access_token = token;
224
+ AuthService.user.profile = this.jwtHelper.decodeToken(token);
225
+ AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
226
+ this.user = AuthService.user;
227
+ localStorage.setItem("language", AuthService.user.profile.locale);
228
+ this.cookieService.set(TOKEN_KEY, token, AuthService.user.expires_at, "/", null, true, 'Lax');
229
+ this.isAuthenticatedSubject.next(true);
230
+ this.setTokenSeconds();
231
+ AuthService.timers.push(this.checkRefreshToken());
232
+ await this.updateLanguage();
233
+ }
234
+ handleAccessTokenWithoutLanguage(response) {
235
+ this.cookieService.delete(TOKEN_KEY, '/');
236
+ const token = response;
237
+ AuthService.user = null;
238
+ AuthService.user = new User();
239
+ AuthService.user.token_type = "Bearer";
240
+ AuthService.user.access_token = token;
241
+ AuthService.user.profile = this.jwtHelper.decodeToken(token);
242
+ AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
243
+ this.setTokenSeconds();
244
+ this.user = AuthService.user;
245
+ localStorage.setItem("language", AuthService.user.profile.locale);
246
+ this.cookieService.set(TOKEN_KEY, token, AuthService.user.expires_at, "/", null, true, 'Lax');
247
+ this.isAuthenticatedSubject.next(true);
248
+ AuthService.timers.push(this.checkRefreshToken());
249
+ }
250
+ async updateLanguage() {
251
+ if (!localStorage.getItem('language') || localStorage.getItem('language') == this.user.profile.locale)
252
+ localStorage.setItem('language', this.user.profile.locale);
253
+ if (this.translateService.currentLang != localStorage.getItem('language')) {
254
+ this.translateService.resetLang(this.translateService.currentLang);
255
+ await this.translateService.reloadLang(localStorage.getItem('language')).subscribe();
256
+ }
257
+ }
258
+ checkRefreshToken() {
259
+ let date = new Date();
260
+ return setInterval(() => {
261
+ if (Math.floor(AuthService.seconds) < 120 && this.isAuthenticated()) {
262
+ AuthService.timers.map(t => clearInterval(t));
263
+ AuthService.timers = [];
264
+ const token = this.cookieService.get(TOKEN_KEY);
265
+ if (token) {
266
+ this.refresh();
267
+ }
268
+ }
269
+ AuthService.seconds--;
270
+ }, 1000);
271
+ }
272
+ setTokenSeconds() {
273
+ let date = new Date();
274
+ AuthService.seconds = (AuthService.user.expires_at - date) / 1000;
275
+ }
276
+ refresh() {
277
+ this.cookieService.delete(TOKEN_KEY, '/');
278
+ const httpOptions = {
279
+ headers: new HttpHeaders({
280
+ 'Content-Type': 'application/json',
281
+ 'Authorization': this.authorizationHeaderValue(),
282
+ }),
283
+ };
284
+ let ApiUrl = '/api/Home/';
285
+ this.http.get(this.environmentService.getApiUrl() + ApiUrl + 'RefreshAccessToken', httpOptions).subscribe((res) => {
286
+ this.handleAccessTokenWithoutLanguage(res.val);
287
+ });
288
+ }
289
+ loginWithUAEPass() {
290
+ const authEndpoint = `${this.environmentService.getUAEPassBaseUrl()}${this.environmentService.getUAEPassAuthorizationEndPoint()}`;
291
+ const queryParams = {
292
+ response_type: 'code',
293
+ client_id: `${this.environmentService.getUAEPassClientID()}`,
294
+ redirect_uri: `${this.environmentService.getBaseUrl()}${this.environmentService.getUAEPassRedirectUrl()}`,
295
+ scope: 'urn:uae:digitalid:profile:general urn:uae:digitalid:profile:general:profileType urn:uae:digitalid:profile:general:unifiedId',
296
+ state: this.translateService.currentLang,
297
+ acr_values: 'urn:safelayer:tws:policies:authentication:level:low',
298
+ ui_locales: this.translateService.currentLang,
299
+ };
300
+ const queryParamsString = Object.entries(queryParams)
301
+ .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
302
+ .join('&');
303
+ const loginUrl = `${authEndpoint}?${queryParamsString}`;
304
+ window.location.href = loginUrl;
305
+ return;
306
+ }
307
+ logoutFromUAEPass() {
308
+ const logoutEndpoint = `${this.environmentService.getUAEPassBaseUrl()}${this.environmentService.getUAEPassLogoutEndPoint()}`;
309
+ const queryParams = {
310
+ redirect_uri: `${this.environmentService.getBaseUrl()}`,
311
+ };
312
+ const queryParamsString = Object.entries(queryParams)
313
+ .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
314
+ .join('&');
315
+ const logoutUrl = `${logoutEndpoint}?${queryParamsString}`;
316
+ window.location.href = logoutUrl;
317
+ return;
318
+ }
319
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: AuthService, deps: [{ token: i0.Injector }, { token: i1$1.HttpClient }, { token: EnvironmentService }, { token: BBSFTranslateService }, { token: i3.Router }, { token: i4.CookieService }, { token: UtilityService }], target: i0.ɵɵFactoryTarget.Injectable }); }
320
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: AuthService, providedIn: 'root' }); }
321
+ }
322
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: AuthService, decorators: [{
323
+ type: Injectable,
324
+ args: [{
325
+ providedIn: 'root',
326
+ }]
327
+ }], ctorParameters: () => [{ type: i0.Injector }, { type: i1$1.HttpClient }, { type: EnvironmentService }, { type: BBSFTranslateService }, { type: i3.Router }, { type: i4.CookieService }, { type: UtilityService }] });
328
+
329
+ class ConfigurationService {
330
+ static { this.JsonData = []; }
331
+ constructor(httpClient, authService) {
332
+ this.httpClient = httpClient;
333
+ this.authService = authService;
334
+ this.httpClient.get("./assets/config/configurations.json")
335
+ .subscribe(data => {
336
+ ConfigurationService.JsonData = data;
337
+ });
338
+ this.currentUserProfile = this.authService.getCurrentUser()?.profile;
339
+ }
340
+ getConfigurationValue(key) {
341
+ var selectedKey = ConfigurationService.JsonData[key];
342
+ if (selectedKey && typeof selectedKey === 'object') {
343
+ if (selectedKey.OrganizationConfigurations) {
344
+ if (this.currentUserProfile && this.currentUserProfile.organizationGUID_ID) {
345
+ let organizationValue = Array(selectedKey.OrganizationConfigurations).find(o => o.OrganizationID_GUID == this.currentUserProfile.organizationGUID_ID);
346
+ return organizationValue;
347
+ }
348
+ }
349
+ else {
350
+ return selectedKey.Value;
351
+ }
352
+ }
353
+ else {
354
+ return selectedKey;
355
+ }
356
+ }
357
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: ConfigurationService, deps: [{ token: i1$1.HttpClient }, { token: AuthService }], target: i0.ɵɵFactoryTarget.Injectable }); }
358
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: ConfigurationService, providedIn: 'root' }); }
359
+ }
360
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: ConfigurationService, decorators: [{
361
+ type: Injectable,
362
+ args: [{
363
+ providedIn: 'root'
364
+ }]
365
+ }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: AuthService }] });
366
+
367
+ class AreaModel {
368
+ }
369
+
370
+ class ErrorModel {
371
+ }
372
+
373
+ class RequestOptionsModel {
374
+ constructor() {
375
+ this.disableSuccessNotification = false;
376
+ this.disableBlockUI = false;
377
+ this.disableErrorHandler = false;
378
+ this.responseType = "";
379
+ this.formGroup = null;
380
+ this.castResponsetoClass = true;
381
+ }
382
+ }
383
+
384
+ class WordDocumentModel {
385
+ constructor() {
386
+ this.options = new DocumentOptionsModel();
387
+ }
388
+ }
389
+ class DocumentOptionsModel {
390
+ }
391
+
392
+ class LanguageDTO {
393
+ }
394
+
395
+ class ControlValidationService {
396
+ constructor(utilityService) {
397
+ this.utilityService = utilityService;
398
+ this.requestOptions = new RequestOptionsModel();
399
+ this.isCreatedBefor = false;
400
+ }
401
+ showGlobalError(errorMessage, formId, deleteOld) {
402
+ let globalErorrElement = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
403
+ if (globalErorrElement.length > 0) {
404
+ this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
405
+ }
406
+ if (this.isCreatedBefor == true) {
407
+ this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
408
+ }
409
+ // tslint:disable-next-line: prefer-const
410
+ if (!formId)
411
+ formId = "currentForm";
412
+ var object = document.getElementById(formId);
413
+ const tagName = 'div';
414
+ // tslint:disable-next-line: prefer-const
415
+ var elementToAppend = document.createElement(tagName); // Your tag name here
416
+ let message = "";
417
+ if (!errorMessage || (typeof errorMessage == "string")) {
418
+ if (localStorage.getItem('language') == "ar")
419
+ message = errorMessage ? errorMessage : "لديك بعص الأخطاء . من فضلك قم بالمراجعه ";
420
+ else
421
+ message = errorMessage ? errorMessage : "You have some validation errors. Please check below";
422
+ 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>";
423
+ elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
424
+ elementToAppend.id += 'errorId';
425
+ // tslint:disable-next-line: prefer-for-of
426
+ const elementToAppen = elementToAppend.cloneNode(true);
427
+ // let targetElement = object.getElementsByClassName("b-control")[0];
428
+ object.insertBefore(elementToAppen, object.firstChild);
429
+ }
430
+ else {
431
+ let ul = document.createElement("ul");
432
+ elementToAppend.appendChild(ul);
433
+ for (const iterator of errorMessage) {
434
+ let li = document.createElement("li");
435
+ li.innerHTML = iterator;
436
+ ul.appendChild(li);
437
+ }
438
+ elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
439
+ elementToAppend.id += 'errorId';
440
+ // tslint:disable-next-line: prefer-for-of
441
+ const elementToAppen = elementToAppend.cloneNode(true);
442
+ // let targetElement = object.getElementsByClassName("b-control")[0];
443
+ object.insertBefore(elementToAppen, object.firstChild);
444
+ }
445
+ this.isCreatedBefor = true;
446
+ }
447
+ removeGlobalError() {
448
+ const removedList = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
449
+ // tslint:disable-next-line: prefer-for-of
450
+ for (let index = 0; index < removedList.length; index++) {
451
+ const element = removedList[index];
452
+ element.remove();
453
+ }
454
+ this.isCreatedBefor = false;
455
+ }
456
+ showInputErro(errors) {
457
+ // show error on top of form
458
+ this.showGlobalError();
459
+ // remove old error from server
460
+ this.removeElementsByClass('errortemplet');
461
+ // Looping in error Object
462
+ for (const key in errors) {
463
+ if (errors.hasOwnProperty(key)) {
464
+ for (const iterator of errors[key]) {
465
+ const input = document.querySelectorAll('[ng-reflect-name=' + key + ']')[0];
466
+ if (input.attributes['ng-reflect-name'].value === key) {
467
+ this.removeElementsByClass('erroclass-' + key);
468
+ const tagName = 'p';
469
+ const elementToAppend = document.createElement(tagName); // Your tag name here
470
+ elementToAppend.innerHTML = iterator;
471
+ elementToAppend.style.color = 'red';
472
+ elementToAppend.className += 'errortemplet erroclass-' + key;
473
+ const elementToappen = elementToAppend.cloneNode(true);
474
+ input.parentNode.insertBefore(elementToappen, input.lastChild);
475
+ break;
476
+ }
477
+ }
478
+ }
479
+ }
480
+ }
481
+ removeElementsByClass(className) {
482
+ const elements = document.getElementsByClassName(className);
483
+ while (elements.length > 0) {
484
+ elements[0].parentNode.removeChild(elements[0]);
485
+ }
486
+ }
487
+ renderServerErrors(form, err, requestOptions, formId) {
488
+ if (err.error == null) {
489
+ return;
490
+ }
491
+ let errorsArray = [];
492
+ this.requestOptions = requestOptions;
493
+ if (err.error.validation_errors) {
494
+ err.error.validation_errors.forEach((element) => {
495
+ let fieldName = element.field;
496
+ let controlName = element.controlName;
497
+ let message = element.message;
498
+ if (form == null) {
499
+ this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(`${message}`);
500
+ }
501
+ else if (controlName && !this.hasControlName(form, controlName)) {
502
+ errorsArray.push(`${fieldName}: ${message}`);
503
+ }
504
+ else {
505
+ this.setFieldError(form, controlName, fieldName, message);
506
+ this.showGlobalError(null, formId);
507
+ }
508
+ });
509
+ if (errorsArray.length > 0)
510
+ this.showGlobalError(errorsArray, formId);
511
+ }
512
+ }
513
+ hasControlName(form, controlName) {
514
+ let control = form.get(controlName);
515
+ return control != null;
266
516
  }
267
517
  setFieldError(form, controlName, fieldName, message) {
268
518
  let control = null;
@@ -456,7 +706,7 @@ class MasterLayoutService {
456
706
  params = params.append('RoleID', permissionSetID);
457
707
  return this.http.post(this.apiUrl + 'SwitchRole', null, null, params);
458
708
  }
459
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: MasterLayoutService, deps: [{ token: i1$1.Router }, { token: RequestHandlerService }, { token: AuthService }, { token: StylesBundleService }, { token: i4.TranslateService }, { token: EnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
709
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: MasterLayoutService, deps: [{ token: i3.Router }, { token: RequestHandlerService }, { token: AuthService }, { token: StylesBundleService }, { token: i4$1.TranslateService }, { token: EnvironmentService }], target: i0.ɵɵFactoryTarget.Injectable }); }
460
710
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: MasterLayoutService, providedIn: 'root' }); }
461
711
  }
462
712
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: MasterLayoutService, decorators: [{
@@ -464,19 +714,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImpor
464
714
  args: [{
465
715
  providedIn: 'root',
466
716
  }]
467
- }], ctorParameters: () => [{ type: i1$1.Router }, { type: RequestHandlerService }, { type: AuthService }, { type: StylesBundleService }, { type: i4.TranslateService }, { type: EnvironmentService }] });
717
+ }], ctorParameters: () => [{ type: i3.Router }, { type: RequestHandlerService }, { type: AuthService }, { type: StylesBundleService }, { type: i4$1.TranslateService }, { type: EnvironmentService }] });
468
718
 
469
719
  class RequestHandlerService {
470
- constructor(http, authService, environmentService, utilityService, bbsfTranslateService, router) {
720
+ constructor(http, authService, environmentService, utilityService, bbsfTranslateService) {
471
721
  this.http = http;
472
722
  this.authService = authService;
473
723
  this.environmentService = environmentService;
474
724
  this.utilityService = utilityService;
475
725
  this.bbsfTranslateService = bbsfTranslateService;
476
- this.router = router;
477
726
  this.requestOptions = new RequestOptionsModel();
478
727
  this.currentLanguage = "";
479
728
  this.onDestroy$ = new Subject();
729
+ this.router = inject(Router);
480
730
  //using localStorage to avoid call getCurrentLanguage() because it is not all to use async in constructor
481
731
  this.bbsfTranslateService.onLangChange.subscribe((event) => {
482
732
  if (this.currentLanguage != event.lang) {
@@ -714,12 +964,15 @@ class RequestHandlerService {
714
964
  'Image-Upload': 'true',
715
965
  });
716
966
  }
717
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: RequestHandlerService, deps: [{ token: i1.HttpClient }, { token: AuthService }, { token: EnvironmentService }, { token: UtilityService }, { token: BBSFTranslateService }, { token: i1$1.Router }], target: i0.ɵɵFactoryTarget.Injectable }); }
718
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: RequestHandlerService }); }
967
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: RequestHandlerService, deps: [{ token: i1$1.HttpClient }, { token: AuthService }, { token: EnvironmentService }, { token: UtilityService }, { token: BBSFTranslateService }], target: i0.ɵɵFactoryTarget.Injectable }); }
968
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: RequestHandlerService, providedIn: 'root' }); }
719
969
  }
720
970
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: RequestHandlerService, decorators: [{
721
- type: Injectable
722
- }], ctorParameters: () => [{ type: i1.HttpClient }, { type: AuthService }, { type: EnvironmentService }, { type: UtilityService }, { type: BBSFTranslateService }, { type: i1$1.Router }] });
971
+ type: Injectable,
972
+ args: [{
973
+ providedIn: 'root',
974
+ }]
975
+ }], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: AuthService }, { type: EnvironmentService }, { type: UtilityService }, { type: BBSFTranslateService }] });
723
976
 
724
977
  class StylesBundleService {
725
978
  constructor(document, translateService) {
@@ -788,87 +1041,6 @@ const TranslationResolverService = () => {
788
1041
  return translateService.getTranslation(translateService.currentLang);
789
1042
  };
790
1043
 
791
- class UtilityService {
792
- constructor(translator, environmentService, injector) {
793
- this.translator = translator;
794
- this.environmentService = environmentService;
795
- this.injector = injector;
796
- this.isCreatedBefore = false;
797
- }
798
- getResourceValue(Key) {
799
- let ResourceValue = this.translator.instant(Key);
800
- return ResourceValue;
801
- }
802
- getCurrentLanguage() {
803
- let currentLanguage = this.environmentService.getDefaultLanguage();
804
- let lang = localStorage.getItem('language');
805
- if (lang)
806
- currentLanguage = lang;
807
- else
808
- localStorage.setItem('language', currentLanguage);
809
- return currentLanguage;
810
- }
811
- isCurrentLanguageEnglish() {
812
- return this.getCurrentLanguage() == "en";
813
- }
814
- isCurrentLanguageArabic() {
815
- return this.getCurrentLanguage() == "ar";
816
- }
817
- notifySuccessMessage(Message, title, time, showHeader = true) {
818
- let MessageTemplate = this.getResourceValue("SuccessMessage");
819
- let titleTemplate;
820
- if (Message) {
821
- MessageTemplate = Message;
822
- }
823
- if (title) {
824
- titleTemplate = title;
825
- }
826
- let toaster = this.injector.get(ToastrService);
827
- showHeader ? toaster.success(MessageTemplate, titleTemplate) : toaster.success(MessageTemplate);
828
- }
829
- notifyErrorMessage(Message, title, time, showHeader = true) {
830
- let MessageTemplate = this.getResourceValue("ErrorMessage");
831
- let titleTemplate = this.getResourceValue("Error");
832
- if (Message) {
833
- MessageTemplate = Message;
834
- }
835
- if (title) {
836
- titleTemplate = title;
837
- }
838
- const toaster = this.injector.get(ToastrService);
839
- showHeader ? toaster.error(MessageTemplate, titleTemplate) : toaster.error(MessageTemplate);
840
- }
841
- notifyWarningMessage(Message, title, time, showHeader = true) {
842
- let MessageTemplate = this.getResourceValue("WarningMessage");
843
- let titleTemplate = this.getResourceValue("Warning");
844
- if (Message) {
845
- MessageTemplate = Message;
846
- }
847
- if (title) {
848
- titleTemplate = title;
849
- }
850
- const toaster = this.injector.get(ToastrService);
851
- showHeader ? toaster.warning(MessageTemplate, titleTemplate) : toaster.warning(MessageTemplate);
852
- }
853
- startBlockUI() {
854
- this.blockUI.start();
855
- }
856
- stopBlockUI() {
857
- this.blockUI.stop();
858
- }
859
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: UtilityService, deps: [{ token: BBSFTranslateService }, { token: EnvironmentService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
860
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: UtilityService, providedIn: 'root' }); }
861
- }
862
- __decorate([
863
- BlockUI()
864
- ], UtilityService.prototype, "blockUI", void 0);
865
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: UtilityService, decorators: [{
866
- type: Injectable,
867
- args: [{
868
- providedIn: 'root'
869
- }]
870
- }], ctorParameters: () => [{ type: BBSFTranslateService }, { type: EnvironmentService }, { type: i0.Injector }], propDecorators: { blockUI: [] } });
871
-
872
1044
  const contentTypesXML = `
873
1045
  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
874
1046
 
@@ -4522,319 +4694,128 @@ class FileLoaderService {
4522
4694
  this.translate.addLangs(this.availableLanguages);
4523
4695
  }
4524
4696
  loadEnvironment() {
4525
- return new Promise((resolve, reject) => {
4526
- const script = document.createElement('script');
4527
- script.src = '/assets/config/environment.js';
4528
- script.onload = () => {
4529
- if (window.Environment) {
4530
- Object.assign(environment, window.Environment);
4531
- resolve();
4532
- }
4533
- else {
4534
- reject('Environment variables not found.');
4535
- }
4536
- };
4537
- script.onerror = () => reject('Failed to load environment.js');
4538
- document.head.appendChild(script);
4539
- });
4540
- }
4541
- async preloadTranslations() {
4542
- console.log('Starting to preload translation files...');
4543
- try {
4544
- const requests = this.availableLanguages.map(async (lang) => {
4545
- const translations = await lastValueFrom(this.http.get(`/assets/i18n/${lang}.json`));
4546
- console.log(`Loaded ${lang} translations:`, translations);
4547
- this.translate.setTranslation(lang, translations, true);
4548
- });
4549
- await Promise.all(requests);
4550
- this.translate.use('en'); // Set default language manually
4551
- console.log('All translations preloaded.');
4552
- }
4553
- catch (error) {
4554
- console.error('Error preloading translations:', error);
4555
- }
4556
- }
4557
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: FileLoaderService, deps: [{ token: BBSFTranslateService }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
4558
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: FileLoaderService, providedIn: 'root' }); }
4559
- }
4560
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: FileLoaderService, decorators: [{
4561
- type: Injectable,
4562
- args: [{
4563
- providedIn: 'root',
4564
- }]
4565
- }], ctorParameters: () => [{ type: BBSFTranslateService }, { type: i1.HttpClient }] });
4566
-
4567
- const TOKEN_KEY = 'access_token';
4568
- class AuthService {
4569
- static { this.user = null; }
4570
- static { this.UserClaims = null; }
4571
- //refresh
4572
- static { this.timers = []; }
4573
- static { this.seconds = 0; }
4574
- constructor(injector, http, environmentService, translateService, router, cookieService, utilityService) {
4575
- this.injector = injector;
4576
- this.http = http;
4577
- this.environmentService = environmentService;
4578
- this.translateService = translateService;
4579
- this.router = router;
4580
- this.cookieService = cookieService;
4581
- this.utilityService = utilityService;
4582
- this.redirectUrl = '';
4583
- this.jwtHelper = new JwtHelperService();
4584
- this.isAuthenticatedSubject = new BehaviorSubject(this.hasToken());
4585
- this.isAuthenticate$ = this.isAuthenticatedSubject.asObservable();
4586
- this.user = this.getUserManager();
4587
- }
4588
- hasToken() {
4589
- const token = this.cookieService.get(TOKEN_KEY);
4590
- return token && !this.jwtHelper.isTokenExpired(token);
4591
- }
4592
- getUserManager() {
4593
- const token = this.cookieService.get(TOKEN_KEY);
4594
- if (token) {
4595
- if (!this.jwtHelper.isTokenExpired(token))
4596
- this.handleAccessTokenWithoutLanguage(token);
4597
- else
4598
- this.cookieService.delete(TOKEN_KEY, '/');
4599
- }
4600
- else {
4601
- AuthService.timers.map(t => clearInterval(t));
4602
- AuthService.timers = [];
4603
- AuthService.user = null;
4604
- this.user = null;
4605
- }
4606
- return AuthService.user;
4607
- }
4608
- getUser() {
4609
- this.user = AuthService.user;
4610
- }
4611
- storUser(User) {
4612
- AuthService.user = this.user = this.user;
4613
- }
4614
- getCurrentUser() {
4615
- return AuthService.user;
4616
- }
4617
- isAuthenticated() {
4618
- return AuthService.user != null && !this.jwtHelper.isTokenExpired(AuthService.user.access_token);
4619
- }
4620
- isUserInRole(allowedPermission) {
4621
- let selectedPermissionSetID = Number.parseInt(AuthService.user.profile['selectedpermissionsetid']);
4622
- return allowedPermission.includes(selectedPermissionSetID);
4623
- }
4624
- authorizationHeaderValue() {
4625
- return AuthService.user
4626
- ? `${AuthService.user.token_type} ${AuthService.user.access_token}`
4627
- : '';
4628
- }
4629
- name() {
4630
- return AuthService.user != null ? AuthService.user.profile.given_name : '';
4631
- }
4632
- setUrl(url) {
4633
- localStorage.setItem('redirectUrl', url);
4634
- }
4635
- getUrl() {
4636
- return localStorage.getItem('redirectUrl') ?? "/";
4697
+ return new Promise((resolve, reject) => {
4698
+ const script = document.createElement('script');
4699
+ script.src = '/assets/config/environment.js';
4700
+ script.onload = () => {
4701
+ if (window.Environment) {
4702
+ Object.assign(environment, window.Environment);
4703
+ resolve();
4704
+ }
4705
+ else {
4706
+ reject('Environment variables not found.');
4707
+ }
4708
+ };
4709
+ script.onerror = () => reject('Failed to load environment.js');
4710
+ document.head.appendChild(script);
4711
+ });
4637
4712
  }
4638
- signOut() {
4639
- let isAuthenticated = this.isAuthenticated();
4640
- this.cookieService.delete(TOKEN_KEY, '/');
4641
- AuthService.timers.map(t => clearInterval(t));
4642
- AuthService.timers = [];
4643
- AuthService.user = null;
4644
- this.user = null;
4645
- localStorage.removeItem("redirectUrl");
4646
- if (isAuthenticated) {
4647
- this.logout().subscribe(res => {
4648
- if (this.environmentService.getBBSFAuthenticationMode() == AuthenticationModes.UAEPass)
4649
- this.logoutFromUAEPass();
4650
- else
4651
- this.router.navigate(['/Admin/account/login']);
4713
+ async preloadTranslations() {
4714
+ console.log('Starting to preload translation files...');
4715
+ try {
4716
+ const requests = this.availableLanguages.map(async (lang) => {
4717
+ const translations = await lastValueFrom(this.http.get(`/assets/i18n/${lang}.json`));
4718
+ console.log(`Loaded ${lang} translations:`, translations);
4719
+ this.translate.setTranslation(lang, translations, true);
4652
4720
  });
4721
+ await Promise.all(requests);
4722
+ this.translate.use('en'); // Set default language manually
4723
+ console.log('All translations preloaded.');
4653
4724
  }
4654
- else {
4655
- if (this.environmentService.getBBSFAuthenticationMode() == AuthenticationModes.UAEPass)
4656
- this.logoutFromUAEPass();
4657
- else
4658
- this.router.navigate(['/Admin/account/login']);
4725
+ catch (error) {
4726
+ console.error('Error preloading translations:', error);
4659
4727
  }
4660
4728
  }
4661
- logout() {
4662
- const httpOptions = {
4663
- headers: new HttpHeaders({
4664
- 'Content-Type': 'application/json',
4665
- }),
4666
- };
4667
- let ApiUrl = '/Account/';
4668
- return this.http.get(this.environmentService.getApiUrl() + ApiUrl + 'Logout', httpOptions);
4729
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: FileLoaderService, deps: [{ token: BBSFTranslateService }, { token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
4730
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: FileLoaderService, providedIn: 'root' }); }
4731
+ }
4732
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: FileLoaderService, decorators: [{
4733
+ type: Injectable,
4734
+ args: [{
4735
+ providedIn: 'root',
4736
+ }]
4737
+ }], ctorParameters: () => [{ type: BBSFTranslateService }, { type: i1$1.HttpClient }] });
4738
+
4739
+ class UtilityService {
4740
+ constructor(translator, environmentService, injector) {
4741
+ this.translator = translator;
4742
+ this.environmentService = environmentService;
4743
+ this.injector = injector;
4744
+ this.isCreatedBefore = false;
4669
4745
  }
4670
- clearUserSessionClaims() {
4671
- const httpOptions = {
4672
- headers: new HttpHeaders({
4673
- 'Content-Type': 'application/json',
4674
- }),
4675
- };
4676
- let ApiUrl = '/api/Home/';
4677
- return this.http.get(this.environmentService.getBaseUrl() + ApiUrl + 'ClearCurrentUserSession', httpOptions);
4746
+ getResourceValue(Key) {
4747
+ let ResourceValue = this.translator.instant(Key);
4748
+ return ResourceValue;
4678
4749
  }
4679
- async handleAccessToken(response) {
4680
- this.cookieService.delete(TOKEN_KEY, '/');
4681
- const token = response;
4682
- AuthService.user = null;
4683
- AuthService.user = new User();
4684
- AuthService.user.token_type = "Bearer";
4685
- AuthService.user.access_token = token;
4686
- AuthService.user.profile = this.jwtHelper.decodeToken(token);
4687
- AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
4688
- this.user = AuthService.user;
4689
- localStorage.setItem("language", AuthService.user.profile.locale);
4690
- this.cookieService.set(TOKEN_KEY, token, AuthService.user.expires_at, "/", null, true, 'Lax');
4691
- this.isAuthenticatedSubject.next(true);
4692
- this.setTokenSeconds();
4693
- AuthService.timers.push(this.checkRefreshToken());
4694
- await this.updateLanguage();
4750
+ getCurrentLanguage() {
4751
+ let currentLanguage = this.environmentService.getDefaultLanguage();
4752
+ let lang = localStorage.getItem('language');
4753
+ if (lang)
4754
+ currentLanguage = lang;
4755
+ else
4756
+ localStorage.setItem('language', currentLanguage);
4757
+ return currentLanguage;
4695
4758
  }
4696
- handleAccessTokenWithoutLanguage(response) {
4697
- this.cookieService.delete(TOKEN_KEY, '/');
4698
- const token = response;
4699
- AuthService.user = null;
4700
- AuthService.user = new User();
4701
- AuthService.user.token_type = "Bearer";
4702
- AuthService.user.access_token = token;
4703
- AuthService.user.profile = this.jwtHelper.decodeToken(token);
4704
- AuthService.user.expires_at = this.jwtHelper.getTokenExpirationDate(token);
4705
- this.setTokenSeconds();
4706
- this.user = AuthService.user;
4707
- localStorage.setItem("language", AuthService.user.profile.locale);
4708
- this.cookieService.set(TOKEN_KEY, token, AuthService.user.expires_at, "/", null, true, 'Lax');
4709
- this.isAuthenticatedSubject.next(true);
4710
- AuthService.timers.push(this.checkRefreshToken());
4759
+ isCurrentLanguageEnglish() {
4760
+ return this.getCurrentLanguage() == "en";
4711
4761
  }
4712
- async updateLanguage() {
4713
- if (!localStorage.getItem('language') || localStorage.getItem('language') == this.user.profile.locale)
4714
- localStorage.setItem('language', this.user.profile.locale);
4715
- if (this.translateService.currentLang != localStorage.getItem('language')) {
4716
- this.translateService.resetLang(this.translateService.currentLang);
4717
- await this.translateService.reloadLang(localStorage.getItem('language')).subscribe();
4718
- }
4762
+ isCurrentLanguageArabic() {
4763
+ return this.getCurrentLanguage() == "ar";
4719
4764
  }
4720
- checkRefreshToken() {
4721
- let date = new Date();
4722
- return setInterval(() => {
4723
- if (Math.floor(AuthService.seconds) < 120 && this.isAuthenticated()) {
4724
- AuthService.timers.map(t => clearInterval(t));
4725
- AuthService.timers = [];
4726
- const token = this.cookieService.get(TOKEN_KEY);
4727
- if (token) {
4728
- this.refresh();
4729
- }
4730
- }
4731
- AuthService.seconds--;
4732
- }, 1000);
4765
+ notifySuccessMessage(Message, title, time, showHeader = true) {
4766
+ let MessageTemplate = this.getResourceValue("SuccessMessage");
4767
+ let titleTemplate;
4768
+ if (Message) {
4769
+ MessageTemplate = Message;
4770
+ }
4771
+ if (title) {
4772
+ titleTemplate = title;
4773
+ }
4774
+ let toaster = this.injector.get(ToastrService);
4775
+ showHeader ? toaster.success(MessageTemplate, titleTemplate) : toaster.success(MessageTemplate);
4733
4776
  }
4734
- setTokenSeconds() {
4735
- let date = new Date();
4736
- AuthService.seconds = (AuthService.user.expires_at - date) / 1000;
4777
+ notifyErrorMessage(Message, title, time, showHeader = true) {
4778
+ let MessageTemplate = this.getResourceValue("ErrorMessage");
4779
+ let titleTemplate = this.getResourceValue("Error");
4780
+ if (Message) {
4781
+ MessageTemplate = Message;
4782
+ }
4783
+ if (title) {
4784
+ titleTemplate = title;
4785
+ }
4786
+ const toaster = this.injector.get(ToastrService);
4787
+ showHeader ? toaster.error(MessageTemplate, titleTemplate) : toaster.error(MessageTemplate);
4737
4788
  }
4738
- refresh() {
4739
- this.cookieService.delete(TOKEN_KEY, '/');
4740
- const httpOptions = {
4741
- headers: new HttpHeaders({
4742
- 'Content-Type': 'application/json',
4743
- 'Authorization': this.authorizationHeaderValue(),
4744
- }),
4745
- };
4746
- let ApiUrl = '/api/Home/';
4747
- this.http.get(this.environmentService.getApiUrl() + ApiUrl + 'RefreshAccessToken', httpOptions).subscribe((res) => {
4748
- this.handleAccessTokenWithoutLanguage(res.val);
4749
- });
4789
+ notifyWarningMessage(Message, title, time, showHeader = true) {
4790
+ let MessageTemplate = this.getResourceValue("WarningMessage");
4791
+ let titleTemplate = this.getResourceValue("Warning");
4792
+ if (Message) {
4793
+ MessageTemplate = Message;
4794
+ }
4795
+ if (title) {
4796
+ titleTemplate = title;
4797
+ }
4798
+ const toaster = this.injector.get(ToastrService);
4799
+ showHeader ? toaster.warning(MessageTemplate, titleTemplate) : toaster.warning(MessageTemplate);
4750
4800
  }
4751
- loginWithUAEPass() {
4752
- const authEndpoint = `${this.environmentService.getUAEPassBaseUrl()}${this.environmentService.getUAEPassAuthorizationEndPoint()}`;
4753
- const queryParams = {
4754
- response_type: 'code',
4755
- client_id: `${this.environmentService.getUAEPassClientID()}`,
4756
- redirect_uri: `${this.environmentService.getBaseUrl()}${this.environmentService.getUAEPassRedirectUrl()}`,
4757
- scope: 'urn:uae:digitalid:profile:general urn:uae:digitalid:profile:general:profileType urn:uae:digitalid:profile:general:unifiedId',
4758
- state: this.translateService.currentLang,
4759
- acr_values: 'urn:safelayer:tws:policies:authentication:level:low',
4760
- ui_locales: this.translateService.currentLang,
4761
- };
4762
- const queryParamsString = Object.entries(queryParams)
4763
- .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
4764
- .join('&');
4765
- const loginUrl = `${authEndpoint}?${queryParamsString}`;
4766
- window.location.href = loginUrl;
4767
- return;
4801
+ startBlockUI() {
4802
+ this.blockUI.start();
4768
4803
  }
4769
- logoutFromUAEPass() {
4770
- const logoutEndpoint = `${this.environmentService.getUAEPassBaseUrl()}${this.environmentService.getUAEPassLogoutEndPoint()}`;
4771
- const queryParams = {
4772
- redirect_uri: `${this.environmentService.getBaseUrl()}`,
4773
- };
4774
- const queryParamsString = Object.entries(queryParams)
4775
- .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
4776
- .join('&');
4777
- const logoutUrl = `${logoutEndpoint}?${queryParamsString}`;
4778
- window.location.href = logoutUrl;
4779
- return;
4804
+ stopBlockUI() {
4805
+ this.blockUI.stop();
4780
4806
  }
4781
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: AuthService, deps: [{ token: i0.Injector }, { token: i1.HttpClient }, { token: EnvironmentService }, { token: BBSFTranslateService }, { token: i1$1.Router }, { token: i4$1.CookieService }, { token: UtilityService }], target: i0.ɵɵFactoryTarget.Injectable }); }
4782
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: AuthService, providedIn: 'root' }); }
4807
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: UtilityService, deps: [{ token: BBSFTranslateService }, { token: EnvironmentService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable }); }
4808
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: UtilityService, providedIn: 'root' }); }
4783
4809
  }
4784
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: AuthService, decorators: [{
4810
+ __decorate([
4811
+ BlockUI()
4812
+ ], UtilityService.prototype, "blockUI", void 0);
4813
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: UtilityService, decorators: [{
4785
4814
  type: Injectable,
4786
4815
  args: [{
4787
- providedIn: 'root',
4788
- }]
4789
- }], ctorParameters: () => [{ type: i0.Injector }, { type: i1.HttpClient }, { type: EnvironmentService }, { type: BBSFTranslateService }, { type: i1$1.Router }, { type: i4$1.CookieService }, { type: UtilityService }] });
4790
-
4791
- class BBSFUtilitiesModule {
4792
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: BBSFUtilitiesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
4793
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.6", ngImport: i0, type: BBSFUtilitiesModule, imports: [CommonModule,
4794
- RouterModule, i1$2.BlockUIModule, i2.ToastrModule] }); }
4795
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: BBSFUtilitiesModule, providers: [
4796
- UtilityService,
4797
- EnvironmentService,
4798
- AuthService,
4799
- RequestHandlerService,
4800
- StylesBundleService,
4801
- TranslateService,
4802
- BBSFTranslateService,
4803
- ControlValidationService,
4804
- MasterLayoutService,
4805
- ConfigurationService,
4806
- CookieService,
4807
- ], imports: [CommonModule,
4808
- RouterModule,
4809
- BlockUIModule.forRoot(),
4810
- ToastrModule.forRoot()] }); }
4811
- }
4812
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.6", ngImport: i0, type: BBSFUtilitiesModule, decorators: [{
4813
- type: NgModule,
4814
- args: [{
4815
- declarations: [],
4816
- imports: [
4817
- CommonModule,
4818
- RouterModule,
4819
- BlockUIModule.forRoot(),
4820
- ToastrModule.forRoot(),
4821
- ],
4822
- exports: [],
4823
- providers: [
4824
- UtilityService,
4825
- EnvironmentService,
4826
- AuthService,
4827
- RequestHandlerService,
4828
- StylesBundleService,
4829
- TranslateService,
4830
- BBSFTranslateService,
4831
- ControlValidationService,
4832
- MasterLayoutService,
4833
- ConfigurationService,
4834
- CookieService,
4835
- ]
4816
+ providedIn: 'root'
4836
4817
  }]
4837
- }] });
4818
+ }], ctorParameters: () => [{ type: BBSFTranslateService }, { type: EnvironmentService }, { type: i0.Injector }], propDecorators: { blockUI: [] } });
4838
4819
 
4839
4820
  /*
4840
4821
  * Public API Surface of @bnsights/bbsf-utilities