zek 14.2.69 → 14.2.71

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/fesm2015/zek.mjs CHANGED
@@ -1117,7 +1117,7 @@ class UrlHelper {
1117
1117
  class AuthService {
1118
1118
  constructor() {
1119
1119
  this._isInitialized = false;
1120
- this._oldValueIsAuthenticated = false;
1120
+ this._oldValue = false;
1121
1121
  this._user = null;
1122
1122
  }
1123
1123
  get user() {
@@ -1167,11 +1167,12 @@ class AuthService {
1167
1167
  isAuthenticated() {
1168
1168
  let expired = this.getExpired() || new Date(0); // if getExpired is null return min JS date
1169
1169
  const newValue = new Date() < expired;
1170
- if (this._oldValueIsAuthenticated !== newValue) {
1171
- this._oldValueIsAuthenticated = newValue;
1172
- if (this._onSignedInSubject) {
1173
- this._onSignedInSubject.next(newValue);
1174
- }
1170
+ if (this._oldValue !== newValue) {
1171
+ this._oldValue = newValue;
1172
+ this.emitOnSignedIn();
1173
+ // if (this._onSignedInSubject) {
1174
+ // this._onSignedInSubject.next(newValue);
1175
+ // }
1175
1176
  //if user is signed in and expired we need to logout (remove from localStorage)
1176
1177
  if (!newValue) {
1177
1178
  this.logout();
@@ -1180,6 +1181,11 @@ class AuthService {
1180
1181
  }
1181
1182
  return newValue;
1182
1183
  }
1184
+ emitOnSignedIn() {
1185
+ if (this._onSignedInSubject) {
1186
+ this._onSignedInSubject.next(this._oldValue);
1187
+ }
1188
+ }
1183
1189
  get onSignedIn() {
1184
1190
  if (!this._onSignedInSubject) {
1185
1191
  this._onSignedInSubject = new BehaviorSubject(false);
@@ -1580,12 +1586,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImpor
1580
1586
 
1581
1587
  /** Handles HttpClient errors */
1582
1588
  class HttpErrorHandler {
1583
- constructor(alertService, translateService, router) {
1584
- this.alertService = alertService;
1585
- this.translateService = translateService;
1589
+ constructor(alert, translate, router) {
1590
+ this.alert = alert;
1591
+ this.translate = translate;
1586
1592
  this.router = router;
1587
1593
  /** Create curried handleError function that already knows the service name */
1588
1594
  this.createHandleError = (serviceName = '') => (operation = 'operation', result = {}, show = true) => this.handleError(serviceName, operation, result, show);
1595
+ this.createHandleErrorJson = (serviceName = '') => (operation = 'operation', show = true) => this.handleErrorJson(serviceName, operation, show);
1589
1596
  }
1590
1597
  /**
1591
1598
  * Returns a function that handles Http operation failures.
@@ -1593,84 +1600,124 @@ class HttpErrorHandler {
1593
1600
  * @param serviceName = name of the data service that attempted the operation
1594
1601
  * @param operation - name of the operation that failed
1595
1602
  * @param result - optional value to return as the observable result
1603
+ * @param show - optional value to show error
1596
1604
  */
1597
1605
  handleError(serviceName = '', operation = 'operation', result = {}, show) {
1598
1606
  return (response) => {
1599
1607
  console.error(response);
1600
1608
  if (show) {
1601
- switch (response.status) {
1602
- case 0: //No Connection
1603
- this.alertService.error(`Can't connect to api server.`);
1604
- break;
1605
- case 400: //Bad Request
1606
- let error;
1607
- if (typeof response.error === 'string' && response.error[0] === '{') {
1608
- error = JSON.parse(response.error);
1609
- }
1610
- else {
1611
- error = response.error;
1612
- }
1613
- if (error instanceof ErrorEvent) {
1614
- this.alertService.error(`${serviceName}: ${operation} failed: ${response.error.message}`);
1615
- }
1616
- if (error === 'string') {
1617
- this.alertService.error(response.error);
1618
- }
1619
- else if (error instanceof Object) {
1620
- const errors = error.traceId || error.success === false
1621
- ? error.errors
1622
- : error;
1623
- const errorMessages = [];
1624
- const properties = Object.getOwnPropertyNames(errors);
1625
- for (let property of properties) {
1626
- const messages = errors[property];
1627
- if (messages instanceof Array) {
1628
- for (let message of messages) {
1629
- const messageKey = `Validation.${message}`;
1630
- let translatedMessage = this.translateService.instant(messageKey);
1631
- // if translation not found then use message
1632
- if (messageKey == translatedMessage) {
1633
- translatedMessage = message;
1634
- }
1635
- if (property) {
1636
- const propertyKey = `Fields.${property}`;
1637
- let translatedProperty = this.translateService.instant(`Fields.${property}`);
1638
- // if translation not found then use property
1639
- if (propertyKey == translatedProperty) {
1640
- translatedProperty = property;
1641
- }
1642
- errorMessages.push(translatedProperty + ' - ' + translatedMessage);
1643
- }
1644
- else {
1645
- errorMessages.push(translatedMessage);
1646
- }
1609
+ this.showError(serviceName, operation, response);
1610
+ }
1611
+ //return throwError('Error! please try again later.');
1612
+ return of(result);
1613
+ };
1614
+ }
1615
+ showError(serviceName, operation, response) {
1616
+ switch (response.status) {
1617
+ case 0: //No Connection
1618
+ this.alert.error(`Can't connect to api server.`);
1619
+ break;
1620
+ case 400: //Bad Request
1621
+ let error;
1622
+ if (typeof response.error === 'string' && response.error[0] === '{') {
1623
+ error = JSON.parse(response.error);
1624
+ }
1625
+ else {
1626
+ error = response.error;
1627
+ }
1628
+ if (error instanceof ErrorEvent) {
1629
+ this.alert.error(`${serviceName}: ${operation} failed: ${response.error.message}`);
1630
+ }
1631
+ if (typeof error === 'string') {
1632
+ this.alert.error(response.error);
1633
+ }
1634
+ else if (typeof error === 'object') {
1635
+ const errors = error.traceId || error.success === false
1636
+ ? error.errors
1637
+ : error;
1638
+ const errorMessages = [];
1639
+ const properties = Object.getOwnPropertyNames(errors);
1640
+ for (let property of properties) {
1641
+ const messages = errors[property];
1642
+ if (messages instanceof Array) {
1643
+ for (let message of messages) {
1644
+ const messageKey = `Validation.${message}`;
1645
+ let translatedMessage = this.translate.instant(messageKey);
1646
+ // if translation not found then use message
1647
+ if (messageKey == translatedMessage) {
1648
+ translatedMessage = message;
1649
+ }
1650
+ if (property) {
1651
+ const propertyKey = `Fields.${property}`;
1652
+ let translatedProperty = this.translate.instant(`Fields.${property}`);
1653
+ // if translation not found then use property
1654
+ if (propertyKey == translatedProperty) {
1655
+ translatedProperty = property;
1647
1656
  }
1657
+ errorMessages.push(translatedProperty + ' - ' + translatedMessage);
1658
+ }
1659
+ else {
1660
+ errorMessages.push(translatedMessage);
1648
1661
  }
1649
1662
  }
1650
- this.alertService.addRange(AlertType.Danger, errorMessages);
1651
1663
  }
1652
- break;
1653
- case 401: //Unauthorized
1654
- this.alertService.error('Unauthorized');
1655
- this.router.navigate(['/login']);
1656
- break;
1657
- case 403: //Forbidden
1658
- this.alertService.error('Forbidden');
1659
- break;
1660
- case 404: //Not Found
1661
- this.alertService.error('Not Found');
1662
- break;
1663
- case 402: //Payment Required
1664
- this.alertService.error('License Payment Required');
1665
- break;
1666
- case 500: //Internal Server Error
1667
- this.alertService.error('Internal Server Error');
1668
- break;
1669
- default:
1670
- break;
1664
+ }
1665
+ this.alert.addRange(AlertType.Danger, errorMessages);
1671
1666
  }
1667
+ break;
1668
+ case 401: //Unauthorized
1669
+ this.alert.error('Unauthorized');
1670
+ this.router.navigate(['/login']);
1671
+ break;
1672
+ case 403: //Forbidden
1673
+ this.alert.error('Forbidden');
1674
+ break;
1675
+ case 404: //Not Found
1676
+ this.alert.error('Not Found');
1677
+ break;
1678
+ case 402: //Payment Required
1679
+ this.alert.error('License Payment Required');
1680
+ break;
1681
+ case 500: //Internal Server Error
1682
+ this.alert.error('Internal Server Error');
1683
+ break;
1684
+ default:
1685
+ break;
1686
+ }
1687
+ }
1688
+ /**
1689
+ * Returns a function that handles Http operation failures.
1690
+ * This error handler lets the app continue to run as if no error occurred.
1691
+ * @param serviceName = name of the data service that attempted the operation
1692
+ * @param operation - name of the operation that failed
1693
+ * @param show - optional value to show error
1694
+ */
1695
+ handleErrorJson(serviceName = '', operation = 'operation', show) {
1696
+ return (response) => {
1697
+ console.error(response);
1698
+ if (show) {
1699
+ this.showError(serviceName, operation, response);
1700
+ }
1701
+ let error;
1702
+ if (typeof response.error === 'string' && response.error[0] === '{') {
1703
+ error = JSON.parse(response.error);
1704
+ }
1705
+ else {
1706
+ error = response.error;
1707
+ }
1708
+ let result;
1709
+ if (error instanceof ErrorEvent) {
1710
+ result = { '': [response.error.message] };
1711
+ }
1712
+ if (typeof error === 'string') {
1713
+ result = { '': [response.error] };
1714
+ }
1715
+ else if (typeof error === 'object') {
1716
+ const errors = error.traceId || error.success === false
1717
+ ? error.errors
1718
+ : error;
1719
+ result = errors;
1672
1720
  }
1673
- //return throwError('Error! please try again later.');
1674
1721
  return of(result);
1675
1722
  };
1676
1723
  }