@geode/opengeodeweb-front 10.5.0 → 10.5.1

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.
@@ -1,15 +1,12 @@
1
1
  // Third party imports
2
- import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json"
3
- import { database } from "@ogw_internal/database/database.js"
4
2
  import { liveQuery } from "dexie"
5
3
  import { useObservable } from "@vueuse/rxjs"
6
4
  import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"
7
5
 
8
6
  // Local imports
9
- import { useGeodeStore } from "@ogw_front/stores/geode"
7
+ import { database } from "@ogw_internal/database/database.js"
10
8
  import { useViewerStore } from "@ogw_front/stores/viewer"
11
9
 
12
- const back_model_schemas = back_schemas.opengeodeweb_back.models
13
10
  const viewer_generic_schemas = viewer_schemas.opengeodeweb_viewer.generic
14
11
 
15
12
  export const useDataStore = defineStore("data", () => {
@@ -33,8 +30,10 @@ export const useDataStore = defineStore("data", () => {
33
30
  )
34
31
  }
35
32
 
36
- async function formatedMeshComponents(id) {
37
- const items = await database.model_components.where({ id }).toArray()
33
+ async function formatedMeshComponents(modelId) {
34
+ const items = await database.model_components
35
+ .where({ id: modelId })
36
+ .toArray()
38
37
  const componentTitles = {
39
38
  Corner: "Corners",
40
39
  Line: "Lines",
@@ -65,9 +64,9 @@ export const useDataStore = defineStore("data", () => {
65
64
  }))
66
65
  }
67
66
 
68
- async function meshComponentType(id, geode_id) {
67
+ async function meshComponentType(modelId, geode_id) {
69
68
  const component = await database.model_components
70
- .where({ id, geode_id })
69
+ .where({ id: modelId, geode_id })
71
70
  .first()
72
71
  return component?.type
73
72
  }
@@ -80,134 +79,118 @@ export const useDataStore = defineStore("data", () => {
80
79
  return await viewerStore.request(viewer_generic_schemas.deregister, { id })
81
80
  }
82
81
 
83
- async function addItem(id, value) {
82
+ function addItem(new_item) {
84
83
  const itemData = {
85
- ...value,
86
- id,
87
- name: value.name || id,
88
- geode_object_type: value.geode_object_type,
89
- visible: value.visible !== undefined ? value.visible : true,
90
- created_at: value.created_at || new Date().toISOString(),
84
+ id: new_item.id,
85
+ name: new_item.name || new_item.id,
86
+ viewer_type: new_item.viewer_type,
87
+ geode_object_type: new_item.geode_object_type,
88
+ visible: true,
89
+ created_at: new Date().toISOString(),
90
+ binary_light_viewable: new_item.binary_light_viewable,
91
91
  }
92
-
93
- const serializedData = structuredClone(itemData)
94
- await database.data.put(serializedData)
95
- }
96
- async function deleteItem(id) {
97
- await database.data.delete(id)
98
- await deleteModelComponents(id)
99
- }
100
- async function updateItem(id, changes) {
101
- await database.data.update(id, changes)
102
- }
103
-
104
- async function addModelComponents(id, values) {
105
- if (!values || values.length === 0) {
106
- console.debug("[addModelComponents] No components to add")
107
- return
92
+ return database.data.put(itemData)
93
+ }
94
+
95
+ function addComponents(new_item) {
96
+ const allComponents = []
97
+ function addModelComponents(components) {
98
+ for (const component of components) {
99
+ allComponents.push({
100
+ id: new_item.id,
101
+ geode_id: component.geode_id,
102
+ type: component.type,
103
+ viewer_id: component.viewer_id,
104
+ name: component.name,
105
+ })
106
+ }
108
107
  }
108
+ addModelComponents(new_item.mesh_components)
109
+ addModelComponents(new_item.collection_components)
110
+ return database.model_components.bulkPut(allComponents)
111
+ }
109
112
 
110
- const { mesh_components, collection_components } = values
111
- const allComponents = [
112
- ...(mesh_components || []),
113
- ...(collection_components || []),
114
- ]
115
-
113
+ function addComponentRelations(new_item) {
116
114
  const relations = []
117
- for (const component of allComponents) {
118
- component.id = id
119
- component.created_at = new Date().toISOString()
120
-
115
+ function addModelComponentRelations(components, parent, type) {
116
+ for (const child of components) {
117
+ relations.push({
118
+ id: new_item.id,
119
+ parent,
120
+ child,
121
+ type,
122
+ })
123
+ }
124
+ }
125
+ for (const component of new_item.mesh_components) {
121
126
  if (component.boundaries) {
122
- for (const boundary_id of component.boundaries) {
123
- relations.push({
124
- id,
125
- parent: component.geode_id,
126
- child: boundary_id,
127
- type: "boundary",
128
- })
129
- }
130
- delete component.boundaries
127
+ addModelComponentRelations(
128
+ component.boundaries,
129
+ component.geode_id,
130
+ "boundary",
131
+ )
131
132
  }
132
133
  if (component.internals) {
133
- for (const internal_id of component.internals) {
134
- relations.push({
135
- id,
136
- parent: component.geode_id,
137
- child: internal_id,
138
- type: "internal",
139
- })
140
- }
141
- delete component.internals
134
+ addModelComponentRelations(
135
+ component.internals,
136
+ component.geode_id,
137
+ "internal",
138
+ )
142
139
  }
140
+ }
141
+ for (const component of new_item.collection_components) {
143
142
  if (component.items) {
144
- for (const item_id of component.items) {
145
- relations.push({
146
- id,
147
- parent: component.geode_id,
148
- child: item_id,
149
- type: "collection",
150
- })
151
- }
152
- delete component.items
143
+ addModelComponentRelations(
144
+ component.items,
145
+ component.geode_id,
146
+ "collection",
147
+ )
153
148
  }
154
149
  }
150
+ return database.model_components_relation.bulkPut(relations)
151
+ }
155
152
 
156
- const serializedComponents = structuredClone(allComponents)
157
- const serializedRelations = structuredClone(relations)
158
-
159
- await database.model_components.bulkAdd(serializedComponents)
160
- if (serializedRelations.length > 0) {
161
- await database.model_components_relation.bulkAdd(serializedRelations)
162
- }
153
+ async function deleteItem(id) {
154
+ await database.data.delete(id)
155
+ await deleteModelComponents(id)
163
156
  }
164
157
 
165
- async function deleteModelComponents(id) {
166
- await database.model_components.where({ id }).delete()
167
- await database.model_components_relation.where({ id }).delete()
158
+ async function updateItem(id, changes) {
159
+ await database.data.update(id, changes)
168
160
  }
169
161
 
170
- async function fetchModelComponents(id) {
171
- const geodeStore = useGeodeStore()
172
- return await geodeStore.request(
173
- back_model_schemas.model_components,
174
- { id },
175
- {
176
- response_function: async (response) => {
177
- await addModelComponents(id, response)
178
- },
179
- },
180
- )
162
+ async function deleteModelComponents(modelId) {
163
+ await database.model_components.where({ id: modelId }).delete()
164
+ await database.model_components_relation.where({ id: modelId }).delete()
181
165
  }
182
166
 
183
- async function getMeshComponentGeodeIds(id, component_type) {
167
+ async function getMeshComponentGeodeIds(modelId, component_type) {
184
168
  const components = await database.model_components
185
- .where({ id, type: component_type })
169
+ .where({ id: modelId, type: component_type })
186
170
  .toArray()
187
171
  return components.map((component) => component.geode_id)
188
172
  }
189
173
 
190
- async function getCornersGeodeIds(id) {
191
- return await getMeshComponentGeodeIds(id, "Corner")
174
+ async function getCornersGeodeIds(modelId) {
175
+ return await getMeshComponentGeodeIds(modelId, "Corner")
192
176
  }
193
177
 
194
- async function getLinesGeodeIds(id) {
195
- return await getMeshComponentGeodeIds(id, "Line")
178
+ async function getLinesGeodeIds(modelId) {
179
+ return await getMeshComponentGeodeIds(modelId, "Line")
196
180
  }
197
181
 
198
- async function getSurfacesGeodeIds(id) {
199
- return await getMeshComponentGeodeIds(id, "Surface")
182
+ async function getSurfacesGeodeIds(modelId) {
183
+ return await getMeshComponentGeodeIds(modelId, "Surface")
200
184
  }
201
185
 
202
- async function getBlocksGeodeIds(id) {
203
- return await getMeshComponentGeodeIds(id, "Block")
186
+ async function getBlocksGeodeIds(modelId) {
187
+ return await getMeshComponentGeodeIds(modelId, "Block")
204
188
  }
205
189
 
206
- async function getMeshComponentsViewerIds(id, meshComponentGeodeIds) {
190
+ async function getMeshComponentsViewerIds(modelId, meshComponentGeodeIds) {
207
191
  const components = await database.model_components
208
- .where("id")
209
- .equals(id)
210
- .and((component) => meshComponentGeodeIds.includes(component.geode_id))
192
+ .where("[id+geode_id]")
193
+ .anyOf(meshComponentGeodeIds.map((geode_id) => [modelId, geode_id]))
211
194
  .toArray()
212
195
  return components.map((component) => component.viewer_id)
213
196
  }
@@ -234,9 +217,10 @@ export const useDataStore = defineStore("data", () => {
234
217
  registerObject,
235
218
  deregisterObject,
236
219
  addItem,
220
+ addComponents,
221
+ addComponentRelations,
237
222
  deleteItem,
238
223
  updateItem,
239
- fetchModelComponents,
240
224
  getCornersGeodeIds,
241
225
  getLinesGeodeIds,
242
226
  getSurfacesGeodeIds,
@@ -1,4 +1,3 @@
1
- import { database } from "@ogw_internal/database/database.js"
2
1
  import { getDefaultStyle } from "@ogw_front/utils/default_styles"
3
2
  import { useDataStore } from "@ogw_front/stores/data"
4
3
  import { useDataStyleStateStore } from "@ogw_internal/stores/data_style/state"
@@ -16,7 +15,7 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
16
15
  }
17
16
 
18
17
  async function setVisibility(id, visibility) {
19
- const item = await database.data.get(id)
18
+ const item = await dataStore.item(id)
20
19
  const viewer_type = item?.viewer_type
21
20
  if (!viewer_type) {
22
21
  throw new Error(`Item not found or not loaded: ${id}`)
@@ -32,12 +31,11 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
32
31
  }
33
32
 
34
33
  async function applyDefaultStyle(id) {
35
- const item = await database.data.get(id)
34
+ const item = await dataStore.item(id)
36
35
  const viewer_type = item?.viewer_type
37
36
  if (!viewer_type) {
38
37
  throw new Error(`Item not found or not loaded: ${id}`)
39
38
  }
40
-
41
39
  if (viewer_type === "mesh") {
42
40
  return meshStyleStore.applyMeshStyle(id)
43
41
  }
@@ -6,7 +6,7 @@ import { newInstance as vtkMapper } from "@kitware/vtk.js/Rendering/Core/Mapper"
6
6
  import { newInstance as vtkXMLPolyDataReader } from "@kitware/vtk.js/IO/XML/XMLPolyDataReader"
7
7
 
8
8
  import { Status } from "@ogw_front/utils/status"
9
- import { database } from "@ogw_internal/database/database.js"
9
+ import { useDataStore } from "@ogw_front/stores/data"
10
10
  import { useViewerStore } from "@ogw_front/stores/viewer"
11
11
  import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"
12
12
 
@@ -26,6 +26,7 @@ const ACTOR_COLOR = [
26
26
  const WHEEL_TIME_OUT_MS = 600
27
27
 
28
28
  export const useHybridViewerStore = defineStore("hybridViewer", () => {
29
+ const dataStore = useDataStore()
29
30
  const viewerStore = useViewerStore()
30
31
  const hybridDb = reactive({})
31
32
  const status = ref(Status.NOT_CREATED)
@@ -69,7 +70,7 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => {
69
70
  if (!genericRenderWindow.value) {
70
71
  return
71
72
  }
72
- const value = await database.data.get(id)
73
+ const value = await dataStore.item(id)
73
74
  console.log("hybridViewerStore.addItem", { value })
74
75
  const reader = vtkXMLPolyDataReader()
75
76
  const textEncoder = new TextEncoder()
@@ -8,8 +8,11 @@ import { useGeodeStore } from "@ogw_front/stores/geode"
8
8
  import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"
9
9
  import { useTreeviewStore } from "@ogw_front/stores/treeview"
10
10
 
11
+ const SECOND = 1000
12
+
11
13
  async function importWorkflow(files) {
12
14
  console.log("importWorkflow", { files })
15
+ const start = Date.now()
13
16
  const promise_array = []
14
17
  for (const file of files) {
15
18
  const { filename, geode_object_type } = file
@@ -19,6 +22,7 @@ async function importWorkflow(files) {
19
22
  const results = await Promise.all(promise_array)
20
23
  const hybridViewerStore = useHybridViewerStore()
21
24
  hybridViewerStore.remoteRender()
25
+ console.log("importWorkflow completed in", (Date.now() - start) / SECOND)
22
26
  return results
23
27
  }
24
28
 
@@ -34,26 +38,45 @@ async function importItem(item) {
34
38
  const dataStyleStore = useDataStyleStore()
35
39
  const hybridViewerStore = useHybridViewerStore()
36
40
  const treeviewStore = useTreeviewStore()
37
- await dataStore.registerObject(item.id)
38
- await dataStore.addItem(item.id, {
39
- ...item,
40
- })
41
-
42
- await treeviewStore.addItem(
41
+ const registerTask = dataStore.registerObject(item.id)
42
+ const addDataTask = dataStore.addItem(item)
43
+ console.log({ dataStore })
44
+ const addDataComponentsTask =
45
+ item.viewer_type === "model"
46
+ ? dataStore.addComponents(item)
47
+ : Promise.resolve()
48
+ const addDataRelationsTask =
49
+ item.viewer_type === "model"
50
+ ? dataStore.addComponentRelations(item)
51
+ : Promise.resolve()
52
+ const addTreeviewTask = treeviewStore.addItem(
43
53
  item.geode_object_type,
44
54
  item.name,
45
55
  item.id,
46
56
  item.viewer_type,
47
57
  )
48
-
49
- await hybridViewerStore.addItem(item.id)
50
- await dataStyleStore.addDataStyle(item.id, item.geode_object_type)
51
-
52
- if (item.viewer_type === "model") {
53
- await dataStore.fetchModelComponents(item.id)
54
- }
55
-
56
- await dataStyleStore.applyDefaultStyle(item.id)
58
+ const addStyleTask = dataStyleStore.addDataStyle(
59
+ item.id,
60
+ item.geode_object_type,
61
+ )
62
+ const addViewerTask = addDataTask.then(() =>
63
+ hybridViewerStore.addItem(item.id),
64
+ )
65
+ const applyStyleTask = Promise.all([
66
+ registerTask,
67
+ addDataComponentsTask,
68
+ addStyleTask,
69
+ ]).then(() => dataStyleStore.applyDefaultStyle(item.id))
70
+ await Promise.all([
71
+ registerTask,
72
+ addDataTask,
73
+ addDataComponentsTask,
74
+ addTreeviewTask,
75
+ addStyleTask,
76
+ addDataRelationsTask,
77
+ addViewerTask,
78
+ applyStyleTask,
79
+ ])
57
80
  return item.id
58
81
  }
59
82
 
@@ -1,8 +1,8 @@
1
1
  import { Dexie } from "dexie"
2
2
  import { ExtendedDatabase } from "./extended_database"
3
- import { dataTable } from "./tables/data_table"
4
- import { modelComponentsTable } from "./tables/model_components"
3
+ import { dataTable } from "./tables/data"
5
4
  import { modelComponentsRelationTable } from "./tables/model_components_relation"
5
+ import { modelComponentsTable } from "./tables/model_components"
6
6
 
7
7
  class Database extends Dexie {
8
8
  constructor() {
@@ -1,7 +1,7 @@
1
1
  import { Dexie } from "dexie"
2
- import { dataTable } from "./tables/data_table"
3
- import { modelComponentsTable } from "./tables/model_components"
2
+ import { dataTable } from "./tables/data"
4
3
  import { modelComponentsRelationTable } from "./tables/model_components_relation"
4
+ import { modelComponentsTable } from "./tables/model_components"
5
5
 
6
6
  export class ExtendedDatabase extends Dexie {
7
7
  constructor(currentVersion, currentStores, newTables) {
@@ -0,0 +1,5 @@
1
+ export const dataTable = {
2
+ name: "data",
3
+ schema:
4
+ "id, name, viewer_type, geode_object_type, visible, created_at, binary_light_viewable",
5
+ }
@@ -1,4 +1,4 @@
1
1
  export const modelComponentsRelationTable = {
2
2
  name: "model_components_relation",
3
- schema: "[id+parent+child+type], id, parent, child, type",
3
+ schema: "[id+parent+child], type",
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geode/opengeodeweb-front",
3
- "version": "10.5.0",
3
+ "version": "10.5.1",
4
4
  "description": "OpenSource Vue/Nuxt/Pinia/Vuetify framework for web applications",
5
5
  "homepage": "https://github.com/Geode-solutions/OpenGeodeWeb-Front",
6
6
  "bugs": {
@@ -5,4 +5,4 @@
5
5
  # pip-compile --output-file=tests/integration/microservices/back/requirements.txt tests/integration/microservices/back/requirements.in
6
6
  #
7
7
 
8
- opengeodeweb-back==6.*,>=6.3.2
8
+ opengeodeweb-back==6.*,>=6.3.3
@@ -218,10 +218,7 @@ function verifyDataManagement() {
218
218
  )
219
219
  expect(dataStyleStoreMock.applyAllStylesFromState).toHaveBeenCalledWith()
220
220
  expect(dataStoreMock.registerObject).toHaveBeenCalledWith("abc123")
221
- expect(dataStoreMock.addItem).toHaveBeenCalledWith(
222
- "abc123",
223
- expect.anything(),
224
- )
221
+ expect(dataStoreMock.addItem).toHaveBeenCalledWith(snapshotMock.data.items[0])
225
222
  expect(treeviewStoreMock.addItem).toHaveBeenCalledWith(
226
223
  "PointSet2D",
227
224
  "My Data",
@@ -1,4 +0,0 @@
1
- export const dataTable = {
2
- name: "data",
3
- schema: "id, name, viewer_type, geode_object_type, visible, created_at",
4
- }