-
Notifications
You must be signed in to change notification settings - Fork 2
feat(save_and_load): add import/export methods #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 79 commits
aa86c91
5b2b4f3
f4ef491
5f3e0c6
e6c54b5
01a9732
0b70454
d577721
df419ec
bb9d02d
a93225c
af41f9d
ea63e2b
97072b5
63464b7
98991cf
6321c8f
35c75dd
22a67fe
caf5a39
18fc885
d4a1cd6
8aec8b8
6a282e4
196be52
fdf547e
c208b30
3ef456f
2ca553b
9fd6c0b
3806d54
3d04f42
24eb5b6
9866872
f01890f
344a873
019fcd4
e512f73
f3140b6
e251104
dbf0a99
a5b1ebf
63f07e2
b1a9353
7b57603
9ae7357
1535343
bbfc846
f6c1304
16b61de
bb5a485
779fbf9
2ad8f46
fdaca90
0802579
769c481
597ca03
5658e72
9eda52e
b686f44
7812125
e23b7e7
57e13f3
2375805
6c3c9cf
6136cde
eecd8b7
328eb14
0398bfe
7d392c0
5f65391
a1725f8
f6e73f2
309b5f4
cdbee18
7ab0049
7a0e43e
9954c87
933cb71
e0cf657
2f464bb
44a70fe
499fc4b
c0df47c
fca8a2a
28abd57
c156eab
e6d2c43
17607da
9853aab
5232228
6a61874
6e67d32
74d2ab5
5334a81
1ad0cae
a9222e8
c58d78d
f20ac1a
16a5aa9
10dcaad
c2859b1
dde3190
b213a23
edc66de
2c53c79
32611bb
3d89884
4978f96
60ef7d1
fb2818a
b53db94
4a88bda
c0419f9
bb9f00c
a8cc6a5
85bc68d
d88b39e
7ec0d6d
2811ff0
2707dc1
6972216
9b0efaf
d54d359
51a3ee9
fd9a30e
e5a95be
70afca8
f06c643
4f6941b
63c01a2
e60ef39
2e15441
6229593
522151b
47bb68b
59da2c4
2235337
5ecfd72
d819dee
559702e
941b3eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" | ||
| import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" | ||
| import fileDownload from "js-file-download" | ||
|
|
||
| export function useProjectManager() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| const geode = useGeodeStore() | ||
| const appStore = useAppStore() | ||
|
|
||
| async function exportProject() { | ||
| geode.start_request() | ||
MaxNumerique marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| await useInfraStore().create_connection() | ||
| const snapshot = appStore.exportStores() | ||
| const schema = back_schemas.opengeodeweb_back.export_project | ||
| const defaultName = "project.zip" | ||
|
|
||
| await api_fetch( | ||
| { schema, params: { snapshot, filename: defaultName } }, | ||
| { | ||
| response_function: async (response) => { | ||
| const data = response._data | ||
| const downloadName = | ||
MaxNumerique marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| response.headers?.get?.("new-file-name") || defaultName | ||
| fileDownload(data, downloadName) | ||
| }, | ||
| }, | ||
| ) | ||
| } finally { | ||
| geode.stop_request() | ||
| } | ||
| } | ||
|
|
||
| async function importProjectFile(file) { | ||
| geode.start_request() | ||
MaxNumerique marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| await useInfraStore().create_connection() | ||
|
|
||
| const schemaImport = back_schemas.opengeodeweb_back.import_project | ||
| const form = new FormData() | ||
| form.append("file", file, file?.name) | ||
|
|
||
| const result = await $fetch(schemaImport.$id, { | ||
| baseURL: geode.base_url, | ||
| method: "POST", | ||
| body: form, | ||
| }) | ||
| const snapshot = result?.snapshot ?? {} | ||
|
|
||
| await viewer_call({ | ||
| schema: viewer_schemas.opengeodeweb_viewer.import_project, | ||
| params: {}, | ||
| }) | ||
| await viewer_call({ | ||
| schema: viewer_schemas.opengeodeweb_viewer.viewer.reset_visualization, | ||
| params: {}, | ||
| }) | ||
|
|
||
| const treeviewStore = useTreeviewStore() | ||
| treeviewStore.isImporting = true | ||
| await treeviewStore.importStores(snapshot?.treeview) | ||
|
|
||
| const hybridViewerStore = useHybridViewerStore() | ||
| await hybridViewerStore.initHybridViewer() | ||
| hybridViewerStore.clear() | ||
| await hybridViewerStore.importStores(snapshot?.hybridViewer) | ||
|
|
||
| const snapshotDataBase = snapshot?.dataBase?.db || {} | ||
| const items = Object.entries(snapshotDataBase).map(([id, item]) => ({ | ||
| id, | ||
| object_type: item.object_type, | ||
| geode_object: item.geode_object, | ||
| native_filename: item.native_filename, | ||
| viewable_filename: item.viewable_filename, | ||
| displayed_name: item.displayed_name, | ||
| vtk_js: { binary_light_viewable: item?.vtk_js?.binary_light_viewable }, | ||
| })) | ||
|
|
||
| await importWorkflowFromSnapshot(items) | ||
|
|
||
| // Appliquer la caméra importée après avoir créé les actors | ||
| await hybridViewerStore.importStores(snapshot?.hybridViewer) | ||
|
|
||
| const dataStyleStore = useDataStyleStore() | ||
| await dataStyleStore.importStores(snapshot?.dataStyle) | ||
| await dataStyleStore.applyAllStylesFromState() | ||
|
|
||
| treeviewStore.finalizeImportSelection() | ||
| treeviewStore.isImporting = false | ||
| } finally { | ||
| geode.stop_request() | ||
| } | ||
| } | ||
|
|
||
| return { exportProject, importProjectFile } | ||
| } | ||
|
|
||
| export default useProjectManager | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,81 +5,72 @@ export const useAppStore = defineStore("app", () => { | |
| const isAlreadyRegistered = stores.some( | ||
| (registeredStore) => registeredStore.$id === store.$id, | ||
| ) | ||
|
|
||
| if (isAlreadyRegistered) { | ||
| console.log( | ||
| `[AppStore] Store "${store.$id}" already registered, skipping`, | ||
| ) | ||
| return | ||
| } | ||
|
|
||
| console.log("[AppStore] Registering store", store.$id) | ||
| stores.push(store) | ||
| } | ||
|
|
||
| function save() { | ||
| function exportStores() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| const snapshot = {} | ||
| let savedCount = 0 | ||
| let exportCount = 0 | ||
|
|
||
| for (const store of stores) { | ||
| if (!store.save) { | ||
| continue | ||
| } | ||
| if (!store.exportStores) continue | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| const storeId = store.$id | ||
| try { | ||
| snapshot[storeId] = store.save() | ||
| savedCount++ | ||
| snapshot[storeId] = store.exportStores() | ||
| exportCount++ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| } catch (error) { | ||
| console.error(`[AppStore] Error saving store "${storeId}":`, error) | ||
| console.error(`[AppStore] Error exporting store "${storeId}":`, error) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| } | ||
| } | ||
|
|
||
| console.log(`[AppStore] Saved ${savedCount} stores`) | ||
| console.log( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| `[AppStore] Exported ${exportCount} stores; snapshot keys:`, | ||
| Object.keys(snapshot), | ||
| ) | ||
| return snapshot | ||
| } | ||
|
|
||
| function load(snapshot) { | ||
| async function importStores(snapshot) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| if (!snapshot) { | ||
| console.warn("[AppStore] load called with invalid snapshot") | ||
| console.warn("[AppStore] import called with invalid snapshot") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| return | ||
| } | ||
| console.log("[AppStore] Import snapshot keys:", Object.keys(snapshot || {})) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
|
|
||
| let loadedCount = 0 | ||
| let importedCount = 0 | ||
| const notFoundStores = [] | ||
|
|
||
| for (const store of stores) { | ||
| if (!store.load) { | ||
| continue | ||
| } | ||
|
|
||
| if (!store.importStores) continue | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| const storeId = store.$id | ||
|
|
||
| if (!snapshot[storeId]) { | ||
| notFoundStores.push(storeId) | ||
| continue | ||
| } | ||
|
|
||
| try { | ||
| store.load(snapshot[storeId]) | ||
| loadedCount++ | ||
| await store.importStores(snapshot[storeId]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| importedCount++ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| } catch (error) { | ||
| console.error(`[AppStore] Error loading store "${storeId}":`, error) | ||
| console.error(`[AppStore] Error importing store "${storeId}":`, error) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| } | ||
| } | ||
|
|
||
| if (notFoundStores.length > 0) { | ||
| console.warn( | ||
| `[AppStore] Stores not found in snapshot: ${notFoundStores.join(", ")}`, | ||
| ) | ||
| } | ||
|
|
||
| console.log(`[AppStore] Loaded ${loadedCount} stores`) | ||
| console.log(`[AppStore] Imported ${importedCount} stores`) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| } | ||
|
|
||
| return { | ||
| stores, | ||
| registerStore, | ||
| save, | ||
| load, | ||
| exportStores, | ||
| importStores, | ||
| } | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,9 @@ export const useDataBaseStore = defineStore("dataBase", () => { | |
| }) | ||
| } | ||
|
|
||
| const treeviewStore = useTreeviewStore() | ||
| const hybridViewerStore = useHybridViewerStore() | ||
|
|
||
| async function addItem( | ||
| id, | ||
| value = { | ||
|
|
@@ -59,7 +62,17 @@ export const useDataBaseStore = defineStore("dataBase", () => { | |
| vtk_js: { binary_light_viewable }, | ||
| }, | ||
| ) { | ||
| console.log("[DataBase] addItem start", { | ||
| id, | ||
| object_type: value.object_type, | ||
| geode_object: value.geode_object, | ||
| }) | ||
| db[id] = value | ||
|
|
||
| if (value.object_type === "model") { | ||
| await fetchMeshComponents(id) | ||
| await fetchUuidToFlatIndexDict(id) | ||
| } | ||
| } | ||
|
|
||
| async function fetchMeshComponents(id) { | ||
|
|
@@ -93,6 +106,37 @@ export const useDataBaseStore = defineStore("dataBase", () => { | |
| ) | ||
| } | ||
|
|
||
| function exportStores() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| const snapshotDb = {} | ||
| for (const [id, item] of Object.entries(db)) { | ||
| if (!item) continue | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| snapshotDb[id] = { | ||
| object_type: item.object_type, | ||
| geode_object: item.geode_object, | ||
| native_filename: item.native_filename, | ||
| viewable_filename: item.viewable_filename, | ||
| displayed_name: item.displayed_name, | ||
| vtk_js: { | ||
| binary_light_viewable: item?.vtk_js?.binary_light_viewable, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| }, | ||
| } | ||
| } | ||
| return { db: snapshotDb } | ||
| } | ||
|
|
||
| async function importStores(snapshot) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| await hybridViewerStore.initHybridViewer() | ||
| hybridViewerStore.clear() | ||
| console.log( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| "[DataBase] importStores entries:", | ||
| Object.keys(snapshot?.db || {}), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| ) | ||
| for (const [id, item] of Object.entries(snapshot?.db || {})) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| await registerObject(id) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| await addItem(id, item) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| } | ||
| } | ||
|
|
||
| function getCornersUuids(id) { | ||
| const { mesh_components } = itemMetaDatas(id) | ||
| return Object.values(mesh_components["Corner"]) | ||
|
|
@@ -134,5 +178,7 @@ export const useDataBaseStore = defineStore("dataBase", () => { | |
| getSurfacesUuids, | ||
| getBlocksUuids, | ||
| getFlatIndexes, | ||
| exportStores, | ||
| importStores, | ||
| } | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import useDataStyleState from "../internal_stores/data_style_state.js" | ||
| import useMeshStyle from "../internal_stores/mesh/index.js" | ||
| import useModelStyle from "../internal_stores/model/index.js" | ||
| import { defineStore } from "pinia" | ||
| import { useDataBaseStore } from "./data_base.js" | ||
|
|
||
| export const useDataStyleStore = defineStore("dataStyle", () => { | ||
| const dataStyleState = useDataStyleState() | ||
|
|
@@ -13,11 +15,12 @@ export const useDataStyleStore = defineStore("dataStyle", () => { | |
| } | ||
|
|
||
| function setVisibility(id, visibility) { | ||
| console.log( | ||
| "dataBaseStore.itemMetaDatas(id)", | ||
| dataBaseStore.itemMetaDatas(id), | ||
| ) | ||
| const object_type = dataBaseStore.itemMetaDatas(id).object_type | ||
| const meta = dataBaseStore.itemMetaDatas(id) | ||
| if (!meta) { | ||
| console.warn("[DataStyle] setVisibility skipped: unknown id", id) | ||
| return Promise.resolve([]) | ||
| } | ||
| const object_type = meta.object_type | ||
| if (object_type === "mesh") { | ||
| return Promise.all([meshStyleStore.setMeshVisibility(id, visibility)]) | ||
| } else if (object_type === "model") { | ||
|
|
@@ -32,8 +35,43 @@ export const useDataStyleStore = defineStore("dataStyle", () => { | |
| return meshStyleStore.applyMeshStyle(id) | ||
| } else if (object_type === "model") { | ||
| return modelStyleStore.applyModelStyle(id) | ||
| } else { | ||
| throw new Error("Unknown object_type: " + object_type) | ||
| } | ||
| return Promise.resolve([]) | ||
| } | ||
|
|
||
| function setModelEdgesVisibility(id, visibility) { | ||
| return modelStyleStore.setModelEdgesVisibility(id, visibility) | ||
| } | ||
|
|
||
| function modelEdgesVisibility(id) { | ||
| return modelStyleStore.modelEdgesVisibility(id) | ||
| } | ||
|
|
||
| function exportStores() { | ||
| return { styles: dataStyleState.styles } | ||
| } | ||
|
|
||
| async function importStores(snapshot) { | ||
| const stylesSnapshot = snapshot?.styles || {} | ||
| for (const id of Object.keys(dataStyleState.styles)) | ||
| delete dataStyleState.styles[id] | ||
| for (const [id, style] of Object.entries(stylesSnapshot)) { | ||
| dataStyleState.styles[id] = style | ||
| } | ||
| } | ||
|
|
||
| async function applyAllStylesFromState() { | ||
| const ids = Object.keys(dataStyleState.styles || {}) | ||
| for (const id of ids) { | ||
| const meta = dataBaseStore.itemMetaDatas(id) | ||
| const objectType = meta?.object_type | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reported by reviewdog 🐶 |
||
| const style = dataStyleState.styles[id] | ||
| if (!style || !objectType) continue | ||
| if (objectType === "mesh") { | ||
| await meshStyleStore.applyMeshStyle(id) | ||
| } else if (objectType === "model") { | ||
| await modelStyleStore.applyModelStyle(id) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -44,5 +82,10 @@ export const useDataStyleStore = defineStore("dataStyle", () => { | |
| addDataStyle, | ||
| applyDefaultStyle, | ||
| setVisibility, | ||
| setModelEdgesVisibility, | ||
| modelEdgesVisibility, | ||
| exportStores, | ||
| importStores, | ||
| applyAllStylesFromState, | ||
| } | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JulienChampagnol que penses tu de cette proposition ?