@geode/opengeodeweb-front 12.2.0-rc.4 → 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 (115) hide show
  1. package/app/components/ClippingPlanes.vue +1 -1
  2. package/app/components/FactorFilterPanel.vue +1 -1
  3. package/app/components/Launcher.vue +3 -2
  4. package/app/components/ThresholdFilter.vue +1 -2
  5. package/app/components/Viewer/Basemap/CropOptions.vue +7 -8
  6. package/app/components/Viewer/Basemap/OpacityOptions.vue +7 -8
  7. package/app/components/Viewer/ContextMenu/CircularItems.vue +6 -43
  8. package/app/components/Viewer/ContextMenu/ContextMenu.vue +1 -6
  9. package/app/components/Viewer/ContextMenu/ContextMenuItem.vue +14 -16
  10. package/app/components/Viewer/EdgedCurve/PointsOptions.vue +5 -4
  11. package/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue +10 -13
  12. package/app/components/Viewer/Generic/Mesh/CellsOptions.vue +8 -11
  13. package/app/components/Viewer/Generic/Mesh/EdgesOptions.vue +16 -13
  14. package/app/components/Viewer/Generic/Mesh/PointsOptions.vue +28 -31
  15. package/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue +9 -11
  16. package/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue +8 -11
  17. package/app/components/Viewer/Generic/Model/BlocksOptions.vue +1 -1
  18. package/app/components/Viewer/Generic/Model/CornersOptions.vue +1 -1
  19. package/app/components/Viewer/Generic/Model/CornersTypeOptions.vue +1 -1
  20. package/app/components/Viewer/Generic/Model/EdgesOptions.vue +7 -8
  21. package/app/components/Viewer/Generic/Model/LinesOptions.vue +1 -1
  22. package/app/components/Viewer/Generic/Model/LinesTypeOptions.vue +1 -1
  23. package/app/components/Viewer/Generic/Model/ModelEdgesCard.vue +5 -7
  24. package/app/components/Viewer/Generic/Model/ModelPointsCard.vue +5 -7
  25. package/app/components/Viewer/Generic/Model/ModelStyleCard.vue +5 -7
  26. package/app/components/Viewer/Generic/Model/ModelStyleOptions.vue +7 -8
  27. package/app/components/Viewer/Generic/Model/PointsOptions.vue +7 -8
  28. package/app/components/Viewer/Generic/Model/SurfacesOptions.vue +1 -1
  29. package/app/components/Viewer/Grid/2D/CellsOptions.vue +6 -4
  30. package/app/components/Viewer/Grid/2D/EdgesOptions.vue +6 -4
  31. package/app/components/Viewer/Grid/2D/PointsOptions.vue +5 -4
  32. package/app/components/Viewer/Grid/3D/CellsOptions.vue +6 -4
  33. package/app/components/Viewer/Grid/3D/EdgesOptions.vue +6 -4
  34. package/app/components/Viewer/Grid/3D/FacetsOptions.vue +6 -4
  35. package/app/components/Viewer/Grid/3D/PointsOptions.vue +5 -4
  36. package/app/components/Viewer/Image/ImageOptions.vue +10 -13
  37. package/app/components/Viewer/ObjectTree/Base/CommonTreeView.vue +5 -0
  38. package/app/components/Viewer/ObjectTree/Base/ComponentRelations.vue +2 -2
  39. package/app/components/Viewer/ObjectTree/Base/StickyHeader.vue +4 -1
  40. package/app/components/Viewer/ObjectTree/Base/TreeRow.vue +6 -8
  41. package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +10 -15
  42. package/app/components/Viewer/ObjectTree/Views/ModelTree.vue +3 -0
  43. package/app/components/Viewer/PointSet/SpecificPointsOptions.vue +28 -31
  44. package/app/components/Viewer/Scene/BackgroundOptions.vue +4 -7
  45. package/app/components/Viewer/Scene/OrientationWidgetOptions.vue +4 -7
  46. package/app/components/Viewer/Scene/TextOptions.vue +4 -7
  47. package/app/components/Viewer/Solid/EdgesOptions.vue +6 -4
  48. package/app/components/Viewer/Solid/PointsOptions.vue +5 -4
  49. package/app/components/Viewer/Solid/PolygonsOptions.vue +6 -4
  50. package/app/components/Viewer/Solid/SpecificPolyhedraOptions.vue +8 -11
  51. package/app/components/Viewer/Surface/EdgesOptions.vue +6 -4
  52. package/app/components/Viewer/Surface/PointsOptions.vue +6 -4
  53. package/app/components/Viewer/Surface/PolygonsOptions.vue +8 -11
  54. package/app/components/Viewer/Surface/Triangulated/TrianglesOptions.vue +5 -4
  55. package/app/components/Viewer/TetrahedralSolid/TetrahedraOptions.vue +6 -4
  56. package/app/components/Viewer/TetrahedralSolid/TrianglesOptions.vue +6 -4
  57. package/app/composables/circular_menu.ts +45 -0
  58. package/app/composables/hover_highlight.ts +1 -1
  59. package/app/composables/model_menu_context.ts +7 -11
  60. package/app/composables/model_tree.ts +3 -3
  61. package/app/composables/project_manager_helpers/types.ts +2 -3
  62. package/app/composables/use_overlapping_picker.ts +7 -19
  63. package/app/composables/viewer_context_menu.ts +2 -1
  64. package/app/stores/api.ts +6 -59
  65. package/app/stores/app.ts +21 -55
  66. package/app/stores/back.ts +86 -145
  67. package/app/stores/camera_manager.ts +12 -25
  68. package/app/stores/cloud.ts +21 -101
  69. package/app/stores/crs.ts +3 -2
  70. package/app/stores/data.ts +66 -409
  71. package/app/stores/data_style.ts +99 -93
  72. package/app/stores/feedback.ts +57 -53
  73. package/app/stores/infra.ts +61 -101
  74. package/app/stores/treeview.ts +12 -31
  75. package/app/stores/viewer.ts +9 -29
  76. package/app/stores/viewer_helpers/actions.ts +1 -23
  77. package/app/utils/backend_lifecycle.ts +155 -0
  78. package/app/utils/import_item.ts +5 -4
  79. package/app/utils/threshold_sources.ts +3 -2
  80. package/app/utils/treeview.ts +25 -1
  81. package/app/utils/viewer_object_type.ts +21 -0
  82. package/internal/database/base_database.ts +2 -1
  83. package/internal/database/database.ts +90 -7
  84. package/internal/database/queries.ts +45 -0
  85. package/internal/database/tables/camera_positions.ts +11 -1
  86. package/internal/database/tables/data.ts +20 -1
  87. package/internal/database/tables/data_style.ts +3 -1
  88. package/internal/database/tables/model_component_datastyle.ts +3 -1
  89. package/internal/database/tables/model_component_type_datastyle.ts +3 -1
  90. package/internal/database/tables/model_components.ts +12 -1
  91. package/internal/database/tables/model_components_relation.ts +11 -1
  92. package/internal/database/tables/scene_style.ts +3 -1
  93. package/internal/database/tables/treeview_config.ts +31 -0
  94. package/internal/stores/data/items.ts +110 -0
  95. package/internal/stores/data/model/collections.ts +107 -0
  96. package/internal/stores/data/model/components.ts +129 -0
  97. package/internal/stores/data/model/mesh_components.ts +134 -0
  98. package/internal/stores/data/model/relations.ts +76 -0
  99. package/internal/stores/data/model/types.ts +14 -0
  100. package/internal/stores/data/registration.ts +54 -0
  101. package/internal/stores/data/snapshot.ts +83 -0
  102. package/internal/stores/data/types.ts +26 -0
  103. package/internal/stores/data_style/model/common_mutations.ts +47 -77
  104. package/internal/stores/data_style/model/selection.ts +3 -10
  105. package/internal/stores/data_style/scene.ts +2 -2
  106. package/internal/stores/data_style/state.ts +10 -8
  107. package/internal/stores/data_style/state_shared.ts +10 -7
  108. package/internal/stores/hybrid_viewer/highlight.ts +9 -14
  109. package/internal/stores/hybrid_viewer/scene.ts +1 -1
  110. package/internal/stores/microservice.ts +192 -0
  111. package/package.json +1 -1
  112. package/tests/browser/helpers/data/helpers/attribute.ts +2 -1
  113. package/app/stores/data_helpers/collections.ts +0 -122
  114. package/app/stores/data_helpers/mesh.ts +0 -167
  115. package/app/stores/data_helpers/relations.ts +0 -94
