@yuuvis/client-core 2.1.34 → 2.2.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.
@@ -1262,6 +1262,7 @@ class SystemService {
1262
1262
  this.#logger = inject(Logger);
1263
1263
  this.#STORAGE_KEY = 'yuv.core.system.definition';
1264
1264
  this.#STORAGE_KEY_AUTH_DATA = 'yuv.core.auth.data';
1265
+ this.#STORAGE_KEY_FORMS = 'yuv.core.forms__';
1265
1266
  // cached icons to avoid backend calls (session cache)
1266
1267
  this.#iconCache = {};
1267
1268
  this.#resolvedClassificationsCache = {};
@@ -1275,6 +1276,7 @@ class SystemService {
1275
1276
  #logger;
1276
1277
  #STORAGE_KEY;
1277
1278
  #STORAGE_KEY_AUTH_DATA;
1279
+ #STORAGE_KEY_FORMS;
1278
1280
  // cached icons to avoid backend calls (session cache)
1279
1281
  #iconCache;
1280
1282
  #resolvedClassificationsCache;
@@ -1561,6 +1563,7 @@ class SystemService {
1561
1563
  * @param user The user to load the system definition for
1562
1564
  */
1563
1565
  getSystemDefinition(authData) {
1566
+ this.#clearObjectTypeFormCache();
1564
1567
  // TODO: Supposed to return 304 if nothing changes
1565
1568
  return this.#fetchSystemDefinition(authData);
1566
1569
  // TODO: remove when 304 is there???
@@ -1762,7 +1765,23 @@ class SystemService {
1762
1765
  * @returns Form model
1763
1766
  */
1764
1767
  getObjectTypeForm(objectTypeId, situation) {
1765
- return this.#backend.get(Utils.buildUri(`/dms/forms/${objectTypeId}`, { situation }));
1768
+ return this.#appCache
1769
+ .getItem(`${this.#STORAGE_KEY_FORMS}${objectTypeId}_${situation}`)
1770
+ .pipe(switchMap((res) => (res ? of(res) : this.#fetchObjectTypeForm(objectTypeId, situation))));
1771
+ }
1772
+ #fetchObjectTypeForm(objectTypeId, situation) {
1773
+ return this.#backend.get(Utils.buildUri(`/dms/forms/${objectTypeId}`, { situation })).pipe(
1774
+ // add form to cache
1775
+ tap((res) => this.#appCache.setItem(`${this.#STORAGE_KEY_FORMS}${objectTypeId}_${situation}`, res).subscribe()));
1776
+ }
1777
+ #clearObjectTypeFormCache() {
1778
+ // reset cache of object forms
1779
+ return this.#appCache
1780
+ .getStorageKeys()
1781
+ .pipe(tap((keys) => {
1782
+ forkJoin(keys.filter((key) => key.startsWith(this.#STORAGE_KEY_FORMS)).map((key) => this.#appCache.removeItem(key).pipe(catchError(() => of(null))))).subscribe();
1783
+ }))
1784
+ .subscribe();
1766
1785
  }
1767
1786
  /**
1768
1787
  * Check whether or not the model has at least one form element. Recursive.