@geogirafe/lib-geoportal 1.2.0-dev.2873796427 → 1.2.0-dev.2889467567

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.
Files changed (97) hide show
  1. package/api/apicontext.d.ts +12 -1
  2. package/api/apicontext.js +19 -111
  3. package/api/apisessionmanager.d.ts +1 -1
  4. package/api/apisessionmanager.js +1 -1
  5. package/base/GirafeSingleton.d.ts +1 -1
  6. package/base/GirafeSingleton.js +1 -1
  7. package/components/navigation/component.d.ts +2 -2
  8. package/components/navigation/component.js +6 -6
  9. package/components/news/news-button/component.d.ts +0 -1
  10. package/components/news/news-button/component.js +0 -6
  11. package/components/news/news-panel/component.d.ts +2 -2
  12. package/components/news/news-panel/component.js +5 -5
  13. package/components/search-filter/component.d.ts +2 -0
  14. package/components/search-filter/component.js +6 -3
  15. package/components/search-filter/style.css +4 -0
  16. package/components/themes/component.d.ts +1 -1
  17. package/components/themes/component.js +4 -4
  18. package/components/userpreferences/component.d.ts +1 -1
  19. package/components/userpreferences/component.js +7 -7
  20. package/package.json +1 -1
  21. package/templates/public/about.json +1 -1
  22. package/tools/app/lifecyclemanager.d.ts +1 -1
  23. package/tools/app/lifecyclemanager.js +1 -1
  24. package/tools/auth/abstractconnectmanager.js +2 -2
  25. package/tools/auth/authmanager.d.ts +1 -1
  26. package/tools/auth/authmanager.js +1 -1
  27. package/tools/auth/pluginmanager.d.ts +1 -1
  28. package/tools/auth/pluginmanager.js +1 -1
  29. package/tools/configuration/configmanager.d.ts +3 -2
  30. package/tools/configuration/configmanager.js +9 -5
  31. package/tools/configuration/girafeconfig.d.ts +7 -5
  32. package/tools/configuration/girafeconfig.js +4 -0
  33. package/tools/context/context.d.ts +1 -0
  34. package/tools/context/context.js +4 -112
  35. package/tools/context/contexthelper.d.ts +6 -0
  36. package/tools/context/contexthelper.js +102 -0
  37. package/tools/error/errormanager.d.ts +1 -1
  38. package/tools/error/errormanager.js +1 -1
  39. package/tools/feedback/feedbackmanager.d.ts +1 -2
  40. package/tools/feedback/feedbackmanager.js +6 -8
  41. package/tools/i18n/i18nmanager.d.ts +1 -1
  42. package/tools/i18n/i18nmanager.js +22 -20
  43. package/tools/layers/layermanager.d.ts +1 -1
  44. package/tools/layers/layermanager.js +1 -1
  45. package/tools/layers/snapmanager.d.ts +1 -1
  46. package/tools/layers/snapmanager.js +1 -1
  47. package/tools/localfile/localfilemanager.d.ts +1 -1
  48. package/tools/localfile/localfilemanager.js +1 -1
  49. package/tools/logging/defaultconsole.d.ts +8 -0
  50. package/tools/logging/defaultconsole.js +9 -0
  51. package/tools/logging/logmanager.d.ts +1 -7
  52. package/tools/logging/logmanager.js +8 -13
  53. package/tools/main.d.ts +3 -1
  54. package/tools/main.js +2 -0
  55. package/tools/offline/offlinemanager.d.ts +3 -3
  56. package/tools/offline/offlinemanager.js +6 -6
  57. package/tools/ogcapi/ogcapifeaturesmanager.d.ts +1 -1
  58. package/tools/ogcapi/ogcapifeaturesmanager.js +1 -1
  59. package/tools/onboarding/onboardingmanager.js +4 -4
  60. package/tools/ordering/orderingmanager.d.ts +1 -1
  61. package/tools/ordering/orderingmanager.js +1 -1
  62. package/tools/search/abstractsearchclient.d.ts +1 -1
  63. package/tools/search/abstractsearchclient.js +2 -2
  64. package/tools/search/searchmanager.d.ts +1 -1
  65. package/tools/search/searchmanager.js +2 -2
  66. package/tools/selection/selectionmanager.d.ts +1 -1
  67. package/tools/selection/selectionmanager.js +1 -1
  68. package/tools/share/sessionmanager.d.ts +1 -1
  69. package/tools/share/sessionmanager.js +1 -1
  70. package/tools/share/sharemanager.d.ts +1 -1
  71. package/tools/share/sharemanager.js +1 -1
  72. package/tools/share/stateserializer.d.ts +1 -1
  73. package/tools/share/stateserializer.js +1 -1
  74. package/tools/state/statemanager.d.ts +1 -1
  75. package/tools/state/statemanager.js +1 -1
  76. package/tools/tests/mockconfig.d.ts +2 -3
  77. package/tools/tests/mockconfig.js +0 -1
  78. package/tools/tests/mockcontext.d.ts +13 -1
  79. package/tools/tests/mockcontext.js +27 -112
  80. package/tools/tests/mockhelper.d.ts +2 -2
  81. package/tools/tests/mockhelper.js +4 -5
  82. package/tools/themes/customthemesmanager.d.ts +3 -3
  83. package/tools/themes/customthemesmanager.js +9 -9
  84. package/tools/themes/themefavoritesmanager.d.ts +5 -5
  85. package/tools/themes/themefavoritesmanager.js +16 -16
  86. package/tools/themes/themeshelper.d.ts +1 -1
  87. package/tools/themes/themeshelper.js +1 -1
  88. package/tools/themes/themesmanager.d.ts +1 -1
  89. package/tools/themes/themesmanager.js +2 -2
  90. package/tools/url/permalinkmanager.d.ts +1 -1
  91. package/tools/url/permalinkmanager.js +1 -1
  92. package/tools/userdata/userdatamanager.d.ts +18 -39
  93. package/tools/userdata/userdatamanager.js +111 -75
  94. package/tools/wfs/wfsmanager.d.ts +1 -1
  95. package/tools/wfs/wfsmanager.js +1 -1
  96. package/tools/wms/wmsmanager.d.ts +1 -1
  97. package/tools/wms/wmsmanager.js +1 -1
