-
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
Open
MaxNumerique
wants to merge
27
commits into
next
Choose a base branch
from
feat/save_and_load
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
aa86c91
feat(save_and_load): add save/load methods to all stores for project …
MaxNumerique 5b2b4f3
Apply prepare changes
MaxNumerique f4ef491
cartStore becomes geodeStore
MaxNumerique 5f3e0c6
Merge branch 'feat/save_and_load' of https://github.com/Geode-solutio…
MaxNumerique e6c54b5
Apply prepare changes
MaxNumerique 01a9732
renames and move tests
MaxNumerique 0b70454
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWe…
MaxNumerique d577721
persist upload folder
MaxNumerique df419ec
renamed app_store store to app
MaxNumerique bb9d02d
rm unused var
MaxNumerique a93225c
importStore & exportStore refacto
MaxNumerique af41f9d
Apply prepare changes
MaxNumerique ea63e2b
testes with import/export
MaxNumerique 97072b5
Merge branch 'feat/save_and_load' of https://github.com/Geode-solutio…
MaxNumerique 63464b7
Apply prepare changes
MaxNumerique 98991cf
test
MaxNumerique 6321c8f
Merge branch 'feat/save_and_load' of https://github.com/Geode-solutio…
MaxNumerique 35c75dd
Apply prepare changes
MaxNumerique 22a67fe
test
MaxNumerique caf5a39
Merge branch 'feat/save_and_load' of https://github.com/Geode-solutio…
MaxNumerique 18fc885
Apply prepare changes
MaxNumerique d4a1cd6
exportStores/importStores and createTestingPinia
MaxNumerique 8aec8b8
Apply prepare changes
MaxNumerique 6a282e4
export working
MaxNumerique 196be52
Merge branch 'feat/save_and_load' of https://github.com/Geode-solutio…
MaxNumerique fdf547e
nothing appear in camera
MaxNumerique c208b30
Apply prepare changes
MaxNumerique File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" | ||
| import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" | ||
|
|
||
| export function useProjectManager() { | ||
| const appStore = useAppStore() | ||
| const geode = useGeodeStore() | ||
|
|
||
| async function exportProject() { | ||
| geode.start_request() | ||
| try { | ||
| await useInfraStore().create_connection() | ||
| const snapshot = appStore.exportStores() | ||
|
|
||
| const schema = back_schemas.opengeodeweb_back.project.export_project | ||
| const url = `${geode.base_url}${schema.$id}` | ||
| const method = schema.methods[0] | ||
|
|
||
| const response = await fetch(url, { | ||
|
||
| method, | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ snapshot }), | ||
| }) | ||
| if (!response.ok) { | ||
| throw new Error(`Export failed: ${response.statusText}`) | ||
| } | ||
| const blob = await response.blob() | ||
| const filename = response.headers.get("new-file-name") | ||
| const urlObject = URL.createObjectURL(blob) | ||
| const a = document.createElement("a") | ||
| a.href = urlObject | ||
|
||
| a.download = filename | ||
| a.click() | ||
| URL.revokeObjectURL(urlObject) | ||
| } finally { | ||
| geode.stop_request() | ||
| } | ||
| } | ||
|
|
||
| async function importProjectFile(file) { | ||
| geode.start_request() | ||
| try { | ||
| const snapshot = JSON.parse(await file.text()) | ||
| await useInfraStore().create_connection() | ||
|
|
||
| await viewer_call({ | ||
| schema: viewer_schemas.opengeodeweb_viewer.utils.import_project, | ||
| params: {}, | ||
| }) | ||
| await viewer_call({ | ||
| schema: viewer_schemas.opengeodeweb_viewer.viewer.reset_visualization, | ||
| params: {}, | ||
| }) | ||
|
|
||
| await appStore.importStores(snapshot) | ||
| } finally { | ||
| geode.stop_request() | ||
| } | ||
| } | ||
|
|
||
| return { exportProject, importProjectFile } | ||
| } | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { beforeEach, describe, expect, test, vi } from "vitest" | ||
| import { setActivePinia } from "pinia" | ||
| import { createTestingPinia } from "@pinia/testing" | ||
| import { useProjectManager } from "@/composables/project_manager.js" | ||
|
|
||
| // Mocks | ||
| const mockAppStore = { | ||
| exportStores: vi.fn(() => ({ projectName: "mockedProject" })), | ||
| importStores: vi.fn(), | ||
| } | ||
| const mockInfraStore = { create_connection: vi.fn() } | ||
|
|
||
| vi.mock("@/stores/app.js", () => ({ useAppStore: () => mockAppStore })) | ||
| vi.mock("@ogw_f/stores/infra", () => ({ useInfraStore: () => mockInfraStore })) | ||
| vi.mock("@/composables/viewer_call.js", () => ({ | ||
| viewer_call: vi.fn(), | ||
| })) | ||
|
|
||
| beforeEach(async () => { | ||
| const pinia = createTestingPinia({ | ||
| stubActions: false, | ||
| createSpy: vi.fn, | ||
| }) | ||
| setActivePinia(pinia) | ||
| const geode_store = useGeodeStore() | ||
| await geode_store.$reset() | ||
| geode_store.base_url = "" | ||
| }) | ||
|
|
||
| vi.mock("@geode/opengeodeweb-back/opengeodeweb_back_schemas.json", () => ({ | ||
| default: { | ||
| opengeodeweb_back: { | ||
| project: { | ||
| export_project: { $id: "/project/export_project", methods: ["POST"] }, | ||
| }, | ||
| }, | ||
| }, | ||
| })) | ||
| vi.mock("@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json", () => ({ | ||
| default: { | ||
| opengeodeweb_viewer: { | ||
| utils: { import_project: { rpc: "utils.import_project" } }, | ||
| viewer: { reset_visualization: { rpc: "viewer.reset_visualization" } }, | ||
| }, | ||
| }, | ||
| })) | ||
|
|
||
| describe("ProjectManager composable", () => { | ||
| test("exportProject triggers download", async () => { | ||
| const clickSpy = vi | ||
| .spyOn(HTMLAnchorElement.prototype, "click") | ||
| .mockImplementation(() => {}) | ||
| vi.spyOn(URL, "createObjectURL").mockReturnValue("blob:url") | ||
| vi.spyOn(URL, "revokeObjectURL").mockImplementation(() => {}) | ||
| const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue({ | ||
| ok: true, | ||
| blob: async () => new Blob(["zipcontent"], { type: "application/zip" }), | ||
| headers: { get: () => 'attachment; filename="project_123.zip"' }, | ||
| statusText: "OK", | ||
| }) | ||
|
|
||
| const { exportProject } = useProjectManager() | ||
| await exportProject() | ||
|
|
||
| const app_store = useAppStore() | ||
| expect(app_store.exportStores).toHaveBeenCalled() | ||
| expect(fetchSpy).toHaveBeenCalledTimes(1) | ||
| expect(clickSpy).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| test("importProjectFile loads snapshot", async () => { | ||
| const { importProjectFile } = useProjectManager() | ||
|
|
||
| const file = { text: () => Promise.resolve('{"dataBase":{"db":{}}}') } | ||
| await importProjectFile(file) | ||
|
|
||
| const infra_store = useInfraStore() | ||
| const app_store = useAppStore() | ||
| const { viewer_call } = await import("@/composables/viewer_call.js") | ||
|
|
||
| expect(infra_store.create_connection).toHaveBeenCalled() | ||
| expect(viewer_call).toHaveBeenCalled() | ||
| expect(app_store.importStores).toHaveBeenCalled() | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ?