@geode/opengeodeweb-front 12.2.0-rc.4 → 12.2.0-rc.6

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 (124) hide show
  1. package/app/components/CameraOrientation.vue +85 -68
  2. package/app/components/CameraOrientationDial.vue +195 -0
  3. package/app/components/ClippingPlanes.vue +1 -1
  4. package/app/components/FactorFilterPanel.vue +1 -1
  5. package/app/components/Launcher.vue +3 -2
  6. package/app/components/ThresholdFilter.vue +1 -2
  7. package/app/components/Viewer/Basemap/CropOptions.vue +7 -8
  8. package/app/components/Viewer/Basemap/OpacityOptions.vue +7 -8
  9. package/app/components/Viewer/ContextMenu/CircularItems.vue +6 -43
  10. package/app/components/Viewer/ContextMenu/ContextMenu.vue +1 -6
  11. package/app/components/Viewer/ContextMenu/ContextMenuItem.vue +14 -16
  12. package/app/components/Viewer/EdgedCurve/PointsOptions.vue +5 -4
  13. package/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue +10 -13
  14. package/app/components/Viewer/Generic/Mesh/CellsOptions.vue +8 -11
  15. package/app/components/Viewer/Generic/Mesh/EdgesOptions.vue +16 -13
  16. package/app/components/Viewer/Generic/Mesh/PointsOptions.vue +28 -31
  17. package/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue +9 -11
  18. package/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue +8 -11
  19. package/app/components/Viewer/Generic/Model/BlocksOptions.vue +1 -1
  20. package/app/components/Viewer/Generic/Model/CornersOptions.vue +1 -1
  21. package/app/components/Viewer/Generic/Model/CornersTypeOptions.vue +1 -1
  22. package/app/components/Viewer/Generic/Model/EdgesOptions.vue +7 -8
  23. package/app/components/Viewer/Generic/Model/LinesOptions.vue +1 -1
  24. package/app/components/Viewer/Generic/Model/LinesTypeOptions.vue +1 -1
  25. package/app/components/Viewer/Generic/Model/ModelEdgesCard.vue +5 -7
  26. package/app/components/Viewer/Generic/Model/ModelPointsCard.vue +5 -7
  27. package/app/components/Viewer/Generic/Model/ModelStyleCard.vue +5 -7
  28. package/app/components/Viewer/Generic/Model/ModelStyleOptions.vue +7 -8
  29. package/app/components/Viewer/Generic/Model/PointsOptions.vue +7 -8
  30. package/app/components/Viewer/Generic/Model/SurfacesOptions.vue +1 -1
  31. package/app/components/Viewer/Grid/2D/CellsOptions.vue +6 -4
  32. package/app/components/Viewer/Grid/2D/EdgesOptions.vue +6 -4
  33. package/app/components/Viewer/Grid/2D/PointsOptions.vue +5 -4
  34. package/app/components/Viewer/Grid/3D/CellsOptions.vue +6 -4
  35. package/app/components/Viewer/Grid/3D/EdgesOptions.vue +6 -4
  36. package/app/components/Viewer/Grid/3D/FacetsOptions.vue +6 -4
  37. package/app/components/Viewer/Grid/3D/PointsOptions.vue +5 -4
  38. package/app/components/Viewer/Image/ImageOptions.vue +10 -13
  39. package/app/components/Viewer/ObjectTree/Base/CommonTreeView.vue +5 -0
  40. package/app/components/Viewer/ObjectTree/Base/ComponentRelations.vue +2 -2
  41. package/app/components/Viewer/ObjectTree/Base/StickyHeader.vue +4 -1
  42. package/app/components/Viewer/ObjectTree/Base/TreeRow.vue +6 -8
  43. package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +10 -15
  44. package/app/components/Viewer/ObjectTree/Views/ModelTree.vue +3 -0
  45. package/app/components/Viewer/OrientationCompass.vue +11 -34
  46. package/app/components/Viewer/OrientationGlobe.vue +2 -2
  47. package/app/components/Viewer/PointSet/SpecificPointsOptions.vue +28 -31
  48. package/app/components/Viewer/Scene/BackgroundOptions.vue +4 -7
  49. package/app/components/Viewer/Scene/OrientationWidgetOptions.vue +4 -7
  50. package/app/components/Viewer/Scene/TextOptions.vue +4 -7
  51. package/app/components/Viewer/Solid/EdgesOptions.vue +6 -4
  52. package/app/components/Viewer/Solid/PointsOptions.vue +5 -4
  53. package/app/components/Viewer/Solid/PolygonsOptions.vue +6 -4
  54. package/app/components/Viewer/Solid/SpecificPolyhedraOptions.vue +8 -11
  55. package/app/components/Viewer/Surface/EdgesOptions.vue +6 -4
  56. package/app/components/Viewer/Surface/PointsOptions.vue +6 -4
  57. package/app/components/Viewer/Surface/PolygonsOptions.vue +8 -11
  58. package/app/components/Viewer/Surface/Triangulated/TrianglesOptions.vue +5 -4
  59. package/app/components/Viewer/TetrahedralSolid/TetrahedraOptions.vue +6 -4
  60. package/app/components/Viewer/TetrahedralSolid/TrianglesOptions.vue +6 -4
  61. package/app/composables/circular_menu.ts +45 -0
  62. package/app/composables/compass_dial.ts +40 -0
  63. package/app/composables/hover_highlight.ts +1 -1
  64. package/app/composables/model_menu_context.ts +7 -11
  65. package/app/composables/model_tree.ts +3 -3
  66. package/app/composables/project_manager_helpers/types.ts +2 -3
  67. package/app/composables/use_overlapping_picker.ts +7 -19
  68. package/app/composables/viewer_context_menu.ts +2 -1
  69. package/app/stores/api.ts +6 -59
  70. package/app/stores/app.ts +21 -55
  71. package/app/stores/back.ts +86 -145
  72. package/app/stores/camera_manager.ts +12 -25
  73. package/app/stores/cloud.ts +21 -101
  74. package/app/stores/crs.ts +3 -2
  75. package/app/stores/data.ts +66 -409
  76. package/app/stores/data_style.ts +99 -93
  77. package/app/stores/feedback.ts +57 -53
  78. package/app/stores/infra.ts +61 -101
  79. package/app/stores/treeview.ts +12 -31
  80. package/app/stores/viewer.ts +9 -29
  81. package/app/stores/viewer_helpers/actions.ts +1 -23
  82. package/app/utils/backend_lifecycle.ts +155 -0
  83. package/app/utils/brand_colors.ts +9 -0
  84. package/app/utils/camera_orientations.ts +136 -0
  85. package/app/utils/import_item.ts +5 -4
  86. package/app/utils/orientation_compass.ts +15 -0
  87. package/app/utils/orientation_cube_style.ts +70 -0
  88. package/app/utils/threshold_sources.ts +3 -2
  89. package/app/utils/treeview.ts +25 -1
  90. package/app/utils/viewer_object_type.ts +21 -0
  91. package/internal/database/base_database.ts +2 -1
  92. package/internal/database/database.ts +90 -7
  93. package/internal/database/queries.ts +45 -0
  94. package/internal/database/tables/camera_positions.ts +11 -1
  95. package/internal/database/tables/data.ts +20 -1
  96. package/internal/database/tables/data_style.ts +3 -1
  97. package/internal/database/tables/model_component_datastyle.ts +3 -1
  98. package/internal/database/tables/model_component_type_datastyle.ts +3 -1
  99. package/internal/database/tables/model_components.ts +12 -1
  100. package/internal/database/tables/model_components_relation.ts +11 -1
  101. package/internal/database/tables/scene_style.ts +3 -1
  102. package/internal/database/tables/treeview_config.ts +31 -0
  103. package/internal/stores/data/items.ts +110 -0
  104. package/internal/stores/data/model/collections.ts +107 -0
  105. package/internal/stores/data/model/components.ts +129 -0
  106. package/internal/stores/data/model/mesh_components.ts +134 -0
  107. package/internal/stores/data/model/relations.ts +76 -0
  108. package/internal/stores/data/model/types.ts +14 -0
  109. package/internal/stores/data/registration.ts +54 -0
  110. package/internal/stores/data/snapshot.ts +83 -0
  111. package/internal/stores/data/types.ts +26 -0
  112. package/internal/stores/data_style/model/common_mutations.ts +47 -77
  113. package/internal/stores/data_style/model/selection.ts +3 -10
  114. package/internal/stores/data_style/scene.ts +2 -2
  115. package/internal/stores/data_style/state.ts +10 -8
  116. package/internal/stores/data_style/state_shared.ts +10 -7
  117. package/internal/stores/hybrid_viewer/highlight.ts +9 -14
  118. package/internal/stores/hybrid_viewer/scene.ts +1 -1
  119. package/internal/stores/microservice.ts +192 -0
  120. package/package.json +1 -1
  121. package/tests/browser/helpers/data/helpers/attribute.ts +2 -1
  122. package/app/stores/data_helpers/collections.ts +0 -122
  123. package/app/stores/data_helpers/mesh.ts +0 -167
  124. package/app/stores/data_helpers/relations.ts +0 -94
