@geode/opengeodeweb-front 12.2.0-rc.3 → 12.2.0-rc.5

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 (135) hide show
  1. package/.build/tests/browser/helpers/object_trees/common.js +3 -1
  2. package/.build/tests/browser/helpers/object_trees/model_tree_bar.js +41 -0
  3. package/.build/tests/browser/helpers/wait_for_action_settled.js +2 -2
  4. package/.build/tests/browser/suites/index.js +2 -0
  5. package/.build/tests/browser/suites/model/collections.js +1 -1
  6. package/.build/tests/browser/suites/object_tree/controls.js +2 -1
  7. package/.build/tests/browser/suites/object_tree/model_tree_bar.js +81 -0
  8. package/app/components/ClippingPlanes.vue +1 -1
  9. package/app/components/FactorFilterPanel.vue +1 -1
  10. package/app/components/Launcher.vue +3 -2
  11. package/app/components/ThresholdFilter.vue +1 -2
  12. package/app/components/Viewer/Basemap/CropOptions.vue +7 -8
  13. package/app/components/Viewer/Basemap/OpacityOptions.vue +7 -8
  14. package/app/components/Viewer/ContextMenu/CircularItems.vue +6 -43
  15. package/app/components/Viewer/ContextMenu/ContextMenu.vue +1 -6
  16. package/app/components/Viewer/ContextMenu/ContextMenuItem.vue +14 -16
  17. package/app/components/Viewer/EdgedCurve/PointsOptions.vue +5 -4
  18. package/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue +10 -13
  19. package/app/components/Viewer/Generic/Mesh/CellsOptions.vue +8 -11
  20. package/app/components/Viewer/Generic/Mesh/EdgesOptions.vue +16 -13
  21. package/app/components/Viewer/Generic/Mesh/PointsOptions.vue +28 -31
  22. package/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue +9 -11
  23. package/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue +8 -11
  24. package/app/components/Viewer/Generic/Model/BlocksOptions.vue +1 -1
  25. package/app/components/Viewer/Generic/Model/CornersOptions.vue +1 -1
  26. package/app/components/Viewer/Generic/Model/CornersTypeOptions.vue +1 -1
  27. package/app/components/Viewer/Generic/Model/EdgesOptions.vue +7 -8
  28. package/app/components/Viewer/Generic/Model/LinesOptions.vue +1 -1
  29. package/app/components/Viewer/Generic/Model/LinesTypeOptions.vue +1 -1
  30. package/app/components/Viewer/Generic/Model/ModelEdgesCard.vue +5 -7
  31. package/app/components/Viewer/Generic/Model/ModelPointsCard.vue +5 -7
  32. package/app/components/Viewer/Generic/Model/ModelStyleCard.vue +5 -7
  33. package/app/components/Viewer/Generic/Model/ModelStyleOptions.vue +7 -8
  34. package/app/components/Viewer/Generic/Model/PointsOptions.vue +7 -8
  35. package/app/components/Viewer/Generic/Model/SurfacesOptions.vue +1 -1
  36. package/app/components/Viewer/Grid/2D/CellsOptions.vue +6 -4
  37. package/app/components/Viewer/Grid/2D/EdgesOptions.vue +6 -4
  38. package/app/components/Viewer/Grid/2D/PointsOptions.vue +5 -4
  39. package/app/components/Viewer/Grid/3D/CellsOptions.vue +6 -4
  40. package/app/components/Viewer/Grid/3D/EdgesOptions.vue +6 -4
  41. package/app/components/Viewer/Grid/3D/FacetsOptions.vue +6 -4
  42. package/app/components/Viewer/Grid/3D/PointsOptions.vue +5 -4
  43. package/app/components/Viewer/Image/ImageOptions.vue +10 -13
  44. package/app/components/Viewer/ObjectTree/Base/CommonTreeView.vue +17 -1
  45. package/app/components/Viewer/ObjectTree/Base/ComponentRelations.vue +2 -2
  46. package/app/components/Viewer/ObjectTree/Base/Controls.vue +26 -2
  47. package/app/components/Viewer/ObjectTree/Base/StickyHeader.vue +4 -1
  48. package/app/components/Viewer/ObjectTree/Base/TreeRow.vue +6 -8
  49. package/app/components/Viewer/ObjectTree/Box.vue +30 -5
  50. package/app/components/Viewer/ObjectTree/Layout.vue +183 -54
  51. package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +10 -15
  52. package/app/components/Viewer/ObjectTree/Views/ModelTree.vue +3 -0
  53. package/app/components/Viewer/PointSet/SpecificPointsOptions.vue +28 -31
  54. package/app/components/Viewer/Scene/BackgroundOptions.vue +4 -7
  55. package/app/components/Viewer/Scene/OrientationWidgetOptions.vue +4 -7
  56. package/app/components/Viewer/Scene/TextOptions.vue +4 -7
  57. package/app/components/Viewer/Solid/EdgesOptions.vue +6 -4
  58. package/app/components/Viewer/Solid/PointsOptions.vue +5 -4
  59. package/app/components/Viewer/Solid/PolygonsOptions.vue +6 -4
  60. package/app/components/Viewer/Solid/SpecificPolyhedraOptions.vue +8 -11
  61. package/app/components/Viewer/Surface/EdgesOptions.vue +6 -4
  62. package/app/components/Viewer/Surface/PointsOptions.vue +6 -4
  63. package/app/components/Viewer/Surface/PolygonsOptions.vue +8 -11
  64. package/app/components/Viewer/Surface/Triangulated/TrianglesOptions.vue +5 -4
  65. package/app/components/Viewer/TetrahedralSolid/TetrahedraOptions.vue +6 -4
  66. package/app/components/Viewer/TetrahedralSolid/TrianglesOptions.vue +6 -4
  67. package/app/composables/circular_menu.ts +45 -0
  68. package/app/composables/hover_highlight.ts +1 -1
  69. package/app/composables/model_menu_context.ts +7 -11
  70. package/app/composables/model_tree.ts +3 -3
  71. package/app/composables/model_tree_drag.ts +56 -0
  72. package/app/composables/project_manager_helpers/types.ts +2 -3
  73. package/app/composables/use_adaptive_styles.ts +15 -8
  74. package/app/composables/use_overlapping_picker.ts +7 -19
  75. package/app/composables/viewer_context_menu.ts +2 -1
  76. package/app/composables/virtual_tree.ts +7 -1
  77. package/app/stores/api.ts +6 -59
  78. package/app/stores/app.ts +21 -55
  79. package/app/stores/back.ts +86 -145
  80. package/app/stores/camera_manager.ts +12 -25
  81. package/app/stores/cloud.ts +21 -101
  82. package/app/stores/crs.ts +3 -2
  83. package/app/stores/data.ts +66 -409
  84. package/app/stores/data_style.ts +99 -93
  85. package/app/stores/feedback.ts +57 -53
  86. package/app/stores/infra.ts +61 -101
  87. package/app/stores/treeview.ts +39 -30
  88. package/app/stores/viewer.ts +9 -29
  89. package/app/stores/viewer_helpers/actions.ts +1 -23
  90. package/app/utils/backend_lifecycle.ts +155 -0
  91. package/app/utils/import_item.ts +5 -4
  92. package/app/utils/threshold_sources.ts +3 -2
  93. package/app/utils/treeview.ts +25 -1
  94. package/app/utils/viewer_object_type.ts +21 -0
  95. package/internal/database/base_database.ts +2 -1
  96. package/internal/database/database.ts +90 -7
  97. package/internal/database/queries.ts +45 -0
  98. package/internal/database/tables/camera_positions.ts +11 -1
  99. package/internal/database/tables/data.ts +20 -1
  100. package/internal/database/tables/data_style.ts +3 -1
  101. package/internal/database/tables/model_component_datastyle.ts +3 -1
  102. package/internal/database/tables/model_component_type_datastyle.ts +3 -1
  103. package/internal/database/tables/model_components.ts +12 -1
  104. package/internal/database/tables/model_components_relation.ts +11 -1
  105. package/internal/database/tables/scene_style.ts +3 -1
  106. package/internal/database/tables/treeview_config.ts +31 -0
  107. package/internal/stores/data/items.ts +110 -0
  108. package/internal/stores/data/model/collections.ts +107 -0
  109. package/internal/stores/data/model/components.ts +129 -0
  110. package/internal/stores/data/model/mesh_components.ts +134 -0
  111. package/internal/stores/data/model/relations.ts +76 -0
  112. package/internal/stores/data/model/types.ts +14 -0
  113. package/internal/stores/data/registration.ts +54 -0
  114. package/internal/stores/data/snapshot.ts +83 -0
  115. package/internal/stores/data/types.ts +26 -0
  116. package/internal/stores/data_style/model/common_mutations.ts +47 -77
  117. package/internal/stores/data_style/model/selection.ts +3 -10
  118. package/internal/stores/data_style/scene.ts +2 -2
  119. package/internal/stores/data_style/state.ts +10 -8
  120. package/internal/stores/data_style/state_shared.ts +10 -7
  121. package/internal/stores/hybrid_viewer/brightness.ts +36 -19
  122. package/internal/stores/hybrid_viewer/highlight.ts +9 -14
  123. package/internal/stores/hybrid_viewer/scene.ts +1 -1
  124. package/internal/stores/microservice.ts +192 -0
  125. package/package.json +1 -1
  126. package/tests/browser/helpers/data/helpers/attribute.ts +2 -1
  127. package/tests/browser/helpers/object_trees/common.ts +4 -0
  128. package/tests/browser/helpers/object_trees/model_tree_bar.ts +78 -0
  129. package/tests/browser/helpers/wait_for_action_settled.ts +2 -3
  130. package/tests/browser/suites/model/collections.ts +2 -1
  131. package/tests/browser/suites/object_tree/controls.ts +3 -0
  132. package/tests/browser/suites/object_tree/model_tree_bar.ts +125 -0
  133. package/app/stores/data_helpers/collections.ts +0 -122
  134. package/app/stores/data_helpers/mesh.ts +0 -167
  135. package/app/stores/data_helpers/relations.ts +0 -94