@@ -8,27 +8,22 @@ import opengeodeweb_viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb
8
8
 
9
9
  // Local imports
10
10
  import { type ViewerRequestArgs, callViewer } from "./viewer_helpers/request.js";
11
- import {
12
- fetchViewerVersion,
13
- launchViewerMicroservice,
14
- pickWorldPosition,
15
- showRenderingWarnings,
16
- } from "./viewer_helpers/actions.js";
17
11
  import {
18
12
  getWebsocketApiPort,
19
13
  getWebsocketApiProtocol,
20
14
  isCloudMode,
21
15
  } from "@ogw_front/utils/stores.js";
16
+ import {
17
+ launchViewerMicroservice,
18
+ pickWorldPosition,
19
+ showRenderingWarnings,
20
+ } from "./viewer_helpers/actions.js";
21
+ import { useMicroserviceVersion, useRequestCounter } from "@ogw_internal/stores/microservice";
22
22
  import { Status } from "@ogw_front/utils/status";
23
23
  import { afterViewerReset } from "@ogw_front/composables/viewer_reset";
24
24
  import { useInfraStore } from "@ogw_front/stores/infra";
25
25
 
26
- import type {
27
- JsonRpcSchema,
28
- MicroserviceVersionSchema,
29
- RequestHandlers,
30
- ResponseOf,
31
- } from "@ogw_shared/utils/types.js";
26
+ import type { JsonRpcSchema, RequestHandlers, ResponseOf } from "@ogw_shared/utils/types.js";
32
27
  import type { RpcClient } from "@ogw_shared/utils/call_raw.js";
