@bnsights/bbsf-utilities 1.0.51 → 1.0.53
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 +7 -0
- package/bnsights-bbsf-utilities-1.0.53.tgz +0 -0
- package/esm2022/lib/shared/authentication/auth.service.mjs +11 -3
- package/esm2022/lib/shared/services/master-layout.service.mjs +13 -9
- package/esm2022/lib/shared/services/request-handler.service.mjs +58 -11
- package/fesm2022/bnsights-bbsf-utilities.mjs +79 -20
- package/fesm2022/bnsights-bbsf-utilities.mjs.map +1 -1
- package/lib/shared/services/request-handler.service.d.ts +1 -1
- package/package.json +1 -1
- package/bnsights-bbsf-utilities-1.0.51.tgz +0 -0
|
@@ -12,8 +12,8 @@ import { ToastrService, ToastrModule } from 'ngx-toastr';
|
|
|
12
12
|
import * as i4$1 from 'ngx-cookie-service';
|
|
13
13
|
import { CookieService } from 'ngx-cookie-service';
|
|
14
14
|
import * as i1 from '@angular/common/http';
|
|
15
|
-
import { HttpParams, HttpHeaders } from '@angular/common/http';
|
|
16
|
-
import { Subject,
|
|
15
|
+
import { HttpParams, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
|
|
16
|
+
import { Subject, throwError, BehaviorSubject } from 'rxjs';
|
|
17
17
|
import { JwtHelperService } from '@auth0/angular-jwt';
|
|
18
18
|
import { __decorate } from 'tslib';
|
|
19
19
|
import { plainToClass } from 'class-transformer';
|
|
@@ -384,15 +384,19 @@ class MasterLayoutService {
|
|
|
384
384
|
this.apiUrl = '/api/Home/';
|
|
385
385
|
}
|
|
386
386
|
switchLang(lang, bundleEnglishName, bundleArabicName) {
|
|
387
|
-
this.
|
|
388
|
-
this.
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
387
|
+
if (this.authService.isAuthenticated()) {
|
|
388
|
+
this.changeLanguage(lang).subscribe((result) => {
|
|
389
|
+
this.updateUserInfo().subscribe((Value) => {
|
|
390
|
+
let UserInfoObject = Value;
|
|
391
|
+
this.authService.handleAccessToken(UserInfoObject.token);
|
|
392
|
+
this.stylesBundleService.loadThemes(lang, bundleEnglishName, bundleArabicName);
|
|
393
|
+
localStorage.setItem('language', lang);
|
|
394
|
+
this.translate.use(lang);
|
|
395
|
+
});
|
|
394
396
|
});
|
|
395
|
-
}
|
|
397
|
+
}
|
|
398
|
+
else
|
|
399
|
+
this.router.navigate(['/Admin/account/login']);
|
|
396
400
|
}
|
|
397
401
|
reloadComponent() {
|
|
398
402
|
let currentUrl = this.router.url;
|
|
@@ -456,16 +460,19 @@ class RequestHandlerService {
|
|
|
456
460
|
}
|
|
457
461
|
});
|
|
458
462
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
const number = Math.floor(Math.random() * 10);
|
|
463
|
-
console.log(number);
|
|
464
|
-
subject.next(number);
|
|
465
|
-
}, 1000);
|
|
466
|
-
}).pipe(takeUntil(this.onDestroy$));
|
|
463
|
+
// Function to check if the internet connection is available
|
|
464
|
+
isOnline() {
|
|
465
|
+
return navigator.onLine || !this.environmentService.getProductionMode();
|
|
467
466
|
}
|
|
467
|
+
// ...
|
|
468
468
|
get(Url, params, responseType, requestOptions) {
|
|
469
|
+
if (!this.isOnline()) {
|
|
470
|
+
const errorCode = 504; // Custom error code for internet disconnection
|
|
471
|
+
const errorMessage = 'Internet connection is disconnected.';
|
|
472
|
+
var error = new HttpErrorResponse({ error: { Message: errorMessage }, status: 504 });
|
|
473
|
+
this.handleError(error);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
469
476
|
if (requestOptions)
|
|
470
477
|
this.requestOptions = requestOptions;
|
|
471
478
|
let headers = this.getHeaders();
|
|
@@ -485,6 +492,13 @@ class RequestHandlerService {
|
|
|
485
492
|
}));
|
|
486
493
|
}
|
|
487
494
|
post(Url, model, responseType, params, requestOptions) {
|
|
495
|
+
if (!this.isOnline()) {
|
|
496
|
+
const errorCode = 504; // Custom error code for internet disconnection
|
|
497
|
+
const errorMessage = 'Internet connection is disconnected.';
|
|
498
|
+
var error = new HttpErrorResponse({ error: { Message: errorMessage }, status: 504 });
|
|
499
|
+
this.handleError(error);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
488
502
|
if (requestOptions)
|
|
489
503
|
this.requestOptions = requestOptions;
|
|
490
504
|
let headers = this.getHeaders();
|
|
@@ -504,6 +518,13 @@ class RequestHandlerService {
|
|
|
504
518
|
}));
|
|
505
519
|
}
|
|
506
520
|
delete(Url, deletedId, requestOptions, responseType, params) {
|
|
521
|
+
if (!this.isOnline()) {
|
|
522
|
+
const errorCode = 504; // Custom error code for internet disconnection
|
|
523
|
+
const errorMessage = 'Internet connection is disconnected.';
|
|
524
|
+
var error = new HttpErrorResponse({ error: { Message: errorMessage }, status: 504 });
|
|
525
|
+
this.handleError(error);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
507
528
|
if (requestOptions)
|
|
508
529
|
this.requestOptions = requestOptions;
|
|
509
530
|
let headers = this.getHeaders();
|
|
@@ -523,6 +544,13 @@ class RequestHandlerService {
|
|
|
523
544
|
}));
|
|
524
545
|
}
|
|
525
546
|
put(Url, model, params, responseType, requestOptions) {
|
|
547
|
+
if (!this.isOnline()) {
|
|
548
|
+
const errorCode = 504; // Custom error code for internet disconnection
|
|
549
|
+
const errorMessage = 'Internet connection is disconnected.';
|
|
550
|
+
var error = new HttpErrorResponse({ error: { Message: errorMessage }, status: 504 });
|
|
551
|
+
this.handleError(error);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
526
554
|
if (requestOptions)
|
|
527
555
|
this.requestOptions = requestOptions;
|
|
528
556
|
let headers = this.getHeaders();
|
|
@@ -542,6 +570,13 @@ class RequestHandlerService {
|
|
|
542
570
|
}));
|
|
543
571
|
}
|
|
544
572
|
patch(Url, model, responseType, params, requestOptions) {
|
|
573
|
+
if (!this.isOnline()) {
|
|
574
|
+
const errorCode = 504; // Custom error code for internet disconnection
|
|
575
|
+
const errorMessage = 'Internet connection is disconnected.';
|
|
576
|
+
var error = new HttpErrorResponse({ error: { Message: errorMessage }, status: 504 });
|
|
577
|
+
this.handleError(error);
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
545
580
|
if (requestOptions)
|
|
546
581
|
this.requestOptions = requestOptions;
|
|
547
582
|
let headers = new HttpHeaders({
|
|
@@ -567,6 +602,13 @@ class RequestHandlerService {
|
|
|
567
602
|
}));
|
|
568
603
|
}
|
|
569
604
|
download(Url, params, requestOptions) {
|
|
605
|
+
if (!this.isOnline()) {
|
|
606
|
+
const errorCode = 504; // Custom error code for internet disconnection
|
|
607
|
+
const errorMessage = 'Internet connection is disconnected.';
|
|
608
|
+
var error = new HttpErrorResponse({ error: { Message: errorMessage }, status: 504 });
|
|
609
|
+
this.handleError(error);
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
570
612
|
if (requestOptions)
|
|
571
613
|
this.requestOptions = requestOptions;
|
|
572
614
|
let headers = this.getHeaders();
|
|
@@ -581,6 +623,13 @@ class RequestHandlerService {
|
|
|
581
623
|
}));
|
|
582
624
|
}
|
|
583
625
|
Upload(Url, model) {
|
|
626
|
+
if (!this.isOnline()) {
|
|
627
|
+
const errorCode = 504; // Custom error code for internet disconnection
|
|
628
|
+
const errorMessage = 'Internet connection is disconnected.';
|
|
629
|
+
var error = new HttpErrorResponse({ error: { Message: errorMessage }, status: 504 });
|
|
630
|
+
this.handleError(error);
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
584
633
|
let headers = this.getHeadersUpdated();
|
|
585
634
|
return this.http.post(this.environmentService.getApiUrl() + Url, model, { headers: headers, reportProgress: true, observe: 'events' }).pipe(takeUntil(this.onDestroy$), tap((result) => {
|
|
586
635
|
if (!this.requestOptions.disableBlockUI)
|
|
@@ -613,6 +662,8 @@ class RequestHandlerService {
|
|
|
613
662
|
this.utilityService.notifyErrorMessage(isEnglish ? "Can not delete this item as it is related to others" : "لا يمكن حذف هذا العنصر لأنه مرتبط بعناصر أخرى");
|
|
614
663
|
else if (err.status == 515)
|
|
615
664
|
this.utilityService.notifyErrorMessage((err.error ? err.error.Message : err.message));
|
|
665
|
+
else if (err.status == 504)
|
|
666
|
+
this.utilityService.notifyErrorMessage((err.error ? err.error.Message : err.message));
|
|
616
667
|
else {
|
|
617
668
|
console.log(`error message is: ${err.error ? err.error.Message : err.message}`);
|
|
618
669
|
this.utilityService.notifyErrorMessage(this.utilityService.getResourceValue("ErrorMassage"));
|
|
@@ -4426,12 +4477,20 @@ class AuthService {
|
|
|
4426
4477
|
AuthService.user = null;
|
|
4427
4478
|
this.user = null;
|
|
4428
4479
|
localStorage.removeItem("redirectUrl");
|
|
4429
|
-
this.
|
|
4480
|
+
if (this.isAuthenticated()) {
|
|
4481
|
+
this.logout().subscribe(res => {
|
|
4482
|
+
if (this.environmentService.getBBSFAuthenticationMode() == AuthenticationModes.UAEPass)
|
|
4483
|
+
this.logoutFromUAEPass();
|
|
4484
|
+
else
|
|
4485
|
+
this.router.navigate(['/Admin/account/login']);
|
|
4486
|
+
});
|
|
4487
|
+
}
|
|
4488
|
+
else {
|
|
4430
4489
|
if (this.environmentService.getBBSFAuthenticationMode() == AuthenticationModes.UAEPass)
|
|
4431
4490
|
this.logoutFromUAEPass();
|
|
4432
4491
|
else
|
|
4433
4492
|
this.router.navigate(['/Admin/account/login']);
|
|
4434
|
-
}
|
|
4493
|
+
}
|
|
4435
4494
|
}
|
|
4436
4495
|
logout() {
|
|
4437
4496
|
const httpOptions = {
|