@@ -5,11 +5,17 @@ import type {
5
5
  ObjectStyle,
6
6
  SceneStyle,
7
7
  } from "@ogw_internal/stores/data_style/types";
8
+ import {
9
+ componentDataStyleDb,
10
+ componentTypeDataStyleDb,
11
+ dataStyleDb,
12
+ sceneStyleDb,
13
+ writeTransaction,
14
+ } from "@ogw_internal/database/database.js";
15
+ import { isImage, isMesh, isModel } from "@ogw_front/utils/viewer_object_type";
8
16
  import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
9
17
  import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types";
10
- import type { Table } from "dexie";
11
18
  import type { Visibility } from "@geode/opengeodeweb-viewer/schema_types";
12
- import { database } from "@ogw_internal/database/database.js";
13
19
  import { getDefaultStyle } from "@ogw_front/utils/default_styles";
14
20
  import { useAttributeTimeStepStyle } from "@ogw_internal/stores/data_style/time_step";
15
21
  import { useDataStore } from "@ogw_front/stores/data";
@@ -23,21 +29,11 @@ interface DataStyleSnapshot {
23
29
  // Projects saved before data_id existed hold their styles with an `id`
24
30
  readonly styles: Record<string, LegacyDataId<ObjectStyle> | ObjectStyle>;
25
31
  readonly componentStyles: Record<string, ModelComponentStyle>;
26
- readonly modelComponentTypeStyles: Record<string, ModelComponentTypeStyle>;
32
+ // Projects saved before the styles by component type (2026-04) have none
33
+ readonly modelComponentTypeStyles?: Record<string, ModelComponentTypeStyle>;
27
34
  readonly sceneStyle?: SceneStyle;
28
35
  }