33
28
 
34
29
  interface ViewSize {
@@ -59,9 +54,8 @@ export const useViewerStore = defineStore(
59
54
  });
60
55
  // Pixel size of the remote rendering view, as sent to the server by RemoteView.resize()
61
56
  const view_size = ref<ViewSize>({ width: 0, height: 0 });
62
- const request_counter = ref(0);
57
+ const { request_counter, is_busy, start_request, stop_request } = useRequestCounter();
63
58
  const status = ref(Status.NOT_CONNECTED);
64
- const version = ref("0.0.0");
65
59
  // The viewer warnings are shown once, not again on each reconnection
66
60
  const rendering_warnings_shown = ref(false);
67
61
  const protocol = computed(() => getWebsocketApiProtocol());
@@ -74,13 +68,6 @@ export const useViewerStore = defineStore(
74
68
  viewer_url += "/ws";
75
69
  return viewer_url;
76
70
  });
77
- function start_request(): void {
78
- request_counter.value += 1;
79
- }
80
- function stop_request(): void {
81
- request_counter.value -= 1;
82
- }
83
- const is_busy = computed(() => request_counter.value > 0);
84
71
  function toggle_picking_mode(value: boolean): void {
85
72
  picking_mode.value = value;
86
73
  }
@@ -157,14 +144,7 @@ export const useViewerStore = defineStore(
157
144
  async function connect(): Promise<void> {
158
145
  await ws_connect();
159
146
  }
160
- async function get_version(
161
- schema: MicroserviceVersionSchema | undefined,
162
- ): Promise<{ microservice_version: string } | undefined> {
163
- const result = await fetchViewerVersion(request, schema, (microservice_version) => {
164
- version.value = microservice_version;
165
- });
166
- return result;
167
- }
147
+ const { version, get_version } = useMicroserviceVersion(request);
168
148
  return {
169
149
  default_local_port,
170
150
  client,
@@ -1,4 +1,3 @@
1
- import type { MicroserviceVersionSchema } from "@ogw_shared/utils/types.js";
2
1
  import type { Vector3 } from "@kitware/vtk.js/types";
3
2
  import type { ViewerRequest } from "./request.js";
4
3
  import { consola } from "consola";
@@ -46,27 +45,6 @@ async function launchViewerMicroservice(
46
45
  return result;
47
46
  }
48
47
 
49
- async function fetchViewerVersion(
50
- request: ViewerRequest,
51
- schema: MicroserviceVersionSchema | undefined,
52
- onVersion: (version: string) => void,
53
- ): Promise<{ microservice_version: string } | undefined> {
54
- if (!schema) {
55
- return undefined;
56
- }
57
- const result = await request(
58
- {
59
- schema,
60
- },
61
- {
62
- response_function: ({ microservice_version }) => {
63
- onVersion(microservice_version);
64
- },
65
- },
66
- );
67
- return result;
68
- }
69
-
70
48
  // Shows the viewer's warnings about its rendering setup, e.g. software rendering fallback.
71
49
  // Informational only: a failure is logged, never thrown, so it cannot break the connection.
72
50
  async function showRenderingWarnings(request: ViewerRequest): Promise<void> {
@@ -82,4 +60,4 @@ async function showRenderingWarnings(request: ViewerRequest): Promise<void> {
82
60
  }
83
61
  }
84
62
 
85
- export { fetchViewerVersion, launchViewerMicroservice, pickWorldPosition, showRenderingWarnings };
63
+ export { launchViewerMicroservice, pickWorldPosition, showRenderingWarnings };
@@ -0,0 +1,155 @@
1
+ // Creates the backend: launches the local microservices, or launches / reaches the cloud service,
2
+ // Then connects every registered microservice. It drives the stores from outside, so the stores
3
+ // Only hold their own state and no store imports another one to orchestrate it.
4
+ import { type Microservice, useInfraStore } from "@ogw_front/stores/infra";
5
+ import { clearCloudUrlParam, getCloudUrlParam } from "@ogw_front/utils/cloud";
6
+ import { Status } from "@ogw_front/utils/status";
7
+ import { api_fetch } from "@ogw_internal/utils/api_fetch";
8
+ import { appMode } from "@ogw_shared/app_mode";
9
+ import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
10
+ import cloud_api_schemas from "@geode/cloud-api/cloud_api_typed_schemas.js";
11
+ import { registerRunningExtensions } from "@ogw_front/utils/extension";
12
+ import { setAppBaseUrl } from "@ogw_shared/scripts";
13
+ import { useAPIStore } from "@ogw_front/stores/api";
14
+ import { useAppStore } from "@ogw_front/stores/app";
15
+ import { useBackStore } from "@ogw_front/stores/back";
16
+ import { useCloudStore } from "@ogw_front/stores/cloud";
17
+
18
+ const CLOUD_PROJECT_FOLDER_PATH = "/project";
19
+
20
+ interface ElectronApi {
21
+ electronAPI: {
22
+ project_folder_path: (args: { projectFolderPath: string }) => void;
23
+ };
24
+ }
25
+
26
+ declare global {
27
+ // oxlint-disable-next-line no-var -- required for global augmentation
28
+ var electronAPI: ElectronApi["electronAPI"];
29
+ }
30
+
31
+ async function launchLocalServices(): Promise<void> {
32
+ const infraStore = useInfraStore();
33
+ const appStore = useAppStore();
34
+ await appStore.createProjectFolder();
35
+ if (infraStore.app_mode === appMode.DESKTOP) {
36
+ globalThis.electronAPI.project_folder_path({
37
+ projectFolderPath: appStore.projectFolderPath,
38
+ });
39
+ }
40
+ await setAppBaseUrl(appStore.base_url);
41
+ const launch_promises: Promise<unknown>[] = infraStore.microservices
42
+ .filter((store: Microservice) => store.launch)
43
+ .map(async (store: Microservice) => {
44
+ const result = await store.launch?.({ projectFolderPath: appStore.projectFolderPath });
45
+ return result;
46
+ });
47
+ launch_promises.push(registerRunningExtensions());
48
+ await Promise.all(launch_promises);
49
+ }
50
+
51
+ async function onCloudConnected(url: string): Promise<void> {
52
+ const appStore = useAppStore();
53
+ useCloudStore().set_connected(true);
54
+ useInfraStore().set_domain_name(url);
55
+ appStore.set_project_folder_path(CLOUD_PROJECT_FOLDER_PATH);
56
+ await setAppBaseUrl(appStore.base_url);
57
+ }
58
+
59
+ // `authToken` is the user's Firebase ID token, checked by the Cloud API
60
+ async function launchCloud(authToken: string): Promise<unknown> {
61
+ const cloudStore = useCloudStore();
62
+ cloudStore.set_connecting();
63
+ const { PROJECT, BRANCH } = useRuntimeConfig().public;
64
+ const result = await useAPIStore().request(
65
+ {
66
+ schema: cloud_api_schemas.cloud_api.cloud.run,
67
+ params: { project: PROJECT, branch: BRANCH },
68
+ headers: { Authorization: `Bearer ${authToken}` },
69
+ },
70
+ {
71
+ request_error_function: () => {
72
+ cloudStore.set_connected(false);
73
+ },
74
+ response_function: async ({ url }) => {
75
+ await onCloudConnected(url);
76
+ },
77
+ response_error_function: () => {
78
+ cloudStore.set_connected(false);
79
+ },
80
+ },
81
+ );
82
+ return result;
83
+ }
84
+
85
+ async function connectExistingCloud(host: string): Promise<void> {
86
+ const cloudStore = useCloudStore();
87
+ cloudStore.set_connecting();
88
+ const backStore = useBackStore();
89
+ // Probe the candidate host directly so domain_name is only updated once the service answers.
90
+ try {
91
+ await api_fetch(
92
+ {
93
+ $id: backStore.$id,
94
+ base_url: backStore.base_url_for(host),
95
+ start_request: () => {
96
+ backStore.start_request();
97
+ },
98
+ stop_request: () => {
99
+ backStore.stop_request();
100
+ },
101
+ },
102
+ { schema: back_schemas.opengeodeweb_back.ping, log_success: false },
103
+ );
104
+ } catch (error) {
105
+ cloudStore.set_connected(false);
106
+ throw error;
107
+ }
108
+ await onCloudConnected(host);
109
+ }
110
+
111
+ // Reuses the running service given by `?cloud_url=` when present, otherwise launches a new one.
112
+ // The param is single use: it is cleared whatever the outcome, so a retry launches a new service.
113
+ async function startCloud(authToken?: string): Promise<void> {
114
+ const existing_host = getCloudUrlParam();
115
+ if (existing_host === undefined) {
116
+ if (authToken === undefined) {
117
+ throw new Error("Launching a cloud service requires an authenticated user");
118
+ }
119
+ await launchCloud(authToken);
120
+ return;
121
+ }
122
+ try {
123
+ await connectExistingCloud(existing_host);
124
+ } finally {
125
+ clearCloudUrlParam();
126
+ }
127
+ }
128
+
129
+ async function createBackend(authToken?: string): Promise<void> {
130
+ const infraStore = useInfraStore();
131
+ if (infraStore.status === Status.CREATED) {
132
+ return;
133
+ }
134
+ await navigator.locks.request("infra.create_backend", async () => {
135
+ if (infraStore.status === Status.CREATED) {
136
+ return;
137
+ }
138
+ infraStore.set_status(Status.CREATING);
139
+ if (infraStore.app_mode === appMode.CLOUD) {
140
+ try {
141
+ await startCloud(authToken);
142
+ } catch (error) {
143
+ // Back to the "Load the app" button so the user is not stuck on the loading screen.
144
+ infraStore.set_status(Status.NOT_CREATED);
145
+ throw error;
146
+ }
147
+ } else {
148
+ await launchLocalServices();
149
+ }
150
+ infraStore.set_status(Status.CREATED);
151
+ await infraStore.create_connection();
152
+ });
153
+ }
154
+
155
+ export { connectExistingCloud, createBackend, launchCloud, startCloud };
@@ -1,6 +1,7 @@
1
1
  // Local imports
2
2
  import { type LegacyDataId, fromLegacyDataId } from "@ogw_front/utils/legacy_data_id";
3
3
  import { type NewDataItem, useDataStore } from "@ogw_front/stores/data";
4
+ import { isModel } from "@ogw_front/utils/viewer_object_type";
4
5
  import { useDataStyleStore } from "@ogw_front/stores/data_style";
5
6
  import { useFeedbackStore } from "@ogw_front/stores/feedback";
6
7
  import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer";
@@ -10,7 +11,7 @@ import { useTreeviewStore } from "@ogw_front/stores/treeview";
10
11
  async function registerWhenViewable(item: NewDataItem, added: Promise<unknown>): Promise<unknown> {
11
12
  const dataStore = useDataStore();
12
13
  await added;
13
- if (!(await dataStore.isItemViewable(item))) {
14
+ if (!(await dataStore.fetchIsViewable(item.data_id))) {
14
15
  return undefined;
15
16
  }
16
17
  return dataStore.registerObject(item.data_id, item.name ?? item.data_id);
@@ -22,7 +23,7 @@ async function addToViewerWhenViewable(
22
23
  ): Promise<unknown> {
23
24
  const dataStore = useDataStore();
24
25
  await added;
25
- if (!(await dataStore.isItemViewable(item))) {
26
+ if (!(await dataStore.fetchIsViewable(item.data_id))) {
26
27
  return undefined;
27
28
  }
28
29
  return useHybridViewerStore().addItem(item.data_id);
@@ -30,7 +31,7 @@ async function addToViewerWhenViewable(
30
31
 
31
32
  async function applyStyleWhenReady(item: NewDataItem, ready: Promise<unknown>): Promise<unknown> {
32
33
  await ready;
33
- if (!(await useDataStore().isItemViewable(item))) {
34
+ if (!(await useDataStore().fetchIsViewable(item.data_id))) {
34
35
  return undefined;
35
36
  }
36
37
  return useDataStyleStore().applyDefaultStyle(item.data_id);
@@ -50,7 +51,7 @@ async function importDataItem(item: NewDataItem): Promise<string> {
50
51
  const registerTask = registerWhenViewable(item, addDataTask);
51
52
  let addDataComponentsTask: Promise<unknown> = Promise.resolve(undefined);
52
53
  let addDataRelationsTask: Promise<unknown> = Promise.resolve(undefined);
53
- if (item.viewer_object_type === "model") {
54
+ if (isModel(item)) {
54
55
  addDataComponentsTask = dataStore.addComponents(item);
55
56
  addDataRelationsTask = dataStore.addComponentRelations(item);
56
57
  }
@@ -3,6 +3,7 @@ import {
3
3
  MODEL_COMPONENT_ATTRIBUTE_SCHEMAS,
4
4
  MODEL_COMPONENT_KINDS,
5
5
  } from "@ogw_front/utils/attributes";
6
+ import { isImage, isMesh } from "@ogw_front/utils/viewer_object_type";
6
7
  import type { AttributeSource } from "@ogw_front/utils/threshold";
7
8
  import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
8
9
  import { attributeSchemas } from "@ogw_front/composables/attribute_coloring_style";
@@ -33,10 +34,10 @@ async function fetchSources(
33
34
  ): Promise<AttributeSource[]> {
34
35
  const item = await dataStore.item(dataId);
35
36
  // An image shows its own colors: it has no attribute to threshold
36
- if (item.viewer_object_type === "image") {
37
+ if (isImage(item)) {
37
38
  return [];
38
39
  }
39
- if (item.viewer_object_type === "mesh") {
40
+ if (isMesh(item)) {
40
41
  return ["vertex", MESH_ELEMENT_KINDS[item.geode_object_type]]
41
42
  .filter((kind): kind is string => kind !== undefined)
42
43
  .map((kind) => attributeSource(kind, "", { id: dataId }));
@@ -1,5 +1,7 @@
1
1
  import type { GeodeObjectTyped, ModelIdentified } from "@ogw_front/types/identifiers";
2
2
  import type { TreeGroup, TreeNode } from "@ogw_front/types/tree";
3
+ import type { DisplayItem } from "@ogw_front/composables/virtual_tree";
4
+ import { isBasemapId } from "@ogw_front/utils/basemap_tree";
3
5
 
4
6
  function compareSelections<Item>(
5
7
  current: readonly Item[],
@@ -86,7 +88,29 @@ function withPendingImports<Child extends TreeNode, Pending extends TreeNode & G
86
88
  return merged;
87
89
  }
88
90
 
89
- export { MODEL_TREE_COLORS, compareSelections, nextModelTreeColor, withPendingImports };
91
+ // In the objects tree, a data row follows its data. The basemap rows and the groups of data types
92
+ // Always show their toggle, except the group of horizon stacks, which open their own modal
93
+ function isObjectTreeRowViewable(
94
+ row: DisplayItem,
95
+ isDataViewable: (dataId: string) => boolean,
96
+ ): boolean {
97
+ const { id, title } = row.raw;
98
+ if (typeof id !== "string" || isBasemapId(id)) {
99
+ return true;
100
+ }
101
+ if (row.isLeaf) {
102
+ return isDataViewable(id);
103
+ }
104
+ return title !== "HorizonStack3D";
105
+ }
106
+
107
+ export {
108
+ MODEL_TREE_COLORS,
109
+ compareSelections,
110
+ isObjectTreeRowViewable,
111
+ nextModelTreeColor,
112
+ withPendingImports,
113
+ };
90
114
  export type {
91
115
  DataMenuPayload,
92
116
  GeodeObjectTypeMenuPayload,
@@ -0,0 +1,21 @@
1
+ import type { ViewerObjectTyped } from "@ogw_front/types/identifiers";
2
+
3
+ function isModel<Item extends Partial<ViewerObjectTyped>>(
4
+ item: Item,
5
+ ): item is Item & { viewer_object_type: "model" } {
6
+ return item.viewer_object_type === "model";
7
+ }
8
+
9
+ function isMesh<Item extends Partial<ViewerObjectTyped>>(
10
+ item: Item,
11
+ ): item is Item & { viewer_object_type: "mesh" } {
12
+ return item.viewer_object_type === "mesh";
13
+ }
14
+
15
+ function isImage<Item extends Partial<ViewerObjectTyped>>(
16
+ item: Item,
17
+ ): item is Item & { viewer_object_type: "image" } {
18
+ return item.viewer_object_type === "image";
19
+ }
20
+
21
+ export { isImage, isMesh, isModel };
@@ -7,6 +7,7 @@ import { modelComponentTypeDataStyleTable } from "./tables/model_component_type_
7
7
  import { modelComponentsRelationTable } from "./tables/model_components_relation";
8
8
  import { modelComponentsTable } from "./tables/model_components";
9
9
  import { sceneStyleTable } from "./tables/scene_style";
10
+ import { treeviewConfigTable } from "./tables/treeview_config";
10
11
 
11
12
  export class BaseDatabase extends Dexie {
12
13
  public static get initialStores(): Record<string, string> {
@@ -19,7 +20,7 @@ export class BaseDatabase extends Dexie {
19
20
  [modelComponentsRelationTable.name]: modelComponentsRelationTable.schema,
20
21
  [cameraPositionsTable.name]: cameraPositionsTable.schema,
21
22
  [sceneStyleTable.name]: sceneStyleTable.schema,
22
- treeview_config: "id",
23
+ [treeviewConfigTable.name]: treeviewConfigTable.schema,
23
24
  };
24
25
  }
25
26
 
@@ -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 };