Skip to content
62 changes: 37 additions & 25 deletions app/stores/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,32 @@ export const useDataStore = defineStore("data", () => {

async function formatedMeshComponents(id) {
const items = await database.model_components.where({ id }).toArray()
const distinctTypes = [...new Set(items.map((item) => item.type))]

const formated_mesh_components = await Promise.all(
distinctTypes.map(async (type) => {
const meshComponents = await database.model_components
.where({ id, type })
.toArray()

return {
id: type,
title: type,
children: meshComponents.map((meshComponent) => ({
id: meshComponent.geode_id,
title: meshComponent.name,
category: meshComponent.type,
})),
}
}),
)
const componentTitles = {
Corner: "Corners",
Line: "Lines",
Surface: "Surfaces",
Block: "Blocks",
}

return formated_mesh_components
const componentsByType = items.reduce((accumulator, item) => {
if (componentTitles[item.type]) {
if (!accumulator[item.type]) accumulator[item.type] = []
accumulator[item.type].push(item)
}
return accumulator
}, {})

return Object.keys(componentTitles)
.filter((type) => componentsByType[type])
.map((type) => ({
id: type,
title: componentTitles[type],
children: componentsByType[type].map((meshComponent) => ({
id: meshComponent.geode_id,
title: meshComponent.name,
category: meshComponent.type,
})),
}))
}

async function meshComponentType(id, geode_id) {
Expand Down Expand Up @@ -109,15 +114,22 @@ export const useDataStore = defineStore("data", () => {
await database.model_components.where({ id }).delete()
}

async function fetchMeshComponents(id) {
async function fetchModelComponents(id) {
const geodeStore = useGeodeStore()
return await geodeStore.request(
back_model_schemas.mesh_components,
back_model_schemas.model_components,
{ id },
{
response_function: async (response) => {
const { mesh_components } = response
await addModelComponents(mesh_components)
const allComponents = [
...response.mesh_components.map(
({ boundaries, internals, ...component }) => component,
),
...response.collection_components.map(
({ items, ...component }) => component,
),
].map((component) => ({ ...component, id }))
await addModelComponents(allComponents)
},
},
)
Expand Down Expand Up @@ -178,7 +190,7 @@ export const useDataStore = defineStore("data", () => {
addItem,
deleteItem,
updateItem,
fetchMeshComponents,
fetchModelComponents,
getCornersGeodeIds,
getLinesGeodeIds,
getSurfacesGeodeIds,
Expand Down
2 changes: 1 addition & 1 deletion app/utils/file_import_workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function importItem(item) {
await dataStyleStore.addDataStyle(item.id, item.geode_object_type)

if (item.viewer_type === "model") {
await dataStore.fetchMeshComponents(item.id)
await dataStore.fetchModelComponents(item.id)
}

await dataStyleStore.applyDefaultStyle(item.id)
Expand Down
2 changes: 1 addition & 1 deletion internal/database/tables/model_components.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const modelComponentsTable = {
name: "model_components",
schema: "[id+geode_id], [id+type], viewer_id, type, name, created_at",
schema: "[id+geode_id], [id+type], viewer_id, name",
}
1 change: 0 additions & 1 deletion tests/integration/microservices/back/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
# pip-compile --output-file=tests/integration/microservices/back/requirements.txt tests/integration/microservices/back/requirements.in
#

opengeodeweb-back==6.*,>=6.1.4rc1
1 change: 0 additions & 1 deletion tests/integration/microservices/viewer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
# pip-compile --output-file=tests/integration/microservices/viewer/requirements.txt tests/integration/microservices/viewer/requirements.in
#

opengeodeweb-viewer==1.*,>=1.15.3
Loading