-
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
base: next
Are you sure you want to change the base?
Changes from 66 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
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,93 @@ | ||
| 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" | ||
|
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 🐶 |
||
|
|
||
| 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() { | ||
|
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 🐶 |
||
| geode.start_request() | ||
| 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) => { | ||
|
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 data = response._data | ||
| const downloadName = | ||
MaxNumerique marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| response.headers?.get?.("new-file-name") || defaultName | ||
|
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 🐶 |
||
| fileDownload(data, downloadName) | ||
| }, | ||
| }, | ||
| ) | ||
| } finally { | ||
| geode.stop_request() | ||
| } | ||
| } | ||
|
|
||
| async function importProjectFile(file) { | ||
|
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 🐶 |
||
| geode.start_request() | ||
| try { | ||
| await useInfraStore().create_connection() | ||
|
|
||
| const schemaImport = back_schemas.opengeodeweb_back.import_project | ||
| const form = new FormData() | ||
| form.append("file", file, file?.name) | ||
|
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 result = await $fetch(schemaImport.$id, { | ||
| baseURL: geode.base_url, | ||
| method: "POST", | ||
| body: form, | ||
| }) | ||
| const snapshot = result?.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 🐶 |
||
|
|
||
| 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) | ||
|
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 hybridViewerStore = useHybridViewerStore() | ||
| await hybridViewerStore.initHybridViewer() | ||
| hybridViewerStore.clear() | ||
|
|
||
| const snapshotDataBase = snapshot?.dataBase?.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 🐶 |
||
| 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 }, | ||
|
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 importWorkflowFromSnapshot(items) | ||
|
|
||
| const dataStyleStore = useDataStyleStore() | ||
| await dataStyleStore.importStores(snapshot?.dataStyle) | ||
|
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 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() | ||
|
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 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", { | ||
|
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 🐶 |
||
| 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() { | ||
| const snapshotDb = {} | ||
| for (const [id, item] of Object.entries(db)) { | ||
| if (!item) continue | ||
| 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, | ||
| }, | ||
| } | ||
| } | ||
| return { db: snapshotDb } | ||
| } | ||
|
|
||
| async function importStores(snapshot) { | ||
| await hybridViewerStore.initHybridViewer() | ||
| hybridViewerStore.clear() | ||
| console.log( | ||
| "[DataBase] importStores entries:", | ||
| Object.keys(snapshot?.db || {}), | ||
| ) | ||
| for (const [id, item] of Object.entries(snapshot?.db || {})) { | ||
| await registerObject(id) | ||
| await addItem(id, item) | ||
| } | ||
| } | ||
|
|
||
| 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, | ||
| } | ||
| }) | ||
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 ?