@@ -5,10 +5,10 @@ declare class CustomThemesManager extends GirafeSingleton {
5
5
  customThemes: CustomTheme[];
6
6
  private readonly storagePath;
7
7
  private readonly serializer;
8
- addTheme(themeName: string, layersList: BaseLayer[]): void;
8
+ addTheme(themeName: string, layersList: BaseLayer[]): Promise<void>;
9
9
  private manageActiveStateForClonedObject;
10
- deleteTheme(theme: CustomTheme): void;
10
+ deleteTheme(theme: CustomTheme): Promise<void>;
11
11
  private saveCustomThemes;
12
- loadCustomThemes(): void;
12
+ loadCustomThemes(): Promise<void>;
13
13
  }
14
14
  export default CustomThemesManager;
@@ -9,7 +9,7 @@ class CustomThemesManager extends GirafeSingleton {
9
9
  customThemes = [];
10
10
  storagePath = 'customThemes';
11
11
  serializer = new CustomLayersSerializer(this.context);
12
- addTheme(themeName, layersList) {
12
+ async addTheme(themeName, layersList) {
13
13
  const theme = new CustomTheme(themeName);
14
14
  for (const layerBase of layersList) {
15
15
  const layer = layerBase.clone();
@@ -17,7 +17,7 @@ class CustomThemesManager extends GirafeSingleton {
17
17
  theme.layers.push(layer);
18
18
  }
19
19
  this.customThemes.push(theme);
20
- this.saveCustomThemes();
20
+ await this.saveCustomThemes();
21
21
  }
22
22
  manageActiveStateForClonedObject(layer) {
23
23
  /** Manage the current active state and default active state
@@ -35,25 +35,25 @@ class CustomThemesManager extends GirafeSingleton {
35
35
  }
36
36
  }
37
37
  }
38
- deleteTheme(theme) {
39
- const index = this.customThemes.findIndex((item) => item === theme);
38
+ async deleteTheme(theme) {
39
+ const index = this.customThemes.indexOf(theme);
40
40
  if (index >= 0) {
41
41
  this.customThemes.splice(index, 1);
42
- this.saveCustomThemes();
42
+ await this.saveCustomThemes();
43
43
  }
44
44
  else {
45
45
  throw new Error('The custom theme to be removed cannot be found in the list of custom themes');
46
46
  }
47
47
  }
48
- saveCustomThemes() {
48
+ async saveCustomThemes() {
49
49
  const serializedObject = {};
50
50
  for (const customTheme of this.customThemes) {
51
51
  serializedObject[customTheme.name] = this.serializer.customThemeSerialize(customTheme);
52
52
  }
53
- this.context.userDataManager.saveUserData(this.storagePath, serializedObject);
53
+ await this.context.userDataManager.saveUserData(this.storagePath, serializedObject);
54
54
  }
55
- loadCustomThemes() {
56
- const customThemes = this.context.userDataManager.getUserData(this.storagePath);
55
+ async loadCustomThemes() {
56
+ const customThemes = (await this.context.userDataManager.getUserData(this.storagePath));
57
57
  if (customThemes) {
58
58
  for (const customThemeName of Object.keys(customThemes)) {
59
59
  try {
@@ -4,13 +4,13 @@ import ThemeLayer from '../../models/layers/themelayer.js';
4
4
  declare class ThemeFavoritesManager extends GirafeSingleton {
5
5
  private themeFavorites;
6
6
  private readonly storagePath;
7
- initializeSingleton(): void;
7
+ initializeSingleton(): Promise<void>;
8
8
  private saveThemeFavorites;
9
9
  private loadThemeFavorites;
10
- addThemeToFavorites(theme: ThemeLayer | CustomTheme): void;
11
- removeThemeFromFavorites(theme: ThemeLayer | CustomTheme): void;
12
- addOrRemoveThemeFromFavorites(theme: ThemeLayer | CustomTheme): void;
13
- clearThemeFavorites(): void;
10
+ addThemeToFavorites(theme: ThemeLayer | CustomTheme): Promise<void>;
11
+ removeThemeFromFavorites(theme: ThemeLayer | CustomTheme): Promise<void>;
12
+ addOrRemoveThemeFromFavorites(theme: ThemeLayer | CustomTheme): Promise<void>;
13
+ clearThemeFavorites(): Promise<void>;
14
14
  isThemeInFavorites(theme: ThemeLayer | CustomTheme): boolean;
15
15
  getThemeFavorites(): Array<number | string>;
16
16
  }
@@ -4,45 +4,45 @@ import ThemeLayer from '../../models/layers/themelayer.js';
4
4
  class ThemeFavoritesManager extends GirafeSingleton {
5
5
  themeFavorites = [];
6
6
  storagePath = 'themeFavorites';
7
- initializeSingleton() {
8
- super.initializeSingleton();
9
- this.loadThemeFavorites();
7
+ async initializeSingleton() {
8
+ await super.initializeSingleton();
9
+ await this.loadThemeFavorites();
10
10
  }
11
- saveThemeFavorites() {
11
+ async saveThemeFavorites() {
12
12
  const serializedThemeFavorites = JSON.stringify(this.themeFavorites);
13
- this.context.userDataManager.saveUserData(this.storagePath, serializedThemeFavorites);
13
+ await this.context.userDataManager.saveUserData(this.storagePath, serializedThemeFavorites);
14
14
  }
15
- loadThemeFavorites() {
16
- const serializedThemeFavorites = this.context.userDataManager.getUserData(this.storagePath);
15
+ async loadThemeFavorites() {
16
+ const serializedThemeFavorites = (await this.context.userDataManager.getUserData(this.storagePath));
17
17
  if (serializedThemeFavorites) {
18
18
  this.themeFavorites = JSON.parse(serializedThemeFavorites);
19
19
  }
20
20
  }
21
- addThemeToFavorites(theme) {
21
+ async addThemeToFavorites(theme) {
22
22
  this.themeFavorites.push(theme instanceof ThemeLayer ? theme.id : theme.name);
23
- this.saveThemeFavorites();
23
+ await this.saveThemeFavorites();
24
24
  }
25
- removeThemeFromFavorites(theme) {
25
+ async removeThemeFromFavorites(theme) {
26
26
  const index = this.themeFavorites.findIndex((themeIdOrName) => theme instanceof ThemeLayer ? themeIdOrName === theme.id : themeIdOrName === theme.name);
27
27
  if (index >= 0) {
28
28
  this.themeFavorites.splice(index, 1);
29
- this.saveThemeFavorites();
29
+ await this.saveThemeFavorites();
30
30
  }
31
31
  else {
32
32
  throw new Error('The theme to be removed cannot be found in the list of favorites');
33
33
  }
34
34
  }
35
- addOrRemoveThemeFromFavorites(theme) {
35
+ async addOrRemoveThemeFromFavorites(theme) {
36
36
  if (this.isThemeInFavorites(theme)) {
37
- this.removeThemeFromFavorites(theme);
37
+ await this.removeThemeFromFavorites(theme);
38
38
  }
39
39
  else {
40
- this.addThemeToFavorites(theme);
40
+ await this.addThemeToFavorites(theme);
41
41
  }
42
42
  }
43
- clearThemeFavorites() {
43
+ async clearThemeFavorites() {
44
44
  this.themeFavorites = [];
45
- this.saveThemeFavorites();
45
+ await this.saveThemeFavorites();
46
46
  }
47
47
  isThemeInFavorites(theme) {
48
48
  return this.themeFavorites.includes(theme instanceof ThemeLayer ? theme.id : theme.name);
@@ -9,7 +9,7 @@ export type LayerTreeChanges = {
9
9
  activatedLayers: BaseLayer[];
10
10
  };
11
11
  export default class ThemesHelper extends GirafeSingleton {
12
- initializeSingleton(): void;
12
+ initializeSingleton(): Promise<void>;
13
13
  private get state();
14
14
  findBaseLayerById(layerId: LayerId): BaseLayer;
15
15
  findBaseLayerRecursiveById(layers: BaseLayer[], layerId: LayerId): BaseLayer | null;
@@ -10,7 +10,7 @@ import WfsFilterCondition, { isWfsOperator } from '../wfs/wfsfiltercondition.js'
10
10
  import { KNOWN_FUNCTIONALITIES } from '../functionalities.js';
11
11
  import WfsFilter from '../wfs/wfsfilter.js';
12
12
  export default class ThemesHelper extends GirafeSingleton {
13
- initializeSingleton() {
13
+ async initializeSingleton() {
14
14
  this.context.stateManager.subscribe('themes.lastSelectedTheme', (_oldTheme, newTheme) => this.onSelectedThemeChanged(newTheme));
15
15
  }
16
16
  get state() {
@@ -4,7 +4,7 @@ declare class ThemesManager extends GirafeSingleton {
4
4
  u: string;
5
5
  };
6
6
  private get state();
7
- initializeSingleton(): void;
7
+ initializeSingleton(): Promise<void>;
8
8
  private initialize;
9
9
  private restoreState;
10
10
  private addBasemapFromUrl;
@@ -25,7 +25,7 @@ class ThemesManager extends GirafeSingleton {
25
25
  get state() {
26
26
  return this.context.stateManager.state;
27
27
  }
28
- initializeSingleton() {
28
+ async initializeSingleton() {
29
29
  // We have to wait the authentication to be able to load the themes with the right user-rights
30
30
  this.context.stateManager.subscribe('application.isReadyToLoadThemes', async () => {
31
31
  if (this.state.application.isReadyToLoadThemes) {
@@ -104,7 +104,7 @@ class ThemesManager extends GirafeSingleton {
104
104
  const themesAndFunctionalities = await this.prepareThemes(content['themes']);
105
105
  this.state.themes._allThemes = themesAndFunctionalities.themes;
106
106
  this.state.themes._allFunctionalities = themesAndFunctionalities.themesFunctionalities;
107
- this.context.customThemesManager.loadCustomThemes();
107
+ await this.context.customThemesManager.loadCustomThemes();
108
108
  this.state.themes.isLoaded = true;
109
109
  if (this.context.configManager.Config.themes.showErrorsOnStart) {
110
110
  // Display themes errors only if configured so.
@@ -5,7 +5,7 @@ export default class PermalinkManager extends GirafeSingleton {
5
5
  private readonly urlParamKeys;
6
6
  private readonly urlParamKeysWithPrefix;
7
7
  private params;
8
- initializeSingleton(): void;
8
+ initializeSingleton(): Promise<void>;
9
9
  private get state();
10
10
  private getPermalinkParamsFromUrl;
11
11
  private removePermalinkParamsFromUrl;
@@ -26,7 +26,7 @@ export default class PermalinkManager extends GirafeSingleton {
26
26
  ];
27
27
  urlParamKeysWithPrefix = ['wfs_'];
28
28
  params = {};
29
- initializeSingleton() {
29
+ async initializeSingleton() {
30
30
  this.getPermalinkParamsFromUrl();
31
31
  this.removePermalinkParamsFromUrl();
32
32
  this.setStateFromParams();
@@ -1,4 +1,5 @@
1
1
  import GirafeSingleton from '../../base/GirafeSingleton.js';
2
+ import { UserDataConfig } from '../configuration/girafeconfig.js';
2
3
  /**
3
4
  * Manages user data storage and retrieval across different storage sources.
4
5
  * The class supports localStorage and server as storage options (server-side implementation currently not available).
@@ -7,51 +8,29 @@ import GirafeSingleton from '../../base/GirafeSingleton.js';
7
8
  */
8
9
  declare class UserDataManager extends GirafeSingleton {
9
10
  private readonly storageKey;
10
- private source?;
11
- private readonly WARNING_UNKNOWN_SOURCE;
12
- private readonly WARNING_NOT_IMPLEMENTED;
13
- setSource(source: string): void;
11
+ private config;
12
+ private allowSaveUserPreferences;
13
+ initializeFromConfig(config: UserDataConfig): void;
14
+ private userData?;
15
+ private userDataPromise?;
14
16
  /**
15
17
  * Retrieves a specific part of the user data defined by the storage path.
16
18
  * @param storagePath path in the user data object to the requested value.
17
- * @param forceLocalStorage if true, reads user data from the local storage, ignoring the source.
18
19
  * @returns the partial user data object.
19
20
  */
20
- getUserData(storagePath: string, forceLocalStorage?: boolean): unknown;
21
- /**
22
- * Saves user data to a specific path in the storage.
23
- * @param storagePath path in the user data object where the value is saved to.
24
- * @param newValue user data value to save.
25
- * @param forceLocalStorage if true, saves user data to the local storage, ignoring the source.
26
- */
27
- saveUserData(storagePath: string, newValue: unknown, forceLocalStorage?: boolean): void;
28
- /**
29
- * Delete a specific part of the user data defined by the storage path.
30
- * @param storagePath path in the user data object that will be deleted.
31
- * @param forceLocalStorage if true, deletes user data in the local storage, ignoring the source.
32
- */
33
- deleteUserData(storagePath: string, forceLocalStorage?: boolean): void;
34
- /**
35
- * Deletes all user data in storage.
36
- * @param forceLocalStorage Force deletion from local storage regardless of the currently set data source.
37
- */
38
- deleteAllUserData(forceLocalStorage?: boolean): void;
39
- /**
40
- * Helper: Load data from the user data storage.
41
- * @param forceLocalStorage forces loading data from local storage, independent of the specified source.
42
- * @returns the full user data object in the storage.
43
- */
21
+ getUserData(storagePath: string): Promise<unknown>;
22
+ getFromLocalStorage(storagePath: string): any;
23
+ private extractValue;
44
24
  private load;
45
- /**
46
- * Helper: Save user data to storage.
47
- * @param fullUserDataObject full user data object that is saved.
48
- * @param forceLocalStorage forces saving data to local storage, independent of the specified source.
49
- * @private
50
- */
25
+ private loadFromLocalStorage;
26
+ private loadFromServer;
27
+ saveUserData(storagePath: string, newValue: unknown): Promise<void>;
28
+ saveToLocalStorage(storagePath: string, newValue: unknown): void;
51
29
  private save;
52
- /**
53
- * Helper: Determines if a particular operation should use the local browser storage.
54
- */
55
- private isInLocalStorage;
30
+ private writeToLocalStorage;
31
+ private writeToServer;
32
+ deleteUserData(storagePath: string): Promise<void>;
33
+ deleteAllUserData(): Promise<void>;
34
+ private deleteFromServer;
56
35
  }
57
36
  export default UserDataManager;
@@ -10,110 +10,146 @@ import { createObjectFromPath, deletePropertyByPath, getPropertyByPath, setPrope
10
10
  class UserDataManager extends GirafeSingleton {
11
11
  // Using the full URL as storage key allows having separate user data for apps under the same base URL (e.g. demo apps)
12
12
  storageKey = window.location.origin + window.location.pathname;
13
- source;
14
- WARNING_UNKNOWN_SOURCE = 'User data source isn’t set';
15
- WARNING_NOT_IMPLEMENTED = 'Server-side functionality is not implemented yet';
16
- setSource(source) {
17
- if (source === 'localStorage' || source === 'server') {
18
- this.source = source;
19
- }
20
- else {
21
- console.warn(`User data source "${source}" not known`);
22
- }
13
+ config;
14
+ allowSaveUserPreferences = true;
15
+ initializeFromConfig(config) {
16
+ this.config = config;
23
17
  }
18
+ userData;
19
+ userDataPromise;
24
20
  /**
25
21
  * Retrieves a specific part of the user data defined by the storage path.
26
22
  * @param storagePath path in the user data object to the requested value.
27
- * @param forceLocalStorage if true, reads user data from the local storage, ignoring the source.
28
23
  * @returns the partial user data object.
29
24
  */
30
- getUserData(storagePath, forceLocalStorage = false) {
31
- const fullUserDataObject = this.load(forceLocalStorage);
32
- const { found, parentObject, lastKey } = getPropertyByPath(fullUserDataObject, storagePath);
25
+ async getUserData(storagePath) {
26
+ if (this.userData) {
27
+ // User Data were already loaded
28
+ return this.extractValue(this.userData, storagePath);
29
+ }
30
+ this.userDataPromise = this.load().catch((error) => {
31
+ this.userDataPromise = undefined;
32
+ throw error;
33
+ });
34
+ this.userData = await this.userDataPromise;
35
+ return this.extractValue(this.userData, storagePath);
36
+ }
37
+ getFromLocalStorage(storagePath) {
38
+ const storedUserData = localStorage.getItem(this.storageKey);
39
+ const userData = storedUserData ? JSON.parse(storedUserData) : {};
40
+ return this.extractValue(userData, storagePath);
41
+ }
42
+ extractValue(data, storagePath) {
43
+ const { found, parentObject, lastKey } = getPropertyByPath(data, storagePath);
33
44
  return found && parentObject && lastKey ? parentObject[lastKey] : undefined;
34
45
  }
35
- /**
36
- * Saves user data to a specific path in the storage.
37
- * @param storagePath path in the user data object where the value is saved to.
38
- * @param newValue user data value to save.
39
- * @param forceLocalStorage if true, saves user data to the local storage, ignoring the source.
40
- */
41
- saveUserData(storagePath, newValue, forceLocalStorage = false) {
42
- let fullUserDataObject = this.load(forceLocalStorage);
46
+ async load() {
47
+ if (this.config.source === 'localStorage') {
48
+ return this.loadFromLocalStorage();
49
+ }
50
+ else if (this.config.source === 'server') {
51
+ const userdata = await this.loadFromServer();
52
+ return userdata;
53
+ }
54
+ throw new Error(`Unknown source for user preferences: ${this.config.source}`);
55
+ }
56
+ loadFromLocalStorage() {
57
+ const storedUserData = localStorage.getItem(this.storageKey);
58
+ return storedUserData ? JSON.parse(storedUserData) : {};
59
+ }
60
+ async loadFromServer() {
61
+ try {
62
+ const response = await fetch(this.config.getUrl);
63
+ const storedUserData = await response.json();
64
+ return storedUserData;
65
+ }
66
+ catch {
67
+ // Cannot load user preference from server.
68
+ // In this case, we deactivate the save process for user preferences
69
+ // (because we do not want to override the existing user-preferences if they could not be loaded for some reason)
70
+ // And we return empty preferences, because we want to be able to start the application
71
+ // even if the user preferences could not be retrieved.
72
+ this.allowSaveUserPreferences = false;
73
+ this.context.errorManager.pushMessage('loadUserPreferencesError', 'User Preferences could not be loaded. Try refreshing the page or contact your administrator.', 'error');
74
+ return {};
75
+ }
76
+ }
77
+ async saveUserData(storagePath, newValue) {
78
+ if (!getPropertyByPath(this.userData, storagePath).found) {
79
+ // Object does not exist in user data yet, create it
80
+ const newUserData = createObjectFromPath(storagePath);
81
+ this.userData = mergeObjects(this.userData ?? {}, newUserData);
82
+ }
83
+ if (setPropertyByPath(this.userData, storagePath, newValue)) {
84
+ await this.save(this.userData ?? {});
85
+ }
86
+ }
87
+ saveToLocalStorage(storagePath, newValue) {
88
+ let fullUserDataObject = this.loadFromLocalStorage();
43
89
  if (!getPropertyByPath(fullUserDataObject, storagePath).found) {
44
90
  // Object does not exist in user data yet, create it
45
91
  const newUserData = createObjectFromPath(storagePath);
46
92
  fullUserDataObject = mergeObjects(fullUserDataObject, newUserData);
47
93
  }
48
94
  if (setPropertyByPath(fullUserDataObject, storagePath, newValue)) {
49
- this.save(fullUserDataObject, forceLocalStorage);
95
+ this.writeToLocalStorage(fullUserDataObject);
50
96
  }
51
97
  }
52
- /**
53
- * Delete a specific part of the user data defined by the storage path.
54
- * @param storagePath path in the user data object that will be deleted.
55
- * @param forceLocalStorage if true, deletes user data in the local storage, ignoring the source.
56
- */
57
- deleteUserData(storagePath, forceLocalStorage = false) {
58
- const currentUserData = this.load(forceLocalStorage);
59
- deletePropertyByPath(currentUserData, storagePath);
60
- this.save(currentUserData, forceLocalStorage);
61
- }
62
- /**
63
- * Deletes all user data in storage.
64
- * @param forceLocalStorage Force deletion from local storage regardless of the currently set data source.
65
- */
66
- deleteAllUserData(forceLocalStorage = false) {
67
- if (this.isInLocalStorage(forceLocalStorage)) {
68
- localStorage.removeItem(this.storageKey);
98
+ async save(fullUserDataObject) {
99
+ if (this.config.source === 'localStorage') {
100
+ this.writeToLocalStorage(fullUserDataObject);
69
101
  }
70
- else if (this.source === 'server') {
71
- console.warn(this.WARNING_NOT_IMPLEMENTED);
102
+ else if (this.config.source === 'server') {
103
+ await this.writeToServer(fullUserDataObject);
72
104
  }
73
105
  else {
74
- console.warn(this.WARNING_UNKNOWN_SOURCE);
106
+ throw new Error(`Unknown source for user preferences: ${this.config.source}`);
75
107
  }
76
108
  }
77
- /**
78
- * Helper: Load data from the user data storage.
79
- * @param forceLocalStorage forces loading data from local storage, independent of the specified source.
80
- * @returns the full user data object in the storage.
81
- */
82
- load(forceLocalStorage) {
83
- if (this.isInLocalStorage(forceLocalStorage)) {
84
- const storedUserData = localStorage.getItem(this.storageKey);
85
- return storedUserData ? JSON.parse(storedUserData) : {};
109
+ writeToLocalStorage(fullUserDataObject) {
110
+ localStorage.setItem(this.storageKey, JSON.stringify(fullUserDataObject));
111
+ }
112
+ async writeToServer(fullUserDataObject) {
113
+ if (!this.allowSaveUserPreferences) {
114
+ return;
86
115
  }
87
- else if (this.source === 'server') {
88
- console.warn(this.WARNING_NOT_IMPLEMENTED);
116
+ const response = await fetch(this.config.postUrl, {
117
+ method: 'POST',
118
+ headers: { 'Content-Type': 'application/json' },
119
+ body: JSON.stringify(fullUserDataObject)
120
+ });
121
+ if (!response.ok) {
122
+ console.error(response.text);
123
+ throw new Error(`Error while saving user preferences: ${response.status}`);
89
124
  }
90
- else {
91
- console.warn(this.WARNING_UNKNOWN_SOURCE);
92
- }
93
- return {};
94
125
  }
95
- /**
96
- * Helper: Save user data to storage.
97
- * @param fullUserDataObject full user data object that is saved.
98
- * @param forceLocalStorage forces saving data to local storage, independent of the specified source.
99
- * @private
100
- */
101
- save(fullUserDataObject, forceLocalStorage) {
102
- if (this.isInLocalStorage(forceLocalStorage)) {
103
- localStorage.setItem(this.storageKey, JSON.stringify(fullUserDataObject));
126
+ async deleteUserData(storagePath) {
127
+ deletePropertyByPath(this.userData, storagePath);
128
+ await this.save(this.userData);
129
+ }
130
+ async deleteAllUserData() {
131
+ this.userData = undefined;
132
+ if (this.config.source === 'localStorage') {
133
+ localStorage.removeItem(this.storageKey);
104
134
  }
105
- else if (this.source === 'server') {
106
- console.warn(this.WARNING_NOT_IMPLEMENTED);
135
+ else if (this.config.source === 'server') {
136
+ await this.deleteFromServer();
107
137
  }
108
138
  else {
109
- console.warn(this.WARNING_UNKNOWN_SOURCE);
139
+ throw new Error(`Unknown source for user preferences: ${this.config.source}`);
110
140
  }
111
141
  }
112
- /**
113
- * Helper: Determines if a particular operation should use the local browser storage.
114
- */
115
- isInLocalStorage(forceLocalStorage) {
116
- return this.source === 'localStorage' || forceLocalStorage;
142
+ async deleteFromServer() {
143
+ if (!this.allowSaveUserPreferences) {
144
+ return;
145
+ }
146
+ const response = await fetch(this.config.postUrl, {
147
+ method: 'DELETE'
148
+ });
149
+ if (!response.ok) {
150
+ console.error(response.text);
151
+ throw new Error(`Error while deleting user preferences: ${response.status}`);
152
+ }
117
153
  }
118
154
  }
119
155
  export default UserDataManager;
@@ -8,7 +8,7 @@ export default class WfsManager extends VendorSpecificOgcServerManager<WfsClient
8
8
  private get state();
9
9
  getClientId(ogcServer: ServerOgc): string;
10
10
  static readonly UnknownFeatureType: string;
11
- initializeSingleton(): void;
11
+ initializeSingleton(): Promise<void>;
12
12
  private onSelectedFeaturesFilterChange;
13
13
  /**
14
14
  * Determines whether the specified layer is the first active child layer of a time-aware group layer,
@@ -10,7 +10,7 @@ export default class WfsManager extends VendorSpecificOgcServerManager {
10
10
  return ogcServer.urlWfs ?? '';
11
11
  }
12
12
  static UnknownFeatureType = 'UNKNOWN';
13
- initializeSingleton() {
13
+ async initializeSingleton() {
14
14
  this.context.stateManager.subscribe(/layers\.layersList\..*\.filter/, (_oldFilter, newFilter) => {
15
15
  void this.onSelectedFeaturesFilterChange(newFilter);
16
16
  });
@@ -8,7 +8,7 @@ import IGirafeContext from '../context/icontext.js';
8
8
  export default class WmsManager extends VendorSpecificOgcServerManager<WmsClient, OlMap> {
9
9
  private readonly map;
10
10
  constructor(context: IGirafeContext);
11
- initializeSingleton(): void;
11
+ initializeSingleton(): Promise<void>;
12
12
  getClientId(ogcServer: ServerOgc): string;
13
13
  createClient(clientClass: new (os: ServerOgc, map: OlMap, context: IGirafeContext) => WmsClient, ogcServer: ServerOgc): WmsClient;
14
14
  selectFeatures(extent: number[]): void;
@@ -6,7 +6,7 @@ export default class WmsManager extends VendorSpecificOgcServerManager {
6
6
  super(context);
7
7
  this.map = this.context.mapManager.getMap();
8
8
  }
9
- initializeSingleton() {
9
+ async initializeSingleton() {
10
10
  // Register the default client
11
11
  this.registerClientClass('default', WmsClientDefault);
12
12
  this.registerClientClass('geoserver', WmsClientGeoServer);