@bnsights/bbsf-utilities 1.0.0 → 1.0.4
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/README.md +5 -5
- package/bnsights-bbsf-utilities-1.0.4.tgz +0 -0
- package/bnsights-bbsf-utilities.metadata.json +1 -1
- package/bundles/bnsights-bbsf-utilities.umd.js +313 -239
- package/bundles/bnsights-bbsf-utilities.umd.js.map +1 -1
- package/esm2015/lib/shared/authentication/auth.service.js +20 -20
- package/esm2015/lib/shared/services/controlvalidation.service.js +48 -31
- package/esm2015/lib/shared/services/environment.service.js +5 -1
- package/esm2015/lib/shared/services/requesthandler.service.js +56 -18
- package/esm2015/lib/shared/services/stylesbundle.service.js +8 -4
- package/esm2015/lib/shared/services/translationresolver.service.js +20 -0
- package/esm2015/lib/shared/services/utility.service.js +21 -21
- package/esm2015/public-api.js +3 -2
- package/fesm2015/bnsights-bbsf-utilities.js +272 -191
- package/fesm2015/bnsights-bbsf-utilities.js.map +1 -1
- package/lib/shared/authentication/auth.service.d.ts +4 -2
- package/lib/shared/services/controlvalidation.service.d.ts +2 -2
- package/lib/shared/services/environment.service.d.ts +1 -0
- package/lib/shared/services/requesthandler.service.d.ts +11 -7
- package/lib/shared/services/stylesbundle.service.d.ts +3 -1
- package/lib/shared/services/translationresolver.service.d.ts +8 -0
- package/lib/shared/services/utility.service.d.ts +7 -5
- package/package.json +3 -16
- package/public-api.d.ts +1 -0
- package/bnsights-bbsf-utilities-1.0.0.tgz +0 -0
package/esm2015/public-api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Public API Surface of bbsf-utilities
|
|
2
|
+
* Public API Surface of @bnsights/bbsf-utilities
|
|
3
3
|
*/
|
|
4
4
|
export * from './lib/bbsf-utilities.module';
|
|
5
5
|
export * from './lib/shared/services/utility.service';
|
|
@@ -9,7 +9,8 @@ export * from './lib/shared/services/stylesbundle.service';
|
|
|
9
9
|
export * from './lib/shared/services/translate.service';
|
|
10
10
|
export * from './lib/shared/services/controlvalidation.service';
|
|
11
11
|
export * from './lib/shared/services/masterlayout.service';
|
|
12
|
+
export * from './lib/shared/services/translationresolver.service';
|
|
12
13
|
export * from './lib/shared/config/environment';
|
|
13
14
|
export * from './lib/shared/authentication/auth.service';
|
|
14
15
|
export * from './lib/shared/models/RequestOptionsModel';
|
|
15
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Byb2plY3RzL2Jic2YtdXRpbGl0aWVzL3NyYy9wdWJsaWMtYXBpLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBRUgsY0FBYyw2QkFBNkIsQ0FBQztBQUU1QyxjQUFjLHVDQUF1QyxDQUFDO0FBQ3RELGNBQWMsMkNBQTJDLENBQUM7QUFDMUQsY0FBYyw4Q0FBOEMsQ0FBQTtBQUM1RCxjQUFjLDRDQUE0QyxDQUFBO0FBQzFELGNBQWMseUNBQXlDLENBQUE7QUFDdkQsY0FBYyxpREFBaUQsQ0FBQTtBQUMvRCxjQUFjLDRDQUE0QyxDQUFBO0FBQzFELGNBQWMsbURBQW1ELENBQUE7QUFHakUsY0FBYyxpQ0FBaUMsQ0FBQztBQUdoRCxjQUFjLDBDQUEwQyxDQUFDO0FBR3pELGNBQWMseUNBQXlDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyIvKlxyXG4gKiBQdWJsaWMgQVBJIFN1cmZhY2Ugb2YgQGJuc2lnaHRzL2Jic2YtdXRpbGl0aWVzXHJcbiAqL1xyXG5cclxuZXhwb3J0ICogZnJvbSAnLi9saWIvYmJzZi11dGlsaXRpZXMubW9kdWxlJztcclxuXHJcbmV4cG9ydCAqIGZyb20gJy4vbGliL3NoYXJlZC9zZXJ2aWNlcy91dGlsaXR5LnNlcnZpY2UnO1xyXG5leHBvcnQgKiBmcm9tICcuL2xpYi9zaGFyZWQvc2VydmljZXMvZW52aXJvbm1lbnQuc2VydmljZSc7XHJcbmV4cG9ydCAqIGZyb20gJy4vbGliL3NoYXJlZC9zZXJ2aWNlcy9yZXF1ZXN0aGFuZGxlci5zZXJ2aWNlJ1xyXG5leHBvcnQgKiBmcm9tICcuL2xpYi9zaGFyZWQvc2VydmljZXMvc3R5bGVzYnVuZGxlLnNlcnZpY2UnXHJcbmV4cG9ydCAqIGZyb20gJy4vbGliL3NoYXJlZC9zZXJ2aWNlcy90cmFuc2xhdGUuc2VydmljZSdcclxuZXhwb3J0ICogZnJvbSAnLi9saWIvc2hhcmVkL3NlcnZpY2VzL2NvbnRyb2x2YWxpZGF0aW9uLnNlcnZpY2UnXHJcbmV4cG9ydCAqIGZyb20gJy4vbGliL3NoYXJlZC9zZXJ2aWNlcy9tYXN0ZXJsYXlvdXQuc2VydmljZSdcclxuZXhwb3J0ICogZnJvbSAnLi9saWIvc2hhcmVkL3NlcnZpY2VzL3RyYW5zbGF0aW9ucmVzb2x2ZXIuc2VydmljZSdcclxuXHJcblxyXG5leHBvcnQgKiBmcm9tICcuL2xpYi9zaGFyZWQvY29uZmlnL2Vudmlyb25tZW50JztcclxuXHJcblxyXG5leHBvcnQgKiBmcm9tICcuL2xpYi9zaGFyZWQvYXV0aGVudGljYXRpb24vYXV0aC5zZXJ2aWNlJztcclxuXHJcblxyXG5leHBvcnQgKiBmcm9tICcuL2xpYi9zaGFyZWQvbW9kZWxzL1JlcXVlc3RPcHRpb25zTW9kZWwnO1xyXG5cclxuIl19
|
|
@@ -4,16 +4,17 @@ import * as i0 from '@angular/core';
|
|
|
4
4
|
import { Injectable, Inject, NgModule, Injector } from '@angular/core';
|
|
5
5
|
import * as i1$3 from '@angular/router';
|
|
6
6
|
import { Router, RouterModule } from '@angular/router';
|
|
7
|
-
import * as i1
|
|
7
|
+
import * as i1 from '@ngx-translate/core';
|
|
8
8
|
import { TranslateService } from '@ngx-translate/core';
|
|
9
9
|
import { BlockUI, BlockUIModule } from 'ng-block-ui';
|
|
10
10
|
import { ToastrService, ToastrModule } from 'ngx-toastr';
|
|
11
11
|
import { HttpModule } from '@angular/http';
|
|
12
12
|
import { __awaiter, __decorate } from 'tslib';
|
|
13
|
-
import * as i1 from '@angular/common/http';
|
|
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
16
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
17
|
+
import { Observable } from 'rxjs/internal/Observable';
|
|
17
18
|
import { takeUntil, tap } from 'rxjs/operators';
|
|
18
19
|
|
|
19
20
|
// This file can be replaced during build by using the `fileReplacements` array.
|
|
@@ -44,6 +45,10 @@ class EnvironmentService {
|
|
|
44
45
|
let Mode = environment["BBSF_IsProduction"];
|
|
45
46
|
return Mode;
|
|
46
47
|
}
|
|
48
|
+
getDefaultLanguage() {
|
|
49
|
+
let Mode = environment["BBSF_DefaultLanguage"];
|
|
50
|
+
return Mode;
|
|
51
|
+
}
|
|
47
52
|
getIdentityServerUrl() {
|
|
48
53
|
let Url = environment["BBSF_IdentityServerUrl"];
|
|
49
54
|
return Url;
|
|
@@ -56,10 +61,20 @@ EnvironmentService.decorators = [
|
|
|
56
61
|
},] }
|
|
57
62
|
];
|
|
58
63
|
|
|
64
|
+
class BBSFTranslateService extends TranslateService {
|
|
65
|
+
}
|
|
66
|
+
BBSFTranslateService.ɵprov = i0.ɵɵdefineInjectable({ factory: function BBSFTranslateService_Factory() { return new BBSFTranslateService(i0.ɵɵinject(i1.TranslateStore), i0.ɵɵinject(i1.TranslateLoader), i0.ɵɵinject(i1.TranslateCompiler), i0.ɵɵinject(i1.TranslateParser), i0.ɵɵinject(i1.MissingTranslationHandler), i0.ɵɵinject(i1.USE_DEFAULT_LANG), i0.ɵɵinject(i1.USE_STORE), i0.ɵɵinject(i1.USE_EXTEND), i0.ɵɵinject(i1.DEFAULT_LANGUAGE)); }, token: BBSFTranslateService, providedIn: "root" });
|
|
67
|
+
BBSFTranslateService.decorators = [
|
|
68
|
+
{ type: Injectable, args: [{
|
|
69
|
+
providedIn: 'root'
|
|
70
|
+
},] }
|
|
71
|
+
];
|
|
72
|
+
|
|
59
73
|
class AuthService {
|
|
60
|
-
constructor(http, environmentService) {
|
|
74
|
+
constructor(http, environmentService, translateService) {
|
|
61
75
|
this.http = http;
|
|
62
76
|
this.environmentService = environmentService;
|
|
77
|
+
this.translateService = translateService;
|
|
63
78
|
// Observable navItem source
|
|
64
79
|
this._authNavStatusSource = new BehaviorSubject(false);
|
|
65
80
|
// Observable navItem stream
|
|
@@ -118,6 +133,13 @@ class AuthService {
|
|
|
118
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
119
134
|
this.user = yield this.manager.signinRedirectCallback();
|
|
120
135
|
AuthService.user = this.user;
|
|
136
|
+
localStorage.setItem("language", this.user.profile.locale);
|
|
137
|
+
if (this.translateService.currentLang != this.user.profile.locale) {
|
|
138
|
+
this.translateService.resetLang(this.translateService.currentLang);
|
|
139
|
+
yield this.translateService.reloadLang(this.user.profile.locale).subscribe((res) => {
|
|
140
|
+
console.log(res);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
121
143
|
this._userSource.next(AuthService.user);
|
|
122
144
|
this._authNavStatusSource.next(yield this.isAuthenticated());
|
|
123
145
|
});
|
|
@@ -141,31 +163,20 @@ class AuthService {
|
|
|
141
163
|
getCurrentUser() {
|
|
142
164
|
return this.manager.getUser();
|
|
143
165
|
}
|
|
144
|
-
isAuthenticated(
|
|
166
|
+
isAuthenticated() {
|
|
145
167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
168
|
let user = yield this.manager.getUser().then(user => {
|
|
147
169
|
return user;
|
|
148
170
|
});
|
|
149
|
-
|
|
150
|
-
if (allowedPermission.length == 0) {
|
|
151
|
-
return this.user != null && !this.user.expired;
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
let isUserInRole = this.isUserInRole(allowedPermission);
|
|
155
|
-
return this.user != null && !this.user.expired && isUserInRole;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
else
|
|
159
|
-
return this.user != null && !this.user.expired;
|
|
171
|
+
return this.user != null && !this.user.expired;
|
|
160
172
|
});
|
|
161
173
|
}
|
|
162
174
|
isUserInRole(allowedPermission) {
|
|
163
|
-
;
|
|
164
|
-
|
|
165
|
-
return allowedPermission.every(i => permissionSetSID.includes(i));
|
|
175
|
+
let selectedPermissionSetID = this.user.profile["selectedPermissionSetID"];
|
|
176
|
+
return allowedPermission.includes(selectedPermissionSetID);
|
|
166
177
|
}
|
|
167
178
|
authorizationHeaderValue() {
|
|
168
|
-
return `${AuthService.user.token_type} ${AuthService.user.access_token}
|
|
179
|
+
return AuthService.user ? `${AuthService.user.token_type} ${AuthService.user.access_token}` : "";
|
|
169
180
|
}
|
|
170
181
|
name() {
|
|
171
182
|
return AuthService.user != null ? AuthService.user.profile.given_name : '';
|
|
@@ -193,7 +204,7 @@ class AuthService {
|
|
|
193
204
|
}
|
|
194
205
|
}
|
|
195
206
|
AuthService.user = null;
|
|
196
|
-
AuthService.ɵprov = i0.ɵɵdefineInjectable({ factory: function AuthService_Factory() { return new AuthService(i0.ɵɵinject(i1.HttpClient), i0.ɵɵinject(EnvironmentService)); }, token: AuthService, providedIn: "root" });
|
|
207
|
+
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" });
|
|
197
208
|
AuthService.decorators = [
|
|
198
209
|
{ type: Injectable, args: [{
|
|
199
210
|
providedIn: 'root'
|
|
@@ -201,46 +212,35 @@ AuthService.decorators = [
|
|
|
201
212
|
];
|
|
202
213
|
AuthService.ctorParameters = () => [
|
|
203
214
|
{ type: HttpClient },
|
|
204
|
-
{ type: EnvironmentService }
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
class BBSFTranslateService extends TranslateService {
|
|
208
|
-
}
|
|
209
|
-
BBSFTranslateService.ɵprov = i0.ɵɵdefineInjectable({ factory: function BBSFTranslateService_Factory() { return new BBSFTranslateService(i0.ɵɵinject(i1$1.TranslateStore), i0.ɵɵinject(i1$1.TranslateLoader), i0.ɵɵinject(i1$1.TranslateCompiler), i0.ɵɵinject(i1$1.TranslateParser), i0.ɵɵinject(i1$1.MissingTranslationHandler), i0.ɵɵinject(i1$1.USE_DEFAULT_LANG), i0.ɵɵinject(i1$1.USE_STORE), i0.ɵɵinject(i1$1.USE_EXTEND), i0.ɵɵinject(i1$1.DEFAULT_LANGUAGE)); }, token: BBSFTranslateService, providedIn: "root" });
|
|
210
|
-
BBSFTranslateService.decorators = [
|
|
211
|
-
{ type: Injectable, args: [{
|
|
212
|
-
providedIn: 'root'
|
|
213
|
-
},] }
|
|
215
|
+
{ type: EnvironmentService },
|
|
216
|
+
{ type: BBSFTranslateService }
|
|
214
217
|
];
|
|
215
218
|
|
|
216
219
|
class UtilityService {
|
|
217
|
-
constructor(
|
|
218
|
-
this.
|
|
220
|
+
constructor(translator, authService, environmentService) {
|
|
221
|
+
this.translator = translator;
|
|
219
222
|
this.authService = authService;
|
|
223
|
+
this.environmentService = environmentService;
|
|
220
224
|
this.isCreatedBefore = false;
|
|
221
225
|
}
|
|
222
226
|
getResourceValue(Key) {
|
|
223
|
-
let ResourceValue =
|
|
224
|
-
this.Translator.get(Key).subscribe(data => { ResourceValue = data; return ResourceValue; });
|
|
227
|
+
let ResourceValue = this.translator.instant(Key);
|
|
225
228
|
return ResourceValue;
|
|
226
229
|
}
|
|
227
230
|
getCurrentLanguage() {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
let currentLanguage = this.environmentService.getDefaultLanguage();
|
|
232
|
+
let lang = localStorage.getItem('language');
|
|
233
|
+
if (lang)
|
|
234
|
+
currentLanguage = lang;
|
|
235
|
+
else
|
|
236
|
+
localStorage.setItem('language', currentLanguage);
|
|
237
|
+
return currentLanguage;
|
|
234
238
|
}
|
|
235
239
|
isCurrentLanguageEnglish() {
|
|
236
|
-
|
|
237
|
-
(yield this.getCurrentLanguage()) == "en" ? true : false;
|
|
238
|
-
});
|
|
240
|
+
this.getCurrentLanguage() == "en";
|
|
239
241
|
}
|
|
240
242
|
isCurrentLanguageArabic() {
|
|
241
|
-
|
|
242
|
-
(yield this.getCurrentLanguage()) == "ar" ? true : false;
|
|
243
|
-
});
|
|
243
|
+
this.getCurrentLanguage() == "ar";
|
|
244
244
|
}
|
|
245
245
|
notifySuccessMessage(Message, title, time) {
|
|
246
246
|
let MessageTemplate = this.getResourceValue("SuccessMessage");
|
|
@@ -285,7 +285,7 @@ class UtilityService {
|
|
|
285
285
|
this.blockUI.stop();
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
-
UtilityService.ɵprov = i0.ɵɵdefineInjectable({ factory: function UtilityService_Factory() { return new UtilityService(i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(AuthService)); }, token: UtilityService, providedIn: "root" });
|
|
288
|
+
UtilityService.ɵprov = i0.ɵɵdefineInjectable({ factory: function UtilityService_Factory() { return new UtilityService(i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(AuthService), i0.ɵɵinject(EnvironmentService)); }, token: UtilityService, providedIn: "root" });
|
|
289
289
|
UtilityService.decorators = [
|
|
290
290
|
{ type: Injectable, args: [{
|
|
291
291
|
providedIn: 'root'
|
|
@@ -293,7 +293,8 @@ UtilityService.decorators = [
|
|
|
293
293
|
];
|
|
294
294
|
UtilityService.ctorParameters = () => [
|
|
295
295
|
{ type: BBSFTranslateService },
|
|
296
|
-
{ type: AuthService }
|
|
296
|
+
{ type: AuthService },
|
|
297
|
+
{ type: EnvironmentService }
|
|
297
298
|
];
|
|
298
299
|
__decorate([
|
|
299
300
|
BlockUI()
|
|
@@ -308,13 +309,170 @@ class RequestOptionsModel {
|
|
|
308
309
|
}
|
|
309
310
|
}
|
|
310
311
|
|
|
312
|
+
class RequestHandlerService {
|
|
313
|
+
constructor(http, authService, environmentService, utilityService, bbsfTranslateService) {
|
|
314
|
+
//using localStorage to avoid call getCurrentLanguage() because it is not all to use async in constructor
|
|
315
|
+
this.http = http;
|
|
316
|
+
this.authService = authService;
|
|
317
|
+
this.environmentService = environmentService;
|
|
318
|
+
this.utilityService = utilityService;
|
|
319
|
+
this.bbsfTranslateService = bbsfTranslateService;
|
|
320
|
+
this.requestOptions = new RequestOptionsModel();
|
|
321
|
+
this.currentLanguage = "";
|
|
322
|
+
this.onDestroy$ = new Subject();
|
|
323
|
+
this.bbsfTranslateService.onLangChange.subscribe((event) => {
|
|
324
|
+
if (this.currentLanguage != event.lang) {
|
|
325
|
+
this.currentLanguage = event.lang;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
getLuckyNumber() {
|
|
330
|
+
return Observable.create((subject) => {
|
|
331
|
+
setInterval(() => {
|
|
332
|
+
const number = Math.floor(Math.random() * 10);
|
|
333
|
+
console.log(number);
|
|
334
|
+
subject.next(number);
|
|
335
|
+
}, 1000);
|
|
336
|
+
}).pipe(takeUntil(this.onDestroy$));
|
|
337
|
+
}
|
|
338
|
+
get(Url, params, requestOptions) {
|
|
339
|
+
if (requestOptions)
|
|
340
|
+
this.requestOptions = requestOptions;
|
|
341
|
+
let headers = new HttpHeaders({
|
|
342
|
+
'Content-Type': 'application/json',
|
|
343
|
+
'Authorization': this.authService.authorizationHeaderValue(),
|
|
344
|
+
});
|
|
345
|
+
this.currentLanguage = localStorage.getItem('language');
|
|
346
|
+
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
347
|
+
headers = headers.set('ignore-cookies', 'true');
|
|
348
|
+
if (!this.requestOptions.disableBlockUI)
|
|
349
|
+
this.utilityService.startBlockUI();
|
|
350
|
+
return this.http.get(this.environmentService.getApiUrl() + Url, { headers: headers, params: params }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
351
|
+
if (!this.requestOptions.disableBlockUI)
|
|
352
|
+
this.utilityService.stopBlockUI();
|
|
353
|
+
}));
|
|
354
|
+
}
|
|
355
|
+
post(Url, model, params, requestOptions) {
|
|
356
|
+
if (requestOptions)
|
|
357
|
+
this.requestOptions = requestOptions;
|
|
358
|
+
let headers = new HttpHeaders({
|
|
359
|
+
'Content-Type': 'application/json',
|
|
360
|
+
'Authorization': this.authService.authorizationHeaderValue(),
|
|
361
|
+
});
|
|
362
|
+
this.currentLanguage = localStorage.getItem('language');
|
|
363
|
+
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
364
|
+
headers = headers.set('ignore-cookies', 'true');
|
|
365
|
+
if (!this.requestOptions.disableBlockUI)
|
|
366
|
+
this.utilityService.startBlockUI();
|
|
367
|
+
return this.http.post(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
368
|
+
if (!this.requestOptions.disableBlockUI)
|
|
369
|
+
this.utilityService.stopBlockUI();
|
|
370
|
+
}));
|
|
371
|
+
}
|
|
372
|
+
delete(Url, deletedId, params, requestOptions) {
|
|
373
|
+
if (requestOptions)
|
|
374
|
+
this.requestOptions = requestOptions;
|
|
375
|
+
let headers = new HttpHeaders({
|
|
376
|
+
'Content-Type': 'application/json',
|
|
377
|
+
'Authorization': this.authService.authorizationHeaderValue(),
|
|
378
|
+
});
|
|
379
|
+
this.currentLanguage = localStorage.getItem('language');
|
|
380
|
+
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
381
|
+
headers = headers.set('ignore-cookies', 'true');
|
|
382
|
+
if (!this.requestOptions.disableBlockUI)
|
|
383
|
+
this.utilityService.startBlockUI();
|
|
384
|
+
return this.http.delete(this.environmentService.getApiUrl() + Url + `/${deletedId}`, { headers: headers, params: params }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
385
|
+
if (!this.requestOptions.disableBlockUI)
|
|
386
|
+
this.utilityService.stopBlockUI();
|
|
387
|
+
}));
|
|
388
|
+
}
|
|
389
|
+
put(Url, model, params, requestOptions) {
|
|
390
|
+
if (requestOptions)
|
|
391
|
+
this.requestOptions = requestOptions;
|
|
392
|
+
let headers = new HttpHeaders({
|
|
393
|
+
'Content-Type': 'application/json',
|
|
394
|
+
'Authorization': this.authService.authorizationHeaderValue(),
|
|
395
|
+
});
|
|
396
|
+
this.currentLanguage = localStorage.getItem('language');
|
|
397
|
+
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
398
|
+
headers = headers.set('ignore-cookies', 'true');
|
|
399
|
+
if (!this.requestOptions.disableBlockUI)
|
|
400
|
+
this.utilityService.startBlockUI();
|
|
401
|
+
return this.http.put(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
402
|
+
if (!this.requestOptions.disableBlockUI)
|
|
403
|
+
this.utilityService.stopBlockUI();
|
|
404
|
+
}));
|
|
405
|
+
}
|
|
406
|
+
destroyHandler() {
|
|
407
|
+
this.onDestroy$.next();
|
|
408
|
+
}
|
|
409
|
+
ngOnDestroy() {
|
|
410
|
+
console.log("clearInterval");
|
|
411
|
+
this.destroyHandler();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
RequestHandlerService.decorators = [
|
|
415
|
+
{ type: Injectable }
|
|
416
|
+
];
|
|
417
|
+
RequestHandlerService.ctorParameters = () => [
|
|
418
|
+
{ type: HttpClient },
|
|
419
|
+
{ type: AuthService },
|
|
420
|
+
{ type: EnvironmentService },
|
|
421
|
+
{ type: UtilityService },
|
|
422
|
+
{ type: BBSFTranslateService }
|
|
423
|
+
];
|
|
424
|
+
|
|
425
|
+
class StylesBundleService {
|
|
426
|
+
constructor(document, translateService) {
|
|
427
|
+
this.document = document;
|
|
428
|
+
this.translateService = translateService;
|
|
429
|
+
}
|
|
430
|
+
loadThemes(lang, bundleEnglishName, bundleArabicName) {
|
|
431
|
+
if (lang == "ar") {
|
|
432
|
+
this.loadStyleBundle(bundleArabicName.toString());
|
|
433
|
+
document.querySelector('html').setAttribute("lang", "ar");
|
|
434
|
+
document.querySelector('html').setAttribute("dir", "rtl");
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
this.loadStyleBundle(bundleEnglishName.toString());
|
|
438
|
+
document.querySelector('html').setAttribute("lang", "en");
|
|
439
|
+
document.querySelector('html').setAttribute("dir", "ltr");
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
loadStyleBundle(styleName) {
|
|
443
|
+
const head = this.document.getElementsByTagName('head')[0];
|
|
444
|
+
let themeLink = this.document.getElementById('client-theme');
|
|
445
|
+
if (themeLink && themeLink.href.includes(styleName)) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
else if (themeLink && !themeLink.href.includes(styleName)) {
|
|
449
|
+
themeLink.remove();
|
|
450
|
+
}
|
|
451
|
+
const style = this.document.createElement('link');
|
|
452
|
+
style.id = 'client-theme';
|
|
453
|
+
style.rel = 'stylesheet';
|
|
454
|
+
style.href = `${styleName}`;
|
|
455
|
+
head.appendChild(style);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
StylesBundleService.ɵprov = i0.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0.ɵɵinject(i1$2.DOCUMENT), i0.ɵɵinject(BBSFTranslateService)); }, token: StylesBundleService, providedIn: "root" });
|
|
459
|
+
StylesBundleService.decorators = [
|
|
460
|
+
{ type: Injectable, args: [{
|
|
461
|
+
providedIn: 'root'
|
|
462
|
+
},] }
|
|
463
|
+
];
|
|
464
|
+
StylesBundleService.ctorParameters = () => [
|
|
465
|
+
{ type: Document, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
|
|
466
|
+
{ type: BBSFTranslateService }
|
|
467
|
+
];
|
|
468
|
+
|
|
311
469
|
class ControlValidationService {
|
|
312
470
|
constructor(utilityService) {
|
|
313
471
|
this.utilityService = utilityService;
|
|
314
472
|
this.requestOptions = new RequestOptionsModel();
|
|
315
473
|
this.isCreatedBefor = false;
|
|
316
474
|
}
|
|
317
|
-
showGlobalError(errorMessage) {
|
|
475
|
+
showGlobalError(errorMessage, formId, deleteOld) {
|
|
318
476
|
let globalErorrElement = document.getElementsByClassName('alert alert-danger alert-InvalidValidation');
|
|
319
477
|
if (globalErorrElement.length > 0) {
|
|
320
478
|
this.removeElementsByClass('alert alert-danger alert-InvalidValidation');
|
|
@@ -323,28 +481,40 @@ class ControlValidationService {
|
|
|
323
481
|
this.removeElementsByClass('alert alert-danger alert-InvalidValidation');
|
|
324
482
|
}
|
|
325
483
|
// tslint:disable-next-line: prefer-const
|
|
326
|
-
|
|
484
|
+
if (!formId)
|
|
485
|
+
formId = "currentForm";
|
|
486
|
+
var object = document.getElementById(formId);
|
|
327
487
|
const tagName = 'div';
|
|
328
488
|
// tslint:disable-next-line: prefer-const
|
|
329
489
|
var elementToAppend = document.createElement(tagName); // Your tag name here
|
|
330
490
|
let message = "";
|
|
331
|
-
if (
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
// const elementToAppen = elementToAppend.cloneNode(true);
|
|
341
|
-
// objects[i].insertBefore(elementToAppen, objects[i].firstChild);
|
|
491
|
+
if (!errorMessage || (typeof errorMessage == "string")) {
|
|
492
|
+
if (localStorage.getItem('language') == "ar")
|
|
493
|
+
message = errorMessage ? errorMessage : "لديك بعص الأخطاء . من فضلك قم بالمراجعه ";
|
|
494
|
+
else
|
|
495
|
+
message = errorMessage ? errorMessage : "You have some validation errors. Please check below";
|
|
496
|
+
elementToAppend.innerHTML = "<ul><li>" + message + "</li></ul>";
|
|
497
|
+
elementToAppend.className += 'alert alert-danger alert-InvalidValidation';
|
|
498
|
+
elementToAppend.id += 'errorId';
|
|
499
|
+
// tslint:disable-next-line: prefer-for-of
|
|
342
500
|
const elementToAppen = elementToAppend.cloneNode(true);
|
|
343
|
-
let targetElement =
|
|
344
|
-
|
|
345
|
-
this.isCreatedBefor = true;
|
|
346
|
-
break;
|
|
501
|
+
// let targetElement = object.getElementsByClassName("b-control")[0];
|
|
502
|
+
object.insertBefore(elementToAppen, object.firstChild);
|
|
347
503
|
}
|
|
504
|
+
else {
|
|
505
|
+
elementToAppend.innerHTML = "<ul>";
|
|
506
|
+
for (const iterator of errorMessage) {
|
|
507
|
+
elementToAppend.innerHTML = "<li>" + iterator + "</li>";
|
|
508
|
+
}
|
|
509
|
+
elementToAppend.innerHTML = "</ul>";
|
|
510
|
+
elementToAppend.className += 'alert alert-danger alert-InvalidValidation';
|
|
511
|
+
elementToAppend.id += 'errorId';
|
|
512
|
+
// tslint:disable-next-line: prefer-for-of
|
|
513
|
+
const elementToAppen = elementToAppend.cloneNode(true);
|
|
514
|
+
// let targetElement = object.getElementsByClassName("b-control")[0];
|
|
515
|
+
object.insertBefore(elementToAppen, object.firstChild);
|
|
516
|
+
}
|
|
517
|
+
this.isCreatedBefor = true;
|
|
348
518
|
}
|
|
349
519
|
RemoveGlobalError() {
|
|
350
520
|
const removedList = document.getElementsByClassName('alert alert-danger alert-InvalidValidation');
|
|
@@ -386,10 +556,11 @@ class ControlValidationService {
|
|
|
386
556
|
elements[0].parentNode.removeChild(elements[0]);
|
|
387
557
|
}
|
|
388
558
|
}
|
|
389
|
-
renderServerErrors(form, err, requestOptions) {
|
|
559
|
+
renderServerErrors(form, err, requestOptions, formId) {
|
|
390
560
|
if (err.error == null) {
|
|
391
561
|
return;
|
|
392
562
|
}
|
|
563
|
+
let errorsArray = [];
|
|
393
564
|
this.requestOptions = requestOptions;
|
|
394
565
|
err.error.validation_errors.forEach((element) => {
|
|
395
566
|
let fieldName = element.field;
|
|
@@ -399,41 +570,45 @@ class ControlValidationService {
|
|
|
399
570
|
this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(`${fieldName}: ${message}`);
|
|
400
571
|
}
|
|
401
572
|
else if (!this.hasControlName(form, controlName)) {
|
|
402
|
-
|
|
573
|
+
errorsArray.push(`${fieldName}: ${message}`);
|
|
574
|
+
// this.showGlobalError(`${fieldName}: ${message}`,formId )
|
|
403
575
|
}
|
|
404
576
|
else {
|
|
405
577
|
this.setFieldError(form, controlName, fieldName, message);
|
|
406
578
|
}
|
|
407
579
|
});
|
|
580
|
+
if (errorsArray.length > 0)
|
|
581
|
+
this.showGlobalError(errorsArray, formId);
|
|
408
582
|
}
|
|
409
583
|
hasControlName(form, controlName) {
|
|
410
584
|
let control = form.get(controlName);
|
|
411
585
|
return control != null;
|
|
412
586
|
}
|
|
413
587
|
setFieldError(form, controlName, fieldName, message) {
|
|
414
|
-
let control =
|
|
415
|
-
|
|
588
|
+
let control = null;
|
|
589
|
+
if (controlName)
|
|
590
|
+
control = form.get(controlName);
|
|
591
|
+
else
|
|
592
|
+
control = form.get(fieldName.split('.')[0]);
|
|
593
|
+
let errors = { "errorMassage": message };
|
|
416
594
|
let fieldNameArray = fieldName.split('.');
|
|
417
595
|
if (fieldNameArray.length >= 1) {
|
|
418
|
-
switch (fieldNameArray[length - 1].toLocaleLowerCase()) {
|
|
596
|
+
switch (fieldNameArray[fieldNameArray.length - 1].toLocaleLowerCase()) {
|
|
419
597
|
case "english":
|
|
420
|
-
let englishControl = control.get("
|
|
598
|
+
let englishControl = control.get("English");
|
|
421
599
|
englishControl.setErrors(errors);
|
|
422
|
-
englishControl.markAsTouched();
|
|
423
|
-
englishControl.updateValueAndValidity();
|
|
424
600
|
break;
|
|
425
601
|
case "arabic":
|
|
426
|
-
let arabicControl = control.get("
|
|
602
|
+
let arabicControl = control.get("Arabic");
|
|
427
603
|
arabicControl.setErrors(errors);
|
|
428
|
-
arabicControl.markAsTouched();
|
|
429
|
-
arabicControl.updateValueAndValidity();
|
|
430
604
|
break;
|
|
431
605
|
default:
|
|
432
606
|
control.setErrors(errors);
|
|
433
|
-
control.markAsTouched();
|
|
434
|
-
control.updateValueAndValidity();
|
|
435
607
|
}
|
|
436
608
|
}
|
|
609
|
+
else if (fieldNameArray.length == 1) {
|
|
610
|
+
control.setErrors(errors);
|
|
611
|
+
}
|
|
437
612
|
else {
|
|
438
613
|
this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(`${fieldName}: ${message}`);
|
|
439
614
|
}
|
|
@@ -452,116 +627,6 @@ __decorate([
|
|
|
452
627
|
BlockUI()
|
|
453
628
|
], ControlValidationService.prototype, "blockUI", void 0);
|
|
454
629
|
|
|
455
|
-
class RequestHandlerService {
|
|
456
|
-
constructor(http, authService, environmentService, utilityService, controlValidationService, bbsfTranslateService) {
|
|
457
|
-
this.http = http;
|
|
458
|
-
this.authService = authService;
|
|
459
|
-
this.environmentService = environmentService;
|
|
460
|
-
this.utilityService = utilityService;
|
|
461
|
-
this.controlValidationService = controlValidationService;
|
|
462
|
-
this.bbsfTranslateService = bbsfTranslateService;
|
|
463
|
-
this.requestOptions = new RequestOptionsModel();
|
|
464
|
-
this.currentLanguage = "";
|
|
465
|
-
this.onDestroy$ = new Subject();
|
|
466
|
-
//using localStorage to avoid call getCurrentLanguage() because it is not all to use async in constructor
|
|
467
|
-
this.currentLanguage = localStorage.getItem('language');
|
|
468
|
-
this.bbsfTranslateService.onLangChange.subscribe((event) => {
|
|
469
|
-
if (this.currentLanguage != event.lang) {
|
|
470
|
-
this.currentLanguage = event.lang;
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
get(Url, params, requestOptions) {
|
|
475
|
-
if (requestOptions)
|
|
476
|
-
this.requestOptions = requestOptions;
|
|
477
|
-
let headers = new HttpHeaders({
|
|
478
|
-
'Content-Type': 'application/json',
|
|
479
|
-
'Authorization': this.authService.authorizationHeaderValue(),
|
|
480
|
-
});
|
|
481
|
-
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
482
|
-
if (!this.requestOptions.disableBlockUI)
|
|
483
|
-
this.utilityService.startBlockUI();
|
|
484
|
-
return this.http.get(this.environmentService.getApiUrl() + Url, { headers: headers, params: params }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
485
|
-
if (!this.requestOptions.disableBlockUI)
|
|
486
|
-
this.utilityService.stopBlockUI();
|
|
487
|
-
}));
|
|
488
|
-
}
|
|
489
|
-
post(Url, model, params, requestOptions) {
|
|
490
|
-
if (requestOptions)
|
|
491
|
-
this.requestOptions = requestOptions;
|
|
492
|
-
let headers = new HttpHeaders({
|
|
493
|
-
'Content-Type': 'application/json',
|
|
494
|
-
'Authorization': this.authService.authorizationHeaderValue(),
|
|
495
|
-
});
|
|
496
|
-
headers = headers.set('Accept-Language', this.currentLanguage.toString());
|
|
497
|
-
if (!this.requestOptions.disableBlockUI)
|
|
498
|
-
this.utilityService.startBlockUI();
|
|
499
|
-
return this.http.post(this.environmentService.getApiUrl() + Url, model, { headers: headers, params: params, responseType: this.requestOptions.responseType }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
500
|
-
if (!this.requestOptions.disableBlockUI)
|
|
501
|
-
this.utilityService.stopBlockUI();
|
|
502
|
-
}));
|
|
503
|
-
}
|
|
504
|
-
destroyHandler() {
|
|
505
|
-
this.onDestroy$.next();
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
RequestHandlerService.ɵprov = i0.ɵɵdefineInjectable({ factory: function RequestHandlerService_Factory() { return new RequestHandlerService(i0.ɵɵinject(i1.HttpClient), i0.ɵɵinject(AuthService), i0.ɵɵinject(EnvironmentService), i0.ɵɵinject(UtilityService), i0.ɵɵinject(ControlValidationService), i0.ɵɵinject(BBSFTranslateService)); }, token: RequestHandlerService, providedIn: "root" });
|
|
509
|
-
RequestHandlerService.decorators = [
|
|
510
|
-
{ type: Injectable, args: [{
|
|
511
|
-
providedIn: 'root'
|
|
512
|
-
},] }
|
|
513
|
-
];
|
|
514
|
-
RequestHandlerService.ctorParameters = () => [
|
|
515
|
-
{ type: HttpClient },
|
|
516
|
-
{ type: AuthService },
|
|
517
|
-
{ type: EnvironmentService },
|
|
518
|
-
{ type: UtilityService },
|
|
519
|
-
{ type: ControlValidationService },
|
|
520
|
-
{ type: BBSFTranslateService }
|
|
521
|
-
];
|
|
522
|
-
|
|
523
|
-
class StylesBundleService {
|
|
524
|
-
constructor(document) {
|
|
525
|
-
this.document = document;
|
|
526
|
-
}
|
|
527
|
-
loadThemes(lang, bundleEnglishName, bundleArabicName) {
|
|
528
|
-
if (lang == "ar") {
|
|
529
|
-
this.loadStyleBundle(bundleArabicName.toString());
|
|
530
|
-
document.querySelector('html').setAttribute("lang", "ar");
|
|
531
|
-
document.querySelector('html').setAttribute("dir", "rtl");
|
|
532
|
-
}
|
|
533
|
-
else {
|
|
534
|
-
this.loadStyleBundle(bundleEnglishName.toString());
|
|
535
|
-
document.querySelector('html').setAttribute("lang", "en");
|
|
536
|
-
document.querySelector('html').setAttribute("dir", "ltr");
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
loadStyleBundle(styleName) {
|
|
540
|
-
const head = this.document.getElementsByTagName('head')[0];
|
|
541
|
-
let themeLink = this.document.getElementById('client-theme');
|
|
542
|
-
if (themeLink && themeLink.href.includes(styleName)) {
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
else if (themeLink && !themeLink.href.includes(styleName)) {
|
|
546
|
-
themeLink.remove();
|
|
547
|
-
}
|
|
548
|
-
const style = this.document.createElement('link');
|
|
549
|
-
style.id = 'client-theme';
|
|
550
|
-
style.rel = 'stylesheet';
|
|
551
|
-
style.href = `${styleName}`;
|
|
552
|
-
head.appendChild(style);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
StylesBundleService.ɵprov = i0.ɵɵdefineInjectable({ factory: function StylesBundleService_Factory() { return new StylesBundleService(i0.ɵɵinject(i1$2.DOCUMENT)); }, token: StylesBundleService, providedIn: "root" });
|
|
556
|
-
StylesBundleService.decorators = [
|
|
557
|
-
{ type: Injectable, args: [{
|
|
558
|
-
providedIn: 'root'
|
|
559
|
-
},] }
|
|
560
|
-
];
|
|
561
|
-
StylesBundleService.ctorParameters = () => [
|
|
562
|
-
{ type: Document, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
|
|
563
|
-
];
|
|
564
|
-
|
|
565
630
|
class MasterLayoutService {
|
|
566
631
|
constructor(router, http, authService, stylesBundleService, translate) {
|
|
567
632
|
this.router = router;
|
|
@@ -600,7 +665,7 @@ class MasterLayoutService {
|
|
|
600
665
|
return this.http.get('/connect/userinfo');
|
|
601
666
|
}
|
|
602
667
|
}
|
|
603
|
-
MasterLayoutService.ɵprov = i0.ɵɵdefineInjectable({ factory: function MasterLayoutService_Factory() { return new MasterLayoutService(i0.ɵɵinject(i1$3.Router), i0.ɵɵinject(RequestHandlerService), i0.ɵɵinject(AuthService), i0.ɵɵinject(StylesBundleService), i0.ɵɵinject(i1
|
|
668
|
+
MasterLayoutService.ɵprov = i0.ɵɵdefineInjectable({ factory: function MasterLayoutService_Factory() { return new MasterLayoutService(i0.ɵɵinject(i1$3.Router), i0.ɵɵinject(RequestHandlerService), i0.ɵɵinject(AuthService), i0.ɵɵinject(StylesBundleService), i0.ɵɵinject(i1.TranslateService)); }, token: MasterLayoutService, providedIn: "root" });
|
|
604
669
|
MasterLayoutService.decorators = [
|
|
605
670
|
{ type: Injectable, args: [{
|
|
606
671
|
providedIn: 'root'
|
|
@@ -649,13 +714,29 @@ BBSFUtilitiesModule.ctorParameters = () => [
|
|
|
649
714
|
{ type: Injector }
|
|
650
715
|
];
|
|
651
716
|
|
|
717
|
+
class TranslationResolverService {
|
|
718
|
+
constructor(translateService) {
|
|
719
|
+
this.translateService = translateService;
|
|
720
|
+
}
|
|
721
|
+
resolve() {
|
|
722
|
+
return this.translateService.getTranslation(this.translateService.currentLang);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
TranslationResolverService.ɵprov = i0.ɵɵdefineInjectable({ factory: function TranslationResolverService_Factory() { return new TranslationResolverService(i0.ɵɵinject(BBSFTranslateService)); }, token: TranslationResolverService, providedIn: "root" });
|
|
726
|
+
TranslationResolverService.decorators = [
|
|
727
|
+
{ type: Injectable, args: [{ providedIn: 'root' },] }
|
|
728
|
+
];
|
|
729
|
+
TranslationResolverService.ctorParameters = () => [
|
|
730
|
+
{ type: BBSFTranslateService }
|
|
731
|
+
];
|
|
732
|
+
|
|
652
733
|
/*
|
|
653
|
-
* Public API Surface of bbsf-utilities
|
|
734
|
+
* Public API Surface of @bnsights/bbsf-utilities
|
|
654
735
|
*/
|
|
655
736
|
|
|
656
737
|
/**
|
|
657
738
|
* Generated bundle index. Do not edit.
|
|
658
739
|
*/
|
|
659
740
|
|
|
660
|
-
export { AppInjector, AuthService, BBSFTranslateService, BBSFUtilitiesModule, ControlValidationService, EnvironmentService, MasterLayoutService, RequestHandlerService, RequestOptionsModel, StylesBundleService, UtilityService, environment };
|
|
741
|
+
export { AppInjector, AuthService, BBSFTranslateService, BBSFUtilitiesModule, ControlValidationService, EnvironmentService, MasterLayoutService, RequestHandlerService, RequestOptionsModel, StylesBundleService, TranslationResolverService, UtilityService, environment };
|
|
661
742
|
//# sourceMappingURL=bnsights-bbsf-utilities.js.map
|