Skip to content

Commit 941b3eb

Browse files
committed
Merge branch 'feat/save_and_load' of https://github.com/Geode-solutions/OpenGeodeWeb-Front into feat/save_and_load
2 parents 559702e + d819dee commit 941b3eb

File tree

1 file changed

+112
-115
lines changed

1 file changed

+112
-115
lines changed

composables/project_manager.js

Lines changed: 112 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,31 @@ export function useProjectManager() {
1212
const schema = back_schemas.opengeodeweb_back.export_project
1313
const defaultName = "project.vease"
1414

15-
16-
await infraStore.create_connection()
17-
let downloaded = false
18-
const result = await api_fetch(
19-
{ schema, params: { snapshot, filename: defaultName } },
20-
{
21-
response_function: function (response) {
22-
if (downloaded) return
23-
downloaded = true
24-
const data = response._data
25-
const headerName =
26-
(response.headers &&
27-
typeof response.headers.get === "function" &&
28-
(response.headers
29-
.get("Content-Disposition")
30-
?.match(/filename=\"(.+?)\"/)?.[1] ||
31-
response.headers.get("new-file-name"))) ||
32-
defaultName
33-
if (!headerName.toLowerCase().endsWith(".vease")) {
34-
throw new Error("Server returned non-.vease project archive")
35-
}
36-
fileDownload(data, headerName)
37-
},
15+
await infraStore.create_connection()
16+
let downloaded = false
17+
const result = await api_fetch(
18+
{ schema, params: { snapshot, filename: defaultName } },
19+
{
20+
response_function: function (response) {
21+
if (downloaded) return
22+
downloaded = true
23+
const data = response._data
24+
const headerName =
25+
(response.headers &&
26+
typeof response.headers.get === "function" &&
27+
(response.headers
28+
.get("Content-Disposition")
29+
?.match(/filename=\"(.+?)\"/)?.[1] ||
30+
response.headers.get("new-file-name"))) ||
31+
defaultName
32+
if (!headerName.toLowerCase().endsWith(".vease")) {
33+
throw new Error("Server returned non-.vease project archive")
34+
}
35+
fileDownload(data, headerName)
3836
},
39-
)
40-
return result
41-
37+
},
38+
)
39+
return result
4240
}
4341

4442
const importProjectFile = async function (file) {
@@ -49,96 +47,95 @@ export function useProjectManager() {
4947
const hybridViewerStore = useHybridViewerStore()
5048
const infraStore = useInfraStore()
5149

52-
53-
await infraStore.create_connection()
54-
await viewerStore.ws_connect()
55-
56-
const client = viewerStore.client
57-
if (client && client.getConnection && client.getConnection().getSession) {
58-
await client
59-
.getConnection()
60-
.getSession()
61-
.call("opengeodeweb_viewer.release_database", [{}])
62-
}
63-
64-
await viewer_call({
65-
schema: viewer_schemas.opengeodeweb_viewer.viewer.reset_visualization,
66-
params: {},
67-
})
68-
69-
treeviewStore.clear()
70-
dataBaseStore.clear()
71-
hybridViewerStore.clear()
72-
73-
const schemaImport = back_schemas.opengeodeweb_back.import_project
74-
const form = new FormData()
75-
const originalFileName = file && file.name ? file.name : "project.vease"
76-
if (!originalFileName.toLowerCase().endsWith(".vease")) {
77-
throw new Error("Uploaded file must be a .vease")
50+
await infraStore.create_connection()
51+
await viewerStore.ws_connect()
52+
53+
const client = viewerStore.client
54+
if (client && client.getConnection && client.getConnection().getSession) {
55+
await client
56+
.getConnection()
57+
.getSession()
58+
.call("opengeodeweb_viewer.release_database", [{}])
59+
}
60+
61+
await viewer_call({
62+
schema: viewer_schemas.opengeodeweb_viewer.viewer.reset_visualization,
63+
params: {},
64+
})
65+
66+
treeviewStore.clear()
67+
dataBaseStore.clear()
68+
hybridViewerStore.clear()
69+
70+
const schemaImport = back_schemas.opengeodeweb_back.import_project
71+
const form = new FormData()
72+
const originalFileName = file && file.name ? file.name : "project.vease"
73+
if (!originalFileName.toLowerCase().endsWith(".vease")) {
74+
throw new Error("Uploaded file must be a .vease")
75+
}
76+
form.append("file", file, originalFileName)
77+
78+
const result = await $fetch(schemaImport.$id, {
79+
baseURL: geode.base_url,
80+
method: "POST",
81+
body: form,
82+
})
83+
const snapshot = result && result.snapshot ? result.snapshot : {}
84+
85+
treeviewStore.isImporting = true
86+
87+
const client2 = viewerStore.client
88+
if (
89+
client2 &&
90+
client2.getConnection &&
91+
client2.getConnection().getSession
92+
) {
93+
await client2
94+
.getConnection()
95+
.getSession()
96+
.call("opengeodeweb_viewer.import_project", [{}])
97+
}
98+
99+
await treeviewStore.importStores(snapshot.treeview)
100+
await hybridViewerStore.initHybridViewer()
101+
await hybridViewerStore.importStores(snapshot.hybridViewer)
102+
103+
const snapshotDataBase =
104+
snapshot && snapshot.dataBase && snapshot.dataBase.db
105+
? snapshot.dataBase.db
106+
: {}
107+
const items = Object.entries(snapshotDataBase).map(function (pair) {
108+
const id = pair[0]
109+
const item = pair[1]
110+
const binaryLightViewable =
111+
item && item.vtk_js && item.vtk_js.binary_light_viewable
112+
? item.vtk_js.binary_light_viewable
113+
: undefined
114+
return {
115+
id: id,
116+
object_type: item.object_type,
117+
geode_object: item.geode_object,
118+
native_filename: item.native_filename,
119+
viewable_filename: item.viewable_filename,
120+
displayed_name: item.displayed_name,
121+
vtk_js: { binary_light_viewable: binaryLightViewable },
78122
}
79-
form.append("file", file, originalFileName)
80-
81-
const result = await $fetch(schemaImport.$id, {
82-
baseURL: geode.base_url,
83-
method: "POST",
84-
body: form,
85-
})
86-
const snapshot = result && result.snapshot ? result.snapshot : {}
87-
88-
treeviewStore.isImporting = true
89-
90-
const client2 = viewerStore.client
91-
if (
92-
client2 &&
93-
client2.getConnection &&
94-
client2.getConnection().getSession
95-
) {
96-
await client2
97-
.getConnection()
98-
.getSession()
99-
.call("opengeodeweb_viewer.import_project", [{}])
100-
}
101-
102-
await treeviewStore.importStores(snapshot.treeview)
103-
await hybridViewerStore.initHybridViewer()
104-
await hybridViewerStore.importStores(snapshot.hybridViewer)
105-
106-
const snapshotDataBase =
107-
snapshot && snapshot.dataBase && snapshot.dataBase.db
108-
? snapshot.dataBase.db
109-
: {}
110-
const items = Object.entries(snapshotDataBase).map(function (pair) {
111-
const id = pair[0]
112-
const item = pair[1]
113-
const binaryLightViewable =
114-
item && item.vtk_js && item.vtk_js.binary_light_viewable
115-
? item.vtk_js.binary_light_viewable
116-
: undefined
117-
return {
118-
id: id,
119-
object_type: item.object_type,
120-
geode_object: item.geode_object,
121-
native_filename: item.native_filename,
122-
viewable_filename: item.viewable_filename,
123-
displayed_name: item.displayed_name,
124-
vtk_js: { binary_light_viewable: binaryLightViewable },
125-
}
126-
})
127-
128-
await importWorkflowFromSnapshot(items)
129-
await hybridViewerStore.importStores(snapshot.hybridViewer)
130-
131-
{
132-
const dataStyleStore = useDataStyleStore()
133-
await dataStyleStore.importStores(snapshot.dataStyle)
134-
}
135-
{
136-
const dataStyleStore = useDataStyleStore()
137-
await dataStyleStore.applyAllStylesFromState()
138-
}
139-
140-
treeviewStore.finalizeImportSelection()
141-
treeviewStore.isImporting = false
123+
})
124+
125+
await importWorkflowFromSnapshot(items)
126+
await hybridViewerStore.importStores(snapshot.hybridViewer)
127+
128+
{
129+
const dataStyleStore = useDataStyleStore()
130+
await dataStyleStore.importStores(snapshot.dataStyle)
131+
}
132+
{
133+
const dataStyleStore = useDataStyleStore()
134+
await dataStyleStore.applyAllStylesFromState()
135+
}
136+
137+
treeviewStore.finalizeImportSelection()
138+
treeviewStore.isImporting = false
142139
}
143140

144141
return { exportProject, importProjectFile }

0 commit comments

Comments
 (0)