@bnsights/bbsf-utilities 1.0.3 → 1.0.7
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.
- package/bnsights-bbsf-utilities-1.0.7.tgz +0 -0
- package/bnsights-bbsf-utilities.metadata.json +1 -1
- package/bundles/bnsights-bbsf-utilities.umd.js +278 -198
- package/bundles/bnsights-bbsf-utilities.umd.js.map +1 -1
- package/esm2015/lib/shared/authentication/auth.service.js +19 -23
- package/esm2015/lib/shared/models/AreaModel.js +3 -0
- package/esm2015/lib/shared/models/ErrorModel.js +1 -1
- package/esm2015/lib/shared/services/controlvalidation.service.js +52 -37
- package/esm2015/lib/shared/services/environment.service.js +2 -1
- package/esm2015/lib/shared/services/masterlayout.service.js +2 -2
- package/esm2015/lib/shared/services/requesthandler.service.js +66 -20
- package/esm2015/lib/shared/services/stylesbundle.service.js +7 -1
- package/esm2015/lib/shared/services/utility.service.js +3 -3
- package/fesm2015/bnsights-bbsf-utilities.js +248 -178
- package/fesm2015/bnsights-bbsf-utilities.js.map +1 -1
- package/lib/shared/authentication/auth.service.d.ts +4 -2
- package/lib/shared/models/AreaModel.d.ts +4 -0
- package/lib/shared/models/ErrorModel.d.ts +1 -1
- package/lib/shared/services/controlvalidation.service.d.ts +2 -2
- package/lib/shared/services/environment.service.d.ts +2 -0
- package/lib/shared/services/requesthandler.service.d.ts +11 -8
- package/lib/shared/services/stylesbundle.service.d.ts +1 -0
- package/lib/shared/services/utility.service.d.ts +2 -2
- package/package.json +7 -5
- package/bnsights-bbsf-utilities-1.0.3.tgz +0 -0
|
@@ -2,7 +2,7 @@ import * as i1$2 from '@angular/common';
|
|
|
2
2
|
import { DOCUMENT, CommonModule } from '@angular/common';
|
|
3
3
|
import * as i0 from '@angular/core';
|
|
4
4
|
import { Injectable, Inject, NgModule, Injector } from '@angular/core';
|
|
5
|
-
import * as
|
|
5
|
+
import * as i4 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';
|
|
@@ -13,8 +13,9 @@ import { __awaiter, __decorate } from 'tslib';
|
|
|
13
13
|
import * as i1$1 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 } from 'rxjs';
|
|
17
|
-
import { takeUntil, tap } from 'rxjs/operators';
|
|
16
|
+
import { BehaviorSubject, Subject, Observable } from 'rxjs';
|
|
17
|
+
import { takeUntil, tap, map } from 'rxjs/operators';
|
|
18
|
+
import { plainToClass } from 'class-transformer';
|
|
18
19
|
|
|
19
20
|
// This file can be replaced during build by using the `fileReplacements` array.
|
|
20
21
|
// `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`.
|
|
@@ -53,6 +54,7 @@ class EnvironmentService {
|
|
|
53
54
|
return Url;
|
|
54
55
|
}
|
|
55
56
|
}
|
|
57
|
+
EnvironmentService.AreaList = [];
|
|
56
58
|
EnvironmentService.ɵprov = i0.ɵɵdefineInjectable({ factory: function EnvironmentService_Factory() { return new EnvironmentService(); }, token: EnvironmentService, providedIn: "root" });
|
|
57
59
|
EnvironmentService.decorators = [
|
|
58
60
|
{ type: Injectable, args: [{
|
|
@@ -70,10 +72,11 @@ BBSFTranslateService.decorators = [
|
|
|
70
72
|
];
|
|
71
73
|
|
|
72
74
|
class AuthService {
|
|
73
|
-
constructor(http, environmentService, translateService) {
|
|
75
|
+
constructor(http, environmentService, translateService, router) {
|
|
74
76
|
this.http = http;
|
|
75
77
|
this.environmentService = environmentService;
|
|
76
78
|
this.translateService = translateService;
|
|
79
|
+
this.router = router;
|
|
77
80
|
// Observable navItem source
|
|
78
81
|
this._authNavStatusSource = new BehaviorSubject(false);
|
|
79
82
|
// Observable navItem stream
|
|
@@ -132,10 +135,11 @@ class AuthService {
|
|
|
132
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
133
136
|
this.user = yield this.manager.signinRedirectCallback();
|
|
134
137
|
AuthService.user = this.user;
|
|
135
|
-
localStorage.
|
|
136
|
-
|
|
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")) {
|
|
137
141
|
this.translateService.resetLang(this.translateService.currentLang);
|
|
138
|
-
yield this.translateService.reloadLang(
|
|
142
|
+
yield this.translateService.reloadLang(localStorage.getItem("language")).subscribe((res) => {
|
|
139
143
|
console.log(res);
|
|
140
144
|
});
|
|
141
145
|
}
|
|
@@ -162,28 +166,17 @@ class AuthService {
|
|
|
162
166
|
getCurrentUser() {
|
|
163
167
|
return this.manager.getUser();
|
|
164
168
|
}
|
|
165
|
-
isAuthenticated(
|
|
169
|
+
isAuthenticated() {
|
|
166
170
|
return __awaiter(this, void 0, void 0, function* () {
|
|
167
171
|
let user = yield this.manager.getUser().then(user => {
|
|
168
172
|
return user;
|
|
169
173
|
});
|
|
170
|
-
|
|
171
|
-
if (allowedPermission.length == 0) {
|
|
172
|
-
return this.user != null && !this.user.expired;
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
let isUserInRole = this.isUserInRole(allowedPermission);
|
|
176
|
-
return this.user != null && !this.user.expired && isUserInRole;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
else
|
|
180
|
-
return this.user != null && !this.user.expired;
|
|
174
|
+
return this.user != null && !this.user.expired;
|
|
181
175
|
});
|
|
182
176
|
}
|
|
183
177
|
isUserInRole(allowedPermission) {
|
|
184
|
-
;
|
|
185
|
-
|
|
186
|
-
return allowedPermission.every(i => permissionSetSID.includes(i));
|
|
178
|
+
let selectedPermissionSetID = Number.parseInt(this.user.profile["selectedpermissionsetid"]);
|
|
179
|
+
return allowedPermission.includes(selectedPermissionSetID);
|
|
187
180
|
}
|
|
188
181
|
authorizationHeaderValue() {
|
|
189
182
|
return AuthService.user ? `${AuthService.user.token_type} ${AuthService.user.access_token}` : "";
|
|
@@ -208,13 +201,15 @@ class AuthService {
|
|
|
208
201
|
}
|
|
209
202
|
signout() {
|
|
210
203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
-
|
|
204
|
+
if (yield !this.isAuthenticated())
|
|
205
|
+
this.router.navigate(['/Admin/account/login']),
|
|
206
|
+
localStorage.clear();
|
|
212
207
|
yield this.manager.signoutRedirect();
|
|
213
208
|
});
|
|
214
209
|
}
|
|
215
210
|
}
|
|
216
211
|
AuthService.user = null;
|
|
217
|
-
AuthService.ɵprov = i0.ɵɵdefineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0.ɵɵinject(i1$1.HttpClient), i0.ɵɵinject(EnvironmentService), i0.ɵɵinject(BBSFTranslateService)); }, token: AuthService, providedIn: "root" });
|
|
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" });
|
|
218
213
|
AuthService.decorators = [
|
|
219
214
|
{ type: Injectable, args: [{
|
|
220
215
|
providedIn: 'root'
|
|
@@ -223,7 +218,8 @@ AuthService.decorators = [
|
|
|
223
218
|
AuthService.ctorParameters = () => [
|
|
224
219
|
{ type: HttpClient },
|
|
225
220
|
{ type: EnvironmentService },
|
|
226
|
-
{ type: BBSFTranslateService }
|
|
221
|
+
{ type: BBSFTranslateService },
|
|
222
|
+
{ type: Router }
|
|
227
223
|
];
|
|
228
224
|
|
|
229
225
|
class UtilityService {
|
|
@@ -247,10 +243,10 @@ class UtilityService {
|
|
|
247
243
|
return currentLanguage;
|
|
248
244
|
}
|
|
249
245
|
isCurrentLanguageEnglish() {
|
|
250
|
-
this.getCurrentLanguage() == "en";
|
|
246
|
+
return this.getCurrentLanguage() == "en";
|
|
251
247
|
}
|
|
252
248
|
isCurrentLanguageArabic() {
|
|
253
|
-
this.getCurrentLanguage() == "ar";
|
|
249
|
+
return this.getCurrentLanguage() == "ar";
|
|
254
250
|
}
|
|
255
251
|
notifySuccessMessage(Message, title, time) {
|
|
256
252
|
let MessageTemplate = this.getResourceValue("SuccessMessage");
|
|
@@ -319,48 +315,230 @@ class RequestOptionsModel {
|
|
|
319
315
|
}
|
|
320
316
|
}
|
|
321
317
|
|
|
318
|
+
class RequestHandlerService {
|
|
319
|
+
constructor(http, authService, environmentService, utilityService, bbsfTranslateService) {
|
|
320
|
+
//using localStorage to avoid call getCurrentLanguage() because it is not all to use async in constructor
|
|
321
|
+
this.http = http;
|
|
322
|
+
this.authService = authService;
|
|
323
|
+
this.environmentService = environmentService;
|
|
324
|
+
this.utilityService = utilityService;
|
|
325
|
+
this.bbsfTranslateService = bbsfTranslateService;
|
|
326
|
+
this.requestOptions = new RequestOptionsModel();
|
|
327
|
+
this.currentLanguage = "";
|
|
328
|
+
this.onDestroy$ = new Subject();
|
|
329
|
+
this.bbsfTranslateService.onLangChange.subscribe((event) => {
|
|
330
|
+
if (this.currentLanguage != event.lang) {
|
|
331
|
+
this.currentLanguage = event.lang;
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
getLuckyNumber() {
|
|
336
|
+
return Observable.create((subject) => {
|
|
337
|
+
setInterval(() => {
|
|
338
|
+
const number = Math.floor(Math.random() * 10);
|
|
339
|
+
console.log(number);
|
|
340
|
+
subject.next(number);
|
|
341
|
+
}, 1000);
|
|
342
|
+
}).pipe(takeUntil(this.onDestroy$));
|
|
343
|
+
}
|
|
344
|
+
get(Url, params, responseType, requestOptions) {
|
|
345
|
+
if (requestOptions)
|
|
346
|
+
this.requestOptions = requestOptions;
|
|
347
|
+
let headers = new HttpHeaders({
|
|
348
|
+
'Content-Type': 'application/json',
|
|
349
|
+
'Authorization': this.authService.authorizationHeaderValue(),
|
|
350
|
+
});
|
|
351
|
+
this.currentLanguage = localStorage.getItem('language');
|
|
352
|
+
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
353
|
+
headers = headers.set('ignore-cookies', 'true');
|
|
354
|
+
if (!this.requestOptions.disableBlockUI)
|
|
355
|
+
this.utilityService.startBlockUI();
|
|
356
|
+
let object;
|
|
357
|
+
return this.http.get(this.environmentService.getApiUrl() + Url, { headers: headers, params: params }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
358
|
+
if (!this.requestOptions.disableBlockUI)
|
|
359
|
+
this.utilityService.stopBlockUI();
|
|
360
|
+
}), map((data) => {
|
|
361
|
+
return plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
362
|
+
}));
|
|
363
|
+
}
|
|
364
|
+
post(Url, model, responseType, params, requestOptions) {
|
|
365
|
+
if (requestOptions)
|
|
366
|
+
this.requestOptions = requestOptions;
|
|
367
|
+
let headers = new HttpHeaders({
|
|
368
|
+
'Content-Type': 'application/json',
|
|
369
|
+
'Authorization': this.authService.authorizationHeaderValue(),
|
|
370
|
+
});
|
|
371
|
+
this.currentLanguage = localStorage.getItem('language');
|
|
372
|
+
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
373
|
+
headers = headers.set('ignore-cookies', 'true');
|
|
374
|
+
if (!this.requestOptions.disableBlockUI)
|
|
375
|
+
this.utilityService.startBlockUI();
|
|
376
|
+
return this.http.post(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
377
|
+
if (!this.requestOptions.disableBlockUI)
|
|
378
|
+
this.utilityService.stopBlockUI();
|
|
379
|
+
}), map((data) => {
|
|
380
|
+
return plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
381
|
+
}));
|
|
382
|
+
}
|
|
383
|
+
delete(Url, deletedId, requestOptions, responseType, params) {
|
|
384
|
+
if (requestOptions)
|
|
385
|
+
this.requestOptions = requestOptions;
|
|
386
|
+
let headers = new HttpHeaders({
|
|
387
|
+
'Content-Type': 'application/json',
|
|
388
|
+
'Authorization': this.authService.authorizationHeaderValue(),
|
|
389
|
+
});
|
|
390
|
+
this.currentLanguage = localStorage.getItem('language');
|
|
391
|
+
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
392
|
+
headers = headers.set('ignore-cookies', 'true');
|
|
393
|
+
if (!this.requestOptions.disableBlockUI)
|
|
394
|
+
this.utilityService.startBlockUI();
|
|
395
|
+
return this.http.delete(this.environmentService.getApiUrl() + Url + `/${deletedId}`, { headers: headers, params: params }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
396
|
+
if (!this.requestOptions.disableBlockUI)
|
|
397
|
+
this.utilityService.stopBlockUI();
|
|
398
|
+
}), map((data) => {
|
|
399
|
+
return plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
400
|
+
}));
|
|
401
|
+
}
|
|
402
|
+
put(Url, model, params, responseType, requestOptions) {
|
|
403
|
+
if (requestOptions)
|
|
404
|
+
this.requestOptions = requestOptions;
|
|
405
|
+
let headers = new HttpHeaders({
|
|
406
|
+
'Content-Type': 'application/json',
|
|
407
|
+
'Authorization': this.authService.authorizationHeaderValue(),
|
|
408
|
+
});
|
|
409
|
+
this.currentLanguage = localStorage.getItem('language');
|
|
410
|
+
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
411
|
+
headers = headers.set('ignore-cookies', 'true');
|
|
412
|
+
if (!this.requestOptions.disableBlockUI)
|
|
413
|
+
this.utilityService.startBlockUI();
|
|
414
|
+
return this.http.put(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
415
|
+
if (!this.requestOptions.disableBlockUI)
|
|
416
|
+
this.utilityService.stopBlockUI();
|
|
417
|
+
}), map((data) => {
|
|
418
|
+
return plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
419
|
+
}));
|
|
420
|
+
}
|
|
421
|
+
destroyHandler() {
|
|
422
|
+
this.onDestroy$.next();
|
|
423
|
+
}
|
|
424
|
+
ngOnDestroy() {
|
|
425
|
+
console.log("clearInterval");
|
|
426
|
+
this.destroyHandler();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
RequestHandlerService.decorators = [
|
|
430
|
+
{ type: Injectable }
|
|
431
|
+
];
|
|
432
|
+
RequestHandlerService.ctorParameters = () => [
|
|
433
|
+
{ type: HttpClient },
|
|
434
|
+
{ type: AuthService },
|
|
435
|
+
{ type: EnvironmentService },
|
|
436
|
+
{ type: UtilityService },
|
|
437
|
+
{ type: BBSFTranslateService }
|
|
438
|
+
];
|
|
439
|
+
|
|
440
|
+
class StylesBundleService {
|
|
441
|
+
constructor(document, translateService) {
|
|
442
|
+
this.document = document;
|
|
443
|
+
this.translateService = translateService;
|
|
444
|
+
}
|
|
445
|
+
loadThemes(lang, bundleEnglishName, bundleArabicName) {
|
|
446
|
+
if (lang == "ar") {
|
|
447
|
+
this.loadStyleBundle(bundleArabicName.toString());
|
|
448
|
+
document.querySelector('html').setAttribute("lang", "ar");
|
|
449
|
+
document.querySelector('html').setAttribute("dir", "rtl");
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
this.loadStyleBundle(bundleEnglishName.toString());
|
|
453
|
+
document.querySelector('html').setAttribute("lang", "en");
|
|
454
|
+
document.querySelector('html').setAttribute("dir", "ltr");
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
loadThemesColor(theme, bundleDarkName, bundleLightName) {
|
|
458
|
+
if (theme == "Light")
|
|
459
|
+
this.loadStyleBundle(bundleLightName.toString());
|
|
460
|
+
else
|
|
461
|
+
this.loadStyleBundle(bundleDarkName.toString());
|
|
462
|
+
}
|
|
463
|
+
loadStyleBundle(styleName) {
|
|
464
|
+
const head = this.document.getElementsByTagName('head')[0];
|
|
465
|
+
let themeLink = this.document.getElementById('client-theme');
|
|
466
|
+
if (themeLink && themeLink.href.includes(styleName)) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
else if (themeLink && !themeLink.href.includes(styleName)) {
|
|
470
|
+
themeLink.remove();
|
|
471
|
+
}
|
|
472
|
+
const style = this.document.createElement('link');
|
|
473
|
+
style.id = 'client-theme';
|
|
474
|
+
style.rel = 'stylesheet';
|
|
475
|
+
style.href = `${styleName}`;
|
|
476
|
+
head.appendChild(style);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
StylesBundleService.ɵprov = i0.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0.ɵɵinject(i1$2.DOCUMENT), i0.ɵɵinject(BBSFTranslateService)); }, token: StylesBundleService, providedIn: "root" });
|
|
480
|
+
StylesBundleService.decorators = [
|
|
481
|
+
{ type: Injectable, args: [{
|
|
482
|
+
providedIn: 'root'
|
|
483
|
+
},] }
|
|
484
|
+
];
|
|
485
|
+
StylesBundleService.ctorParameters = () => [
|
|
486
|
+
{ type: Document, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
|
|
487
|
+
{ type: BBSFTranslateService }
|
|
488
|
+
];
|
|
489
|
+
|
|
322
490
|
class ControlValidationService {
|
|
323
491
|
constructor(utilityService) {
|
|
324
492
|
this.utilityService = utilityService;
|
|
325
493
|
this.requestOptions = new RequestOptionsModel();
|
|
326
494
|
this.isCreatedBefor = false;
|
|
327
495
|
}
|
|
328
|
-
showGlobalError(errorMessage, formId) {
|
|
329
|
-
let globalErorrElement = document.getElementsByClassName('alert alert-danger
|
|
496
|
+
showGlobalError(errorMessage, formId, deleteOld) {
|
|
497
|
+
let globalErorrElement = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
|
|
330
498
|
if (globalErorrElement.length > 0) {
|
|
331
|
-
this.removeElementsByClass('alert alert-danger
|
|
499
|
+
this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
|
|
332
500
|
}
|
|
333
501
|
if (this.isCreatedBefor == true) {
|
|
334
|
-
this.removeElementsByClass('alert alert-danger
|
|
502
|
+
this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
|
|
335
503
|
}
|
|
336
504
|
// tslint:disable-next-line: prefer-const
|
|
337
505
|
if (!formId)
|
|
338
506
|
formId = "currentForm";
|
|
339
|
-
var
|
|
507
|
+
var object = document.getElementById(formId);
|
|
340
508
|
const tagName = 'div';
|
|
341
509
|
// tslint:disable-next-line: prefer-const
|
|
342
510
|
var elementToAppend = document.createElement(tagName); // Your tag name here
|
|
343
511
|
let message = "";
|
|
344
|
-
if (
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
// const elementToAppen = elementToAppend.cloneNode(true);
|
|
354
|
-
// objects[i].insertBefore(elementToAppen, objects[i].firstChild);
|
|
512
|
+
if (!errorMessage || (typeof errorMessage == "string")) {
|
|
513
|
+
if (localStorage.getItem('language') == "ar")
|
|
514
|
+
message = errorMessage ? errorMessage : "لديك بعص الأخطاء . من فضلك قم بالمراجعه ";
|
|
515
|
+
else
|
|
516
|
+
message = errorMessage ? errorMessage : "You have some validation errors. Please check below";
|
|
517
|
+
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>";
|
|
518
|
+
elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
|
|
519
|
+
elementToAppend.id += 'errorId';
|
|
520
|
+
// tslint:disable-next-line: prefer-for-of
|
|
355
521
|
const elementToAppen = elementToAppend.cloneNode(true);
|
|
356
|
-
let targetElement =
|
|
357
|
-
|
|
358
|
-
this.isCreatedBefor = true;
|
|
359
|
-
break;
|
|
522
|
+
// let targetElement = object.getElementsByClassName("b-control")[0];
|
|
523
|
+
object.insertBefore(elementToAppen, object.firstChild);
|
|
360
524
|
}
|
|
525
|
+
else {
|
|
526
|
+
elementToAppend.innerHTML = "<ul>";
|
|
527
|
+
for (const iterator of errorMessage) {
|
|
528
|
+
elementToAppend.innerHTML = "<li>" + iterator + "</li>";
|
|
529
|
+
}
|
|
530
|
+
elementToAppend.innerHTML = "</ul>";
|
|
531
|
+
elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
|
|
532
|
+
elementToAppend.id += 'errorId';
|
|
533
|
+
// tslint:disable-next-line: prefer-for-of
|
|
534
|
+
const elementToAppen = elementToAppend.cloneNode(true);
|
|
535
|
+
// let targetElement = object.getElementsByClassName("b-control")[0];
|
|
536
|
+
object.insertBefore(elementToAppen, object.firstChild);
|
|
537
|
+
}
|
|
538
|
+
this.isCreatedBefor = true;
|
|
361
539
|
}
|
|
362
540
|
RemoveGlobalError() {
|
|
363
|
-
const removedList = document.getElementsByClassName('alert alert-danger
|
|
541
|
+
const removedList = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
|
|
364
542
|
// tslint:disable-next-line: prefer-for-of
|
|
365
543
|
for (let index = 0; index < removedList.length; index++) {
|
|
366
544
|
const element = removedList[index];
|
|
@@ -399,54 +577,59 @@ class ControlValidationService {
|
|
|
399
577
|
elements[0].parentNode.removeChild(elements[0]);
|
|
400
578
|
}
|
|
401
579
|
}
|
|
402
|
-
renderServerErrors(form, err, requestOptions) {
|
|
580
|
+
renderServerErrors(form, err, requestOptions, formId) {
|
|
403
581
|
if (err.error == null) {
|
|
404
582
|
return;
|
|
405
583
|
}
|
|
584
|
+
let errorsArray = [];
|
|
406
585
|
this.requestOptions = requestOptions;
|
|
407
586
|
err.error.validation_errors.forEach((element) => {
|
|
408
587
|
let fieldName = element.field;
|
|
409
|
-
let controlName = element.
|
|
588
|
+
let controlName = element.controlName;
|
|
410
589
|
let message = element.message;
|
|
411
590
|
if (form == null) {
|
|
412
591
|
this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(`${fieldName}: ${message}`);
|
|
413
592
|
}
|
|
414
|
-
else if (!this.hasControlName(form, controlName)) {
|
|
415
|
-
|
|
593
|
+
else if (controlName && !this.hasControlName(form, controlName)) {
|
|
594
|
+
errorsArray.push(`${fieldName}: ${message}`);
|
|
595
|
+
// this.showGlobalError(`${fieldName}: ${message}`,formId )
|
|
416
596
|
}
|
|
417
597
|
else {
|
|
418
598
|
this.setFieldError(form, controlName, fieldName, message);
|
|
419
599
|
}
|
|
420
600
|
});
|
|
601
|
+
if (errorsArray.length > 0)
|
|
602
|
+
this.showGlobalError(errorsArray, formId);
|
|
421
603
|
}
|
|
422
604
|
hasControlName(form, controlName) {
|
|
423
605
|
let control = form.get(controlName);
|
|
424
606
|
return control != null;
|
|
425
607
|
}
|
|
426
608
|
setFieldError(form, controlName, fieldName, message) {
|
|
427
|
-
let control =
|
|
428
|
-
|
|
609
|
+
let control = null;
|
|
610
|
+
if (controlName)
|
|
611
|
+
control = form.get(controlName);
|
|
612
|
+
else
|
|
613
|
+
control = form.get(fieldName.split('.')[0]);
|
|
614
|
+
let errors = { "errorMassage": message };
|
|
429
615
|
let fieldNameArray = fieldName.split('.');
|
|
430
616
|
if (fieldNameArray.length >= 1) {
|
|
431
|
-
switch (fieldNameArray[length - 1].toLocaleLowerCase()) {
|
|
617
|
+
switch (fieldNameArray[fieldNameArray.length - 1].toLocaleLowerCase()) {
|
|
432
618
|
case "english":
|
|
433
|
-
let englishControl = control.get("
|
|
619
|
+
let englishControl = control.get("English");
|
|
434
620
|
englishControl.setErrors(errors);
|
|
435
|
-
englishControl.markAsTouched();
|
|
436
|
-
englishControl.updateValueAndValidity();
|
|
437
621
|
break;
|
|
438
622
|
case "arabic":
|
|
439
|
-
let arabicControl = control.get("
|
|
623
|
+
let arabicControl = control.get("Arabic");
|
|
440
624
|
arabicControl.setErrors(errors);
|
|
441
|
-
arabicControl.markAsTouched();
|
|
442
|
-
arabicControl.updateValueAndValidity();
|
|
443
625
|
break;
|
|
444
626
|
default:
|
|
445
627
|
control.setErrors(errors);
|
|
446
|
-
control.markAsTouched();
|
|
447
|
-
control.updateValueAndValidity();
|
|
448
628
|
}
|
|
449
629
|
}
|
|
630
|
+
else if (fieldNameArray.length == 1) {
|
|
631
|
+
control.setErrors(errors);
|
|
632
|
+
}
|
|
450
633
|
else {
|
|
451
634
|
this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(`${fieldName}: ${message}`);
|
|
452
635
|
}
|
|
@@ -465,119 +648,6 @@ __decorate([
|
|
|
465
648
|
BlockUI()
|
|
466
649
|
], ControlValidationService.prototype, "blockUI", void 0);
|
|
467
650
|
|
|
468
|
-
class RequestHandlerService {
|
|
469
|
-
constructor(http, authService, environmentService, utilityService, controlValidationService, bbsfTranslateService) {
|
|
470
|
-
//using localStorage to avoid call getCurrentLanguage() because it is not all to use async in constructor
|
|
471
|
-
this.http = http;
|
|
472
|
-
this.authService = authService;
|
|
473
|
-
this.environmentService = environmentService;
|
|
474
|
-
this.utilityService = utilityService;
|
|
475
|
-
this.controlValidationService = controlValidationService;
|
|
476
|
-
this.bbsfTranslateService = bbsfTranslateService;
|
|
477
|
-
this.requestOptions = new RequestOptionsModel();
|
|
478
|
-
this.currentLanguage = "";
|
|
479
|
-
this.onDestroy$ = new Subject();
|
|
480
|
-
this.bbsfTranslateService.onLangChange.subscribe((event) => {
|
|
481
|
-
if (this.currentLanguage != event.lang) {
|
|
482
|
-
this.currentLanguage = event.lang;
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
get(Url, params, requestOptions) {
|
|
487
|
-
if (requestOptions)
|
|
488
|
-
this.requestOptions = requestOptions;
|
|
489
|
-
let headers = new HttpHeaders({
|
|
490
|
-
'Content-Type': 'application/json',
|
|
491
|
-
'Authorization': this.authService.authorizationHeaderValue(),
|
|
492
|
-
});
|
|
493
|
-
this.currentLanguage = localStorage.getItem('language');
|
|
494
|
-
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
495
|
-
if (!this.requestOptions.disableBlockUI)
|
|
496
|
-
this.utilityService.startBlockUI();
|
|
497
|
-
return this.http.get(this.environmentService.getApiUrl() + Url, { headers: headers, params: params }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
498
|
-
if (!this.requestOptions.disableBlockUI)
|
|
499
|
-
this.utilityService.stopBlockUI();
|
|
500
|
-
}));
|
|
501
|
-
}
|
|
502
|
-
post(Url, model, params, requestOptions) {
|
|
503
|
-
if (requestOptions)
|
|
504
|
-
this.requestOptions = requestOptions;
|
|
505
|
-
let headers = new HttpHeaders({
|
|
506
|
-
'Content-Type': 'application/json',
|
|
507
|
-
'Authorization': this.authService.authorizationHeaderValue(),
|
|
508
|
-
});
|
|
509
|
-
this.currentLanguage = localStorage.getItem('language');
|
|
510
|
-
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
511
|
-
if (!this.requestOptions.disableBlockUI)
|
|
512
|
-
this.utilityService.startBlockUI();
|
|
513
|
-
return this.http.post(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
514
|
-
if (!this.requestOptions.disableBlockUI)
|
|
515
|
-
this.utilityService.stopBlockUI();
|
|
516
|
-
}));
|
|
517
|
-
}
|
|
518
|
-
destroyHandler() {
|
|
519
|
-
this.onDestroy$.next();
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
RequestHandlerService.ɵprov = i0.ɵɵdefineInjectable({ factory: function RequestHandlerService_Factory() { return new RequestHandlerService(i0.ɵɵinject(i1$1.HttpClient), i0.ɵɵinject(AuthService), i0.ɵɵinject(EnvironmentService), i0.ɵɵinject(UtilityService), i0.ɵɵinject(ControlValidationService), i0.ɵɵinject(BBSFTranslateService)); }, token: RequestHandlerService, providedIn: "root" });
|
|
523
|
-
RequestHandlerService.decorators = [
|
|
524
|
-
{ type: Injectable, args: [{
|
|
525
|
-
providedIn: 'root'
|
|
526
|
-
},] }
|
|
527
|
-
];
|
|
528
|
-
RequestHandlerService.ctorParameters = () => [
|
|
529
|
-
{ type: HttpClient },
|
|
530
|
-
{ type: AuthService },
|
|
531
|
-
{ type: EnvironmentService },
|
|
532
|
-
{ type: UtilityService },
|
|
533
|
-
{ type: ControlValidationService },
|
|
534
|
-
{ type: BBSFTranslateService }
|
|
535
|
-
];
|
|
536
|
-
|
|
537
|
-
class StylesBundleService {
|
|
538
|
-
constructor(document, translateService) {
|
|
539
|
-
this.document = document;
|
|
540
|
-
this.translateService = translateService;
|
|
541
|
-
}
|
|
542
|
-
loadThemes(lang, bundleEnglishName, bundleArabicName) {
|
|
543
|
-
if (lang == "ar") {
|
|
544
|
-
this.loadStyleBundle(bundleArabicName.toString());
|
|
545
|
-
document.querySelector('html').setAttribute("lang", "ar");
|
|
546
|
-
document.querySelector('html').setAttribute("dir", "rtl");
|
|
547
|
-
}
|
|
548
|
-
else {
|
|
549
|
-
this.loadStyleBundle(bundleEnglishName.toString());
|
|
550
|
-
document.querySelector('html').setAttribute("lang", "en");
|
|
551
|
-
document.querySelector('html').setAttribute("dir", "ltr");
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
loadStyleBundle(styleName) {
|
|
555
|
-
const head = this.document.getElementsByTagName('head')[0];
|
|
556
|
-
let themeLink = this.document.getElementById('client-theme');
|
|
557
|
-
if (themeLink && themeLink.href.includes(styleName)) {
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
else if (themeLink && !themeLink.href.includes(styleName)) {
|
|
561
|
-
themeLink.remove();
|
|
562
|
-
}
|
|
563
|
-
const style = this.document.createElement('link');
|
|
564
|
-
style.id = 'client-theme';
|
|
565
|
-
style.rel = 'stylesheet';
|
|
566
|
-
style.href = `${styleName}`;
|
|
567
|
-
head.appendChild(style);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
StylesBundleService.ɵprov = i0.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0.ɵɵinject(i1$2.DOCUMENT), i0.ɵɵinject(BBSFTranslateService)); }, token: StylesBundleService, providedIn: "root" });
|
|
571
|
-
StylesBundleService.decorators = [
|
|
572
|
-
{ type: Injectable, args: [{
|
|
573
|
-
providedIn: 'root'
|
|
574
|
-
},] }
|
|
575
|
-
];
|
|
576
|
-
StylesBundleService.ctorParameters = () => [
|
|
577
|
-
{ type: Document, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
|
|
578
|
-
{ type: BBSFTranslateService }
|
|
579
|
-
];
|
|
580
|
-
|
|
581
651
|
class MasterLayoutService {
|
|
582
652
|
constructor(router, http, authService, stylesBundleService, translate) {
|
|
583
653
|
this.router = router;
|
|
@@ -610,13 +680,13 @@ class MasterLayoutService {
|
|
|
610
680
|
let params = new HttpParams();
|
|
611
681
|
params = params.append("UserId", this.authService.user.profile.id);
|
|
612
682
|
params = params.append("LanguageKey", key);
|
|
613
|
-
return this.http.post(this.ApiUrl + 'updateLaguage', null, params);
|
|
683
|
+
return this.http.post(this.ApiUrl + 'updateLaguage', null, null, params);
|
|
614
684
|
}
|
|
615
685
|
updateUserInfo() {
|
|
616
686
|
return this.http.get('/connect/userinfo');
|
|
617
687
|
}
|
|
618
688
|
}
|
|
619
|
-
MasterLayoutService.ɵprov = i0.ɵɵdefineInjectable({ factory: function MasterLayoutService_Factory() { return new MasterLayoutService(i0.ɵɵinject(
|
|
689
|
+
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" });
|
|
620
690
|
MasterLayoutService.decorators = [
|
|
621
691
|
{ type: Injectable, args: [{
|
|
622
692
|
providedIn: 'root'
|