@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
@@ -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
+ };
@@ -0,0 +1,134 @@
1
+ import type { GeodeIdentified, ModelId } from "@ogw_front/types/identifiers";
2
+ import { modelComponentsOf, modelComponentsOfType } from "@ogw_internal/database/queries.js";
3
+ import type { ModelComponentRecord } from "@ogw_internal/database/tables/model_components";
4
+ import type { ReadonlyTreeGroup } from "@ogw_front/types/tree";
5
+ import type { ViewerId } from "@geode/opengeodeweb-viewer/schema_types";
6
+ import { liveObservable } from "@ogw_front/utils/live_observable";
7
+ import { useObservable } from "@vueuse/rxjs";
8
+
9
+ interface FormattedComponent extends Readonly<GeodeIdentified> {
10
+ readonly id: string;
11
+ readonly title: string;
12
+ readonly category: string;
13
+ readonly viewer_id: ViewerId;
14
+ readonly is_active: boolean;
15
+ }
16
+
17
+ type FormattedComponentGroup = ReadonlyTreeGroup<FormattedComponent>;
18
+
19
+ function toFormattedComponent(meshComponent: ModelComponentRecord): FormattedComponent {
20
+ return {
21
+ id: meshComponent.geode_id,
22
+ geode_id: meshComponent.geode_id,
23
+ title: meshComponent.name,
24
+ category: meshComponent.type,
25
+ viewer_id: Math.trunc(Number(meshComponent.viewer_id)),
26
+ is_active: meshComponent.is_active,
27
+ };
28
+ }
29
+
30
+ async function getMeshComponentGeodeIds(modelId: ModelId, type: string): Promise<string[]> {
31
+ const components = await modelComponentsOfType(modelId, type).toArray();
32
+ return components.map((component: ModelComponentRecord) => component.geode_id);
33
+ }
34
+
35
+ async function formatedMeshComponents(modelId: ModelId): Promise<FormattedComponentGroup[]> {
36
+ const items = await modelComponentsOf(modelId).toArray();
37
+ const componentTitles: Record<string, string> = {
38
+ Corner: "Corners",
39
+ Line: "Lines",
40
+ Surface: "Surfaces",
41
+ Block: "Blocks",
42
+ };
43
+
44
+ const componentsByType: Record<string, ModelComponentRecord[]> = {};
45
+ for (const component_item of items) {
46
+ if (componentTitles[component_item.type] !== undefined) {
47
+ componentsByType[component_item.type] ??= [];
48
+ componentsByType[component_item.type]?.push(component_item);
49
+ }
50
+ }
51
+
52
+ return Object.keys(componentTitles)
53
+ .filter((type) => componentsByType[type])
54
+ .map((type) => ({
55
+ id: type,
56
+ title: componentTitles[type] ?? type,
57
+ children: (componentsByType[type] ?? []).map((item: ModelComponentRecord) =>
58
+ toFormattedComponent(item),
59
+ ),
60
+ }));
61
+ }
62
+
63
+ function refFormatedMeshComponents(modelId: ModelId): Ref<FormattedComponentGroup[] | undefined> {
64
+ return useObservable(
65
+ liveObservable(async () => {
66
+ const components = await formatedMeshComponents(modelId);
67
+ return components;
68
+ }),
69
+ {
70
+ initialValue: undefined,
71
+ },
72
+ );
73
+ }
74
+
75
+ async function getMeshComponentsByType(
76
+ modelId: ModelId,
77
+ type: string,
78
+ ): Promise<FormattedComponent[]> {
79
+ const components = await modelComponentsOfType(modelId, type).toArray();
80
+ return components.map((item: ModelComponentRecord) => toFormattedComponent(item));
81
+ }
82
+
83
+ async function getAllMeshComponents(modelId: ModelId): Promise<FormattedComponent[]> {
84
+ const items = await modelComponentsOf(modelId).toArray();
85
+ return items.map((item: ModelComponentRecord) => toFormattedComponent(item));
86
+ }
87
+
88
+ async function fetchAllMeshComponents(
89
+ modelId: ModelId,
90
+ ): Promise<Record<string, FormattedComponent[]>> {
91
+ const components = await getAllMeshComponents(modelId);
92
+ const byType: Record<string, FormattedComponent[]> = {};
93
+ for (const component of components) {
94
+ byType[component.category] ??= [];
95
+ byType[component.category]?.push(component);
96
+ }
97
+ return byType;
98
+ }
99
+
100
+ async function getCornersGeodeIds(modelId: ModelId): Promise<string[]> {
101
+ const geodeIds = await getMeshComponentGeodeIds(modelId, "Corner");
102
+ return geodeIds;
103
+ }
104
+
105
+ async function getLinesGeodeIds(modelId: ModelId): Promise<string[]> {
106
+ const geodeIds = await getMeshComponentGeodeIds(modelId, "Line");
107
+ return geodeIds;
108
+ }
109
+
110
+ async function getSurfacesGeodeIds(modelId: ModelId): Promise<string[]> {
111
+ const geodeIds = await getMeshComponentGeodeIds(modelId, "Surface");
112
+ return geodeIds;
113
+ }
114
+
115
+ async function getBlocksGeodeIds(modelId: ModelId): Promise<string[]> {
116
+ const geodeIds = await getMeshComponentGeodeIds(modelId, "Block");
117
+ return geodeIds;
118
+ }
119
+
120
+ export {
121
+ fetchAllMeshComponents,
122
+ formatedMeshComponents,
123
+ getAllMeshComponents,
124
+ getBlocksGeodeIds,
125
+ getCornersGeodeIds,
126
+ getLinesGeodeIds,
127
+ getMeshComponentGeodeIds,
128
+ getMeshComponentsByType,
129
+ getSurfacesGeodeIds,
130
+ refFormatedMeshComponents,
131
+ toFormattedComponent,
132
+ };
133
+ export type { FormattedComponent, FormattedComponentGroup };
134
+ export type { ModelComponentRecord } from "@ogw_internal/database/tables/model_components";