@@ -1,6 +1,24 @@
1
- import { Dexie, type Table } from "dexie";
1
+ import { type CameraPositionRecord, cameraPositionsTable } from "./tables/camera_positions";
2
+ import { type DataItem, dataTable } from "./tables/data";
3
+ import { Dexie, type IndexableType, type Table } from "dexie";
4
+ import { type ModelComponentRecord, modelComponentsTable } from "./tables/model_components";
5
+ import {
6
+ type ModelComponentRelationRecord,
7
+ modelComponentsRelationTable,
8
+ } from "./tables/model_components_relation";
9
+ import type {
10
+ ModelComponentStyle,
11
+ ModelComponentTypeStyle,
12
+ ObjectStyle,
13
+ SceneStyle,
14
+ } from "@ogw_internal/stores/data_style/types";
15
+ import { type TreeviewConfigRecord, treeviewConfigTable } from "./tables/treeview_config";
2
16
  import { BaseDatabase } from "./base_database";
3
17
  import { ExtendedDatabase } from "./extended_database";
18
+ import { dataStyleTable } from "./tables/data_style";
19
+ import { modelComponentDataStyleTable } from "./tables/model_component_datastyle";
20
+ import { modelComponentTypeDataStyleTable } from "./tables/model_component_type_datastyle";
21
+ import { sceneStyleTable } from "./tables/scene_style";
4
22
 