29
36
 
30
- // The database's table map is dynamically assembled at runtime (see internal/database/database.ts), so its exported type is a loose `{}`; cast it to the shape it actually has at runtime rather than widening every call site.
31
- type DatabaseTables = Record<string, Table<Record<string, unknown>, string> | undefined>;
32
-
33
- // `noUncheckedIndexedAccess` sees these as possibly undefined even though they're always registered before this store is used; guard defensively rather than asserting.
34
- function requireTable<TableValue>(table: TableValue | undefined, name: string): TableValue {
35
- if (table === undefined) {
36
- throw new Error(`Database table not initialized: ${name}`);
37
- }
38
- return table;
39
- }
40
-
41
37
  function isRecord(value: unknown): value is Record<string, unknown> {
42
38
  return typeof value === "object" && value !== null;
43
39
  }
@@ -51,63 +47,86 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
51
47
  const sceneStyleStore = useSceneStyle();
52
48
  const attributeTimeStepStyle = useAttributeTimeStepStyle();
53
49
  const dataStore = useDataStore();
54
- // oxlint-disable-next-line no-unsafe-type-assertion -- the database Proxy is typed as `{}` at its export site; this cast documents its real runtime shape.
55
- const typedDatabase = database as unknown as DatabaseTables;
56
- const data_style_db = requireTable(typedDatabase.data_style, "data_style");
57
- const model_component_type_datastyle_db = requireTable(
58
- typedDatabase.model_component_type_datastyle,
59
- "model_component_type_datastyle",
60
- );
61
- const component_datastyle_db = requireTable(
62
- typedDatabase.model_component_datastyle,
63
- "model_component_datastyle",
64
- );
50
+ const dataStyleTable = dataStyleDb();
51
+ // Keyed by [id_model, type] and [id_model, id_component]
52
+ const componentTypeDataStyleTable = componentTypeDataStyleDb();
53
+ const componentDataStyleTable = componentDataStyleDb();
65
54
 
