zek 14.2.58 → 14.2.60

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
@@ -1110,22 +1110,34 @@ class UrlHelper {
1110
1110
 
1111
1111
  class AuthService {
1112
1112
  constructor() {
1113
- this.subject = new BehaviorSubject(false); //todo check if need BehaviorSubject
1114
- this.model = null;
1115
- this.expired = null;
1116
- this.oldValueIsAuthenticated = false;
1113
+ this._isInitialized = false;
1114
+ this._subject = new BehaviorSubject(false); //todo check if need BehaviorSubject
1115
+ this._oldValueIsAuthenticated = false;
1116
+ this._user = null;
1117
+ }
1118
+ get user() {
1119
+ if (!this._isInitialized) {
1120
+ let tmp = StorageHelper.get('login');
1121
+ if (tmp) {
1122
+ tmp.expired = DateHelper.parseDate(tmp.expired);
1123
+ tmp.refreshTokenTime = DateHelper.parseDate(tmp.refreshTokenTime);
1124
+ }
1125
+ this._user = tmp;
1126
+ this._isInitialized = true;
1127
+ }
1128
+ return this._user;
1117
1129
  }
1130
+ // private _expired: Date | null = null;
1131
+ // private _refreshTokenExpired: Date | null = null;
1118
1132
  isAuthenticated() {
1119
- let expired = this.getExpired();
1120
- if (!expired)
1121
- expired = new Date(0);
1133
+ let expired = this.getExpired() || new Date(0);
1122
1134
  const newValue = new Date() < expired;
1123
- if (this.oldValueIsAuthenticated != newValue) {
1124
- this.oldValueIsAuthenticated = newValue;
1135
+ if (this._oldValueIsAuthenticated != newValue) {
1136
+ this._oldValueIsAuthenticated = newValue;
1125
1137
  if (this.onSignedInSubject) {
1126
1138
  this.onSignedInSubject.next(newValue);
1127
1139
  }
1128
- this.subject.next(newValue);
1140
+ this._subject.next(newValue);
1129
1141
  //if user is signed in and expired we need to logout (remove from localStorage)
1130
1142
  if (!newValue) {
1131
1143
  this.logout();
@@ -1138,7 +1150,7 @@ class AuthService {
1138
1150
  * @deprecated The method should not be used. please use onSignedIn
1139
1151
  */
1140
1152
  isSignedIn() {
1141
- return this.subject.asObservable();
1153
+ return this._subject.asObservable();
1142
1154
  }
1143
1155
  get onSignedIn() {
1144
1156
  if (!this.onSignedInSubject) {
@@ -1149,39 +1161,39 @@ class AuthService {
1149
1161
  throw new Error("onExecuteObservable is undefined");
1150
1162
  return this.onSignedInObservable;
1151
1163
  }
1152
- login(tmp) {
1153
- this.model = undefined;
1154
- if (tmp) {
1155
- //Globals.setServerDate(tmpModel.currentDateTime);
1156
- //this.permissionsService.flushPermissions();
1157
- if (tmp.roles) {
1158
- tmp.roles = tmp.roles.map(function (e) { return e.toUpperCase(); });
1159
- //this.permissionsService.loadPermissions(model.roles);
1164
+ login(user) {
1165
+ if (user) {
1166
+ if (Array.isArray(user.roles)) {
1167
+ user.roles = user.roles.map(function (e) { return e.toUpperCase(); });
1160
1168
  }
1161
1169
  }
1162
- //delete tmpModel.currentDateTime;
1163
- this.model = tmp;
1164
- this.expired = null;
1165
- StorageHelper.set('login', this.model);
1170
+ StorageHelper.set('login', user);
1171
+ this._user = null;
1172
+ this._isInitialized = false;
1166
1173
  this.isAuthenticated(); //this method need to execute subject.next();
1167
1174
  }
1168
1175
  logout() {
1169
1176
  this.login(null);
1170
1177
  }
1171
- getUser() {
1172
- if (!this.model) {
1173
- this.model = StorageHelper.get('login');
1178
+ // getUser(): LoginToken | null {
1179
+ // if (!this.model) {
1180
+ // this.model = StorageHelper.get('login');
1181
+ // }
1182
+ // return this.model;
1183
+ // }
1184
+ getExpired() {
1185
+ let user = this.user;
1186
+ if (user) {
1187
+ return user.expired;
1174
1188
  }
1175
- return this.model;
1189
+ return null;
1176
1190
  }
1177
- getExpired() {
1178
- if (!this.expired) {
1179
- const tmp = this.getUser();
1180
- if (tmp && tmp.expired) {
1181
- this.expired = new Date(tmp.expired);
1182
- }
1191
+ getRefreshTokenExpired() {
1192
+ let user = this.user;
1193
+ if (user) {
1194
+ return user.refreshTokenTime;
1183
1195
  }
1184
- return this.expired;
1196
+ return null;
1185
1197
  }
1186
1198
  // isInRole(allowedRoles: string[]): boolean {
1187
1199
  // if (!allowedRoles || allowedRoles.length === 0) {
@@ -1217,8 +1229,8 @@ class AuthService {
1217
1229
  if (!permissions || permissions.length === 0) {
1218
1230
  return true;
1219
1231
  }
1220
- const tmp = this.getUser();
1221
- const userPermissions = tmp ? tmp.permissions : null;
1232
+ const user = this.user;
1233
+ const userPermissions = user ? user.permissions : null;
1222
1234
  if (!userPermissions) {
1223
1235
  return false;
1224
1236
  }
@@ -1729,7 +1741,7 @@ class WebApiClient {
1729
1741
  getHeaders() {
1730
1742
  let httpHeaders = new HttpHeaders();
1731
1743
  httpHeaders = httpHeaders.set('Content-Type', 'application/json');
1732
- const tmp = this.authService.getUser();
1744
+ const tmp = this.authService.user;
1733
1745
  const token = tmp ? tmp.token : undefined;
1734
1746
  if (token)
1735
1747
  httpHeaders = httpHeaders.set('Authorization', token);
@@ -1847,7 +1859,7 @@ class BaseComponent extends CoreComponent {
1847
1859
  }
1848
1860
  get url() {
1849
1861
  if (!this._url)
1850
- this._url = this.router.url.split(';')[0];
1862
+ this._url = UrlHelper.getNoParam(this.router.url);
1851
1863
  return this._url;
1852
1864
  }
1853
1865
  getParam(name) {
@@ -2457,7 +2469,7 @@ class ListBaseComponent extends BaseComponent {
2457
2469
  this.bindModel();
2458
2470
  }
2459
2471
  create() {
2460
- const url = this.router.url.split(';')[0];
2472
+ const url = UrlHelper.getNoParam(this.router.url);
2461
2473
  this.router.navigate([url, 'create', { returnUrl: url + ';filter=1' }]);
2462
2474
  }
2463
2475
  delete(id) {
@@ -4538,7 +4550,7 @@ class ListToolbarComponent {
4538
4550
  this.onRefresh.emit();
4539
4551
  }
4540
4552
  create() {
4541
- const url = this.router.url.split(';')[0];
4553
+ const url = UrlHelper.getNoParam(this.router.url);
4542
4554
  this.router.navigate([url, 'create', { returnUrl: url + ';filter=1' }]);
4543
4555
  }
4544
4556
  filter() {