@koalarx/ui 13.2.4 → 13.2.7

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.
@@ -15,7 +15,7 @@ import { MatTooltipModule } from '@angular/material/tooltip';
15
15
  import * as i2$1 from '@angular/router';
16
16
  import { NavigationError, NavigationEnd, NavigationCancel, NavigationStart, RouterModule } from '@angular/router';
17
17
  import * as i7 from '@angular/material/core';
18
- import { BehaviorSubject, interval, Observable } from 'rxjs';
18
+ import { BehaviorSubject, interval, Observable, skipWhile } from 'rxjs';
19
19
  import jwt from 'jwt-decode';
20
20
  import * as i4 from '@koalarx/ui/menu';
21
21
  import { menuStateSubject } from '@koalarx/ui/menu';
@@ -1243,21 +1243,59 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1243
1243
  args: [{ providedIn: "root" }]
1244
1244
  }], ctorParameters: function () { return [{ type: i1$2.HttpClient }, { type: KoalaOAuth2Service }]; } });
1245
1245
 
1246
+ class KoalaApiRequesterCache {
1247
+ static createCache(name) {
1248
+ if (!this.hasCache(name)) {
1249
+ this.cache.push({
1250
+ name,
1251
+ data: new BehaviorSubject(undefined)
1252
+ });
1253
+ }
1254
+ }
1255
+ static setDataInCache(name, data) {
1256
+ this.getCacheSubject(name)?.next(data);
1257
+ }
1258
+ static getCacheSubject(name) {
1259
+ return this.cache.find(item => item.name === name)?.data;
1260
+ }
1261
+ static getCacheAsObservable(name) {
1262
+ return new Observable(observe => {
1263
+ this.getCacheSubject(name)
1264
+ .pipe(skipWhile(value => value === undefined))
1265
+ .subscribe({
1266
+ next: value => {
1267
+ observe.next(value);
1268
+ observe.complete();
1269
+ },
1270
+ error: err => {
1271
+ observe.error(err);
1272
+ observe.complete();
1273
+ }
1274
+ });
1275
+ });
1276
+ }
1277
+ static hasCache(name) {
1278
+ return !!this.getCacheSubject(name);
1279
+ }
1280
+ }
1281
+ KoalaApiRequesterCache.cache = [];
1282
+
1246
1283
  class KoalaApiRequesterBase {
1247
- constructor(koalaService, endpoint, environmentNameToEndpointApi = 'endpointApi', isMockup = false) {
1284
+ constructor(koalaService, endpoint, enableCache = false, environmentNameToEndpointApi = 'endpointApi', isMockup = false) {
1248
1285
  this.koalaService = koalaService;
1249
1286
  this.endpoint = endpoint;
1287
+ this.enableCache = enableCache;
1250
1288
  koalaService.apiUrl = KoalaEnvironment.environment?.[environmentNameToEndpointApi];
1251
1289
  koalaService.isMockup = isMockup;
1252
1290
  }
1253
1291
  getAll(filter) {
1254
- return this.koalaService.request('get', this.endpoint, this.getParams(filter));
1292
+ return this.request('get', this.endpoint, this.getParams(filter));
1255
1293
  }
1256
1294
  getById(id) {
1257
- return this.koalaService.request('get', this.endpoint + '/' + id);
1295
+ return this.request('get', this.endpoint + '/' + id);
1258
1296
  }
1259
1297
  getBySomething(something) {
1260
- return this.koalaService.request('get', this.endpoint + '/' + something);
1298
+ return this.request('get', this.endpoint + '/' + something);
1261
1299
  }
1262
1300
  save(data, id) {
1263
1301
  return this.koalaService.request((id ? 'put' : 'post'), `${this.endpoint}${(id ? `/${id}` : '')}`, data);
@@ -1301,6 +1339,22 @@ class KoalaApiRequesterBase {
1301
1339
  }
1302
1340
  return filter ?? null;
1303
1341
  }
1342
+ request(method, url, data = {}) {
1343
+ this.startCache(url);
1344
+ return this.koalaService
1345
+ .request(method, url, data)
1346
+ .pipe(map(response => {
1347
+ if (this.enableCache)
1348
+ KoalaApiRequesterCache.setDataInCache(url, response);
1349
+ return response;
1350
+ }));
1351
+ }
1352
+ startCache(endpoint) {
1353
+ if (this.enableCache && KoalaApiRequesterCache.hasCache(endpoint)) {
1354
+ return KoalaApiRequesterCache.getCacheAsObservable(endpoint);
1355
+ }
1356
+ KoalaApiRequesterCache.createCache(endpoint);
1357
+ }
1304
1358
  }
1305
1359
 
1306
1360
  class KoalaRequestService {
@@ -1398,5 +1452,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImpo
1398
1452
  * Generated bundle index. Do not edit.
1399
1453
  */
1400
1454
 
1401
- export { KOALA_LOADER_SUBJECT, KoalaApiRequesterBase, KoalaApiRequesterService, KoalaClientError, KoalaEnvironment, KoalaErrorsHelper, KoalaLanguageHelper, KoalaLoaderService, KoalaNotFoundError, KoalaOAuth2Service, KoalaOauthConfig, KoalaPageModule, KoalaParameterHashLocationStrategy, KoalaRequestHeaderHelper, KoalaRequestService, KoalaResponseFactory, KoalaSuccessError, KoalaTokenService, KoalaUnhautorizedError, LoaderBarPageComponent, NgxKoalaModule, NotificationComponent, PageComponent };
1455
+ export { KOALA_LOADER_SUBJECT, KoalaApiRequesterBase, KoalaApiRequesterCache, KoalaApiRequesterService, KoalaClientError, KoalaEnvironment, KoalaErrorsHelper, KoalaLanguageHelper, KoalaLoaderService, KoalaNotFoundError, KoalaOAuth2Service, KoalaOauthConfig, KoalaPageModule, KoalaParameterHashLocationStrategy, KoalaRequestHeaderHelper, KoalaRequestService, KoalaResponseFactory, KoalaSuccessError, KoalaTokenService, KoalaUnhautorizedError, LoaderBarPageComponent, NgxKoalaModule, NotificationComponent, PageComponent };
1402
1456
  //# sourceMappingURL=koalarx-ui-core.mjs.map