66
55
  async function addDataStyle(dataId: DataId, geodeObjectType: GeodeObjectType): Promise<void> {
67
56
  const defaultStyle = getDefaultStyle(geodeObjectType);
68
- await data_style_db.put(
57
+ await dataStyleTable.put(
69
58
  structuredClone({ data_id: dataId, ...(isRecord(defaultStyle) ? defaultStyle : {}) }),
70
59
  );
71
60
  }
72
61
 
73
- async function setVisibility(dataId: DataId, visibility: Visibility): Promise<unknown> {
62
+ // Runs the image, the mesh or the model implementation for a data, or `notViewable` for a data the viewer
63
+ // Does not show. An unknown viewer_object_type throws, unless `unknownType` handles it
64
+ async function forViewerType<Result>(
65
+ dataId: DataId,
66
+ handlers: {
67
+ image: (id: DataId) => Promise<Result>;
68
+ mesh: (id: DataId) => Promise<Result>;
69
+ model: (id: DataId) => Promise<Result>;
70
+ notViewable: (id: DataId) => Promise<Result> | Result;
71
+ unknownType?: (id: DataId) => Result;
72
+ },
73
+ ): Promise<Result> {
74
74
  const item = await dataStore.item(dataId);
75
- if (!(await dataStore.isItemViewable(item))) {
76
- return dataStyleState.mutateStyle(dataId, { visibility });
75
+ if (!(await dataStore.fetchIsViewable(dataId))) {
76
+ const result = await handlers.notViewable(dataId);
77
+ return result;
77
78
  }
78
-
79
- const { viewer_object_type } = item;
80
-
81
- if (viewer_object_type === "image") {
82
- return imageStyleStore.setImageVisibility(dataId, visibility);
79
+ if (isImage(item)) {
80
+ const result = await handlers.image(dataId);
81
+ return result;
83
82
  }
84
- if (viewer_object_type === "mesh") {
85
- return meshStyleStore.setMeshVisibility(dataId, visibility);
83
+ if (isMesh(item)) {
84
+ const result = await handlers.mesh(dataId);
85
+ return result;
86
86
  }
87
- if (viewer_object_type === "model") {
88
- return modelStyleStore.setModelVisibility(dataId, visibility);
87
+ if (isModel(item)) {
88
+ const result = await handlers.model(dataId);
89
+ return result;
89
90
  }
90
- throw new Error("Unknown viewer_object_type");
91
- }
92
-
93
- async function applyDefaultStyle(dataId: DataId): Promise<unknown[]> {
94
- const item = await dataStore.item(dataId);
95
- if (!(await dataStore.isItemViewable(item))) {
96
- throw new Error(`applyDefaultStyle called for non-viewable item: ${dataId}`);
91
+ if (handlers.unknownType) {
92
+ return handlers.unknownType(dataId);
97
93
  }
94
+ throw new Error(`Unknown viewer_object_type: ${item.viewer_object_type}`);
95
+ }
98
96
 
99
- const { viewer_object_type } = item;
97
+ // A data the viewer does not show only keeps its visibility in its style
98
+ async function setVisibility(dataId: DataId, visibility: Visibility): Promise<unknown> {
99
+ const result = await forViewerType<unknown>(dataId, {
100
+ image: async (id) => {
101
+ const image_result = await imageStyleStore.setImageVisibility(id, visibility);
102
+ return image_result;
103
+ },
104
+ mesh: async (id) => {
105
+ const mesh_result = await meshStyleStore.setMeshVisibility(id, visibility);
106
+ return mesh_result;
107
+ },
108
+ model: async (id) => {
109
+ const model_result = await modelStyleStore.setModelVisibility(id, visibility);
110
+ return model_result;
111
+ },
112
+ notViewable: async (id) => {
113
+ const style_result = await dataStyleState.mutateStyle(id, { visibility });
114
+ return style_result;
115
+ },
116
+ });
117
+ return result;
118
+ }
100
119
 
101
- if (viewer_object_type === "image") {
102
- return imageStyleStore.applyImageStyle(dataId);
103
- }
104
- if (viewer_object_type === "mesh") {
105
- return meshStyleStore.applyMeshStyle(dataId);
106
- }
107
- if (viewer_object_type === "model") {
108
- return modelStyleStore.applyModelStyle(dataId);
109
- }
110
- throw new Error(`Unknown viewer_object_type: ${String(viewer_object_type)}`);
120
+ async function applyDefaultStyle(dataId: DataId): Promise<unknown[]> {
121
+ const result = await forViewerType(dataId, {
122
+ image: imageStyleStore.applyImageStyle,
123
+ mesh: meshStyleStore.applyMeshStyle,
124
+ model: modelStyleStore.applyModelStyle,
125
+ notViewable: () => {
126
+ throw new Error(`applyDefaultStyle called for non-viewable item: ${dataId}`);
127
+ },
128
+ });
129
+ return result;
111
130
  }
112
131
 
113
132
  function exportStores(): DataStyleSnapshot {
@@ -123,56 +142,43 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
123
142
  async function importStores(snapshot: DataStyleSnapshot): Promise<void> {
124
143
  const stylesSnapshot = snapshot.styles;
125
144
  const componentStylesSnapshot = snapshot.componentStyles;
126
- const modelComponentTypeStylesSnapshot = snapshot.modelComponentTypeStyles;
145
+ const modelComponentTypeStylesSnapshot = snapshot.modelComponentTypeStyles ?? {};
127
146
 
128
- await dataStyleState.clear();
129
-
130
- const style_promises = Object.entries(stylesSnapshot).map(
147
+ const styles = Object.entries(stylesSnapshot).map(
131
148
  // oxlint-disable-next-line prefer-readonly-parameter-types -- same external ObjectStyle limitation as above.
132
- async ([dataId, style]: readonly [string, LegacyDataId<ObjectStyle> | ObjectStyle]) => {
133
- const key = await data_style_db.put(
134
- structuredClone({ ...fromLegacyDataId<ObjectStyle>(style), data_id: dataId }),
135
- );
136
- return key;
137
- },
149
+ ([dataId, style]: readonly [string, LegacyDataId<ObjectStyle> | ObjectStyle]) =>
150
+ structuredClone({ ...fromLegacyDataId<ObjectStyle>(style), data_id: dataId }),
138
151
  );
139
- const component_style_promises = Object.values(componentStylesSnapshot).map(
140
- async (style: ModelComponentStyle) => {
141
- const key = await component_datastyle_db.put(structuredClone(style));
142
- return key;
143
- },
152
+ const componentStyles = structuredClone(Object.values(componentStylesSnapshot));
153
+ const modelComponentTypeStyles = structuredClone(
154
+ Object.values(modelComponentTypeStylesSnapshot),
144
155
  );
145
- const model_component_type_style_promises = Object.values(modelComponentTypeStylesSnapshot).map(
146
- async (style: ModelComponentTypeStyle) => {
147
- const key = await model_component_type_datastyle_db.put(structuredClone(style));
148
- return key;
156
+
157
+ // The snapshot replaces the stored styles as a whole: a failed import leaves the previous ones
158
+ await writeTransaction(
159
+ [dataStyleTable, componentDataStyleTable, componentTypeDataStyleTable, sceneStyleDb()],
160
+ async () => {
161
+ await dataStyleState.clear();
162
+ await dataStyleTable.bulkPut(styles);
163
+ await componentDataStyleTable.bulkPut(componentStyles);
164
+ await componentTypeDataStyleTable.bulkPut(modelComponentTypeStyles);
149
165
  },
150
166
  );
151
-
152
- await Promise.all([
153
- ...style_promises,
154
- ...component_style_promises,
155
- ...model_component_type_style_promises,
156
- ]);
157
167
  await dataStyleState.loadFromDatabase();
158
168
  await sceneStyleStore.importSceneStyle(snapshot.sceneStyle);
159
169
  }
160
170
 
161
171
  async function applyAllStylesFromState(): Promise<void> {
162
172
  const ids = Object.keys(dataStyleState.styles.value);
173
+ // Restores what can be shown: a non viewable data or an unknown type is skipped
163
174
  const promises = ids.map(async (dataId) => {
164
- const meta = await dataStore.item(dataId);
165
- if (!(await dataStore.isItemViewable(meta))) {
166
- return;
167
- }
168
- const viewerObjectType = meta.viewer_object_type;
169
- if (viewerObjectType === "image") {
170
- await imageStyleStore.applyImageStyle(dataId);
171
- } else if (viewerObjectType === "mesh") {
172
- await meshStyleStore.applyMeshStyle(dataId);
173
- } else if (viewerObjectType === "model") {
174
- await modelStyleStore.applyModelStyle(dataId);
175
- }
175
+ await forViewerType<unknown>(dataId, {
176
+ image: imageStyleStore.applyImageStyle,
177
+ mesh: meshStyleStore.applyMeshStyle,
178
+ model: modelStyleStore.applyModelStyle,
179
+ notViewable: () => undefined,
180
+ unknownType: () => undefined,
181
+ });
176
182
  });
177
183
  await Promise.all(promises);
178
184
  await sceneStyleStore.applySceneStyle();
@@ -22,59 +22,63 @@ interface Feedback {
22
22
  action?: FeedbackAction;
23
23
  }
24
24
 
25
- export const useFeedbackStore = defineStore("feedback", {
26
- state: () => ({
27
- feedbacks: [] as Feedback[],
28
- server_error: false,
29
- feedbacks_timeout_miliseconds: DEFAULT_FEEDBACKS_TIMEOUT_SECONDS * MILLISECONDS_IN_SECOND,
30
- }),
31
- actions: {
32
- add_error(code: number, route: string, name: string, description: string) {
33
- const feedbackId = uuidv4();
34
- this.feedbacks.push({
35
- id: feedbackId,
36
- type: "error",
37
- code,
38
- route,
39
- name: name === "" ? DEFAULT_ERROR_NAME : name,
40
- // The snackbar only shows the description: never leave it empty
41
- description: [description, name].find((text) => text !== "") ?? DEFAULT_ERROR_DESCRIPTION,
42
- });
43
- setTimeout(() => {
44
- this.delete_feedback(feedbackId);
45
- }, this.feedbacks_timeout_miliseconds);
46
- },
47
- add_success(description: string, action?: FeedbackAction) {
48
- const feedbackId = uuidv4();
49
- this.feedbacks.push({
50
- id: feedbackId,
51
- type: "success",
52
- description,
53
- ...(action !== undefined && { action }),
54
- });
55
- setTimeout(() => {
56
- this.delete_feedback(feedbackId);
57
- }, this.feedbacks_timeout_miliseconds);
58
- },
59
- add_warning(description: string, action?: FeedbackAction) {
60
- const feedbackId = uuidv4();
61
- this.feedbacks.push({
62
- id: feedbackId,
63
- type: "warning",
64
- description,
65
- ...(action !== undefined && { action }),
66
- });
67
- setTimeout(() => {
68
- this.delete_feedback(feedbackId);
69
- }, this.feedbacks_timeout_miliseconds);
70
- },
71
- delete_feedback(feedbackId: string) {
72
- this.feedbacks = this.feedbacks.filter((feedback) => feedback.id !== feedbackId);
73
- },
74
- delete_server_error() {
75
- this.server_error = false;
76
- },
77
- },
25
+ export const useFeedbackStore = defineStore("feedback", () => {
26
+ const feedbacks = ref<Feedback[]>([]);
27
+ const server_error = ref(false);
28
+ const feedbacks_timeout_miliseconds = ref(
29
+ DEFAULT_FEEDBACKS_TIMEOUT_SECONDS * MILLISECONDS_IN_SECOND,
30
+ );
31
+
32
+ function delete_feedback(feedbackId: string): void {
33
+ feedbacks.value = feedbacks.value.filter((feedback) => feedback.id !== feedbackId);
34
+ }
35
+
36
+ function push_feedback(feedback: Omit<Feedback, "id">): void {
37
+ const feedbackId = uuidv4();
38
+ feedbacks.value.push({ id: feedbackId, ...feedback });
39
+ setTimeout(() => {
40
+ delete_feedback(feedbackId);
41
+ }, feedbacks_timeout_miliseconds.value);
42
+ }
43
+
44
+ function add_error(code: number, route: string, name: string, description: string): void {
45
+ push_feedback({
46
+ type: "error",
47
+ code,
48
+ route,
49
+ name: name === "" ? DEFAULT_ERROR_NAME : name,
50
+ // The snackbar only shows the description: never leave it empty
51
+ description: [description, name].find((text) => text !== "") ?? DEFAULT_ERROR_DESCRIPTION,
52
+ });
53
+ }
54
+
55
+ function add_success(description: string, action?: FeedbackAction): void {
56
+ push_feedback({ type: "success", description, ...(action !== undefined && { action }) });
57
+ }
58
+
59
+ function add_warning(description: string, action?: FeedbackAction): void {
60
+ push_feedback({ type: "warning", description, ...(action !== undefined && { action }) });
61
+ }
62
+
63
+ function set_server_error(value: boolean): void {
64
+ server_error.value = value;
65
+ }
66
+
67
+ function delete_server_error(): void {
68
+ set_server_error(false);
69
+ }
70
+
71
+ return {
72
+ feedbacks,
73
+ server_error,
74
+ feedbacks_timeout_miliseconds,
75
+ add_error,
76
+ add_success,
77
+ add_warning,
78
+ delete_feedback,
79
+ set_server_error,
80
+ delete_server_error,
81
+ };
78
82
  });
79
83
 
80
84
  export type { FeedbackAction };
@@ -1,126 +1,86 @@
1
1
  import { Status } from "@ogw_front/utils/status";
2
- import { appMode } from "@ogw_shared/app_mode";
3
- import { setAppBaseUrl } from "@ogw_shared/scripts";
4
- import { useCloudStore } from "@ogw_front/stores/cloud";
5
2
 
6
3
  const LOCALHOST = "localhost";
7
4
  const IPV4_LOOPBACK = "127.0.0.1";
8
5
 
9
- interface ElectronApi {
10
- electronAPI: {
11
- project_folder_path: (args: { projectFolderPath: string }) => void;
12
- };
13
- }
14
-
15
- declare global {
16
- // oxlint-disable-next-line no-var -- required for global augmentation
17
- var electronAPI: ElectronApi["electronAPI"];
18
- }
6
+ export const useInfraStore = defineStore(
7
+ "infra",
8
+ // oxlint-disable-next-line max-lines-per-function
9
+ () => {
10
+ const app_mode = ref(useRuntimeConfig().public.MODE);
11
+ // Set by the backend lifecycle (utils/backend_lifecycle.ts), which creates the backend
12
+ const status = ref(Status.NOT_CREATED);
13
+ const microservices = ref<Microservice[]>([]);
14
+ const domain_name = ref(globalThis.location.hostname);
19
15
 
20
- async function launchLocalServices(
21
- currentMode: string,
22
- microservices: readonly Microservice[],
23
- ): Promise<void> {
24
- const { useAppStore } = await import("@ogw_front/stores/app");
25
- const appStore = useAppStore();
26
- await appStore.createProjectFolder();
27
- if (currentMode === appMode.DESKTOP) {
28
- globalThis.electronAPI.project_folder_path({
29
- projectFolderPath: appStore.projectFolderPath,
30
- });
31
- }
32
- await setAppBaseUrl(appStore.base_url);
33
- const microservices_with_launch = microservices.filter((store: Microservice) => store.launch);
34
- const launch_promises = microservices_with_launch.map(async (store: Microservice) => {
35
- const result = await store.launch?.({
36
- projectFolderPath: appStore.projectFolderPath,
37
- });
38
- return result;
39
- });
40
- const { registerRunningExtensions } = await import("@ogw_front/utils/extension");
41
- launch_promises.push(registerRunningExtensions());
42
- await Promise.all(launch_promises);
43
- }
44
-
45
- export const useInfraStore = defineStore("infra", {
46
- state: () => ({
47
- app_mode: useRuntimeConfig().public.MODE,
48
- status: Status.NOT_CREATED,
49
- microservices: [] as Microservice[],
50
- domain_name: globalThis.location.hostname,
51
- }),
52
- getters: {
53
- microservices_connected(): boolean {
54
- return this.microservices.every((store: Microservice) => store.status === Status.CONNECTED);
55
- },
56
- microservices_busy(): boolean {
57
- return this.microservices.some((store: Microservice) => store.is_busy === true);
58
- },
16
+ const microservices_connected = computed(() =>
17
+ microservices.value.every((store: Microservice) => store.status === Status.CONNECTED),
18
+ );
19
+ const microservices_busy = computed(() =>
20
+ microservices.value.some((store: Microservice) => store.is_busy === true),
21
+ );
59
22
  // The local Flask microservices (Werkzeug) only listen on IPv4. With "localhost", browsers try ::1 first.
60
23
  // Windows is slow to refuse it: every request to them would pay that delay.
61
24
  // The page host stays in domain_name: the app store must remain same-origin (its API has no CORS).
62
- microservice_domain_name(): string {
63
- return this.domain_name === LOCALHOST ? IPV4_LOOPBACK : this.domain_name;
64
- },
65
- },
66
- actions: {
67
- register_microservice(store: Microservice) {
68
- const store_name = store.$id;
25
+ const microservice_domain_name = computed(() =>
26
+ domain_name.value === LOCALHOST ? IPV4_LOOPBACK : domain_name.value,
27
+ );
69
28
 
70
- if (
71
- !this.microservices.some((microservice: Microservice) => microservice.$id === store_name)
72
- ) {
73
- this.microservices.push(store);
29
+ function register_microservice(store: Microservice): void {
30
+ const store_name = store.$id;
31
+ if (!microservices.value.some((microservice) => microservice.$id === store_name)) {
32
+ microservices.value.push(store);
74
33
  }
75
- },
76
- unregister_microservice(microserviceId: string) {
77
- this.microservices = this.microservices.filter(
78
- (microservice: Microservice) => microservice.$id !== microserviceId,
34
+ }
35
+
36
+ function unregister_microservice(microserviceId: string): void {
37
+ microservices.value = microservices.value.filter(
38
+ (microservice) => microservice.$id !== microserviceId,
79
39
  );
80
- },
81
- async create_backend(authToken?: string) {
82
- if (this.status === Status.CREATED) {
83
- return undefined;
84
- }
85
- await navigator.locks.request("infra.create_backend", async () => {
86
- if (this.status === Status.CREATED) {
87
- return;
88
- }
89
- this.status = Status.CREATING;
90
- if (this.app_mode === appMode.CLOUD) {
91
- const cloudStore = useCloudStore();
92
- try {
93
- await cloudStore.start(authToken);
94
- } catch (error) {
95
- // Back to the "Load the app" button so the user is not stuck on the loading screen.
96
- this.status = Status.NOT_CREATED;
97
- throw error;
98
- }
99
- } else {
100
- await launchLocalServices(this.app_mode, this.microservices);
101
- }
102
- this.status = Status.CREATED;
103
- return this.create_connection();
104
- });
105
- return undefined;
106
- },
107
- async create_connection() {
40
+ }
41
+
42
+ async function create_connection(): Promise<void> {
108
43
  await Promise.all(
109
- this.microservices.map(async (store: Microservice) => {
44
+ microservices.value.map(async (store: Microservice) => {
110
45
  await store.connect();
111
46
  }),
112
47
  );
113
- },
48
+ }
49
+
50
+ function set_status(value: string): void {
51
+ status.value = value;
52
+ }
53
+
54
+ function set_domain_name(value: string): void {
55
+ domain_name.value = value;
56
+ }
57
+
58
+ return {
59
+ app_mode,
60
+ status,
61
+ microservices,
62
+ domain_name,
63
+ microservices_connected,
64
+ microservices_busy,
65
+ microservice_domain_name,
66
+ register_microservice,
67
+ unregister_microservice,
68
+ set_status,
69
+ set_domain_name,
70
+ create_connection,
71
+ };
114
72
  },
115
- share: {
116
- omit: ["microservices"],
73
+ {
74
+ share: {
75
+ omit: ["microservices"],
76
+ },
117
77
  },
118
- });
78
+ );
119
79
 
120
80
  export interface Microservice {
121
81
  $id: string;
122
82
  status?: string;
123
83
  is_busy?: boolean;
124
84
  launch?: (params: { projectFolderPath: string }) => Promise<unknown>;
125
- connect: () => Promise<void>;
85
+ connect: () => void | Promise<void>;
126
86
  }