@bnsights/bbsf-utilities 1.0.0
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 +24 -0
- package/bnsights-bbsf-utilities-1.0.0.tgz +0 -0
- package/bnsights-bbsf-utilities.d.ts +4 -0
- package/bnsights-bbsf-utilities.metadata.json +1 -0
- package/bundles/bnsights-bbsf-utilities.umd.js +1127 -0
- package/bundles/bnsights-bbsf-utilities.umd.js.map +1 -0
- package/esm2015/bnsights-bbsf-utilities.js +5 -0
- package/esm2015/lib/bbsf-utilities.module.js +50 -0
- package/esm2015/lib/shared/authentication/auth.service.js +157 -0
- package/esm2015/lib/shared/config/environment.js +12 -0
- package/esm2015/lib/shared/models/ErrorModel.js +3 -0
- package/esm2015/lib/shared/models/RequestOptionsModel.js +9 -0
- package/esm2015/lib/shared/services/controlvalidation.service.js +151 -0
- package/esm2015/lib/shared/services/environment.service.js +31 -0
- package/esm2015/lib/shared/services/masterlayout.service.js +65 -0
- package/esm2015/lib/shared/services/requesthandler.service.js +85 -0
- package/esm2015/lib/shared/services/stylesbundle.service.js +46 -0
- package/esm2015/lib/shared/services/translate.service.js +13 -0
- package/esm2015/lib/shared/services/utility.service.js +96 -0
- package/esm2015/public-api.js +15 -0
- package/fesm2015/bnsights-bbsf-utilities.js +661 -0
- package/fesm2015/bnsights-bbsf-utilities.js.map +1 -0
- package/lib/bbsf-utilities.module.d.ts +6 -0
- package/lib/shared/authentication/auth.service.d.ts +32 -0
- package/lib/shared/config/environment.d.ts +1 -0
- package/lib/shared/models/ErrorModel.d.ts +5 -0
- package/lib/shared/models/RequestOptionsModel.d.ts +9 -0
- package/lib/shared/services/controlvalidation.service.d.ts +19 -0
- package/lib/shared/services/environment.service.d.ts +7 -0
- package/lib/shared/services/masterlayout.service.d.ts +18 -0
- package/lib/shared/services/requesthandler.service.d.ts +23 -0
- package/lib/shared/services/stylesbundle.service.d.ts +6 -0
- package/lib/shared/services/translate.service.d.ts +3 -0
- package/lib/shared/services/utility.service.d.ts +19 -0
- package/package.json +38 -0
- package/public-api.d.ts +11 -0
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
import * as i1$2 from '@angular/common';
|
|
2
|
+
import { DOCUMENT, CommonModule } from '@angular/common';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { Injectable, Inject, NgModule, Injector } from '@angular/core';
|
|
5
|
+
import * as i1$3 from '@angular/router';
|
|
6
|
+
import { Router, RouterModule } from '@angular/router';
|
|
7
|
+
import * as i1$1 from '@ngx-translate/core';
|
|
8
|
+
import { TranslateService } from '@ngx-translate/core';
|
|
9
|
+
import { BlockUI, BlockUIModule } from 'ng-block-ui';
|
|
10
|
+
import { ToastrService, ToastrModule } from 'ngx-toastr';
|
|
11
|
+
import { HttpModule } from '@angular/http';
|
|
12
|
+
import { __awaiter, __decorate } from 'tslib';
|
|
13
|
+
import * as i1 from '@angular/common/http';
|
|
14
|
+
import { HttpHeaders, HttpClient, HttpParams } from '@angular/common/http';
|
|
15
|
+
import { UserManager, WebStorageStateStore } from 'oidc-client';
|
|
16
|
+
import { BehaviorSubject, Subject } from 'rxjs';
|
|
17
|
+
import { takeUntil, tap } from 'rxjs/operators';
|
|
18
|
+
|
|
19
|
+
// This file can be replaced during build by using the `fileReplacements` array.
|
|
20
|
+
// `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`.
|
|
21
|
+
// The list of file replacements can be found in `angular.json`.
|
|
22
|
+
const environment = Object.assign({}, window.Envirnment);
|
|
23
|
+
/*
|
|
24
|
+
* In development mode, to ignore zone related error stack frames such as
|
|
25
|
+
* `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can
|
|
26
|
+
* import the following file, but please comment it out in production mode
|
|
27
|
+
* because it will have performance impact when throw error
|
|
28
|
+
*/
|
|
29
|
+
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
|
|
30
|
+
|
|
31
|
+
class EnvironmentService {
|
|
32
|
+
getEnvironmentObject() {
|
|
33
|
+
return environment;
|
|
34
|
+
}
|
|
35
|
+
getBaseUrl() {
|
|
36
|
+
let Url = environment["BBSF_BaseUrl"];
|
|
37
|
+
return Url;
|
|
38
|
+
}
|
|
39
|
+
getApiUrl() {
|
|
40
|
+
let Url = environment["BBSF_ApiUrl"];
|
|
41
|
+
return Url;
|
|
42
|
+
}
|
|
43
|
+
getProductionMode() {
|
|
44
|
+
let Mode = environment["BBSF_IsProduction"];
|
|
45
|
+
return Mode;
|
|
46
|
+
}
|
|
47
|
+
getIdentityServerUrl() {
|
|
48
|
+
let Url = environment["BBSF_IdentityServerUrl"];
|
|
49
|
+
return Url;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
EnvironmentService.ɵprov = i0.ɵɵdefineInjectable({ factory: function EnvironmentService_Factory() { return new EnvironmentService(); }, token: EnvironmentService, providedIn: "root" });
|
|
53
|
+
EnvironmentService.decorators = [
|
|
54
|
+
{ type: Injectable, args: [{
|
|
55
|
+
providedIn: 'root'
|
|
56
|
+
},] }
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
class AuthService {
|
|
60
|
+
constructor(http, environmentService) {
|
|
61
|
+
this.http = http;
|
|
62
|
+
this.environmentService = environmentService;
|
|
63
|
+
// Observable navItem source
|
|
64
|
+
this._authNavStatusSource = new BehaviorSubject(false);
|
|
65
|
+
// Observable navItem stream
|
|
66
|
+
this.authNavStatus$ = this._authNavStatusSource.asObservable();
|
|
67
|
+
// Observable navItem source
|
|
68
|
+
this._userSource = new Subject();
|
|
69
|
+
this.UserStatus$ = this._userSource.asObservable();
|
|
70
|
+
this.manager = new UserManager({
|
|
71
|
+
authority: this.environmentService.getIdentityServerUrl(),
|
|
72
|
+
client_id: 'angular_spa',
|
|
73
|
+
redirect_uri: this.environmentService.getIdentityServerUrl() + '/Admin/authentication/auth-callback',
|
|
74
|
+
post_logout_redirect_uri: this.environmentService.getBaseUrl(),
|
|
75
|
+
response_type: "id_token token",
|
|
76
|
+
scope: "openid profile email IdentityServerApi",
|
|
77
|
+
filterProtocolClaims: true,
|
|
78
|
+
loadUserInfo: true,
|
|
79
|
+
automaticSilentRenew: true,
|
|
80
|
+
silent_redirect_uri: this.environmentService.getIdentityServerUrl() + '/assets/silent-callback.html',
|
|
81
|
+
userStore: new WebStorageStateStore({ store: window.localStorage })
|
|
82
|
+
});
|
|
83
|
+
this.redirectUrl = "";
|
|
84
|
+
this.manager.getUser().then((user) => __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
this.manager.storeUser(user);
|
|
86
|
+
AuthService.user = user;
|
|
87
|
+
this.user = user;
|
|
88
|
+
this._authNavStatusSource.next(yield this.isAuthenticated());
|
|
89
|
+
}));
|
|
90
|
+
this.manager.events.addAccessTokenExpired(_ => {
|
|
91
|
+
this._authNavStatusSource.next(false);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
login() {
|
|
95
|
+
return this.manager.signinRedirect();
|
|
96
|
+
}
|
|
97
|
+
getUser() {
|
|
98
|
+
this.manager.getUser().then((user) => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
;
|
|
100
|
+
AuthService.user = user;
|
|
101
|
+
this.user = user;
|
|
102
|
+
this._authNavStatusSource.next(yield this.isAuthenticated());
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
storUser(User) {
|
|
106
|
+
this.manager.storeUser(User);
|
|
107
|
+
}
|
|
108
|
+
revokeAccessToken() {
|
|
109
|
+
this.manager.revokeAccessToken();
|
|
110
|
+
}
|
|
111
|
+
signinSilent() {
|
|
112
|
+
let x = this.manager.signinSilentCallback();
|
|
113
|
+
x.then(s => {
|
|
114
|
+
//console.log(s)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
completeAuthentication() {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
this.user = yield this.manager.signinRedirectCallback();
|
|
120
|
+
AuthService.user = this.user;
|
|
121
|
+
this._userSource.next(AuthService.user);
|
|
122
|
+
this._authNavStatusSource.next(yield this.isAuthenticated());
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
refreshToken(token) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const httpOptions = {
|
|
128
|
+
headers: new HttpHeaders({
|
|
129
|
+
'Content-Type': 'application/json',
|
|
130
|
+
'Authorization': token
|
|
131
|
+
})
|
|
132
|
+
};
|
|
133
|
+
this.manager.revokeAccessToken();
|
|
134
|
+
return yield this.http.post(`${this.environmentService.getIdentityServerUrl()}/users/refresh-token`, httpOptions, { withCredentials: true }).subscribe((user) => {
|
|
135
|
+
this._userSource.next(user);
|
|
136
|
+
AuthService.user = user;
|
|
137
|
+
this.user = user;
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
getCurrentUser() {
|
|
142
|
+
return this.manager.getUser();
|
|
143
|
+
}
|
|
144
|
+
isAuthenticated(allowedPermission) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
let user = yield this.manager.getUser().then(user => {
|
|
147
|
+
return user;
|
|
148
|
+
});
|
|
149
|
+
if (allowedPermission != null && allowedPermission != undefined) {
|
|
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;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
isUserInRole(allowedPermission) {
|
|
163
|
+
;
|
|
164
|
+
let permissionSetSID = this.user.profile["permissionSetSID"].split `,`.map(x => +x);
|
|
165
|
+
return allowedPermission.every(i => permissionSetSID.includes(i));
|
|
166
|
+
}
|
|
167
|
+
authorizationHeaderValue() {
|
|
168
|
+
return `${AuthService.user.token_type} ${AuthService.user.access_token}`;
|
|
169
|
+
}
|
|
170
|
+
name() {
|
|
171
|
+
return AuthService.user != null ? AuthService.user.profile.given_name : '';
|
|
172
|
+
}
|
|
173
|
+
setUrl(url) {
|
|
174
|
+
localStorage.setItem("redirectUrl", url);
|
|
175
|
+
}
|
|
176
|
+
getUrl() {
|
|
177
|
+
return localStorage.getItem("redirectUrl");
|
|
178
|
+
}
|
|
179
|
+
signinSilentCallback() {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
let user = yield this.manager.signinSilentCallback();
|
|
182
|
+
//await this.manager.storeUser(user);
|
|
183
|
+
AuthService.user = user;
|
|
184
|
+
console.log("Token from signinSilentCallback :" + AuthService.user);
|
|
185
|
+
this.user = user;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
signout() {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
localStorage.clear();
|
|
191
|
+
yield this.manager.signoutRedirect();
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
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" });
|
|
197
|
+
AuthService.decorators = [
|
|
198
|
+
{ type: Injectable, args: [{
|
|
199
|
+
providedIn: 'root'
|
|
200
|
+
},] }
|
|
201
|
+
];
|
|
202
|
+
AuthService.ctorParameters = () => [
|
|
203
|
+
{ 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
|
+
},] }
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
class UtilityService {
|
|
217
|
+
constructor(Translator, authService) {
|
|
218
|
+
this.Translator = Translator;
|
|
219
|
+
this.authService = authService;
|
|
220
|
+
this.isCreatedBefore = false;
|
|
221
|
+
}
|
|
222
|
+
getResourceValue(Key) {
|
|
223
|
+
let ResourceValue = "";
|
|
224
|
+
this.Translator.get(Key).subscribe(data => { ResourceValue = data; return ResourceValue; });
|
|
225
|
+
return ResourceValue;
|
|
226
|
+
}
|
|
227
|
+
getCurrentLanguage() {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
let user = yield this.authService.getCurrentUser().then((user) => {
|
|
230
|
+
return user;
|
|
231
|
+
});
|
|
232
|
+
return user.profile.locale;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
isCurrentLanguageEnglish() {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
(yield this.getCurrentLanguage()) == "en" ? true : false;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
isCurrentLanguageArabic() {
|
|
241
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
(yield this.getCurrentLanguage()) == "ar" ? true : false;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
notifySuccessMessage(Message, title, time) {
|
|
246
|
+
let MessageTemplate = this.getResourceValue("SuccessMessage");
|
|
247
|
+
let titleTemplate = this.getResourceValue("Success");
|
|
248
|
+
if (Message) {
|
|
249
|
+
MessageTemplate = Message;
|
|
250
|
+
}
|
|
251
|
+
if (title) {
|
|
252
|
+
titleTemplate = title;
|
|
253
|
+
}
|
|
254
|
+
let toaster = AppInjector.get(ToastrService);
|
|
255
|
+
toaster.success(MessageTemplate, titleTemplate);
|
|
256
|
+
}
|
|
257
|
+
notifyErrorMessage(Message, title, time) {
|
|
258
|
+
let MessageTemplate = this.getResourceValue("ErrorMessage");
|
|
259
|
+
let titleTemplate = this.getResourceValue("Error");
|
|
260
|
+
if (Message) {
|
|
261
|
+
MessageTemplate = Message;
|
|
262
|
+
}
|
|
263
|
+
if (title) {
|
|
264
|
+
titleTemplate = title;
|
|
265
|
+
}
|
|
266
|
+
const toaster = AppInjector.get(ToastrService);
|
|
267
|
+
toaster.error(MessageTemplate, titleTemplate);
|
|
268
|
+
}
|
|
269
|
+
notifyWarningMessage(Message, title, time) {
|
|
270
|
+
let MessageTemplate = this.getResourceValue("WarningMessage");
|
|
271
|
+
let titleTemplate = this.getResourceValue("Warning");
|
|
272
|
+
if (Message) {
|
|
273
|
+
MessageTemplate = Message;
|
|
274
|
+
}
|
|
275
|
+
if (title) {
|
|
276
|
+
titleTemplate = title;
|
|
277
|
+
}
|
|
278
|
+
const toaster = AppInjector.get(ToastrService);
|
|
279
|
+
toaster.warning(MessageTemplate, titleTemplate);
|
|
280
|
+
}
|
|
281
|
+
startBlockUI() {
|
|
282
|
+
this.blockUI.start();
|
|
283
|
+
}
|
|
284
|
+
stopBlockUI() {
|
|
285
|
+
this.blockUI.stop();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
UtilityService.ɵprov = i0.ɵɵdefineInjectable({ factory: function UtilityService_Factory() { return new UtilityService(i0.ɵɵinject(BBSFTranslateService), i0.ɵɵinject(AuthService)); }, token: UtilityService, providedIn: "root" });
|
|
289
|
+
UtilityService.decorators = [
|
|
290
|
+
{ type: Injectable, args: [{
|
|
291
|
+
providedIn: 'root'
|
|
292
|
+
},] }
|
|
293
|
+
];
|
|
294
|
+
UtilityService.ctorParameters = () => [
|
|
295
|
+
{ type: BBSFTranslateService },
|
|
296
|
+
{ type: AuthService }
|
|
297
|
+
];
|
|
298
|
+
__decorate([
|
|
299
|
+
BlockUI()
|
|
300
|
+
], UtilityService.prototype, "blockUI", void 0);
|
|
301
|
+
|
|
302
|
+
class RequestOptionsModel {
|
|
303
|
+
constructor() {
|
|
304
|
+
this.disableSuccessNotification = false;
|
|
305
|
+
this.disableBlockUI = false;
|
|
306
|
+
this.responseType = "";
|
|
307
|
+
this.formGroup = null;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
class ControlValidationService {
|
|
312
|
+
constructor(utilityService) {
|
|
313
|
+
this.utilityService = utilityService;
|
|
314
|
+
this.requestOptions = new RequestOptionsModel();
|
|
315
|
+
this.isCreatedBefor = false;
|
|
316
|
+
}
|
|
317
|
+
showGlobalError(errorMessage) {
|
|
318
|
+
let globalErorrElement = document.getElementsByClassName('alert alert-danger alert-InvalidValidation');
|
|
319
|
+
if (globalErorrElement.length > 0) {
|
|
320
|
+
this.removeElementsByClass('alert alert-danger alert-InvalidValidation');
|
|
321
|
+
}
|
|
322
|
+
if (this.isCreatedBefor == true) {
|
|
323
|
+
this.removeElementsByClass('alert alert-danger alert-InvalidValidation');
|
|
324
|
+
}
|
|
325
|
+
// tslint:disable-next-line: prefer-const
|
|
326
|
+
var objects = document.querySelectorAll('form.ng-invalid.ng-touched');
|
|
327
|
+
const tagName = 'div';
|
|
328
|
+
// tslint:disable-next-line: prefer-const
|
|
329
|
+
var elementToAppend = document.createElement(tagName); // Your tag name here
|
|
330
|
+
let message = "";
|
|
331
|
+
if (localStorage.getItem('language') == "ar")
|
|
332
|
+
message = errorMessage ? errorMessage : "لديك بعص الأخطاء . من فضلك قم بالمراجعه ";
|
|
333
|
+
else
|
|
334
|
+
message = errorMessage ? errorMessage : "You have some validation errors. Please check below";
|
|
335
|
+
elementToAppend.innerHTML = "<ul><li>" + message + "</li></ul>";
|
|
336
|
+
elementToAppend.className += 'alert alert-danger alert-InvalidValidation';
|
|
337
|
+
elementToAppend.id += 'errorId';
|
|
338
|
+
// tslint:disable-next-line: prefer-for-of
|
|
339
|
+
for (let i = 0; i < objects.length; i++) {
|
|
340
|
+
// const elementToAppen = elementToAppend.cloneNode(true);
|
|
341
|
+
// objects[i].insertBefore(elementToAppen, objects[i].firstChild);
|
|
342
|
+
const elementToAppen = elementToAppend.cloneNode(true);
|
|
343
|
+
let targetElement = objects[i].getElementsByClassName("b-control")[0];
|
|
344
|
+
targetElement.parentNode.insertBefore(elementToAppen, targetElement);
|
|
345
|
+
this.isCreatedBefor = true;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
RemoveGlobalError() {
|
|
350
|
+
const removedList = document.getElementsByClassName('alert alert-danger alert-InvalidValidation');
|
|
351
|
+
// tslint:disable-next-line: prefer-for-of
|
|
352
|
+
for (let index = 0; index < removedList.length; index++) {
|
|
353
|
+
const element = removedList[index];
|
|
354
|
+
element.remove();
|
|
355
|
+
}
|
|
356
|
+
this.isCreatedBefor = false;
|
|
357
|
+
}
|
|
358
|
+
showInputErro(errors) {
|
|
359
|
+
// show error on top of form
|
|
360
|
+
this.showGlobalError();
|
|
361
|
+
// remove old error from server
|
|
362
|
+
this.removeElementsByClass('errortemplet');
|
|
363
|
+
// Looping in error Object
|
|
364
|
+
for (const key in errors) {
|
|
365
|
+
if (errors.hasOwnProperty(key)) {
|
|
366
|
+
for (const iterator of errors[key]) {
|
|
367
|
+
const input = document.querySelectorAll('[ng-reflect-name=' + key + ']')[0];
|
|
368
|
+
if (input.attributes['ng-reflect-name'].value === key) {
|
|
369
|
+
this.removeElementsByClass('erroclass-' + key);
|
|
370
|
+
const tagName = 'p';
|
|
371
|
+
const elementToAppend = document.createElement(tagName); // Your tag name here
|
|
372
|
+
elementToAppend.innerHTML = iterator;
|
|
373
|
+
elementToAppend.style.color = 'red';
|
|
374
|
+
elementToAppend.className += 'errortemplet erroclass-' + key;
|
|
375
|
+
const elementToappen = elementToAppend.cloneNode(true);
|
|
376
|
+
input.parentNode.insertBefore(elementToappen, input.lastChild);
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
removeElementsByClass(className) {
|
|
384
|
+
const elements = document.getElementsByClassName(className);
|
|
385
|
+
while (elements.length > 0) {
|
|
386
|
+
elements[0].parentNode.removeChild(elements[0]);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
renderServerErrors(form, err, requestOptions) {
|
|
390
|
+
if (err.error == null) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
this.requestOptions = requestOptions;
|
|
394
|
+
err.error.validation_errors.forEach((element) => {
|
|
395
|
+
let fieldName = element.field;
|
|
396
|
+
let controlName = element.control_name;
|
|
397
|
+
let message = element.message;
|
|
398
|
+
if (form == null) {
|
|
399
|
+
this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(`${fieldName}: ${message}`);
|
|
400
|
+
}
|
|
401
|
+
else if (!this.hasControlName(form, controlName)) {
|
|
402
|
+
this.showGlobalError(`${fieldName}: ${message}`);
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
this.setFieldError(form, controlName, fieldName, message);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
hasControlName(form, controlName) {
|
|
410
|
+
let control = form.get(controlName);
|
|
411
|
+
return control != null;
|
|
412
|
+
}
|
|
413
|
+
setFieldError(form, controlName, fieldName, message) {
|
|
414
|
+
let control = form.get(controlName);
|
|
415
|
+
let errors = { [message]: true };
|
|
416
|
+
let fieldNameArray = fieldName.split('.');
|
|
417
|
+
if (fieldNameArray.length >= 1) {
|
|
418
|
+
switch (fieldNameArray[length - 1].toLocaleLowerCase()) {
|
|
419
|
+
case "english":
|
|
420
|
+
let englishControl = control.get("EnglishValue");
|
|
421
|
+
englishControl.setErrors(errors);
|
|
422
|
+
englishControl.markAsTouched();
|
|
423
|
+
englishControl.updateValueAndValidity();
|
|
424
|
+
break;
|
|
425
|
+
case "arabic":
|
|
426
|
+
let arabicControl = control.get("ArabicValue");
|
|
427
|
+
arabicControl.setErrors(errors);
|
|
428
|
+
arabicControl.markAsTouched();
|
|
429
|
+
arabicControl.updateValueAndValidity();
|
|
430
|
+
break;
|
|
431
|
+
default:
|
|
432
|
+
control.setErrors(errors);
|
|
433
|
+
control.markAsTouched();
|
|
434
|
+
control.updateValueAndValidity();
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(`${fieldName}: ${message}`);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
ControlValidationService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ControlValidationService_Factory() { return new ControlValidationService(i0.ɵɵinject(UtilityService)); }, token: ControlValidationService, providedIn: "root" });
|
|
443
|
+
ControlValidationService.decorators = [
|
|
444
|
+
{ type: Injectable, args: [{
|
|
445
|
+
providedIn: 'root'
|
|
446
|
+
},] }
|
|
447
|
+
];
|
|
448
|
+
ControlValidationService.ctorParameters = () => [
|
|
449
|
+
{ type: UtilityService }
|
|
450
|
+
];
|
|
451
|
+
__decorate([
|
|
452
|
+
BlockUI()
|
|
453
|
+
], ControlValidationService.prototype, "blockUI", void 0);
|
|
454
|
+
|
|
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
|
+
class MasterLayoutService {
|
|
566
|
+
constructor(router, http, authService, stylesBundleService, translate) {
|
|
567
|
+
this.router = router;
|
|
568
|
+
this.http = http;
|
|
569
|
+
this.authService = authService;
|
|
570
|
+
this.stylesBundleService = stylesBundleService;
|
|
571
|
+
this.translate = translate;
|
|
572
|
+
this.ApiUrl = "/api/admin/Users/";
|
|
573
|
+
}
|
|
574
|
+
switchLang(lang, bundleEnglishName, bundleArabicName) {
|
|
575
|
+
this.changeLanguage(lang).subscribe((result) => {
|
|
576
|
+
this.updateUserInfo().subscribe((Value) => {
|
|
577
|
+
let UserInfoObject = Value;
|
|
578
|
+
this.authService.getUser();
|
|
579
|
+
this.authService.user.profile = Object.assign(this.authService.user.profile, UserInfoObject);
|
|
580
|
+
this.authService.storUser(this.authService.user);
|
|
581
|
+
this.stylesBundleService.loadThemes(lang, bundleEnglishName, bundleArabicName);
|
|
582
|
+
localStorage.setItem('language', lang);
|
|
583
|
+
this.translate.use(lang);
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
reloadComponent() {
|
|
588
|
+
let currentUrl = this.router.url;
|
|
589
|
+
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
|
|
590
|
+
this.router.onSameUrlNavigation = 'reload';
|
|
591
|
+
this.router.navigate([currentUrl]);
|
|
592
|
+
}
|
|
593
|
+
changeLanguage(key) {
|
|
594
|
+
let params = new HttpParams();
|
|
595
|
+
params = params.append("UserId", this.authService.user.profile.id);
|
|
596
|
+
params = params.append("LanguageKey", key);
|
|
597
|
+
return this.http.post(this.ApiUrl + 'updateLaguage', null, params);
|
|
598
|
+
}
|
|
599
|
+
updateUserInfo() {
|
|
600
|
+
return this.http.get('/connect/userinfo');
|
|
601
|
+
}
|
|
602
|
+
}
|
|
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$1.TranslateService)); }, token: MasterLayoutService, providedIn: "root" });
|
|
604
|
+
MasterLayoutService.decorators = [
|
|
605
|
+
{ type: Injectable, args: [{
|
|
606
|
+
providedIn: 'root'
|
|
607
|
+
},] }
|
|
608
|
+
];
|
|
609
|
+
MasterLayoutService.ctorParameters = () => [
|
|
610
|
+
{ type: Router },
|
|
611
|
+
{ type: RequestHandlerService },
|
|
612
|
+
{ type: AuthService },
|
|
613
|
+
{ type: StylesBundleService },
|
|
614
|
+
{ type: TranslateService }
|
|
615
|
+
];
|
|
616
|
+
|
|
617
|
+
let AppInjector;
|
|
618
|
+
class BBSFUtilitiesModule {
|
|
619
|
+
constructor(injector) {
|
|
620
|
+
this.injector = injector;
|
|
621
|
+
AppInjector = this.injector;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
BBSFUtilitiesModule.decorators = [
|
|
625
|
+
{ type: NgModule, args: [{
|
|
626
|
+
declarations: [],
|
|
627
|
+
imports: [
|
|
628
|
+
CommonModule,
|
|
629
|
+
BlockUIModule.forRoot(),
|
|
630
|
+
HttpModule,
|
|
631
|
+
RouterModule,
|
|
632
|
+
ToastrModule.forRoot(),
|
|
633
|
+
],
|
|
634
|
+
exports: [],
|
|
635
|
+
providers: [
|
|
636
|
+
UtilityService,
|
|
637
|
+
EnvironmentService,
|
|
638
|
+
AuthService,
|
|
639
|
+
RequestHandlerService,
|
|
640
|
+
StylesBundleService,
|
|
641
|
+
TranslateService,
|
|
642
|
+
BBSFTranslateService,
|
|
643
|
+
ControlValidationService,
|
|
644
|
+
MasterLayoutService
|
|
645
|
+
]
|
|
646
|
+
},] }
|
|
647
|
+
];
|
|
648
|
+
BBSFUtilitiesModule.ctorParameters = () => [
|
|
649
|
+
{ type: Injector }
|
|
650
|
+
];
|
|
651
|
+
|
|
652
|
+
/*
|
|
653
|
+
* Public API Surface of bbsf-utilities
|
|
654
|
+
*/
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Generated bundle index. Do not edit.
|
|
658
|
+
*/
|
|
659
|
+
|
|
660
|
+
export { AppInjector, AuthService, BBSFTranslateService, BBSFUtilitiesModule, ControlValidationService, EnvironmentService, MasterLayoutService, RequestHandlerService, RequestOptionsModel, StylesBundleService, UtilityService, environment };
|
|
661
|
+
//# sourceMappingURL=bnsights-bbsf-utilities.js.map
|