5
23
  interface DatabaseContainer {
6
24
  instance: Dexie | undefined;
@@ -104,7 +122,7 @@ function currentInstance(): Dexie {
104
122
  return databaseContainer.instance;
105
123
  }
106
124
 
107
- function liveTable<TRow>(tableName: string): Table<TRow, string> {
125
+ function liveTable<TRow, TKey extends IndexableType>(tableName: string): Table<TRow, TKey> {
108
126
  const handler: ProxyHandler<object> = {
109
127
  get(_target, prop: string | symbol): unknown {
110
128
  const table = currentInstance().table(tableName);
@@ -121,7 +139,7 @@ function liveTable<TRow>(tableName: string): Table<TRow, string> {
121
139
  },
122
140
  };
123
141
  // oxlint-disable-next-line no-unsafe-type-assertion -- the proxy forwards every access to a Dexie Table.
124
- return new Proxy({}, handler) as Table<TRow, string>;
142
+ return new Proxy({}, handler) as Table<TRow, TKey>;
125
143
  }
126
144
 
127
145
  function isTableName(instance: Dexie, prop: string | symbol): prop is string {
@@ -149,9 +167,74 @@ const database = new Proxy<DatabaseTables>(
149
167
  },
150
168
  );
151
169
 
152
- // Callers cast to the row type they know a given table holds.
153
- function getTable<TRow>(tableName: string): Table<TRow, string> {
154
- return liveTable<TRow>(tableName);
170
+ // For the tables an extension registers at runtime, which the accessors below do not know.
171
+ // The caller gives the row type, and the key type when it is not a string.
172
+ function getTable<TRow, TKey extends IndexableType = string>(tableName: string): Table<TRow, TKey> {
173
+ return liveTable<TRow, TKey>(tableName);
155
174
  }
156
175
 
157
- export { Database, database, getTable };
176
+ // One accessor per table: its row and key types are written once, here
177
+ function dataDb(): Table<DataItem, string> {
178
+ return liveTable(dataTable.name);
179
+ }
180
+
181
+ function modelComponentsDb(): Table<ModelComponentRecord, string> {
182
+ return liveTable(modelComponentsTable.name);
183
+ }
184
+
185
+ function modelComponentsRelationDb(): Table<ModelComponentRelationRecord, string> {
186
+ return liveTable(modelComponentsRelationTable.name);
187
+ }
188
+
189
+ function dataStyleDb(): Table<ObjectStyle, string> {
190
+ return liveTable(dataStyleTable.name);
191
+ }
192
+
193
+ // Keyed by [id_model, id_component]
194
+ function componentDataStyleDb(): Table<ModelComponentStyle, [string, string]> {
195
+ return liveTable(modelComponentDataStyleTable.name);
196
+ }
197
+
198
+ // Keyed by [id_model, type]
199
+ function componentTypeDataStyleDb(): Table<ModelComponentTypeStyle, [string, string]> {
200
+ return liveTable(modelComponentTypeDataStyleTable.name);
201
+ }
202
+
203
+ function sceneStyleDb(): Table<SceneStyle, string> {
204
+ return liveTable(sceneStyleTable.name);
205
+ }
206
+
207
+ // Keyed by an auto-incremented number
208
+ function cameraPositionsDb(): Table<CameraPositionRecord, number> {
209
+ return liveTable(cameraPositionsTable.name);
210
+ }
211
+
212
+ function treeviewConfigDb(): Table<TreeviewConfigRecord, string> {
213
+ return liveTable(treeviewConfigTable.name);
214
+ }
215
+
216
+ // Runs `scope` in one read-write transaction over `tables`: its writes all apply, or none do.
217
+ // Only database calls may be awaited inside `scope`, or Dexie commits the transaction early.
218
+ async function writeTransaction<Result>(
219
+ tables: readonly Table[],
220
+ scope: () => Promise<Result>,
221
+ ): Promise<Result> {
222
+ const result = await currentInstance().transaction("rw", [...tables], scope);
223
+ return result;
224
+ }
225
+
226
+ export {
227
+ Database,
228
+ cameraPositionsDb,
229
+ componentDataStyleDb,
230
+ componentTypeDataStyleDb,
231
+ dataDb,
232
+ dataStyleDb,
233
+ database,
234
+ getTable,
235
+ modelComponentsDb,
236
+ modelComponentsRelationDb,
237
+ sceneStyleDb,
238
+ treeviewConfigDb,
239
+ writeTransaction,
240
+ };
@@ -0,0 +1,45 @@
1
+ import { type Collection, Dexie } from "dexie";
2
+ import { modelComponentsDb, modelComponentsRelationDb } from "./database";
3
+ import type { ModelComponentRecord } from "./tables/model_components";
4
+ import type { ModelComponentRelationRecord } from "./tables/model_components_relation";
5
+
6
+ type ModelComponents = Collection<ModelComponentRecord, string>;
7
+ type ModelComponentRelations = Collection<ModelComponentRelationRecord, string>;
8
+
9
+ function modelComponentsOf(modelId: string): ModelComponents {
10
+ return modelComponentsDb().where("data_id").equals(modelId);
11
+ }
12
+
13
+ function modelComponentsOfType(modelId: string, type: string): ModelComponents {
14
+ return modelComponentsDb().where("[data_id+type]").equals([modelId, type]);
15
+ }
16
+
17
+ function modelComponent(modelId: string, geodeId: string): ModelComponents {
18
+ return modelComponentsDb().where("[data_id+geode_id]").equals([modelId, geodeId]);
19
+ }
20
+
21
+ function modelComponentsByGeodeIds(modelId: string, geodeIds: readonly string[]): ModelComponents {
22
+ return modelComponentsDb()
23
+ .where("[data_id+geode_id]")
24
+ .anyOf(geodeIds.map((geodeId) => [modelId, geodeId]));
25
+ }
26
+
27
+ function modelComponentRelationsOf(modelId: string): ModelComponentRelations {
28
+ return modelComponentsRelationDb().where("data_id").equals(modelId);
29
+ }
30
+
31
+ // The relations whose parent is the given component
32
+ function componentRelationsOf(modelId: string, parentId: string): ModelComponentRelations {
33
+ return modelComponentsRelationDb()
34
+ .where("[data_id+parent+child]")
35
+ .between([modelId, parentId, Dexie.minKey], [modelId, parentId, Dexie.maxKey]);
36
+ }
37
+
38
+ export {
39
+ componentRelationsOf,
40
+ modelComponent,
41
+ modelComponentRelationsOf,
42
+ modelComponentsByGeodeIds,
43
+ modelComponentsOf,
44
+ modelComponentsOfType,
45
+ };
@@ -1,6 +1,16 @@
1
+ import type { CameraOptions } from "@ogw_internal/stores/hybrid_viewer/vtk_types.js";
1
2
  import type { TableDefinition } from "./table_definition";
2
3
 
3
- export const cameraPositionsTable: TableDefinition = {
4
+ interface CameraPositionRecord {
5
+ id?: number;
6
+ name: string;
7
+ camera_options: CameraOptions;
8
+ }
9
+
10
+ const cameraPositionsTable: TableDefinition = {
4
11
  name: "camera_positions",
5
12
  schema: "++id, name",
6
13
  };
14
+
15
+ export { cameraPositionsTable };
16
+ export type { CameraPositionRecord };
@@ -1,7 +1,26 @@
1
+ import type {
2
+ DataIdentified,
3
+ GeodeIdentified,
4
+ GeodeObjectTyped,
5
+ ViewerObjectTyped,
6
+ } from "@ogw_front/types/identifiers";
7
+ import type { CRS } from "@geode/opengeodeweb-back/schema_types";
1
8
  import type { TableDefinition } from "./table_definition";
2
9
 
3
- export const dataTable: TableDefinition = {
10
+ interface DataItem extends DataIdentified, GeodeIdentified, GeodeObjectTyped, ViewerObjectTyped {
11
+ name: string;
12
+ visible: boolean;
13
+ created_at: string;
14
+ is_viewable?: boolean;
15
+ binary_light_viewable?: string;
16
+ crs?: CRS;
17
+ }
18
+
19
+ const dataTable: TableDefinition = {
4
20
  name: "data",
5
21
  schema:
6
22
  "data_id, geode_id, name, viewer_object_type, geode_object_type, visible, created_at, binary_light_viewable",
7
23
  };
24
+
25
+ export { dataTable };
26
+ export type { DataItem };
@@ -1,6 +1,8 @@
1
1
  import type { TableDefinition } from "./table_definition";
2
2
 
3
- export const dataStyleTable: TableDefinition = {
3
+ const dataStyleTable: TableDefinition = {
4
4
  name: "data_style",
5
5
  schema: "data_id",
6
6
  };
7
+
8
+ export { dataStyleTable };
@@ -1,6 +1,8 @@
1
1
  import type { TableDefinition } from "./table_definition";
2
2
 
3
- export const modelComponentDataStyleTable: TableDefinition = {
3
+ const modelComponentDataStyleTable: TableDefinition = {
4
4
  name: "model_component_datastyle",
5
5
  schema: "[id_model+id_component], id_model",
6
6
  };
7
+
8
+ export { modelComponentDataStyleTable };
@@ -1,6 +1,8 @@
1
1
  import type { TableDefinition } from "./table_definition";
2
2
 
3
- export const modelComponentTypeDataStyleTable: TableDefinition = {
3
+ const modelComponentTypeDataStyleTable: TableDefinition = {
4
4
  name: "model_component_type_datastyle",
5
5
  schema: "[id_model+type], id_model",
6
6
  };
7
+
8
+ export { modelComponentTypeDataStyleTable };
@@ -1,6 +1,17 @@
1
+ import type { DataIdentified, GeodeIdentified } from "@ogw_front/types/identifiers";
1
2
  import type { TableDefinition } from "./table_definition";
2
3
 
3
- export const modelComponentsTable: TableDefinition = {
4
+ interface ModelComponentRecord extends DataIdentified, GeodeIdentified {
5
+ type: string;
6
+ viewer_id: string | number;
7
+ name: string;
8
+ is_active: boolean;
9
+ }
10
+
11
+ const modelComponentsTable: TableDefinition = {
4
12
  name: "model_components",
5
13
  schema: "[data_id+geode_id], data_id, [data_id+type], viewer_id, name, is_active",
6
14
  };
15
+
16
+ export { modelComponentsTable };
17
+ export type { ModelComponentRecord };
@@ -1,6 +1,16 @@
1
+ import type { DataIdentified } from "@ogw_front/types/identifiers";
1
2
  import type { TableDefinition } from "./table_definition";
2
3
 
3
- export const modelComponentsRelationTable: TableDefinition = {
4
+ interface ModelComponentRelationRecord extends DataIdentified {
5
+ parent: string;
6
+ child: string;
7
+ type: string;
8
+ }
9
+
10
+ const modelComponentsRelationTable: TableDefinition = {
4
11
  name: "model_components_relation",
5
12
  schema: "[data_id+parent+child], data_id, type",
6
13
  };
14
+
15
+ export { modelComponentsRelationTable };
16
+ export type { ModelComponentRelationRecord };
@@ -1,6 +1,8 @@
1
1
  import type { TableDefinition } from "./table_definition";
2
2
 
3
- export const sceneStyleTable: TableDefinition = {
3
+ const sceneStyleTable: TableDefinition = {
4
4
  name: "scene_style",
5
5
  schema: "id",
6
6
  };
7
+
8
+ export { sceneStyleTable };
@@ -0,0 +1,31 @@
1
+ import type { GeodeObjectTyped } from "@ogw_front/types/identifiers";
2
+ import type { TableDefinition } from "./table_definition";
3
+
4
+ interface OpenedView extends Partial<GeodeObjectTyped> {
5
+ type: "object" | "component";
6
+ id: string;
7
+ title: string;
8
+ scrollTop: number;
9
+ opened: string[];
10
+ // Ties a model tree to its row in the objects tree
11
+ color?: string;
12
+ // A model tree reduced to its button in the activity bar: still open, with its state kept
13
+ collapsed?: boolean;
14
+ }
15
+
16
+ interface TreeviewConfigRecord {
17
+ id: string;
18
+ opened_views: OpenedView[];
19
+ panelWidth: number;
20
+ additionalPanelWidth: number;
21
+ selectionIds: string[];
22
+ rowHeights: number[];
23
+ }
24
+
25
+ const treeviewConfigTable: TableDefinition = {
26
+ name: "treeview_config",
27
+ schema: "id",
28
+ };
29
+
30
+ export { treeviewConfigTable };
31
+ export type { OpenedView, TreeviewConfigRecord };
@@ -0,0 +1,110 @@
1
+ import type { ComputedRef, Ref } from "vue";
2
+ import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
3
+ import type { DataItem } from "@ogw_internal/database/tables/data";
4
+ import type { NewDataItem } from "./types";
5
+ import { dataDb } from "@ogw_internal/database/database.js";
6
+ import { liveObservable } from "@ogw_front/utils/live_observable";
7
+ import { useObservable } from "@vueuse/rxjs";
8
+
9
+ const dataTable = dataDb();
10
+
11
+ // A missing data is not viewable. Data imported before `is_viewable` existed fall back on their viewable file
12
+ function isDataItemViewable(dataItem: DataItem | undefined): boolean {
13
+ if (dataItem === undefined) {
14
+ return false;
15
+ }
16
+ if (dataItem.is_viewable !== undefined) {
17
+ return dataItem.is_viewable;
18
+ }
19
+ if (dataItem.binary_light_viewable !== undefined) {
20
+ return dataItem.binary_light_viewable !== "not_viewable";
21
+ }
22
+ return dataItem.geode_object_type !== "HorizonStack3D";
23
+ }
24
+
25
+ async function item(dataId: DataId): Promise<DataItem> {
26
+ const dataItem = await dataTable.get(dataId);
27
+ if (!dataItem) {
28
+ throw new Error(`Item not found: ${dataId}`);
29
+ }
30
+ return dataItem;
31
+ }
32
+
33
+ async function allItems(): Promise<DataItem[]> {
34
+ const storedItems = await dataTable.toArray();
35
+ return storedItems;
36
+ }
37
+
38
+ function refItem(dataId: DataId): Ref<DataItem | undefined> {
39
+ return useObservable(
40
+ liveObservable(async () => {
41
+ const dataItem = await dataTable.get(dataId);
42
+ return dataItem;
43
+ }),
44
+ {
45
+ // oxlint-disable-next-line no-unsafe-type-assertion -- placeholder until the live query resolves; consumers must treat this as possibly incomplete.
46
+ initialValue: {} as DataItem,
47
+ },
48
+ );
49
+ }
50
+
51
+ // From the database: for code right after a write, which the live items may not show yet
52
+ async function fetchIsViewable(dataId: DataId): Promise<boolean> {
53
+ const dataItem = await dataTable.get(dataId);
54
+ return isDataItemViewable(dataItem);
55
+ }
56
+
57
+ // NewDataItem has mutable array fields (mesh_components, collection_components), so it can't
58
+ // Satisfy prefer-readonly-parameter-types deeply; same pattern as app/utils/import_workflow.ts.
59
+ async function addItem(newItem: NewDataItem): Promise<string> {
60
+ const itemData: DataItem = {
61
+ data_id: newItem.data_id,
62
+ geode_id: newItem.geode_id,
63
+ name: newItem.name ?? newItem.data_id,
64
+ viewer_object_type: newItem.viewer_object_type,
65
+ geode_object_type: newItem.geode_object_type,
66
+ visible: true,
67
+ created_at: new Date().toISOString(),
68
+ is_viewable: newItem.is_viewable,
69
+ };
70
+ if (newItem.binary_light_viewable !== undefined && newItem.binary_light_viewable !== null) {
71
+ itemData.binary_light_viewable = newItem.binary_light_viewable;
72
+ }
73
+ if (newItem.crs !== undefined) {
74
+ itemData.crs = newItem.crs;
75
+ }
76
+ const dataId = await dataTable.put(itemData);
77
+ return dataId;
78
+ }
79
+
80
+ async function updateItem(dataId: DataId, changes: Partial<DataItem>): Promise<void> {
81
+ await dataTable.update(dataId, changes);
82
+ }
83
+
84
+ // A single live query of the data table, shared by every reader
85
+ function useDataItems(): {
86
+ items: ComputedRef<DataItem[]>;
87
+ itemsById: ComputedRef<Map<string, DataItem>>;
88
+ isViewable: (dataId: DataId) => boolean;
89
+ } {
90
+ const liveItems = useObservable(
91
+ liveObservable(async () => {
92
+ const storedItems = await dataTable.toArray();
93
+ return storedItems;
94
+ }),
95
+ { initialValue: [] as DataItem[] },
96
+ );
97
+ const items = computed(() => liveItems.value);
98
+ const itemsById = computed(
99
+ () => new Map(items.value.map((dataItem) => [dataItem.data_id, dataItem])),
100
+ );
101
+
102
+ // From the live items: reactive, for the data already shown
103
+ function isViewable(dataId: DataId): boolean {
104
+ return isDataItemViewable(itemsById.value.get(dataId));
105
+ }
106
+
107
+ return { items, itemsById, isViewable };
108
+ }
109
+
110
+ export { addItem, allItems, fetchIsViewable, item, refItem, updateItem, useDataItems };
@@ -0,0 +1,107 @@
1
+ import {
2
+ type FormattedComponent,
3
+ type ModelComponentRecord,
4
+ getAllMeshComponents,
5
+ } from "./mesh_components.js";
6
+ import { modelComponentRelationsOf, modelComponentsOf } from "@ogw_internal/database/queries.js";
7
+ import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles";
8
+ import type { ModelComponentRelationRecord } from "./relations.js";
9
+ import type { ModelId } from "@ogw_front/types/identifiers";
10
+ import type { ReadonlyTreeGroup } from "@ogw_front/types/tree";
11
+ import type { Ref } from "vue";
12
+ import { liveObservable } from "@ogw_front/utils/live_observable";
13
+ import { pluralize } from "@ogw_front/utils/string";
14
+ import { useObservable } from "@vueuse/rxjs";
15
+
16
+ interface CollectionComponent extends FormattedComponent {
17
+ readonly children: readonly FormattedComponent[];
18
+ }
19
+
20
+ type CollectionComponentGroup = ReadonlyTreeGroup<CollectionComponent>;
21
+
22
+ async function hasCollectionComponents(modelId: ModelId): Promise<boolean> {
23
+ const count = await modelComponentsOf(modelId)
24
+ .and((component: ModelComponentRecord) => !MESH_COMPONENT_TYPES.includes(component.type))
25
+ .count();
26
+ return count > 0;
27
+ }
28
+
29
+ async function getAllCollectionComponents(modelId: ModelId): Promise<FormattedComponent[]> {
30
+ const items = await modelComponentsOf(modelId).toArray();
31
+ return items
32
+ .filter((component: ModelComponentRecord) => !MESH_COMPONENT_TYPES.includes(component.type))
33
+ .map((component: ModelComponentRecord) => ({
34
+ id: component.geode_id,
35
+ geode_id: component.geode_id,
36
+ title: component.name,
37
+ category: component.type,
38
+ viewer_id: Number(component.viewer_id),
39
+ is_active: component.is_active,
40
+ }));
41
+ }
42
+
43
+ async function fetchAllCollectionComponents(
44
+ modelId: ModelId,
45
+ ): Promise<Record<string, CollectionComponent[]>> {
46
+ const components = await getAllCollectionComponents(modelId);
47
+ const relations = await modelComponentRelationsOf(modelId).toArray();
48
+ const allMeshComponents = await getAllMeshComponents(modelId);
49
+ const meshComponentsById: Record<string, FormattedComponent> = {};
50
+ for (const meshComponent of allMeshComponents) {
51
+ meshComponentsById[meshComponent.id] = meshComponent;
52
+ }
53
+
54
+ const byType: Record<string, CollectionComponent[]> = {};
55
+ for (const component of components) {
56
+ byType[component.category] ??= [];
57
+ const itemRelations = relations.filter(
58
+ (relation: ModelComponentRelationRecord) =>
59
+ relation.parent === component.id && relation.type === "collection",
60
+ );
61
+ const children = itemRelations
62
+ .map((relation: ModelComponentRelationRecord) => meshComponentsById[relation.child])
63
+ .filter((child): child is FormattedComponent => Boolean(child));
64
+ byType[component.category]?.push({
65
+ ...component,
66
+ children,
67
+ });
68
+ }
69
+ return byType;
70
+ }
71
+
72
+ async function formatedCollectionComponents(modelId: ModelId): Promise<CollectionComponentGroup[]> {
73
+ const byType = await fetchAllCollectionComponents(modelId);
74
+ const collectionTypes = Object.keys(byType);
75
+
76
+ return collectionTypes
77
+ .filter((type) => (byType[type]?.length ?? 0) > 0)
78
+ .map((type) => ({
79
+ id: type,
80
+ title: pluralize(type),
81
+ children: byType[type] ?? [],
82
+ }));
83
+ }
84
+
85
+ function refFormatedCollectionComponents(
86
+ modelId: ModelId,
87
+ ): Ref<CollectionComponentGroup[] | undefined> {
88
+ return useObservable(
89
+ liveObservable(async () => {
90
+ const groups = await formatedCollectionComponents(modelId);
91
+ return groups;
92
+ }),
93
+ {
94
+ initialValue: undefined,
95
+ },
96
+ );
97
+ }
98
+
99
+ export type { CollectionComponent, CollectionComponentGroup };
100
+
101
+ export {
102
+ fetchAllCollectionComponents,
103
+ formatedCollectionComponents,
104
+ getAllCollectionComponents,
105
+ hasCollectionComponents,
106
+ refFormatedCollectionComponents,
107
+ };
@@ -0,0 +1,129 @@
1
+ import {
2
+ modelComponent,
3
+ modelComponentsByGeodeIds,
4
+ modelComponentsOf,
5
+ } from "@ogw_internal/database/queries.js";
6
+ import { modelComponentsDb, modelComponentsRelationDb } from "@ogw_internal/database/database.js";
7
+ import type { GeodeId } from "@geode/opengeodeweb-microservice/schema_types";
8
+ import type { ModelComponentInput } from "@ogw_internal/stores/data/model/types";
9
+ import type { ModelComponentRecord } from "@ogw_internal/database/tables/model_components";
10
+ import type { ModelComponentRelationRecord } from "@ogw_internal/database/tables/model_components_relation";
11
+ import type { ModelId } from "@ogw_front/types/identifiers";
12
+ import type { NewDataItem } from "@ogw_internal/stores/data/types";
13
+
14
+ const modelComponentsTable = modelComponentsDb();
15
+ const modelComponentsRelationTable = modelComponentsRelationDb();
16
+
17
+ async function meshComponentType(modelId: ModelId, geodeId: GeodeId): Promise<string | undefined> {
18
+ const component = await modelComponent(modelId, geodeId).first();
19
+ return component?.type;
20
+ }
21
+
22
+ async function getAllModelComponentsViewerIds(modelId: ModelId): Promise<number[]> {
23
+ const components = await modelComponentsOf(modelId).toArray();
24
+ return components.map((component: ModelComponentRecord) =>
25
+ Math.trunc(Number(component.viewer_id)),
26
+ );
27
+ }
28
+
29
+ async function getMeshComponentsViewerIds(
30
+ modelId: ModelId,
31
+ meshComponentGeodeIds: readonly string[],
32
+ ): Promise<number[]> {
33
+ const components = await modelComponentsByGeodeIds(modelId, meshComponentGeodeIds).toArray();
34
+ return components.map((component: ModelComponentRecord) =>
35
+ Math.trunc(Number(component.viewer_id)),
36
+ );
37
+ }
38
+
39
+ async function getComponentByViewerId(
40
+ modelId: ModelId,
41
+ viewerId: string | number,
42
+ ): Promise<ModelComponentRecord | undefined> {
43
+ const component = await modelComponentsTable
44
+ .where("viewer_id")
45
+ .equals(Number(viewerId))
46
+ .and((candidate: ModelComponentRecord) => candidate.data_id === modelId)
47
+ .first();
48
+ return component;
49
+ }
50
+
51
+ async function getComponentsByViewerIds(
52
+ modelId: ModelId,
53
+ viewerIds: number[],
54
+ ): Promise<ModelComponentRecord[]> {
55
+ const components = await modelComponentsTable
56
+ .where("viewer_id")
57
+ .anyOf(viewerIds)
58
+ .and((candidate: ModelComponentRecord) => candidate.data_id === modelId)
59
+ .toArray();
60
+ return components;
61
+ }
62
+
63
+ // NewDataItem has mutable array fields (mesh_components, collection_components), so it can't
64
+ // Satisfy prefer-readonly-parameter-types deeply; same pattern as app/utils/import_workflow.ts.
65
+ async function addComponents(newItem: NewDataItem): Promise<string> {
66
+ const allComponents: ModelComponentRecord[] = [];
67
+ // ModelComponentInput has mutable array fields (boundaries, internals, items), so a readonly
68
+ // Array of it can't satisfy prefer-readonly-parameter-types deeply; same limitation as above.
69
+ function addModelComponents(components: readonly ModelComponentInput[]): void {
70
+ for (const component of components) {
71
+ allComponents.push({
72
+ data_id: newItem.data_id,
73
+ geode_id: component.geode_id,
74
+ type: component.type,
75
+ viewer_id: component.viewer_id,
76
+ name: component.name,
77
+ is_active: component.is_active,
78
+ });
79
+ }
80
+ }
81
+ if (newItem.mesh_components) {
82
+ addModelComponents(newItem.mesh_components);
83
+ }
84
+ if (newItem.collection_components) {
85
+ addModelComponents(newItem.collection_components);
86
+ }
87
+ const lastKey = await modelComponentsTable.bulkPut(allComponents);
88
+ return lastKey;
89
+ }
90
+
91
+ // NewDataItem has mutable array fields (mesh_components, collection_components), so it can't
92
+ // Satisfy prefer-readonly-parameter-types deeply; same pattern as app/utils/import_workflow.ts.
93
+ async function addComponentRelations(newItem: NewDataItem): Promise<string> {
94
+ const relations: ModelComponentRelationRecord[] = [];
95
+ function addModelComponentRelations(
96
+ components: readonly string[],
97
+ parent: string,
98
+ type: string,
99
+ ): void {
100
+ for (const child of components) {
101
+ relations.push({ data_id: newItem.data_id, parent, child, type });
102
+ }
103
+ }
104
+ for (const component of newItem.mesh_components ?? []) {
105
+ if (component.boundaries) {
106
+ addModelComponentRelations(component.boundaries, component.geode_id, "boundary");
107
+ }
108
+ if (component.internals) {
109
+ addModelComponentRelations(component.internals, component.geode_id, "internal");
110
+ }
111
+ }
112
+ for (const component of newItem.collection_components ?? []) {
113
+ if (component.items) {
114
+ addModelComponentRelations(component.items, component.geode_id, "collection");
115
+ }
116
+ }
117
+ const lastKey = await modelComponentsRelationTable.bulkPut(relations);
118
+ return lastKey;
119
+ }
120
+
121
+ export {
122
+ addComponentRelations,
123
+ addComponents,
124
+ getAllModelComponentsViewerIds,
125
+ getComponentByViewerId,
126
+ getComponentsByViewerIds,
127
+ getMeshComponentsViewerIds,
128
+ meshComponentType,
129
+ };