From b70dd662ff68056b2dfceddef22f9b570941532c Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Thu, 15 Jan 2026 09:22:07 +0100 Subject: [PATCH 01/11] wip useFetch -> $fetch --- app/components/CrsSelector.vue | 2 +- app/components/ExtensionSelector.vue | 2 +- app/components/FileSelector.vue | 2 +- app/components/Inspector/InspectionButton.vue | 2 +- app/components/ObjectSelector.vue | 4 +- app/components/PackagesVersions.vue | 2 +- .../Viewer/Options/CellAttributeSelector.vue | 2 +- .../Options/PolygonAttributeSelector.vue | 2 +- .../Options/PolyhedronAttributeSelector.vue | 3 +- app/components/Viewer/Options/TextureItem.vue | 4 +- .../Options/VertexAttributeSelector.vue | 2 +- app/stores/data.js | 57 ++++++++++++------- app/stores/data_style.js | 2 + app/stores/geode.js | 44 +++++++------- app/stores/lambda.js | 6 +- app/utils/file_import_workflow.js | 7 +-- app/utils/local.js | 6 +- app/utils/upload_file.js | 4 +- internal/database/database.js | 7 ++- internal/database/tables/model_components.js | 4 ++ internal/stores/model/blocks.js | 18 ++++-- internal/stores/model/corners.js | 20 ++++--- internal/stores/model/index.js | 3 + internal/stores/model/lines.js | 12 ++-- internal/stores/model/surfaces.js | 18 ++++-- internal/utils/api_fetch.js | 6 +- .../data_style/model/blocks.nuxt.test.js | 11 ++-- .../data_style/model/corners.nuxt.test.js | 14 +++-- .../data_style/model/lines.nuxt.test.js | 14 +++-- .../data_style/model/surfaces.nuxt.test.js | 8 +-- .../unit/composables/upload_file.nuxt.test.js | 2 +- 31 files changed, 176 insertions(+), 114 deletions(-) create mode 100644 internal/database/tables/model_components.js diff --git a/app/components/CrsSelector.vue b/app/components/CrsSelector.vue index 5d35f627..1bf34f31 100644 --- a/app/components/CrsSelector.vue +++ b/app/components/CrsSelector.vue @@ -70,7 +70,7 @@ toggle_loading() await geodeStore.request(schema, params, { response_function: (response) => { - crs_list.value = response._data.crs_list + crs_list.value = response.crs_list }, }) toggle_loading() diff --git a/app/components/ExtensionSelector.vue b/app/components/ExtensionSelector.vue index e324e9af..64efabe8 100644 --- a/app/components/ExtensionSelector.vue +++ b/app/components/ExtensionSelector.vue @@ -90,7 +90,7 @@ geodeStore.request(schema, params, { request_error_function: () => reject(), response_function: (response) => { - resolve(response._data.geode_objects_and_output_extensions) + resolve(response.geode_objects_and_output_extensions) }, response_error_function: () => reject(), }) diff --git a/app/components/FileSelector.vue b/app/components/FileSelector.vue index 081eeaeb..d3e206ff 100644 --- a/app/components/FileSelector.vue +++ b/app/components/FileSelector.vue @@ -58,7 +58,7 @@ toggle_loading() const geodeStore = useGeodeStore() const response = await geodeStore.request(schema, {}) - accept.value = response.data.value.extensions + accept.value = response.extensions .map((extension) => "." + extension) .join(",") toggle_loading() diff --git a/app/components/Inspector/InspectionButton.vue b/app/components/Inspector/InspectionButton.vue index 00a20435..73c15376 100644 --- a/app/components/Inspector/InspectionButton.vue +++ b/app/components/Inspector/InspectionButton.vue @@ -39,7 +39,7 @@ await geodeStore.request(schema, params, { response_function: (response) => { emit("update_values", { - inspection_result: [response._data.inspection_result], + inspection_result: [response.inspection_result], }) emit("increment_step") }, diff --git a/app/components/ObjectSelector.vue b/app/components/ObjectSelector.vue index e419ae43..27c020f6 100644 --- a/app/components/ObjectSelector.vue +++ b/app/components/ObjectSelector.vue @@ -115,9 +115,7 @@ return geodeStore.request(schema, { filename }) }) const responses = await Promise.all(promise_array) - const allowed_objects_list = responses.map( - (r) => r.data.value.allowed_objects, - ) + const allowed_objects_list = responses.map((r) => r.allowed_objects) const all_keys = [...new Set(allowed_objects_list.flatMap(Object.keys))] const common_keys = all_keys.filter((key) => allowed_objects_list.every((obj) => key in obj), diff --git a/app/components/PackagesVersions.vue b/app/components/PackagesVersions.vue index 6d2b1440..8a98839e 100644 --- a/app/components/PackagesVersions.vue +++ b/app/components/PackagesVersions.vue @@ -35,7 +35,7 @@ {}, { response_function: (response) => { - packages_versions.value = response._data.versions + packages_versions.value = response.versions }, }, ) diff --git a/app/components/Viewer/Options/CellAttributeSelector.vue b/app/components/Viewer/Options/CellAttributeSelector.vue index 19a49234..cd0c3153 100644 --- a/app/components/Viewer/Options/CellAttributeSelector.vue +++ b/app/components/Viewer/Options/CellAttributeSelector.vue @@ -44,7 +44,7 @@ }, { response_function: (response) => { - cell_attribute_names.value = response._data.cell_attribute_names + cell_attribute_names.value = response.cell_attribute_names }, }, ) diff --git a/app/components/Viewer/Options/PolygonAttributeSelector.vue b/app/components/Viewer/Options/PolygonAttributeSelector.vue index efd930c8..0c24c1b6 100644 --- a/app/components/Viewer/Options/PolygonAttributeSelector.vue +++ b/app/components/Viewer/Options/PolygonAttributeSelector.vue @@ -44,7 +44,7 @@ }, { response_function: (response) => { - polygon_attribute_names.value = response._data.polygon_attribute_names + polygon_attribute_names.value = response.polygon_attribute_names }, }, ) diff --git a/app/components/Viewer/Options/PolyhedronAttributeSelector.vue b/app/components/Viewer/Options/PolyhedronAttributeSelector.vue index 6bf2cd27..b4e86a39 100644 --- a/app/components/Viewer/Options/PolyhedronAttributeSelector.vue +++ b/app/components/Viewer/Options/PolyhedronAttributeSelector.vue @@ -46,8 +46,7 @@ { id: props.id }, { response_function: (response) => { - polyhedron_attribute_names.value = - response._data.polyhedron_attribute_names + polyhedron_attribute_names.value = response.polyhedron_attribute_names }, }, ) diff --git a/app/components/Viewer/Options/TextureItem.vue b/app/components/Viewer/Options/TextureItem.vue index 3cd558aa..a1d77878 100644 --- a/app/components/Viewer/Options/TextureItem.vue +++ b/app/components/Viewer/Options/TextureItem.vue @@ -67,7 +67,7 @@ { id: props.id }, { response_function: (response) => { - texture_coordinates.value = response._data.texture_coordinates + texture_coordinates.value = response.texture_coordinates }, }, ) @@ -86,7 +86,7 @@ }, { response_function: async (response) => { - texture_id.value = response._data.id + texture_id.value = response.id }, }, ) diff --git a/app/components/Viewer/Options/VertexAttributeSelector.vue b/app/components/Viewer/Options/VertexAttributeSelector.vue index 39cb021b..3dcc5036 100644 --- a/app/components/Viewer/Options/VertexAttributeSelector.vue +++ b/app/components/Viewer/Options/VertexAttributeSelector.vue @@ -41,7 +41,7 @@ { id: props.id }, { response_function: (response) => { - vertex_attribute_names.value = response._data.vertex_attribute_names + vertex_attribute_names.value = response.vertex_attribute_names }, }, ) diff --git a/app/stores/data.js b/app/stores/data.js index 8f196b64..4f964533 100644 --- a/app/stores/data.js +++ b/app/stores/data.js @@ -96,10 +96,20 @@ export const useDataStore = defineStore("data", () => { await database.data.delete(id) } + async function deleteMeshComponents(id) { + await database.mesh_components.delete(id) + } + async function updateItem(id, changes) { + console.log(updateItem.name, { id, changes }) await database.data.update(id, changes) } + async function updateMeshComponents(id, changes) { + console.log(updateMeshComponents.name, { id, changes }) + await database.mesh_components.update(id, changes) + } + async function fetchMeshComponents(id) { const geodeStore = useGeodeStore() return geodeStore.request( @@ -107,26 +117,29 @@ export const useDataStore = defineStore("data", () => { { id }, { response_function: async (response) => { - const mesh_components = response._data.uuid_dict + console.log(fetchMeshComponents.name, { response }) + const mesh_components = response.uuid_dict await updateItem(id, { mesh_components }) }, }, ) } - async function fetchUuidToFlatIndexDict(id) { - const geodeStore = useGeodeStore() - return geodeStore.request( - back_model_schemas.vtm_component_indices, - { id }, - { - response_function: async (response) => { - const uuid_to_flat_index = response._data.uuid_to_flat_index - await updateItem(id, { uuid_to_flat_index }) - }, - }, - ) - } + // async function fetchUuidToFlatIndexDict(id) { + // console.log(fetchUuidToFlatIndexDict.name, { id }) + // const geodeStore = useGeodeStore() + // return geodeStore.request( + // back_model_schemas.vtm_component_indices, + // { id }, + // { + // response_function: async (response) => { + // console.log(fetchUuidToFlatIndexDict.name, { response }) + // const uuid_to_flat_index = response._data.uuid_to_flat_index + // await updateMeshComponents(id, { uuid_to_flat_index }) + // }, + // }, + // ) + // } async function getCornersUuids(id) { const item = await getItem(id).fetch() @@ -156,17 +169,19 @@ export const useDataStore = defineStore("data", () => { return Object.values(mesh_components["Block"] || {}) } - async function getFlatIndexes(id, mesh_component_ids) { + async function getViewerIndexes(id, mesh_component_ids) { const item = await getItem(id).fetch() + console.log(getViewerIndexes.name, { item }) + // await fetchUuidToFlatIndexDict(id) if (!item || !item.uuid_to_flat_index) return [] const { uuid_to_flat_index } = item - const flat_indexes = [] + const viewer_indexes = [] for (const mesh_component_id of mesh_component_ids) { if (uuid_to_flat_index[mesh_component_id] !== undefined) { - flat_indexes.push(uuid_to_flat_index[mesh_component_id]) + viewer_indexes.push(uuid_to_flat_index[mesh_component_id]) } } - return flat_indexes + return viewer_indexes } async function exportStores() { @@ -191,14 +206,16 @@ export const useDataStore = defineStore("data", () => { deregisterObject, addItem, deleteItem, + deleteMeshComponents, updateItem, - fetchUuidToFlatIndexDict, + updateMeshComponents, + // fetchUuidToFlatIndexDict, fetchMeshComponents, getCornersUuids, getLinesUuids, getSurfacesUuids, getBlocksUuids, - getFlatIndexes, + getViewerIndexes, exportStores, importStores, clear, diff --git a/app/stores/data_style.js b/app/stores/data_style.js index 747a59ac..ee5517ad 100644 --- a/app/stores/data_style.js +++ b/app/stores/data_style.js @@ -31,7 +31,9 @@ export const useDataStyleStore = defineStore("dataStyle", () => { async function applyDefaultStyle(id) { const item = await dataStore.getItem(id).fetch() + console.log("applyDefaultStyle", { item }) const viewer_type = item?.viewer_type + console.log("applyDefaultStyle", { viewer_type }) if (!viewer_type) { throw new Error("Item not found or not loaded: " + id) } diff --git a/app/stores/geode.js b/app/stores/geode.js index 3fb12f48..71d71b0d 100644 --- a/app/stores/geode.js +++ b/app/stores/geode.js @@ -44,33 +44,36 @@ export const useGeodeStore = defineStore("geode", { }, }, actions: { - ping_task() { + set_ping() { + console.log("set_ping") + this.ping() setInterval(() => { - this.do_ping() + this.ping() }, 10 * 1000) }, - do_ping() { + ping() { + console.log("ping") const geodeStore = this const feedbackStore = useFeedbackStore() - return useFetch(back_schemas.opengeodeweb_back.ping.$id, { - baseURL: this.base_url, - method: back_schemas.opengeodeweb_back.ping.methods[0], - body: {}, - onRequestError({ error }) { - feedbackStore.$patch({ server_error: true }) - geodeStore.status = Status.NOT_CONNECTED - }, - onResponse({ response }) { - if (response.ok) { + + return api_fetch( + this, + { schema: back_schemas.opengeodeweb_back.ping }, + { + request_error_function: async () => { + feedbackStore.$patch({ server_error: true }) + geodeStore.status = Status.NOT_CONNECTED + }, + response_function: async () => { feedbackStore.$patch({ server_error: false }) geodeStore.status = Status.CONNECTED - } - }, - onResponseError({ response }) { - feedbackStore.$patch({ server_error: true }) - geodeStore.status = Status.NOT_CONNECTED + }, + response_error_function: async () => { + feedbackStore.$patch({ server_error: true }) + geodeStore.status = Status.NOT_CONNECTED + }, }, - }) + ) }, start_request() { this.request_counter++ @@ -84,7 +87,8 @@ export const useGeodeStore = defineStore("geode", { }, connect() { console.log("[GEODE] Connecting to geode microservice...") - return this.ping_task() + this.set_ping() + return Promise.resolve() }, request(schema, params, callbacks = {}) { console.log("[GEODE] Request:", schema.$id) diff --git a/app/stores/lambda.js b/app/stores/lambda.js index 3064c1cd..4bf30e5a 100644 --- a/app/stores/lambda.js +++ b/app/stores/lambda.js @@ -35,11 +35,11 @@ export const useLambdaStore = defineStore("lambda", { console.log("[LAMBDA] Launching lambda backend...") const feedbackStore = useFeedbackStore() - const { data, error } = await useFetch(this.base_url, { + const { data, error } = await $fetch(this.base_url, { method: "POST", }) - if (error.value || !data.value) { + if (error.value) { this.status = Status.NOT_CONNECTED feedbackStore.server_error = true console.error("[LAMBDA] Failed to launch lambda backend", error.value) @@ -47,7 +47,7 @@ export const useLambdaStore = defineStore("lambda", { } this.status = Status.CONNECTED - const id = data.value.ID + const id = data.ID console.log("[LAMBDA] Lambda launched, ID:", id) return id diff --git a/app/utils/file_import_workflow.js b/app/utils/file_import_workflow.js index 72de3c7b..35346012 100644 --- a/app/utils/file_import_workflow.js +++ b/app/utils/file_import_workflow.js @@ -52,7 +52,7 @@ async function importItem(item) { if (item.viewer_type === "model") { await Promise.all([ dataStore.fetchMeshComponents(item.id), - dataStore.fetchUuidToFlatIndexDict(item.id), + // dataStore.fetchUuidToFlatIndexDict(item.id), ]) } @@ -70,10 +70,7 @@ async function importFile(filename, geode_object_type) { }, ) - const item = buildImportItemFromPayloadApi( - response.data.value, - geode_object_type, - ) + const item = buildImportItemFromPayloadApi(response, geode_object_type) return importItem(item) } diff --git a/app/utils/local.js b/app/utils/local.js index ce34bfc0..71c36322 100644 --- a/app/utils/local.js +++ b/app/utils/local.js @@ -143,7 +143,8 @@ async function run_back( "--allowed_origin http://localhost:*", "--timeout " + 0, ] - if (process.env.NODE_ENV === "development") { + console.log("process.env.NODE_ENV", process.env.NODE_ENV) + if (process.env.NODE_ENV === "development" || !process.env.NODE_ENV) { back_args.push("--debug") } console.log("run_back", executable_name, executable_path, back_args) @@ -169,6 +170,9 @@ async function run_viewer( "--data_folder_path " + args.project_folder_path, "--timeout " + 0, ] + if (process.env.NODE_ENV === "development") { + viewer_args.push("--debug") + } console.log("run_viewer", executable_name, executable_path, viewer_args) await run_script( executable_name, diff --git a/app/utils/upload_file.js b/app/utils/upload_file.js index 28e04518..38f30bc3 100644 --- a/app/utils/upload_file.js +++ b/app/utils/upload_file.js @@ -43,8 +43,8 @@ export async function upload_file( feedbackStore.add_error( response.status, route, - response._data.name, - response._data.description, + response.name, + response.description, ) if (response_error_function) { response_error_function(response) diff --git a/internal/database/database.js b/internal/database/database.js index 8aa65378..a8666e73 100644 --- a/internal/database/database.js +++ b/internal/database/database.js @@ -1,5 +1,6 @@ import Dexie from "dexie" -import { dataTable } from "./tables/data_table.js" +import { dataTable } from "./tables/data_table" +import { modelComponentsTable } from "./tables/model_components" export class Database extends Dexie { constructor() { @@ -7,6 +8,7 @@ export class Database extends Dexie { this.version(1).stores({ [dataTable.name]: dataTable.schema, + [modelComponentsTable.name]: modelComponentsTable.schema, }) } @@ -15,7 +17,7 @@ export class Database extends Dexie { await tempDb.open() if (tempDb.tables.some((t) => t.name === tableName)) { - console.warn(`Table "${tableName}" existe déjà`) + console.warn(`Table "${tableName}" already exists`) tempDb.close() return tempDb } @@ -39,6 +41,7 @@ export class Database extends Dexie { if (v === 1) { this.version(1).stores({ [dataTable.name]: dataTable.schema, + [modelComponentsTable.name]: modelComponentsTable.schema, }) } else { this.version(v).stores(currentStores) diff --git a/internal/database/tables/model_components.js b/internal/database/tables/model_components.js new file mode 100644 index 00000000..834eb7f7 --- /dev/null +++ b/internal/database/tables/model_components.js @@ -0,0 +1,4 @@ +export const modelComponentsTable = { + name: "model_components", + schema: "[id+geode_uuid], viewer_id, type, created_at", +} diff --git a/internal/stores/model/blocks.js b/internal/stores/model/blocks.js index 28f9be1f..b29eb11c 100644 --- a/internal/stores/model/blocks.js +++ b/internal/stores/model/blocks.js @@ -32,13 +32,16 @@ export function useModelBlocksStyle() { modelBlockStyle(id, block_id).visibility = visibility } async function setModelBlocksVisibility(id, block_ids, visibility) { - const blocks_flat_indexes = await dataStore.getFlatIndexes(id, block_ids) - if (blocks_flat_indexes.length === 0) { + const blocks_viewer_indexes = await dataStore.getViewerIndexes( + id, + block_ids, + ) + if (blocks_viewer_indexes.length === 0) { return Promise.resolve() } return viewerStore.request( model_blocks_schemas.visibility, - { id, block_ids: blocks_flat_indexes, visibility }, + { id, block_ids: blocks_viewer_indexes, visibility }, { response_function: () => { for (const block_id of block_ids) { @@ -63,13 +66,16 @@ export function useModelBlocksStyle() { } async function setModelBlocksColor(id, block_ids, color) { - const blocks_flat_indexes = await dataStore.getFlatIndexes(id, block_ids) - if (blocks_flat_indexes.length === 0) { + const blocks_viewer_indexes = await dataStore.getViewerIndexes( + id, + block_ids, + ) + if (blocks_viewer_indexes.length === 0) { return Promise.resolve() } return viewerStore.request( model_blocks_schemas.color, - { id, block_ids: blocks_flat_indexes, color }, + { id, block_ids: blocks_viewer_indexes, color }, { response_function: () => { for (const block_id of block_ids) { diff --git a/internal/stores/model/corners.js b/internal/stores/model/corners.js index c6e402f6..8782c717 100644 --- a/internal/stores/model/corners.js +++ b/internal/stores/model/corners.js @@ -32,13 +32,13 @@ export function useModelCornersStyle() { modelCornerStyle(id, corner_id).visibility = visibility } async function setModelCornersVisibility(id, corner_ids, visibility) { - const corner_flat_indexes = await dataStore.getFlatIndexes(id, corner_ids) - if (corner_flat_indexes.length === 0) { - return Promise.resolve() - } + const corner_viewer_indexes = await dataStore.getViewerIndexes( + id, + corner_ids, + ) return viewerStore.request( model_corners_schemas.visibility, - { id, block_ids: corner_flat_indexes, visibility }, + { id, block_ids: corner_viewer_indexes, visibility }, { response_function: () => { for (const corner_id of corner_ids) { @@ -64,13 +64,17 @@ export function useModelCornersStyle() { } async function setModelCornersColor(id, corner_ids, color) { - const corner_flat_indexes = await dataStore.getFlatIndexes(id, corner_ids) - if (corner_flat_indexes.length === 0) { + const corner_viewer_indexes = await dataStore.getViewerIndexes( + id, + corner_ids, + ) + console.log(setModelCornersColor.name, { corner_viewer_indexes }) + if (corner_viewer_indexes.length === 0) { return Promise.resolve() } return viewerStore.request( model_corners_schemas.color, - { id, block_ids: corner_flat_indexes, color }, + { id, block_ids: corner_viewer_indexes, color }, { response_function: () => { for (const corner_id of corner_ids) { diff --git a/internal/stores/model/index.js b/internal/stores/model/index.js index a2d38a22..35c6fd78 100644 --- a/internal/stores/model/index.js +++ b/internal/stores/model/index.js @@ -134,7 +134,9 @@ export default function useModelStyle() { } function applyModelStyle(id) { + console.log(applyModelStyle.name, { id }) const style = dataStyleStateStore.getStyle(id) + console.log(applyModelStyle.name, { style }) const promise_array = [] for (const [key, value] of Object.entries(style)) { if (key === "visibility") { @@ -155,6 +157,7 @@ export default function useModelStyle() { throw new Error("Unknown model key: " + key) } } + console.log(applyModelStyle.name, { promise_array }) return Promise.all(promise_array) } diff --git a/internal/stores/model/lines.js b/internal/stores/model/lines.js index fb302ff4..20d2d08a 100644 --- a/internal/stores/model/lines.js +++ b/internal/stores/model/lines.js @@ -32,13 +32,13 @@ export function useModelLinesStyle() { modelLineStyle(id, line_id).visibility = visibility } async function setModelLinesVisibility(id, line_ids, visibility) { - const line_flat_indexes = await dataStore.getFlatIndexes(id, line_ids) - if (line_flat_indexes.length === 0) { + const line_viewer_indexes = await dataStore.getViewerIndexes(id, line_ids) + if (line_viewer_indexes.length === 0) { return Promise.resolve() } return viewerStore.request( model_lines_schemas.visibility, - { id, block_ids: line_flat_indexes, visibility }, + { id, block_ids: line_viewer_indexes, visibility }, { response_function: () => { for (const line_id of line_ids) { @@ -62,13 +62,13 @@ export function useModelLinesStyle() { modelLineStyle(id, line_id).color = color } async function setModelLinesColor(id, line_ids, color) { - const line_flat_indexes = await dataStore.getFlatIndexes(id, line_ids) - if (line_flat_indexes.length === 0) { + const line_viewer_indexes = await dataStore.getViewerIndexes(id, line_ids) + if (line_viewer_indexes.length === 0) { return Promise.resolve() } return viewerStore.request( model_lines_schemas.color, - { id, block_ids: line_flat_indexes, color }, + { id, block_ids: line_viewer_indexes, color }, { response_function: () => { for (const line_id of line_ids) { diff --git a/internal/stores/model/surfaces.js b/internal/stores/model/surfaces.js index f50d48fc..23c8b38d 100644 --- a/internal/stores/model/surfaces.js +++ b/internal/stores/model/surfaces.js @@ -31,13 +31,16 @@ export function useModelSurfacesStyle() { modelSurfaceStyle(id, surface_id).visibility = visibility } async function setModelSurfacesVisibility(id, surface_ids, visibility) { - const surface_flat_indexes = await dataStore.getFlatIndexes(id, surface_ids) - if (surface_flat_indexes.length === 0) { + const surface_viewer_indexes = await dataStore.getViewerIndexes( + id, + surface_ids, + ) + if (surface_viewer_indexes.length === 0) { return Promise.resolve() } return viewerStore.request( model_surfaces_schemas.visibility, - { id, block_ids: surface_flat_indexes, visibility }, + { id, block_ids: surface_viewer_indexes, visibility }, { response_function: () => { for (const surface_id of surface_ids) { @@ -61,13 +64,16 @@ export function useModelSurfacesStyle() { } async function setModelSurfacesColor(id, surface_ids, color) { - const surface_flat_indexes = await dataStore.getFlatIndexes(id, surface_ids) - if (surface_flat_indexes.length === 0) { + const surface_viewer_indexes = await dataStore.getViewerIndexes( + id, + surface_ids, + ) + if (surface_viewer_indexes.length === 0) { return Promise.resolve() } return viewerStore.request( model_surfaces_schemas.color, - { id, block_ids: surface_flat_indexes, color }, + { id, block_ids: surface_viewer_indexes, color }, { response_function: () => { for (const surface_id of surface_ids) { diff --git a/internal/utils/api_fetch.js b/internal/utils/api_fetch.js index caa4ba53..75298abc 100644 --- a/internal/utils/api_fetch.js +++ b/internal/utils/api_fetch.js @@ -34,7 +34,7 @@ export function api_fetch( if (schema.max_retry) { request_options.max_retry = schema.max_retry } - return useFetch(schema.$id, { + return $fetch(schema.$id, { baseURL: microservice.base_url, ...request_options, async onRequestError({ error }) { @@ -62,8 +62,8 @@ export function api_fetch( await feedbackStore.add_error( response.status, schema.$id, - response._data.name, - response._data.description, + response.name, + response.description, ) if (response_error_function) { await response_error_function(response) diff --git a/tests/integration/stores/data_style/model/blocks.nuxt.test.js b/tests/integration/stores/data_style/model/blocks.nuxt.test.js index 547f307c..967ccf30 100644 --- a/tests/integration/stores/data_style/model/blocks.nuxt.test.js +++ b/tests/integration/stores/data_style/model/blocks.nuxt.test.js @@ -44,14 +44,17 @@ describe("Model blocks", () => { const viewerStore = useViewerStore() const dataStore = useDataStore() const block_ids = await dataStore.getBlocksUuids(id) - const block_flat_indexes = await dataStore.getFlatIndexes(id, block_ids) + const block_viewer_indexes = await dataStore.getViewerIndexes( + id, + block_ids, + ) const visibility = false const spy = vi.spyOn(viewerStore, "request") spy.mockClear() await dataStyleStore.setModelBlocksVisibility(id, block_ids, visibility) expect(spy).toHaveBeenCalledWith( model_blocks_schemas.visibility, - { id, block_ids: block_flat_indexes, visibility }, + { id, block_ids: block_viewer_indexes, visibility }, { response_function: expect.any(Function), }, @@ -71,13 +74,13 @@ describe("Model blocks", () => { // const viewerStore = useViewerStore() // const dataStore = useDataStore() // const block_ids = await dataStore.getBlocksUuids(id) - // const block_flat_indexes = dataStore.getFlatIndexes(id, block_ids) + // const block_viewer_indexes = dataStore.getViewerIndexes(id, block_ids) // const color = { r: 255, g: 0, b: 0 } // const spy = vi.spyOn(viewerStore, "request") // await dataStyleStore.setModelBlocksColor(id, block_ids, color) // expect(spy).toHaveBeenCalledWith( // model_blocks_schemas.color, - // { id, block_ids: block_flat_indexes, color }, + // { id, block_ids: block_viewer_indexes, color }, // { // response_function: expect.any(Function), // }, diff --git a/tests/integration/stores/data_style/model/corners.nuxt.test.js b/tests/integration/stores/data_style/model/corners.nuxt.test.js index 112454ba..0d77ae13 100644 --- a/tests/integration/stores/data_style/model/corners.nuxt.test.js +++ b/tests/integration/stores/data_style/model/corners.nuxt.test.js @@ -44,14 +44,17 @@ describe("Model corners", () => { const viewerStore = useViewerStore() const dataStore = useDataStore() const corner_ids = await dataStore.getCornersUuids(id) - const corner_flat_indexes = await dataStore.getFlatIndexes(id, corner_ids) + const corner_viewer_indexes = await dataStore.getViewerIndexes( + id, + corner_ids, + ) const visibility = false const spy = vi.spyOn(viewerStore, "request") spy.mockClear() await dataStyleStore.setModelCornersVisibility(id, corner_ids, visibility) expect(spy).toHaveBeenCalledWith( model_corners_schemas.visibility, - { id, block_ids: corner_flat_indexes, visibility }, + { id, block_ids: corner_viewer_indexes, visibility }, { response_function: expect.any(Function), }, @@ -71,14 +74,17 @@ describe("Model corners", () => { const viewerStore = useViewerStore() const dataStore = useDataStore() const corner_ids = await dataStore.getCornersUuids(id) - const corner_flat_indexes = await dataStore.getFlatIndexes(id, corner_ids) + const corner_viewer_indexes = await dataStore.getViewerIndexes( + id, + corner_ids, + ) const color = { r: 255, g: 0, b: 0 } const spy = vi.spyOn(viewerStore, "request") spy.mockClear() await dataStyleStore.setModelCornersColor(id, corner_ids, color) expect(spy).toHaveBeenCalledWith( model_corners_schemas.color, - { id, block_ids: corner_flat_indexes, color }, + { id, block_ids: corner_viewer_indexes, color }, { response_function: expect.any(Function), }, diff --git a/tests/integration/stores/data_style/model/lines.nuxt.test.js b/tests/integration/stores/data_style/model/lines.nuxt.test.js index e7cbc465..12933d60 100644 --- a/tests/integration/stores/data_style/model/lines.nuxt.test.js +++ b/tests/integration/stores/data_style/model/lines.nuxt.test.js @@ -40,14 +40,17 @@ describe("Model lines", () => { const viewerStore = useViewerStore() const dataStore = useDataStore() const line_ids = await dataStore.getLinesUuids(id) - const lines_flat_indexes = await dataStore.getFlatIndexes(id, line_ids) + const lines_viewer_indexes = await dataStore.getViewerIndexes( + id, + line_ids, + ) const visibility = false const spy = vi.spyOn(viewerStore, "request") spy.mockClear() await dataStyleStore.setModelLinesVisibility(id, line_ids, visibility) expect(spy).toHaveBeenCalledWith( model_lines_schemas.visibility, - { id, block_ids: lines_flat_indexes, visibility }, + { id, block_ids: lines_viewer_indexes, visibility }, { response_function: expect.any(Function), }, @@ -65,14 +68,17 @@ describe("Model lines", () => { const viewerStore = useViewerStore() const dataStore = useDataStore() const line_ids = await dataStore.getLinesUuids(id) - const lines_flat_indexes = await dataStore.getFlatIndexes(id, line_ids) + const lines_viewer_indexes = await dataStore.getViewerIndexes( + id, + line_ids, + ) const color = { r: 255, g: 0, b: 0 } const spy = vi.spyOn(viewerStore, "request") spy.mockClear() await dataStyleStore.setModelLinesColor(id, line_ids, color) expect(spy).toHaveBeenCalledWith( model_lines_schemas.color, - { id, block_ids: lines_flat_indexes, color }, + { id, block_ids: lines_viewer_indexes, color }, { response_function: expect.any(Function), }, diff --git a/tests/integration/stores/data_style/model/surfaces.nuxt.test.js b/tests/integration/stores/data_style/model/surfaces.nuxt.test.js index c45afcf8..99229315 100644 --- a/tests/integration/stores/data_style/model/surfaces.nuxt.test.js +++ b/tests/integration/stores/data_style/model/surfaces.nuxt.test.js @@ -44,7 +44,7 @@ describe("Model surfaces", () => { const viewerStore = useViewerStore() const dataStore = useDataStore() const surface_ids = await dataStore.getSurfacesUuids(id) - const surface_flat_indexes = await dataStore.getFlatIndexes( + const surface_viewer_indexes = await dataStore.getViewerIndexes( id, surface_ids, ) @@ -58,7 +58,7 @@ describe("Model surfaces", () => { ) expect(spy).toHaveBeenCalledWith( model_surfaces_schemas.visibility, - { id, block_ids: surface_flat_indexes, visibility }, + { id, block_ids: surface_viewer_indexes, visibility }, { response_function: expect.any(Function), }, @@ -78,7 +78,7 @@ describe("Model surfaces", () => { const viewerStore = useViewerStore() const dataStore = useDataStore() const surface_ids = await dataStore.getSurfacesUuids(id) - const surface_flat_indexes = await dataStore.getFlatIndexes( + const surface_viewer_indexes = await dataStore.getViewerIndexes( id, surface_ids, ) @@ -88,7 +88,7 @@ describe("Model surfaces", () => { await dataStyleStore.setModelSurfacesColor(id, surface_ids, color) expect(spy).toHaveBeenCalledWith( model_surfaces_schemas.color, - { id, block_ids: surface_flat_indexes, color }, + { id, block_ids: surface_viewer_indexes, color }, { response_function: expect.any(Function), }, diff --git a/tests/unit/composables/upload_file.nuxt.test.js b/tests/unit/composables/upload_file.nuxt.test.js index 5f8231b0..f9a8b4e6 100644 --- a/tests/unit/composables/upload_file.nuxt.test.js +++ b/tests/unit/composables/upload_file.nuxt.test.js @@ -43,7 +43,7 @@ describe("upload_file", () => { { route: schema.$id, file }, { response_function: (response) => { - response_value = response._data.test + response_value = response.test }, }, ) From 1ec288c4adb00d1311b6bb7f4e405766aae5dd1c Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Thu, 15 Jan 2026 14:27:25 +0100 Subject: [PATCH 02/11] fix(Models): get geode/viewer_ids from db --- app/stores/data.js | 131 +++++++----------- app/utils/file_import_workflow.js | 5 +- internal/database/tables/model_components.js | 2 +- internal/stores/model/blocks.js | 16 +-- internal/stores/model/corners.js | 15 +- internal/stores/model/lines.js | 22 +-- internal/stores/model/surfaces.js | 16 +-- .../data_style/model/blocks.nuxt.test.js | 12 +- .../data_style/model/corners.nuxt.test.js | 12 +- .../data_style/model/lines.nuxt.test.js | 12 +- .../data_style/model/surfaces.nuxt.test.js | 12 +- 11 files changed, 101 insertions(+), 154 deletions(-) diff --git a/app/stores/data.js b/app/stores/data.js index 4f964533..e0110890 100644 --- a/app/stores/data.js +++ b/app/stores/data.js @@ -44,11 +44,11 @@ export const useDataStore = defineStore("data", () => { const { mesh_components } = item const formated_mesh_components = [] - for (const [category, uuids] of Object.entries(mesh_components)) { + for (const [category, GeodeIds] of Object.entries(mesh_components)) { formated_mesh_components.push({ id: category, title: category, - children: uuids.map((uuid) => ({ + children: GeodeIds.map((uuid) => ({ id: uuid, title: uuid, category, @@ -58,16 +58,8 @@ export const useDataStore = defineStore("data", () => { return formated_mesh_components } - function meshComponentType(id, uuid) { - const item = getItem(id).value - if (!item || !item.mesh_components) return null - const { mesh_components } = item - - if (mesh_components["Corner"]?.includes(uuid)) return "corner" - else if (mesh_components["Line"]?.includes(uuid)) return "line" - else if (mesh_components["Surface"]?.includes(uuid)) return "surface" - else if (mesh_components["Block"]?.includes(uuid)) return "block" - return null + async function meshComponentType(id, geode_id) { + return database.model_components.get({ id, geode_id }) } async function registerObject(id) { @@ -91,23 +83,17 @@ export const useDataStore = defineStore("data", () => { const serializedData = JSON.parse(JSON.stringify(itemData)) await database.data.put(serializedData) } - async function deleteItem(id) { await database.data.delete(id) } - - async function deleteMeshComponents(id) { - await database.mesh_components.delete(id) - } - async function updateItem(id, changes) { console.log(updateItem.name, { id, changes }) await database.data.update(id, changes) } - async function updateMeshComponents(id, changes) { - console.log(updateMeshComponents.name, { id, changes }) - await database.mesh_components.update(id, changes) + async function addModelComponent(value) { + const serializedData = JSON.parse(JSON.stringify(value)) + await database.model_components.put(serializedData) } async function fetchMeshComponents(id) { @@ -117,71 +103,52 @@ export const useDataStore = defineStore("data", () => { { id }, { response_function: async (response) => { - console.log(fetchMeshComponents.name, { response }) - const mesh_components = response.uuid_dict - await updateItem(id, { mesh_components }) + const { mesh_components } = response._data + for (const mesh_component of mesh_components) { + await addModelComponent(mesh_component) + } }, }, ) } - // async function fetchUuidToFlatIndexDict(id) { - // console.log(fetchUuidToFlatIndexDict.name, { id }) - // const geodeStore = useGeodeStore() - // return geodeStore.request( - // back_model_schemas.vtm_component_indices, - // { id }, - // { - // response_function: async (response) => { - // console.log(fetchUuidToFlatIndexDict.name, { response }) - // const uuid_to_flat_index = response._data.uuid_to_flat_index - // await updateMeshComponents(id, { uuid_to_flat_index }) - // }, - // }, - // ) - // } - - async function getCornersUuids(id) { - const item = await getItem(id).fetch() - if (!item || !item.mesh_components) return [] - const { mesh_components } = item - return Object.values(mesh_components["Corner"] || {}) + async function getMeshComponentGeodeIds(id, meshComponentType) { + console.log(getMeshComponentGeodeIds.name, { id, meshComponentType }) + return ( + await database.model_components + .where({ id, type: meshComponentType }) + .toArray() + ).map((component) => component.geode_id) } - async function getLinesUuids(id) { - const item = await getItem(id).fetch() - if (!item || !item.mesh_components) return [] - const { mesh_components } = item - return Object.values(mesh_components["Line"] || {}) + async function getCornersGeodeIds(id) { + console.log(getCornersGeodeIds.name, { id }) + return getMeshComponentGeodeIds(id, "Corner") } - async function getSurfacesUuids(id) { - const item = await getItem(id).fetch() - if (!item || !item.mesh_components) return [] - const { mesh_components } = item - return Object.values(mesh_components["Surface"] || {}) + async function getLinesGeodeIds(id) { + console.log(getLinesGeodeIds.name, { id }) + return getMeshComponentGeodeIds(id, "Line") } - async function getBlocksUuids(id) { - const item = await getItem(id).fetch() - if (!item || !item.mesh_components) return [] - const { mesh_components } = item - return Object.values(mesh_components["Block"] || {}) - } - - async function getViewerIndexes(id, mesh_component_ids) { - const item = await getItem(id).fetch() - console.log(getViewerIndexes.name, { item }) - // await fetchUuidToFlatIndexDict(id) - if (!item || !item.uuid_to_flat_index) return [] - const { uuid_to_flat_index } = item - const viewer_indexes = [] - for (const mesh_component_id of mesh_component_ids) { - if (uuid_to_flat_index[mesh_component_id] !== undefined) { - viewer_indexes.push(uuid_to_flat_index[mesh_component_id]) - } - } - return viewer_indexes + async function getSurfacesGeodeIds(id) { + console.log(getSurfacesGeodeIds.name, { id }) + return getMeshComponentGeodeIds(id, "Surface") + } + + async function getBlocksGeodeIds(id) { + console.log(getBlocksGeodeIds.name, { id }) + return getMeshComponentGeodeIds(id, "Block") + } + + async function getMeshComponentsViewerIds(id, meshComponentGeodeIds) { + return ( + await database.model_components + .where("id") + .equals(id) + .and((component) => meshComponentGeodeIds.includes(component.geode_id)) + .toArray() + ).map((component) => component.viewer_id) } async function exportStores() { @@ -206,16 +173,14 @@ export const useDataStore = defineStore("data", () => { deregisterObject, addItem, deleteItem, - deleteMeshComponents, updateItem, - updateMeshComponents, - // fetchUuidToFlatIndexDict, + addModelComponent, fetchMeshComponents, - getCornersUuids, - getLinesUuids, - getSurfacesUuids, - getBlocksUuids, - getViewerIndexes, + getCornersGeodeIds, + getLinesGeodeIds, + getSurfacesGeodeIds, + getBlocksGeodeIds, + getMeshComponentsViewerIds, exportStores, importStores, clear, diff --git a/app/utils/file_import_workflow.js b/app/utils/file_import_workflow.js index 35346012..09a64e1e 100644 --- a/app/utils/file_import_workflow.js +++ b/app/utils/file_import_workflow.js @@ -50,10 +50,7 @@ async function importItem(item) { await dataStyleStore.addDataStyle(item.id, item.geode_object_type) if (item.viewer_type === "model") { - await Promise.all([ - dataStore.fetchMeshComponents(item.id), - // dataStore.fetchUuidToFlatIndexDict(item.id), - ]) + await dataStore.fetchMeshComponents(item.id) } await dataStyleStore.applyDefaultStyle(item.id) diff --git a/internal/database/tables/model_components.js b/internal/database/tables/model_components.js index 834eb7f7..a260bf5c 100644 --- a/internal/database/tables/model_components.js +++ b/internal/database/tables/model_components.js @@ -1,4 +1,4 @@ export const modelComponentsTable = { name: "model_components", - schema: "[id+geode_uuid], viewer_id, type, created_at", + schema: "[id+geode_id], viewer_id, type, name, created_at", } diff --git a/internal/stores/model/blocks.js b/internal/stores/model/blocks.js index b29eb11c..bc1b92ae 100644 --- a/internal/stores/model/blocks.js +++ b/internal/stores/model/blocks.js @@ -32,16 +32,13 @@ export function useModelBlocksStyle() { modelBlockStyle(id, block_id).visibility = visibility } async function setModelBlocksVisibility(id, block_ids, visibility) { - const blocks_viewer_indexes = await dataStore.getViewerIndexes( + const blocks_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, block_ids, ) - if (blocks_viewer_indexes.length === 0) { - return Promise.resolve() - } return viewerStore.request( model_blocks_schemas.visibility, - { id, block_ids: blocks_viewer_indexes, visibility }, + { id, block_ids: blocks_viewer_ids, visibility }, { response_function: () => { for (const block_id of block_ids) { @@ -66,16 +63,13 @@ export function useModelBlocksStyle() { } async function setModelBlocksColor(id, block_ids, color) { - const blocks_viewer_indexes = await dataStore.getViewerIndexes( + const blocks_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, block_ids, ) - if (blocks_viewer_indexes.length === 0) { - return Promise.resolve() - } return viewerStore.request( model_blocks_schemas.color, - { id, block_ids: blocks_viewer_indexes, color }, + { id, block_ids: blocks_viewer_ids, color }, { response_function: () => { for (const block_id of block_ids) { @@ -95,7 +89,7 @@ export function useModelBlocksStyle() { async function applyModelBlocksStyle(id) { const style = modelBlocksStyle(id) - const blocks_ids = await dataStore.getBlocksUuids(id) + const blocks_ids = await dataStore.getBlocksGeodeIds(id) return Promise.all([ setModelBlocksVisibility(id, blocks_ids, style.visibility), setModelBlocksColor(id, blocks_ids, style.color), diff --git a/internal/stores/model/corners.js b/internal/stores/model/corners.js index 8782c717..e1323f79 100644 --- a/internal/stores/model/corners.js +++ b/internal/stores/model/corners.js @@ -32,13 +32,13 @@ export function useModelCornersStyle() { modelCornerStyle(id, corner_id).visibility = visibility } async function setModelCornersVisibility(id, corner_ids, visibility) { - const corner_viewer_indexes = await dataStore.getViewerIndexes( + const corner_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, corner_ids, ) return viewerStore.request( model_corners_schemas.visibility, - { id, block_ids: corner_viewer_indexes, visibility }, + { id, block_ids: corner_viewer_ids, visibility }, { response_function: () => { for (const corner_id of corner_ids) { @@ -64,17 +64,13 @@ export function useModelCornersStyle() { } async function setModelCornersColor(id, corner_ids, color) { - const corner_viewer_indexes = await dataStore.getViewerIndexes( + const corner_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, corner_ids, ) - console.log(setModelCornersColor.name, { corner_viewer_indexes }) - if (corner_viewer_indexes.length === 0) { - return Promise.resolve() - } return viewerStore.request( model_corners_schemas.color, - { id, block_ids: corner_viewer_indexes, color }, + { id, block_ids: corner_viewer_ids, color }, { response_function: () => { for (const corner_id of corner_ids) { @@ -93,7 +89,8 @@ export function useModelCornersStyle() { async function applyModelCornersStyle(id) { const style = modelCornersStyle(id) - const corner_ids = await dataStore.getCornersUuids(id) + const corner_ids = await dataStore.getCornersGeodeIds(id) + console.log(applyModelCornersStyle.name, { id }, { corner_ids }) return Promise.all([ setModelCornersVisibility(id, corner_ids, style.visibility), setModelCornersColor(id, corner_ids, style.color), diff --git a/internal/stores/model/lines.js b/internal/stores/model/lines.js index 20d2d08a..a8b61ca6 100644 --- a/internal/stores/model/lines.js +++ b/internal/stores/model/lines.js @@ -32,13 +32,13 @@ export function useModelLinesStyle() { modelLineStyle(id, line_id).visibility = visibility } async function setModelLinesVisibility(id, line_ids, visibility) { - const line_viewer_indexes = await dataStore.getViewerIndexes(id, line_ids) - if (line_viewer_indexes.length === 0) { - return Promise.resolve() - } + const line_viewer_ids = await dataStore.getMeshComponentsViewerIds( + id, + line_ids, + ) return viewerStore.request( model_lines_schemas.visibility, - { id, block_ids: line_viewer_indexes, visibility }, + { id, block_ids: line_viewer_ids, visibility }, { response_function: () => { for (const line_id of line_ids) { @@ -62,13 +62,13 @@ export function useModelLinesStyle() { modelLineStyle(id, line_id).color = color } async function setModelLinesColor(id, line_ids, color) { - const line_viewer_indexes = await dataStore.getViewerIndexes(id, line_ids) - if (line_viewer_indexes.length === 0) { - return Promise.resolve() - } + const line_viewer_ids = await dataStore.getMeshComponentsViewerIds( + id, + line_ids, + ) return viewerStore.request( model_lines_schemas.color, - { id, block_ids: line_viewer_indexes, color }, + { id, block_ids: line_viewer_ids, color }, { response_function: () => { for (const line_id of line_ids) { @@ -87,7 +87,7 @@ export function useModelLinesStyle() { async function applyModelLinesStyle(id) { const style = modelLinesStyle(id) - const line_ids = await dataStore.getLinesUuids(id) + const line_ids = await dataStore.getLinesGeodeIds(id) return Promise.all([ setModelLinesVisibility(id, line_ids, style.visibility), setModelLinesColor(id, line_ids, style.color), diff --git a/internal/stores/model/surfaces.js b/internal/stores/model/surfaces.js index 23c8b38d..ee555bf3 100644 --- a/internal/stores/model/surfaces.js +++ b/internal/stores/model/surfaces.js @@ -31,16 +31,13 @@ export function useModelSurfacesStyle() { modelSurfaceStyle(id, surface_id).visibility = visibility } async function setModelSurfacesVisibility(id, surface_ids, visibility) { - const surface_viewer_indexes = await dataStore.getViewerIndexes( + const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, surface_ids, ) - if (surface_viewer_indexes.length === 0) { - return Promise.resolve() - } return viewerStore.request( model_surfaces_schemas.visibility, - { id, block_ids: surface_viewer_indexes, visibility }, + { id, block_ids: surface_viewer_ids, visibility }, { response_function: () => { for (const surface_id of surface_ids) { @@ -64,16 +61,13 @@ export function useModelSurfacesStyle() { } async function setModelSurfacesColor(id, surface_ids, color) { - const surface_viewer_indexes = await dataStore.getViewerIndexes( + const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, surface_ids, ) - if (surface_viewer_indexes.length === 0) { - return Promise.resolve() - } return viewerStore.request( model_surfaces_schemas.color, - { id, block_ids: surface_viewer_indexes, color }, + { id, block_ids: surface_viewer_ids, color }, { response_function: () => { for (const surface_id of surface_ids) { @@ -92,7 +86,7 @@ export function useModelSurfacesStyle() { async function applyModelSurfacesStyle(id) { const style = modelSurfacesStyle(id) - const surface_ids = await dataStore.getSurfacesUuids(id) + const surface_ids = await dataStore.getSurfacesGeodeIds(id) return Promise.all([ setModelSurfacesVisibility(id, surface_ids, style.visibility), setModelSurfacesColor(id, surface_ids, style.color), diff --git a/tests/integration/stores/data_style/model/blocks.nuxt.test.js b/tests/integration/stores/data_style/model/blocks.nuxt.test.js index 967ccf30..965a47ab 100644 --- a/tests/integration/stores/data_style/model/blocks.nuxt.test.js +++ b/tests/integration/stores/data_style/model/blocks.nuxt.test.js @@ -43,8 +43,8 @@ describe("Model blocks", () => { const dataStyleStore = useDataStyleStore() const viewerStore = useViewerStore() const dataStore = useDataStore() - const block_ids = await dataStore.getBlocksUuids(id) - const block_viewer_indexes = await dataStore.getViewerIndexes( + const block_ids = await dataStore.getBlocksGeodeIds(id) + const block_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, block_ids, ) @@ -54,7 +54,7 @@ describe("Model blocks", () => { await dataStyleStore.setModelBlocksVisibility(id, block_ids, visibility) expect(spy).toHaveBeenCalledWith( model_blocks_schemas.visibility, - { id, block_ids: block_viewer_indexes, visibility }, + { id, block_ids: block_viewer_ids, visibility }, { response_function: expect.any(Function), }, @@ -73,14 +73,14 @@ describe("Model blocks", () => { // const dataStyleStore = useDataStyleStore() // const viewerStore = useViewerStore() // const dataStore = useDataStore() - // const block_ids = await dataStore.getBlocksUuids(id) - // const block_viewer_indexes = dataStore.getViewerIndexes(id, block_ids) + // const block_ids = await dataStore.getBlocksGeodeIds(id) + // const block_viewer_ids = dataStore.getMeshComponentsViewerIds(id, block_ids) // const color = { r: 255, g: 0, b: 0 } // const spy = vi.spyOn(viewerStore, "request") // await dataStyleStore.setModelBlocksColor(id, block_ids, color) // expect(spy).toHaveBeenCalledWith( // model_blocks_schemas.color, - // { id, block_ids: block_viewer_indexes, color }, + // { id, block_ids: block_viewer_ids, color }, // { // response_function: expect.any(Function), // }, diff --git a/tests/integration/stores/data_style/model/corners.nuxt.test.js b/tests/integration/stores/data_style/model/corners.nuxt.test.js index 0d77ae13..edb97840 100644 --- a/tests/integration/stores/data_style/model/corners.nuxt.test.js +++ b/tests/integration/stores/data_style/model/corners.nuxt.test.js @@ -43,8 +43,8 @@ describe("Model corners", () => { const dataStyleStore = useDataStyleStore() const viewerStore = useViewerStore() const dataStore = useDataStore() - const corner_ids = await dataStore.getCornersUuids(id) - const corner_viewer_indexes = await dataStore.getViewerIndexes( + const corner_ids = await dataStore.getCornersGeodeIds(id) + const corner_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, corner_ids, ) @@ -54,7 +54,7 @@ describe("Model corners", () => { await dataStyleStore.setModelCornersVisibility(id, corner_ids, visibility) expect(spy).toHaveBeenCalledWith( model_corners_schemas.visibility, - { id, block_ids: corner_viewer_indexes, visibility }, + { id, block_ids: corner_viewer_ids, visibility }, { response_function: expect.any(Function), }, @@ -73,8 +73,8 @@ describe("Model corners", () => { const dataStyleStore = useDataStyleStore() const viewerStore = useViewerStore() const dataStore = useDataStore() - const corner_ids = await dataStore.getCornersUuids(id) - const corner_viewer_indexes = await dataStore.getViewerIndexes( + const corner_ids = await dataStore.getCornersGeodeIds(id) + const corner_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, corner_ids, ) @@ -84,7 +84,7 @@ describe("Model corners", () => { await dataStyleStore.setModelCornersColor(id, corner_ids, color) expect(spy).toHaveBeenCalledWith( model_corners_schemas.color, - { id, block_ids: corner_viewer_indexes, color }, + { id, block_ids: corner_viewer_ids, color }, { response_function: expect.any(Function), }, diff --git a/tests/integration/stores/data_style/model/lines.nuxt.test.js b/tests/integration/stores/data_style/model/lines.nuxt.test.js index 12933d60..346d0235 100644 --- a/tests/integration/stores/data_style/model/lines.nuxt.test.js +++ b/tests/integration/stores/data_style/model/lines.nuxt.test.js @@ -39,8 +39,8 @@ describe("Model lines", () => { const dataStyleStore = useDataStyleStore() const viewerStore = useViewerStore() const dataStore = useDataStore() - const line_ids = await dataStore.getLinesUuids(id) - const lines_viewer_indexes = await dataStore.getViewerIndexes( + const line_ids = await dataStore.getLinesGeodeIds(id) + const lines_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, line_ids, ) @@ -50,7 +50,7 @@ describe("Model lines", () => { await dataStyleStore.setModelLinesVisibility(id, line_ids, visibility) expect(spy).toHaveBeenCalledWith( model_lines_schemas.visibility, - { id, block_ids: lines_viewer_indexes, visibility }, + { id, block_ids: lines_viewer_ids, visibility }, { response_function: expect.any(Function), }, @@ -67,8 +67,8 @@ describe("Model lines", () => { const dataStyleStore = useDataStyleStore() const viewerStore = useViewerStore() const dataStore = useDataStore() - const line_ids = await dataStore.getLinesUuids(id) - const lines_viewer_indexes = await dataStore.getViewerIndexes( + const line_ids = await dataStore.getLinesGeodeIds(id) + const lines_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, line_ids, ) @@ -78,7 +78,7 @@ describe("Model lines", () => { await dataStyleStore.setModelLinesColor(id, line_ids, color) expect(spy).toHaveBeenCalledWith( model_lines_schemas.color, - { id, block_ids: lines_viewer_indexes, color }, + { id, block_ids: lines_viewer_ids, color }, { response_function: expect.any(Function), }, diff --git a/tests/integration/stores/data_style/model/surfaces.nuxt.test.js b/tests/integration/stores/data_style/model/surfaces.nuxt.test.js index 99229315..f1effe97 100644 --- a/tests/integration/stores/data_style/model/surfaces.nuxt.test.js +++ b/tests/integration/stores/data_style/model/surfaces.nuxt.test.js @@ -43,8 +43,8 @@ describe("Model surfaces", () => { const dataStyleStore = useDataStyleStore() const viewerStore = useViewerStore() const dataStore = useDataStore() - const surface_ids = await dataStore.getSurfacesUuids(id) - const surface_viewer_indexes = await dataStore.getViewerIndexes( + const surface_ids = await dataStore.getSurfacesGeodeIds(id) + const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, surface_ids, ) @@ -58,7 +58,7 @@ describe("Model surfaces", () => { ) expect(spy).toHaveBeenCalledWith( model_surfaces_schemas.visibility, - { id, block_ids: surface_viewer_indexes, visibility }, + { id, block_ids: surface_viewer_ids, visibility }, { response_function: expect.any(Function), }, @@ -77,8 +77,8 @@ describe("Model surfaces", () => { const dataStyleStore = useDataStyleStore() const viewerStore = useViewerStore() const dataStore = useDataStore() - const surface_ids = await dataStore.getSurfacesUuids(id) - const surface_viewer_indexes = await dataStore.getViewerIndexes( + const surface_ids = await dataStore.getSurfacesGeodeIds(id) + const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds( id, surface_ids, ) @@ -88,7 +88,7 @@ describe("Model surfaces", () => { await dataStyleStore.setModelSurfacesColor(id, surface_ids, color) expect(spy).toHaveBeenCalledWith( model_surfaces_schemas.color, - { id, block_ids: surface_viewer_indexes, color }, + { id, block_ids: surface_viewer_ids, color }, { response_function: expect.any(Function), }, From ed3e3fdee11a68583e415f123ff0f951e2d476df Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Thu, 15 Jan 2026 17:33:01 +0100 Subject: [PATCH 03/11] fix component treeview --- app/components/Viewer/TreeComponent.vue | 86 +++++-------------------- app/stores/data.js | 28 ++++---- app/stores/geode.js | 1 - internal/stores/model/index.js | 25 +++++-- 4 files changed, 49 insertions(+), 91 deletions(-) diff --git a/app/components/Viewer/TreeComponent.vue b/app/components/Viewer/TreeComponent.vue index b339d67a..a4d721b5 100644 --- a/app/components/Viewer/TreeComponent.vue +++ b/app/components/Viewer/TreeComponent.vue @@ -26,9 +26,9 @@ const props = defineProps({ id: { type: String, required: true } }) - const items = dataStore.formatedMeshComponents(props.id) - const mesh_components_selection = ref( - dataStyleStore.visibleMeshComponents(props.id), + const items = await dataStore.formatedMeshComponents(props.id) + const mesh_components_selection = dataStyleStore.visibleMeshComponents( + props.id, ) watch( @@ -37,79 +37,23 @@ if (!previous) previous = [] else { const { added, removed } = compareSelections(current, previous) - - const [added_corners, added_lines, added_surfaces, added_blocks] = - sortMeshComponents(added) - const [ - removed_corners, - removed_lines, - removed_surfaces, - removed_blocks, - ] = sortMeshComponents(removed) - if (added_corners.length > 0) { - dataStyleStore.setModelCornersVisibility( - props.id, - added_corners, - true, - ) - } - if (added_lines.length > 0) { - dataStyleStore.setModelLinesVisibility(props.id, added_lines, true) - } - if (added_surfaces.length > 0) { - dataStyleStore.setModelSurfacesVisibility( - props.id, - added_surfaces, - true, - ) - } - if (added_blocks.length > 0) { - dataStyleStore.setModelBlocksVisibility(props.id, added_blocks, true) - } - if (removed_corners.length > 0) { - dataStyleStore.setModelCornersVisibility( - props.id, - removed_corners, - false, - ) + if (added.length > 0) { + dataStyleStore + .setModelMeshComponentVisibility(props.id, added, true) + .then(() => { + hybridViewerStore.remoteRender() + }) + } else if (removed.length > 0) { + dataStyleStore + .setModelMeshComponentVisibility(props.id, removed, false) + .then(() => { + hybridViewerStore.remoteRender() + }) } - if (removed_lines.length > 0) { - dataStyleStore.setModelLinesVisibility(props.id, removed_lines, false) - } - if (removed_surfaces.length > 0) { - dataStyleStore.setModelSurfacesVisibility( - props.id, - removed_surfaces, - false, - ) - } - if (removed_blocks.length > 0) { - dataStyleStore.setModelBlocksVisibility( - props.id, - removed_blocks, - false, - ) - } - hybridViewerStore.remoteRender() } }, { immediate: true, deep: true }, ) - - function sortMeshComponents(items) { - var corner_ids = [], - line_ids = [], - surface_ids = [], - block_ids = [] - for (const item of items) { - const item_type = dataStore.meshComponentType(props.id, item) - if (item_type === "corner") corner_ids.push(item) - else if (item_type === "line") line_ids.push(item) - else if (item_type === "surface") surface_ids.push(item) - else if (item_type === "block") block_ids.push(item) - } - return [corner_ids, line_ids, surface_ids, block_ids] - }