@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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('@angular/router'), require('@ngx-translate/core'), require('ng-block-ui'), require('ngx-toastr'), require('@angular/http'), require('@angular/common/http'), require('oidc-client'), require('rxjs'), require('rxjs/operators')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@bnsights/bbsf-utilities', ['exports', '@angular/common', '@angular/core', '@angular/router', '@ngx-translate/core', 'ng-block-ui', 'ngx-toastr', '@angular/http', '@angular/common/http', 'oidc-client', 'rxjs', 'rxjs/operators'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.bnsights = global.bnsights || {}, global.bnsights["bbsf-utilities"] = {}), global.ng.common, global.ng.core, global.ng.router, global.i1, global.ngBlockUi, global.ngxToastr, global.ng.http, global.ng.common.http, global.oidcClient, global.rxjs, global.rxjs.operators));
|
|
5
|
-
})(this, (function (exports, i1$2, i0,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('@angular/router'), require('@ngx-translate/core'), require('ng-block-ui'), require('ngx-toastr'), require('@angular/http'), require('@angular/common/http'), require('oidc-client'), require('rxjs'), require('rxjs/operators'), require('class-transformer')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define('@bnsights/bbsf-utilities', ['exports', '@angular/common', '@angular/core', '@angular/router', '@ngx-translate/core', 'ng-block-ui', 'ngx-toastr', '@angular/http', '@angular/common/http', 'oidc-client', 'rxjs', 'rxjs/operators', 'class-transformer'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.bnsights = global.bnsights || {}, global.bnsights["bbsf-utilities"] = {}), global.ng.common, global.ng.core, global.ng.router, global.i1, global.ngBlockUi, global.ngxToastr, global.ng.http, global.ng.common.http, global.oidcClient, global.rxjs, global.rxjs.operators, global.classTransformer));
|
|
5
|
+
})(this, (function (exports, i1$2, i0, i4, i1, ngBlockUi, ngxToastr, http, i1$1, oidcClient, rxjs, operators, classTransformer) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopNamespace(e) {
|
|
8
8
|
if (e && e.__esModule) return e;
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
var i1__namespace$2 = /*#__PURE__*/_interopNamespace(i1$2);
|
|
26
26
|
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
|
|
27
|
-
var
|
|
27
|
+
var i4__namespace = /*#__PURE__*/_interopNamespace(i4);
|
|
28
28
|
var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
|
|
29
29
|
var i1__namespace$1 = /*#__PURE__*/_interopNamespace(i1$1);
|
|
30
30
|
|
|
@@ -386,6 +386,7 @@
|
|
|
386
386
|
};
|
|
387
387
|
return EnvironmentService;
|
|
388
388
|
}());
|
|
389
|
+
EnvironmentService.AreaList = [];
|
|
389
390
|
EnvironmentService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function EnvironmentService_Factory() { return new EnvironmentService(); }, token: EnvironmentService, providedIn: "root" });
|
|
390
391
|
EnvironmentService.decorators = [
|
|
391
392
|
{ type: i0.Injectable, args: [{
|
|
@@ -408,11 +409,12 @@
|
|
|
408
409
|
];
|
|
409
410
|
|
|
410
411
|
var AuthService = /** @class */ (function () {
|
|
411
|
-
function AuthService(http, environmentService, translateService) {
|
|
412
|
+
function AuthService(http, environmentService, translateService, router) {
|
|
412
413
|
var _this = this;
|
|
413
414
|
this.http = http;
|
|
414
415
|
this.environmentService = environmentService;
|
|
415
416
|
this.translateService = translateService;
|
|
417
|
+
this.router = router;
|
|
416
418
|
// Observable navItem source
|
|
417
419
|
this._authNavStatusSource = new rxjs.BehaviorSubject(false);
|
|
418
420
|
// Observable navItem stream
|
|
@@ -499,10 +501,11 @@
|
|
|
499
501
|
case 1:
|
|
500
502
|
_a.user = _d.sent();
|
|
501
503
|
AuthService.user = this.user;
|
|
502
|
-
localStorage.
|
|
503
|
-
|
|
504
|
+
if (!localStorage.getItem("language") || localStorage.getItem("language") == this.user.profile.locale)
|
|
505
|
+
localStorage.setItem("language", this.user.profile.locale);
|
|
506
|
+
if (!(this.translateService.currentLang != localStorage.getItem("language"))) return [3 /*break*/, 3];
|
|
504
507
|
this.translateService.resetLang(this.translateService.currentLang);
|
|
505
|
-
return [4 /*yield*/, this.translateService.reloadLang(
|
|
508
|
+
return [4 /*yield*/, this.translateService.reloadLang(localStorage.getItem("language")).subscribe(function (res) {
|
|
506
509
|
console.log(res);
|
|
507
510
|
})];
|
|
508
511
|
case 2:
|
|
@@ -546,9 +549,9 @@
|
|
|
546
549
|
AuthService.prototype.getCurrentUser = function () {
|
|
547
550
|
return this.manager.getUser();
|
|
548
551
|
};
|
|
549
|
-
AuthService.prototype.isAuthenticated = function (
|
|
552
|
+
AuthService.prototype.isAuthenticated = function () {
|
|
550
553
|
return __awaiter(this, void 0, void 0, function () {
|
|
551
|
-
var user
|
|
554
|
+
var user;
|
|
552
555
|
return __generator(this, function (_a) {
|
|
553
556
|
switch (_a.label) {
|
|
554
557
|
case 0: return [4 /*yield*/, this.manager.getUser().then(function (user) {
|
|
@@ -556,26 +559,14 @@
|
|
|
556
559
|
})];
|
|
557
560
|
case 1:
|
|
558
561
|
user = _a.sent();
|
|
559
|
-
|
|
560
|
-
if (allowedPermission.length == 0) {
|
|
561
|
-
return [2 /*return*/, this.user != null && !this.user.expired];
|
|
562
|
-
}
|
|
563
|
-
else {
|
|
564
|
-
isUserInRole = this.isUserInRole(allowedPermission);
|
|
565
|
-
return [2 /*return*/, this.user != null && !this.user.expired && isUserInRole];
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
else
|
|
569
|
-
return [2 /*return*/, this.user != null && !this.user.expired];
|
|
570
|
-
return [2 /*return*/];
|
|
562
|
+
return [2 /*return*/, this.user != null && !this.user.expired];
|
|
571
563
|
}
|
|
572
564
|
});
|
|
573
565
|
});
|
|
574
566
|
};
|
|
575
567
|
AuthService.prototype.isUserInRole = function (allowedPermission) {
|
|
576
|
-
;
|
|
577
|
-
|
|
578
|
-
return allowedPermission.every(function (i) { return permissionSetSID.includes(i); });
|
|
568
|
+
var selectedPermissionSetID = Number.parseInt(this.user.profile["selectedpermissionsetid"]);
|
|
569
|
+
return allowedPermission.includes(selectedPermissionSetID);
|
|
579
570
|
};
|
|
580
571
|
AuthService.prototype.authorizationHeaderValue = function () {
|
|
581
572
|
return AuthService.user ? AuthService.user.token_type + " " + AuthService.user.access_token : "";
|
|
@@ -610,10 +601,13 @@
|
|
|
610
601
|
return __awaiter(this, void 0, void 0, function () {
|
|
611
602
|
return __generator(this, function (_a) {
|
|
612
603
|
switch (_a.label) {
|
|
613
|
-
case 0:
|
|
614
|
-
localStorage.clear();
|
|
615
|
-
return [4 /*yield*/, this.manager.signoutRedirect()];
|
|
604
|
+
case 0: return [4 /*yield*/, !this.isAuthenticated()];
|
|
616
605
|
case 1:
|
|
606
|
+
if (_a.sent())
|
|
607
|
+
this.router.navigate(['/Admin/account/login']),
|
|
608
|
+
localStorage.clear();
|
|
609
|
+
return [4 /*yield*/, this.manager.signoutRedirect()];
|
|
610
|
+
case 2:
|
|
617
611
|
_a.sent();
|
|
618
612
|
return [2 /*return*/];
|
|
619
613
|
}
|
|
@@ -623,7 +617,7 @@
|
|
|
623
617
|
return AuthService;
|
|
624
618
|
}());
|
|
625
619
|
AuthService.user = null;
|
|
626
|
-
AuthService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0__namespace.ɵɵinject(i1__namespace$1.HttpClient), i0__namespace.ɵɵinject(EnvironmentService), i0__namespace.ɵɵinject(BBSFTranslateService)); }, token: AuthService, providedIn: "root" });
|
|
620
|
+
AuthService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0__namespace.ɵɵinject(i1__namespace$1.HttpClient), i0__namespace.ɵɵinject(EnvironmentService), i0__namespace.ɵɵinject(BBSFTranslateService), i0__namespace.ɵɵinject(i4__namespace.Router)); }, token: AuthService, providedIn: "root" });
|
|
627
621
|
AuthService.decorators = [
|
|
628
622
|
{ type: i0.Injectable, args: [{
|
|
629
623
|
providedIn: 'root'
|
|
@@ -632,9 +626,9 @@
|
|
|
632
626
|
AuthService.ctorParameters = function () { return [
|
|
633
627
|
{ type: i1$1.HttpClient },
|
|
634
628
|
{ type: EnvironmentService },
|
|
635
|
-
{ type: BBSFTranslateService }
|
|
636
|
-
|
|
637
|
-
|
|
629
|
+
{ type: BBSFTranslateService },
|
|
630
|
+
{ type: i4.Router }
|
|
631
|
+
]; };
|
|
638
632
|
|
|
639
633
|
var UtilityService = /** @class */ (function () {
|
|
640
634
|
function UtilityService(translator, authService, environmentService) {
|
|
@@ -657,10 +651,10 @@
|
|
|
657
651
|
return currentLanguage;
|
|
658
652
|
};
|
|
659
653
|
UtilityService.prototype.isCurrentLanguageEnglish = function () {
|
|
660
|
-
this.getCurrentLanguage() == "en";
|
|
654
|
+
return this.getCurrentLanguage() == "en";
|
|
661
655
|
};
|
|
662
656
|
UtilityService.prototype.isCurrentLanguageArabic = function () {
|
|
663
|
-
this.getCurrentLanguage() == "ar";
|
|
657
|
+
return this.getCurrentLanguage() == "ar";
|
|
664
658
|
};
|
|
665
659
|
UtilityService.prototype.notifySuccessMessage = function (Message, title, time) {
|
|
666
660
|
var MessageTemplate = this.getResourceValue("SuccessMessage");
|
|
@@ -731,48 +725,248 @@
|
|
|
731
725
|
return RequestOptionsModel;
|
|
732
726
|
}());
|
|
733
727
|
|
|
728
|
+
var RequestHandlerService = /** @class */ (function () {
|
|
729
|
+
function RequestHandlerService(http, authService, environmentService, utilityService, bbsfTranslateService) {
|
|
730
|
+
var _this = this;
|
|
731
|
+
//using localStorage to avoid call getCurrentLanguage() because it is not all to use async in constructor
|
|
732
|
+
this.http = http;
|
|
733
|
+
this.authService = authService;
|
|
734
|
+
this.environmentService = environmentService;
|
|
735
|
+
this.utilityService = utilityService;
|
|
736
|
+
this.bbsfTranslateService = bbsfTranslateService;
|
|
737
|
+
this.requestOptions = new RequestOptionsModel();
|
|
738
|
+
this.currentLanguage = "";
|
|
739
|
+
this.onDestroy$ = new rxjs.Subject();
|
|
740
|
+
this.bbsfTranslateService.onLangChange.subscribe(function (event) {
|
|
741
|
+
if (_this.currentLanguage != event.lang) {
|
|
742
|
+
_this.currentLanguage = event.lang;
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
RequestHandlerService.prototype.getLuckyNumber = function () {
|
|
747
|
+
return rxjs.Observable.create(function (subject) {
|
|
748
|
+
setInterval(function () {
|
|
749
|
+
var number = Math.floor(Math.random() * 10);
|
|
750
|
+
console.log(number);
|
|
751
|
+
subject.next(number);
|
|
752
|
+
}, 1000);
|
|
753
|
+
}).pipe(operators.takeUntil(this.onDestroy$));
|
|
754
|
+
};
|
|
755
|
+
RequestHandlerService.prototype.get = function (Url, params, responseType, requestOptions) {
|
|
756
|
+
var _this = this;
|
|
757
|
+
if (requestOptions)
|
|
758
|
+
this.requestOptions = requestOptions;
|
|
759
|
+
var headers = new i1$1.HttpHeaders({
|
|
760
|
+
'Content-Type': 'application/json',
|
|
761
|
+
'Authorization': this.authService.authorizationHeaderValue(),
|
|
762
|
+
});
|
|
763
|
+
this.currentLanguage = localStorage.getItem('language');
|
|
764
|
+
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
765
|
+
headers = headers.set('ignore-cookies', 'true');
|
|
766
|
+
if (!this.requestOptions.disableBlockUI)
|
|
767
|
+
this.utilityService.startBlockUI();
|
|
768
|
+
var object;
|
|
769
|
+
return this.http.get(this.environmentService.getApiUrl() + Url, { headers: headers, params: params }).pipe(operators.takeUntil(this.onDestroy$), operators.tap(function (result) {
|
|
770
|
+
if (!_this.requestOptions.disableBlockUI)
|
|
771
|
+
_this.utilityService.stopBlockUI();
|
|
772
|
+
}), operators.map(function (data) {
|
|
773
|
+
return classTransformer.plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
774
|
+
}));
|
|
775
|
+
};
|
|
776
|
+
RequestHandlerService.prototype.post = function (Url, model, responseType, params, requestOptions) {
|
|
777
|
+
var _this = this;
|
|
778
|
+
if (requestOptions)
|
|
779
|
+
this.requestOptions = requestOptions;
|
|
780
|
+
var headers = new i1$1.HttpHeaders({
|
|
781
|
+
'Content-Type': 'application/json',
|
|
782
|
+
'Authorization': this.authService.authorizationHeaderValue(),
|
|
783
|
+
});
|
|
784
|
+
this.currentLanguage = localStorage.getItem('language');
|
|
785
|
+
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
786
|
+
headers = headers.set('ignore-cookies', 'true');
|
|
787
|
+
if (!this.requestOptions.disableBlockUI)
|
|
788
|
+
this.utilityService.startBlockUI();
|
|
789
|
+
return this.http.post(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(operators.takeUntil(this.onDestroy$), operators.tap(function (result) {
|
|
790
|
+
if (!_this.requestOptions.disableBlockUI)
|
|
791
|
+
_this.utilityService.stopBlockUI();
|
|
792
|
+
}), operators.map(function (data) {
|
|
793
|
+
return classTransformer.plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
794
|
+
}));
|
|
795
|
+
};
|
|
796
|
+
RequestHandlerService.prototype.delete = function (Url, deletedId, requestOptions, responseType, params) {
|
|
797
|
+
var _this = this;
|
|
798
|
+
if (requestOptions)
|
|
799
|
+
this.requestOptions = requestOptions;
|
|
800
|
+
var headers = new i1$1.HttpHeaders({
|
|
801
|
+
'Content-Type': 'application/json',
|
|
802
|
+
'Authorization': this.authService.authorizationHeaderValue(),
|
|
803
|
+
});
|
|
804
|
+
this.currentLanguage = localStorage.getItem('language');
|
|
805
|
+
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
806
|
+
headers = headers.set('ignore-cookies', 'true');
|
|
807
|
+
if (!this.requestOptions.disableBlockUI)
|
|
808
|
+
this.utilityService.startBlockUI();
|
|
809
|
+
return this.http.delete(this.environmentService.getApiUrl() + Url + ("/" + deletedId), { headers: headers, params: params }).pipe(operators.takeUntil(this.onDestroy$), operators.tap(function (result) {
|
|
810
|
+
if (!_this.requestOptions.disableBlockUI)
|
|
811
|
+
_this.utilityService.stopBlockUI();
|
|
812
|
+
}), operators.map(function (data) {
|
|
813
|
+
return classTransformer.plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
814
|
+
}));
|
|
815
|
+
};
|
|
816
|
+
RequestHandlerService.prototype.put = function (Url, model, params, responseType, requestOptions) {
|
|
817
|
+
var _this = this;
|
|
818
|
+
if (requestOptions)
|
|
819
|
+
this.requestOptions = requestOptions;
|
|
820
|
+
var headers = new i1$1.HttpHeaders({
|
|
821
|
+
'Content-Type': 'application/json',
|
|
822
|
+
'Authorization': this.authService.authorizationHeaderValue(),
|
|
823
|
+
});
|
|
824
|
+
this.currentLanguage = localStorage.getItem('language');
|
|
825
|
+
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
826
|
+
headers = headers.set('ignore-cookies', 'true');
|
|
827
|
+
if (!this.requestOptions.disableBlockUI)
|
|
828
|
+
this.utilityService.startBlockUI();
|
|
829
|
+
return this.http.put(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(operators.takeUntil(this.onDestroy$), operators.tap(function (result) {
|
|
830
|
+
if (!_this.requestOptions.disableBlockUI)
|
|
831
|
+
_this.utilityService.stopBlockUI();
|
|
832
|
+
}), operators.map(function (data) {
|
|
833
|
+
return classTransformer.plainToClass(responseType, data, { excludeExtraneousValues: true });
|
|
834
|
+
}));
|
|
835
|
+
};
|
|
836
|
+
RequestHandlerService.prototype.destroyHandler = function () {
|
|
837
|
+
this.onDestroy$.next();
|
|
838
|
+
};
|
|
839
|
+
RequestHandlerService.prototype.ngOnDestroy = function () {
|
|
840
|
+
console.log("clearInterval");
|
|
841
|
+
this.destroyHandler();
|
|
842
|
+
};
|
|
843
|
+
return RequestHandlerService;
|
|
844
|
+
}());
|
|
845
|
+
RequestHandlerService.decorators = [
|
|
846
|
+
{ type: i0.Injectable }
|
|
847
|
+
];
|
|
848
|
+
RequestHandlerService.ctorParameters = function () { return [
|
|
849
|
+
{ type: i1$1.HttpClient },
|
|
850
|
+
{ type: AuthService },
|
|
851
|
+
{ type: EnvironmentService },
|
|
852
|
+
{ type: UtilityService },
|
|
853
|
+
{ type: BBSFTranslateService }
|
|
854
|
+
]; };
|
|
855
|
+
|
|
856
|
+
var StylesBundleService = /** @class */ (function () {
|
|
857
|
+
function StylesBundleService(document, translateService) {
|
|
858
|
+
this.document = document;
|
|
859
|
+
this.translateService = translateService;
|
|
860
|
+
}
|
|
861
|
+
StylesBundleService.prototype.loadThemes = function (lang, bundleEnglishName, bundleArabicName) {
|
|
862
|
+
if (lang == "ar") {
|
|
863
|
+
this.loadStyleBundle(bundleArabicName.toString());
|
|
864
|
+
document.querySelector('html').setAttribute("lang", "ar");
|
|
865
|
+
document.querySelector('html').setAttribute("dir", "rtl");
|
|
866
|
+
}
|
|
867
|
+
else {
|
|
868
|
+
this.loadStyleBundle(bundleEnglishName.toString());
|
|
869
|
+
document.querySelector('html').setAttribute("lang", "en");
|
|
870
|
+
document.querySelector('html').setAttribute("dir", "ltr");
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
StylesBundleService.prototype.loadThemesColor = function (theme, bundleDarkName, bundleLightName) {
|
|
874
|
+
if (theme == "Light")
|
|
875
|
+
this.loadStyleBundle(bundleLightName.toString());
|
|
876
|
+
else
|
|
877
|
+
this.loadStyleBundle(bundleDarkName.toString());
|
|
878
|
+
};
|
|
879
|
+
StylesBundleService.prototype.loadStyleBundle = function (styleName) {
|
|
880
|
+
var head = this.document.getElementsByTagName('head')[0];
|
|
881
|
+
var themeLink = this.document.getElementById('client-theme');
|
|
882
|
+
if (themeLink && themeLink.href.includes(styleName)) {
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
else if (themeLink && !themeLink.href.includes(styleName)) {
|
|
886
|
+
themeLink.remove();
|
|
887
|
+
}
|
|
888
|
+
var style = this.document.createElement('link');
|
|
889
|
+
style.id = 'client-theme';
|
|
890
|
+
style.rel = 'stylesheet';
|
|
891
|
+
style.href = "" + styleName;
|
|
892
|
+
head.appendChild(style);
|
|
893
|
+
};
|
|
894
|
+
return StylesBundleService;
|
|
895
|
+
}());
|
|
896
|
+
StylesBundleService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0__namespace.ɵɵinject(i1__namespace$2.DOCUMENT), i0__namespace.ɵɵinject(BBSFTranslateService)); }, token: StylesBundleService, providedIn: "root" });
|
|
897
|
+
StylesBundleService.decorators = [
|
|
898
|
+
{ type: i0.Injectable, args: [{
|
|
899
|
+
providedIn: 'root'
|
|
900
|
+
},] }
|
|
901
|
+
];
|
|
902
|
+
StylesBundleService.ctorParameters = function () { return [
|
|
903
|
+
{ type: Document, decorators: [{ type: i0.Inject, args: [i1$2.DOCUMENT,] }] },
|
|
904
|
+
{ type: BBSFTranslateService }
|
|
905
|
+
]; };
|
|
906
|
+
|
|
734
907
|
var ControlValidationService = /** @class */ (function () {
|
|
735
908
|
function ControlValidationService(utilityService) {
|
|
736
909
|
this.utilityService = utilityService;
|
|
737
910
|
this.requestOptions = new RequestOptionsModel();
|
|
738
911
|
this.isCreatedBefor = false;
|
|
739
912
|
}
|
|
740
|
-
ControlValidationService.prototype.showGlobalError = function (errorMessage, formId) {
|
|
741
|
-
var
|
|
913
|
+
ControlValidationService.prototype.showGlobalError = function (errorMessage, formId, deleteOld) {
|
|
914
|
+
var e_1, _a;
|
|
915
|
+
var globalErorrElement = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
|
|
742
916
|
if (globalErorrElement.length > 0) {
|
|
743
|
-
this.removeElementsByClass('alert alert-danger
|
|
917
|
+
this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
|
|
744
918
|
}
|
|
745
919
|
if (this.isCreatedBefor == true) {
|
|
746
|
-
this.removeElementsByClass('alert alert-danger
|
|
920
|
+
this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
|
|
747
921
|
}
|
|
748
922
|
// tslint:disable-next-line: prefer-const
|
|
749
923
|
if (!formId)
|
|
750
924
|
formId = "currentForm";
|
|
751
|
-
var
|
|
925
|
+
var object = document.getElementById(formId);
|
|
752
926
|
var tagName = 'div';
|
|
753
927
|
// tslint:disable-next-line: prefer-const
|
|
754
928
|
var elementToAppend = document.createElement(tagName); // Your tag name here
|
|
755
929
|
var message = "";
|
|
756
|
-
if (
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
//
|
|
930
|
+
if (!errorMessage || (typeof errorMessage == "string")) {
|
|
931
|
+
if (localStorage.getItem('language') == "ar")
|
|
932
|
+
message = errorMessage ? errorMessage : "لديك بعص الأخطاء . من فضلك قم بالمراجعه ";
|
|
933
|
+
else
|
|
934
|
+
message = errorMessage ? errorMessage : "You have some validation errors. Please check below";
|
|
935
|
+
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>";
|
|
936
|
+
elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
|
|
937
|
+
elementToAppend.id += 'errorId';
|
|
938
|
+
// tslint:disable-next-line: prefer-for-of
|
|
939
|
+
var elementToAppen = elementToAppend.cloneNode(true);
|
|
940
|
+
// let targetElement = object.getElementsByClassName("b-control")[0];
|
|
941
|
+
object.insertBefore(elementToAppen, object.firstChild);
|
|
942
|
+
}
|
|
943
|
+
else {
|
|
944
|
+
elementToAppend.innerHTML = "<ul>";
|
|
945
|
+
try {
|
|
946
|
+
for (var errorMessage_1 = __values(errorMessage), errorMessage_1_1 = errorMessage_1.next(); !errorMessage_1_1.done; errorMessage_1_1 = errorMessage_1.next()) {
|
|
947
|
+
var iterator = errorMessage_1_1.value;
|
|
948
|
+
elementToAppend.innerHTML = "<li>" + iterator + "</li>";
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
952
|
+
finally {
|
|
953
|
+
try {
|
|
954
|
+
if (errorMessage_1_1 && !errorMessage_1_1.done && (_a = errorMessage_1.return)) _a.call(errorMessage_1);
|
|
955
|
+
}
|
|
956
|
+
finally { if (e_1) throw e_1.error; }
|
|
957
|
+
}
|
|
958
|
+
elementToAppend.innerHTML = "</ul>";
|
|
959
|
+
elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
|
|
960
|
+
elementToAppend.id += 'errorId';
|
|
961
|
+
// tslint:disable-next-line: prefer-for-of
|
|
767
962
|
var elementToAppen = elementToAppend.cloneNode(true);
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
this.isCreatedBefor = true;
|
|
771
|
-
break;
|
|
963
|
+
// let targetElement = object.getElementsByClassName("b-control")[0];
|
|
964
|
+
object.insertBefore(elementToAppen, object.firstChild);
|
|
772
965
|
}
|
|
966
|
+
this.isCreatedBefor = true;
|
|
773
967
|
};
|
|
774
968
|
ControlValidationService.prototype.RemoveGlobalError = function () {
|
|
775
|
-
var removedList = document.getElementsByClassName('alert alert-danger
|
|
969
|
+
var removedList = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
|
|
776
970
|
// tslint:disable-next-line: prefer-for-of
|
|
777
971
|
for (var index = 0; index < removedList.length; index++) {
|
|
778
972
|
var element = removedList[index];
|
|
@@ -781,7 +975,7 @@
|
|
|
781
975
|
this.isCreatedBefor = false;
|
|
782
976
|
};
|
|
783
977
|
ControlValidationService.prototype.showInputErro = function (errors) {
|
|
784
|
-
var
|
|
978
|
+
var e_2, _a;
|
|
785
979
|
// show error on top of form
|
|
786
980
|
this.showGlobalError();
|
|
787
981
|
// remove old error from server
|
|
@@ -790,7 +984,7 @@
|
|
|
790
984
|
for (var key in errors) {
|
|
791
985
|
if (errors.hasOwnProperty(key)) {
|
|
792
986
|
try {
|
|
793
|
-
for (var _b = (
|
|
987
|
+
for (var _b = (e_2 = void 0, __values(errors[key])), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
794
988
|
var iterator = _c.value;
|
|
795
989
|
var input = document.querySelectorAll('[ng-reflect-name=' + key + ']')[0];
|
|
796
990
|
if (input.attributes['ng-reflect-name'].value === key) {
|
|
@@ -806,12 +1000,12 @@
|
|
|
806
1000
|
}
|
|
807
1001
|
}
|
|
808
1002
|
}
|
|
809
|
-
catch (
|
|
1003
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
810
1004
|
finally {
|
|
811
1005
|
try {
|
|
812
1006
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
813
1007
|
}
|
|
814
|
-
finally { if (
|
|
1008
|
+
finally { if (e_2) throw e_2.error; }
|
|
815
1009
|
}
|
|
816
1010
|
}
|
|
817
1011
|
}
|
|
@@ -822,56 +1016,60 @@
|
|
|
822
1016
|
elements[0].parentNode.removeChild(elements[0]);
|
|
823
1017
|
}
|
|
824
1018
|
};
|
|
825
|
-
ControlValidationService.prototype.renderServerErrors = function (form, err, requestOptions) {
|
|
1019
|
+
ControlValidationService.prototype.renderServerErrors = function (form, err, requestOptions, formId) {
|
|
826
1020
|
var _this = this;
|
|
827
1021
|
if (err.error == null) {
|
|
828
1022
|
return;
|
|
829
1023
|
}
|
|
1024
|
+
var errorsArray = [];
|
|
830
1025
|
this.requestOptions = requestOptions;
|
|
831
1026
|
err.error.validation_errors.forEach(function (element) {
|
|
832
1027
|
var fieldName = element.field;
|
|
833
|
-
var controlName = element.
|
|
1028
|
+
var controlName = element.controlName;
|
|
834
1029
|
var message = element.message;
|
|
835
1030
|
if (form == null) {
|
|
836
1031
|
_this.requestOptions.customErrorMessage ? _this.utilityService.notifyErrorMessage(_this.requestOptions.customErrorMessage) : _this.utilityService.notifyErrorMessage(fieldName + ": " + message);
|
|
837
1032
|
}
|
|
838
|
-
else if (!_this.hasControlName(form, controlName)) {
|
|
839
|
-
|
|
1033
|
+
else if (controlName && !_this.hasControlName(form, controlName)) {
|
|
1034
|
+
errorsArray.push(fieldName + ": " + message);
|
|
1035
|
+
// this.showGlobalError(`${fieldName}: ${message}`,formId )
|
|
840
1036
|
}
|
|
841
1037
|
else {
|
|
842
1038
|
_this.setFieldError(form, controlName, fieldName, message);
|
|
843
1039
|
}
|
|
844
1040
|
});
|
|
1041
|
+
if (errorsArray.length > 0)
|
|
1042
|
+
this.showGlobalError(errorsArray, formId);
|
|
845
1043
|
};
|
|
846
1044
|
ControlValidationService.prototype.hasControlName = function (form, controlName) {
|
|
847
1045
|
var control = form.get(controlName);
|
|
848
1046
|
return control != null;
|
|
849
1047
|
};
|
|
850
1048
|
ControlValidationService.prototype.setFieldError = function (form, controlName, fieldName, message) {
|
|
851
|
-
var
|
|
852
|
-
|
|
853
|
-
|
|
1049
|
+
var control = null;
|
|
1050
|
+
if (controlName)
|
|
1051
|
+
control = form.get(controlName);
|
|
1052
|
+
else
|
|
1053
|
+
control = form.get(fieldName.split('.')[0]);
|
|
1054
|
+
var errors = { "errorMassage": message };
|
|
854
1055
|
var fieldNameArray = fieldName.split('.');
|
|
855
1056
|
if (fieldNameArray.length >= 1) {
|
|
856
|
-
switch (fieldNameArray[length - 1].toLocaleLowerCase()) {
|
|
1057
|
+
switch (fieldNameArray[fieldNameArray.length - 1].toLocaleLowerCase()) {
|
|
857
1058
|
case "english":
|
|
858
|
-
var englishControl = control.get("
|
|
1059
|
+
var englishControl = control.get("English");
|
|
859
1060
|
englishControl.setErrors(errors);
|
|
860
|
-
englishControl.markAsTouched();
|
|
861
|
-
englishControl.updateValueAndValidity();
|
|
862
1061
|
break;
|
|
863
1062
|
case "arabic":
|
|
864
|
-
var arabicControl = control.get("
|
|
1063
|
+
var arabicControl = control.get("Arabic");
|
|
865
1064
|
arabicControl.setErrors(errors);
|
|
866
|
-
arabicControl.markAsTouched();
|
|
867
|
-
arabicControl.updateValueAndValidity();
|
|
868
1065
|
break;
|
|
869
1066
|
default:
|
|
870
1067
|
control.setErrors(errors);
|
|
871
|
-
control.markAsTouched();
|
|
872
|
-
control.updateValueAndValidity();
|
|
873
1068
|
}
|
|
874
1069
|
}
|
|
1070
|
+
else if (fieldNameArray.length == 1) {
|
|
1071
|
+
control.setErrors(errors);
|
|
1072
|
+
}
|
|
875
1073
|
else {
|
|
876
1074
|
this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(fieldName + ": " + message);
|
|
877
1075
|
}
|
|
@@ -891,124 +1089,6 @@
|
|
|
891
1089
|
ngBlockUi.BlockUI()
|
|
892
1090
|
], ControlValidationService.prototype, "blockUI", void 0);
|
|
893
1091
|
|
|
894
|
-
var RequestHandlerService = /** @class */ (function () {
|
|
895
|
-
function RequestHandlerService(http, authService, environmentService, utilityService, controlValidationService, bbsfTranslateService) {
|
|
896
|
-
var _this = this;
|
|
897
|
-
//using localStorage to avoid call getCurrentLanguage() because it is not all to use async in constructor
|
|
898
|
-
this.http = http;
|
|
899
|
-
this.authService = authService;
|
|
900
|
-
this.environmentService = environmentService;
|
|
901
|
-
this.utilityService = utilityService;
|
|
902
|
-
this.controlValidationService = controlValidationService;
|
|
903
|
-
this.bbsfTranslateService = bbsfTranslateService;
|
|
904
|
-
this.requestOptions = new RequestOptionsModel();
|
|
905
|
-
this.currentLanguage = "";
|
|
906
|
-
this.onDestroy$ = new rxjs.Subject();
|
|
907
|
-
this.bbsfTranslateService.onLangChange.subscribe(function (event) {
|
|
908
|
-
if (_this.currentLanguage != event.lang) {
|
|
909
|
-
_this.currentLanguage = event.lang;
|
|
910
|
-
}
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
RequestHandlerService.prototype.get = function (Url, params, requestOptions) {
|
|
914
|
-
var _this = this;
|
|
915
|
-
if (requestOptions)
|
|
916
|
-
this.requestOptions = requestOptions;
|
|
917
|
-
var headers = new i1$1.HttpHeaders({
|
|
918
|
-
'Content-Type': 'application/json',
|
|
919
|
-
'Authorization': this.authService.authorizationHeaderValue(),
|
|
920
|
-
});
|
|
921
|
-
this.currentLanguage = localStorage.getItem('language');
|
|
922
|
-
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
923
|
-
if (!this.requestOptions.disableBlockUI)
|
|
924
|
-
this.utilityService.startBlockUI();
|
|
925
|
-
return this.http.get(this.environmentService.getApiUrl() + Url, { headers: headers, params: params }).pipe(operators.takeUntil(this.onDestroy$), operators.tap(function (result) {
|
|
926
|
-
if (!_this.requestOptions.disableBlockUI)
|
|
927
|
-
_this.utilityService.stopBlockUI();
|
|
928
|
-
}));
|
|
929
|
-
};
|
|
930
|
-
RequestHandlerService.prototype.post = function (Url, model, params, requestOptions) {
|
|
931
|
-
var _this = this;
|
|
932
|
-
if (requestOptions)
|
|
933
|
-
this.requestOptions = requestOptions;
|
|
934
|
-
var headers = new i1$1.HttpHeaders({
|
|
935
|
-
'Content-Type': 'application/json',
|
|
936
|
-
'Authorization': this.authService.authorizationHeaderValue(),
|
|
937
|
-
});
|
|
938
|
-
this.currentLanguage = localStorage.getItem('language');
|
|
939
|
-
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
940
|
-
if (!this.requestOptions.disableBlockUI)
|
|
941
|
-
this.utilityService.startBlockUI();
|
|
942
|
-
return this.http.post(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(operators.takeUntil(this.onDestroy$), operators.tap(function (result) {
|
|
943
|
-
if (!_this.requestOptions.disableBlockUI)
|
|
944
|
-
_this.utilityService.stopBlockUI();
|
|
945
|
-
}));
|
|
946
|
-
};
|
|
947
|
-
RequestHandlerService.prototype.destroyHandler = function () {
|
|
948
|
-
this.onDestroy$.next();
|
|
949
|
-
};
|
|
950
|
-
return RequestHandlerService;
|
|
951
|
-
}());
|
|
952
|
-
RequestHandlerService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function RequestHandlerService_Factory() { return new RequestHandlerService(i0__namespace.ɵɵinject(i1__namespace$1.HttpClient), i0__namespace.ɵɵinject(AuthService), i0__namespace.ɵɵinject(EnvironmentService), i0__namespace.ɵɵinject(UtilityService), i0__namespace.ɵɵinject(ControlValidationService), i0__namespace.ɵɵinject(BBSFTranslateService)); }, token: RequestHandlerService, providedIn: "root" });
|
|
953
|
-
RequestHandlerService.decorators = [
|
|
954
|
-
{ type: i0.Injectable, args: [{
|
|
955
|
-
providedIn: 'root'
|
|
956
|
-
},] }
|
|
957
|
-
];
|
|
958
|
-
RequestHandlerService.ctorParameters = function () { return [
|
|
959
|
-
{ type: i1$1.HttpClient },
|
|
960
|
-
{ type: AuthService },
|
|
961
|
-
{ type: EnvironmentService },
|
|
962
|
-
{ type: UtilityService },
|
|
963
|
-
{ type: ControlValidationService },
|
|
964
|
-
{ type: BBSFTranslateService }
|
|
965
|
-
]; };
|
|
966
|
-
|
|
967
|
-
var StylesBundleService = /** @class */ (function () {
|
|
968
|
-
function StylesBundleService(document, translateService) {
|
|
969
|
-
this.document = document;
|
|
970
|
-
this.translateService = translateService;
|
|
971
|
-
}
|
|
972
|
-
StylesBundleService.prototype.loadThemes = function (lang, bundleEnglishName, bundleArabicName) {
|
|
973
|
-
if (lang == "ar") {
|
|
974
|
-
this.loadStyleBundle(bundleArabicName.toString());
|
|
975
|
-
document.querySelector('html').setAttribute("lang", "ar");
|
|
976
|
-
document.querySelector('html').setAttribute("dir", "rtl");
|
|
977
|
-
}
|
|
978
|
-
else {
|
|
979
|
-
this.loadStyleBundle(bundleEnglishName.toString());
|
|
980
|
-
document.querySelector('html').setAttribute("lang", "en");
|
|
981
|
-
document.querySelector('html').setAttribute("dir", "ltr");
|
|
982
|
-
}
|
|
983
|
-
};
|
|
984
|
-
StylesBundleService.prototype.loadStyleBundle = function (styleName) {
|
|
985
|
-
var head = this.document.getElementsByTagName('head')[0];
|
|
986
|
-
var themeLink = this.document.getElementById('client-theme');
|
|
987
|
-
if (themeLink && themeLink.href.includes(styleName)) {
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
990
|
-
else if (themeLink && !themeLink.href.includes(styleName)) {
|
|
991
|
-
themeLink.remove();
|
|
992
|
-
}
|
|
993
|
-
var style = this.document.createElement('link');
|
|
994
|
-
style.id = 'client-theme';
|
|
995
|
-
style.rel = 'stylesheet';
|
|
996
|
-
style.href = "" + styleName;
|
|
997
|
-
head.appendChild(style);
|
|
998
|
-
};
|
|
999
|
-
return StylesBundleService;
|
|
1000
|
-
}());
|
|
1001
|
-
StylesBundleService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0__namespace.ɵɵinject(i1__namespace$2.DOCUMENT), i0__namespace.ɵɵinject(BBSFTranslateService)); }, token: StylesBundleService, providedIn: "root" });
|
|
1002
|
-
StylesBundleService.decorators = [
|
|
1003
|
-
{ type: i0.Injectable, args: [{
|
|
1004
|
-
providedIn: 'root'
|
|
1005
|
-
},] }
|
|
1006
|
-
];
|
|
1007
|
-
StylesBundleService.ctorParameters = function () { return [
|
|
1008
|
-
{ type: Document, decorators: [{ type: i0.Inject, args: [i1$2.DOCUMENT,] }] },
|
|
1009
|
-
{ type: BBSFTranslateService }
|
|
1010
|
-
]; };
|
|
1011
|
-
|
|
1012
1092
|
var MasterLayoutService = /** @class */ (function () {
|
|
1013
1093
|
function MasterLayoutService(router, http, authService, stylesBundleService, translate) {
|
|
1014
1094
|
this.router = router;
|
|
@@ -1042,21 +1122,21 @@
|
|
|
1042
1122
|
var params = new i1$1.HttpParams();
|
|
1043
1123
|
params = params.append("UserId", this.authService.user.profile.id);
|
|
1044
1124
|
params = params.append("LanguageKey", key);
|
|
1045
|
-
return this.http.post(this.ApiUrl + 'updateLaguage', null, params);
|
|
1125
|
+
return this.http.post(this.ApiUrl + 'updateLaguage', null, null, params);
|
|
1046
1126
|
};
|
|
1047
1127
|
MasterLayoutService.prototype.updateUserInfo = function () {
|
|
1048
1128
|
return this.http.get('/connect/userinfo');
|
|
1049
1129
|
};
|
|
1050
1130
|
return MasterLayoutService;
|
|
1051
1131
|
}());
|
|
1052
|
-
MasterLayoutService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function MasterLayoutService_Factory() { return new MasterLayoutService(i0__namespace.ɵɵinject(
|
|
1132
|
+
MasterLayoutService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function MasterLayoutService_Factory() { return new MasterLayoutService(i0__namespace.ɵɵinject(i4__namespace.Router), i0__namespace.ɵɵinject(RequestHandlerService), i0__namespace.ɵɵinject(AuthService), i0__namespace.ɵɵinject(StylesBundleService), i0__namespace.ɵɵinject(i1__namespace.TranslateService)); }, token: MasterLayoutService, providedIn: "root" });
|
|
1053
1133
|
MasterLayoutService.decorators = [
|
|
1054
1134
|
{ type: i0.Injectable, args: [{
|
|
1055
1135
|
providedIn: 'root'
|
|
1056
1136
|
},] }
|
|
1057
1137
|
];
|
|
1058
1138
|
MasterLayoutService.ctorParameters = function () { return [
|
|
1059
|
-
{ type:
|
|
1139
|
+
{ type: i4.Router },
|
|
1060
1140
|
{ type: RequestHandlerService },
|
|
1061
1141
|
{ type: AuthService },
|
|
1062
1142
|
{ type: StylesBundleService },
|
|
@@ -1078,7 +1158,7 @@
|
|
|
1078
1158
|
i1$2.CommonModule,
|
|
1079
1159
|
ngBlockUi.BlockUIModule.forRoot(),
|
|
1080
1160
|
http.HttpModule,
|
|
1081
|
-
|
|
1161
|
+
i4.RouterModule,
|
|
1082
1162
|
ngxToastr.ToastrModule.forRoot(),
|
|
1083
1163
|
],
|
|
1084
1164
|
exports: [],
|