From 074aebfb476a74bb9fbc2dce3fbab7ae01aa4e33 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Thu, 19 Mar 2026 14:11:07 +0100 Subject: [PATCH 01/11] fix(oxlint): pedantic oxlint rules support --- .oxlintrc.json | 80 +++-- app/stores/app.js | 264 +++++++------- app/stores/feedback.js | 37 +- app/stores/geode.js | 115 +++--- app/stores/hybrid_viewer.js | 338 +++++++++--------- app/stores/infra.js | 100 +++--- app/stores/lambda.js | 52 +-- app/stores/treeview.js | 122 +++---- app/stores/viewer.js | 7 +- app/utils/local/microservices.js | 6 +- app/utils/local/path.js | 72 ++-- app/utils/server.js | 45 ++- internal/database/database.js | 11 +- .../stores/data_style/mesh/cells/index.js | 84 ++--- .../stores/data_style/mesh/edges/index.js | 90 ++--- .../stores/data_style/mesh/points/index.js | 84 ++--- .../stores/data_style/mesh/polygons/index.js | 81 ++--- .../stores/data_style/mesh/polyhedra/index.js | 71 ++-- internal/stores/data_style/model/index.js | 184 +++++----- internal/utils/upload_file.js | 43 +-- server/api/extensions/upload.put.js | 110 +++--- .../stores/data_style/mesh/cells.nuxt.test.js | 206 +++++------ .../data_style/model/surfaces.nuxt.test.js | 139 +++---- tests/integration/stores/viewer.nuxt.test.js | 73 ++-- .../components/FeedBack/Snackers.nuxt.test.js | 36 +- .../unit/components/FileSelector.nuxt.test.js | 116 +++--- .../unit/components/FileUploader.nuxt.test.js | 74 ++-- .../Inspector/InspectionButton.nuxt.test.js | 56 +-- .../Inspector/ResultPanel.nuxt.test.js | 49 ++- tests/unit/components/Launcher.nuxt.test.js | 42 ++- .../components/PackagesVersions.nuxt.test.js | 32 +- tests/unit/components/Step.nuxt.test.js | 37 +- tests/unit/composables/api_fetch.nuxt.test.js | 70 ++-- ..._when_microservices_connected.nuxt.test.js | 72 ++-- tests/unit/stores/lambda.nuxt.test.js | 146 ++++---- 35 files changed, 1472 insertions(+), 1672 deletions(-) diff --git a/.oxlintrc.json b/.oxlintrc.json index 728bd785..832c2f09 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -2,7 +2,7 @@ "categories": { "correctness": "error", "suspicious": "error", - "pedantic": "warn", + "pedantic": "error", "perf": "error", "style": "error", "restriction": "error" @@ -25,38 +25,65 @@ "eslint/id-length": [ "error", { - "exceptions": [ - "x", - "y", - "z", - "i", - "j", - "k", - "r", - "g", - "b", - "id", - "ID", - "fs", - "os", - "_" - ], + "exceptions": ["x", "y", "z", "i", "j", "k", "r", "g", "b", "id", "ID", "fs", "os", "_"], "min": 3 } ], "eslint/no-console": "warn", // Disable for debugging. Disable later to not have browser logs - "sort-imports": ["error", { "allowSeparatedGroups": true }], + "sort-imports": [ + "error", + { + "allowSeparatedGroups": true + } + ], "eslint/no-undefined": "off", // Conflict with unicorn/no-typeof-undefined which prefers direct undefined comparison "import/prefer-default-export": "off", "import/no-named-export": "off", - "import/no-namespace": ["error", { "ignore": ["vuetify/*"] }], - "vue/max-props": ["error", { "maxProps": 8 }], + "import/no-namespace": [ + "error", + { + "ignore": ["vuetify/*"] + } + ], + "import/max-dependencies": [ + "warn", + { + "max": 10 + } + ], + "max-lines-per-function": [ + "warn", + { + "max": 50, + "skipBlankLines": true, + "skipComments": true, + } + ], + "unicorn/no-useless-undefined": "off", + "max-lines": [ + "error", + { + "skipBlankLines": true, + "skipComments": true, + } + ], + "vue/max-props": [ + "error", + { + "maxProps": 8 + } + ], "oxc/no-optional-chaining": "off", "node/no-process-env": "off", "no-continue": "off", "vitest/require-hook": "off", "import/unambiguous": "off", - "max-params": ["warn", { "max": 4 }], + "max-params": [ + "warn", + { + "max": 4 + } + ], "import/no-nodejs-modules": "off", "eslint/no-magic-numbers": [ "error", @@ -79,12 +106,7 @@ } }, { - "files": [ - "app/plugins/**", - "node_scripts/**", - "server/**", - "*.config.js" - ], + "files": ["app/plugins/**", "node_scripts/**", "server/**", "*.config.js"], "rules": { "import/no-default-export": "off" } @@ -94,7 +116,9 @@ "rules": { "vitest/require-hook": "off", "vitest/no-hooks": "off", - "vitest/no-importing-vitest-globals": "off" + "vitest/no-importing-vitest-globals": "off", + "max-lines-per-function": "off", + "max-statements": "off" } }, { diff --git a/app/stores/app.js b/app/stores/app.js index bb9b2eee..c11128ab 100644 --- a/app/stores/app.js +++ b/app/stores/app.js @@ -1,271 +1,251 @@ -import { api_fetch } from "@ogw_internal/utils/api_fetch.js" -import { upload_file } from "@ogw_internal/utils/upload_file.js" +import { api_fetch } from "@ogw_internal/utils/api_fetch.js"; +import { upload_file } from "@ogw_internal/utils/upload_file.js"; export const useAppStore = defineStore("app", () => { - const stores = [] + const stores = []; function registerStore(store) { - const isAlreadyRegistered = stores.some( - (registeredStore) => registeredStore.$id === store.$id, - ) + const isAlreadyRegistered = stores.some((registeredStore) => registeredStore.$id === store.$id); if (isAlreadyRegistered) { - console.log( - `[AppStore] Store "${store.$id}" already registered, skipping`, - ) - return + console.log(`[AppStore] Store "${store.$id}" already registered, skipping`); + return; } - console.log("[AppStore] Registering store", store.$id) - stores.push(store) + console.log("[AppStore] Registering store", store.$id); + stores.push(store); } async function exportStores(params = {}) { - const snapshot = {} - let exportCount = 0 + const snapshot = {}; + let exportCount = 0; - console.log( - `[AppStore] Exporting stores, total registered: ${stores.length}`, - ) + console.log(`[AppStore] Exporting stores, total registered: ${stores.length}`); await Promise.all( stores.map(async (store) => { if (!store.exportStores) { - return + return; } - const storeId = store.$id + const storeId = store.$id; try { - snapshot[storeId] = await store.exportStores(params) - exportCount += 1 + snapshot[storeId] = await store.exportStores(params); + exportCount += 1; } catch (error) { - console.error(`[AppStore] Error exporting store "${storeId}":`, error) + console.error(`[AppStore] Error exporting store "${storeId}":`, error); } }), - ) - console.log( - `[AppStore] Exported ${exportCount} stores; snapshot keys:`, - Object.keys(snapshot), - ) - return snapshot + ); + console.log(`[AppStore] Exported ${exportCount} stores; snapshot keys:`, Object.keys(snapshot)); + return snapshot; } async function importStores(snapshot) { if (!snapshot) { - console.warn("[AppStore] import called with invalid snapshot") - return + console.warn("[AppStore] import called with invalid snapshot"); + return; } - console.log("[AppStore] Import snapshot keys:", Object.keys(snapshot || {})) + console.log("[AppStore] Import snapshot keys:", Object.keys(snapshot || {})); - let importedCount = 0 - const notFoundStores = [] + let importedCount = 0; + const notFoundStores = []; await Promise.all( stores.map(async (store) => { if (!store.importStores) { - return + return; } - const storeId = store.$id + const storeId = store.$id; if (!snapshot[storeId]) { - notFoundStores.push(storeId) - return + notFoundStores.push(storeId); + return; } try { - await store.importStores(snapshot[storeId]) - importedCount += 1 + await store.importStores(snapshot[storeId]); + importedCount += 1; } catch (error) { - console.error(`[AppStore] Error importing store "${storeId}":`, error) + console.error(`[AppStore] Error importing store "${storeId}":`, error); } }), - ) + ); if (notFoundStores.length > 0) { - console.warn( - `[AppStore] Stores not found in snapshot: ${notFoundStores.join(", ")}`, - ) + console.warn(`[AppStore] Stores not found in snapshot: ${notFoundStores.join(", ")}`); } - console.log(`[AppStore] Imported ${importedCount} stores`) + console.log(`[AppStore] Imported ${importedCount} stores`); } - const loadedExtensions = ref(new Map()) - const extensionAPI = ref(undefined) - const codeTransformer = ref(undefined) + const loadedExtensions = ref(new Map()); + const extensionAPI = ref(undefined); + const codeTransformer = ref(undefined); function setExtensionAPI(api) { - extensionAPI.value = api + extensionAPI.value = api; } function setCodeTransformer(transformer) { - codeTransformer.value = transformer + codeTransformer.value = transformer; } function getExtension(id) { - return loadedExtensions.value.get(id) + return loadedExtensions.value.get(id); } - async function loadExtension(path, backendPath = undefined) { + async function loadExtension(path, backendPath = "") { try { - let finalURL = path + let finalURL = path; if (codeTransformer.value && path.startsWith("blob:")) { - const response = await fetch(path) - const code = await response.text() - const transformedCode = codeTransformer.value(code) + const response = await fetch(path); + const code = await response.text(); + const transformedCode = codeTransformer.value(code); const newBlob = new Blob([transformedCode], { type: "application/javascript", - }) - finalURL = URL.createObjectURL(newBlob) + }); + finalURL = URL.createObjectURL(newBlob); } - const extensionModule = await import(/* @vite-ignore */ finalURL) + // oxlint-disable-next-line no-inline-comments + const extensionModule = await import(/* @vite-ignore */ finalURL); if (finalURL !== path && finalURL.startsWith("blob:")) { - URL.revokeObjectURL(finalURL) + URL.revokeObjectURL(finalURL); } if (!extensionModule.metadata?.id) { - throw new Error("Extension must have metadata.id") + throw new Error("Extension must have metadata.id"); } - const extensionId = extensionModule.metadata.id + const extensionId = extensionModule.metadata.id; if (loadedExtensions.value.has(extensionId)) { - console.warn(`[AppStore] Extension "${extensionId}" is already loaded`) - throw new Error(`Extension "${extensionId}" is already loaded.`) + console.warn(`[AppStore] Extension "${extensionId}" is already loaded`); + throw new Error(`Extension "${extensionId}" is already loaded.`); } if (!extensionAPI.value) { - throw new Error("Extension API not initialized") + throw new Error("Extension API not initialized"); } - if (typeof extensionModule.install === "function") { - await extensionModule.install(extensionAPI.value, backendPath) - - const extensionData = { - module: extensionModule, - id: extensionId, - path, - backendPath, - loadedAt: new Date().toISOString(), - metadata: extensionModule.metadata, - enabled: true, - } - loadedExtensions.value.set(extensionId, extensionData) - - console.log(`[AppStore] Extension loaded successfully: ${extensionId}`) - return extensionModule - } else { - throw new Error("Extension must export an install function") + if (typeof extensionModule.install !== "function") { + throw new TypeError("Extension must export an install function"); } + + await extensionModule.install(extensionAPI.value, backendPath); + + const extensionData = { + module: extensionModule, + id: extensionId, + path, + backendPath, + loadedAt: new Date().toISOString(), + metadata: extensionModule.metadata, + enabled: true, + }; + loadedExtensions.value.set(extensionId, extensionData); + + console.log(`[AppStore] Extension loaded successfully: ${extensionId}`); + return extensionModule; } catch (error) { - console.error(`[AppStore] Failed to load extension from ${path}:`, error) - throw error + console.error(`[AppStore] Failed to load extension from ${path}:`, error); + throw error; } } function getLoadedExtensions() { - return [...loadedExtensions.value.values()] + return [...loadedExtensions.value.values()]; } function unloadExtension(id) { - const extensionData = getExtension(id) + const extensionData = getExtension(id); if (!extensionData) { - return false + return false; } - if ( - extensionData.module && - typeof extensionData.module.uninstall === "function" - ) { + if (extensionData.module && typeof extensionData.module.uninstall === "function") { try { - extensionData.module.uninstall(extensionAPI.value) - console.log(`[AppStore] Extension uninstall called: ${id}`) + extensionData.module.uninstall(extensionAPI.value); + console.log(`[AppStore] Extension uninstall called: ${id}`); } catch (error) { - console.error(`[AppStore] Error calling uninstall for ${id}:`, error) + console.error(`[AppStore] Error calling uninstall for ${id}:`, error); } } - if ( - extensionAPI.value && - typeof extensionAPI.value.unregisterToolsByExtension === "function" - ) { - extensionAPI.value.unregisterToolsByExtension(id) + if (extensionAPI.value && typeof extensionAPI.value.unregisterToolsByExtension === "function") { + extensionAPI.value.unregisterToolsByExtension(id); } - loadedExtensions.value.delete(id) - console.log(`[AppStore] Extension unloaded: ${id}`) - return true + loadedExtensions.value.delete(id); + console.log(`[AppStore] Extension unloaded: ${id}`); + return true; } function toggleExtension(id) { - const extensionData = getExtension(id) + const extensionData = getExtension(id); if (!extensionData) { - return false + return false; } - extensionData.enabled = !extensionData.enabled - console.log( - `[AppStore] Extension ${extensionData.enabled ? "enabled" : "disabled"}: ${id}`, - ) - return extensionData.enabled + extensionData.enabled = !extensionData.enabled; + console.log(`[AppStore] Extension ${extensionData.enabled ? "enabled" : "disabled"}: ${id}`); + return extensionData.enabled; } function setExtensionEnabled(id, enabled) { - const extensionData = getExtension(id) + const extensionData = getExtension(id); if (!extensionData) { - return false + return false; } - extensionData.enabled = enabled - console.log( - `[AppStore] Extension ${enabled ? "enabled" : "disabled"}: ${id}`, - ) - return true + extensionData.enabled = enabled; + console.log(`[AppStore] Extension ${enabled ? "enabled" : "disabled"}: ${id}`); + return true; } function getExtensionEnabled(id) { - return getExtension(id)?.enabled ?? false + return getExtension(id)?.enabled ?? false; } function upload(file, callbacks = {}) { - const route = "/api/extensions/upload" - const store = useAppStore() + const route = "/api/extensions/upload"; + const store = useAppStore(); return upload_file( store, { route, file }, { ...callbacks, response_function: async (response) => { - console.log("[APP] Request completed:", route) + console.log("[APP] Request completed:", route); if (callbacks.response_function) { - await callbacks.response_function(response) + await callbacks.response_function(response); } }, }, - ) + ); } function request(schema, params, callbacks = {}) { - console.log("[APP] Request:", schema.$id) + console.log("[APP] Request:", schema.$id); - const store = useAppStore() + const store = useAppStore(); return api_fetch( store, { schema, params }, { ...callbacks, response_function: async (response) => { - console.log("[APP] Request completed:", schema.$id) + console.log("[APP] Request completed:", schema.$id); if (callbacks.response_function) { - await callbacks.response_function(response) + await callbacks.response_function(response); } }, }, - ) + ); } - const request_counter = ref(0) + const request_counter = ref(0); function start_request() { - request_counter.value += 1 + request_counter.value += 1; } function stop_request() { - request_counter.value -= 1 + request_counter.value -= 1; } - const projectFolderPath = ref("") + const projectFolderPath = ref(""); function createProjectFolder() { - const { PROJECT } = useRuntimeConfig().public + const { PROJECT } = useRuntimeConfig().public; const schema = { $id: "/api/app/project_folder_path", methods: ["POST"], @@ -275,17 +255,17 @@ export const useAppStore = defineStore("app", () => { }, required: ["PROJECT"], additionalProperties: true, - } - const params = { PROJECT } + }; + const params = { PROJECT }; - console.log(createProjectFolder.name, { PROJECT }) + console.log(createProjectFolder.name, { PROJECT }); return request(schema, params, { - response_function: async (response) => { - console.log(`[APP] ${response.projectFolderPath} created`) - projectFolderPath.value = response.projectFolderPath + response_function: (response) => { + console.log(`[APP] ${response.projectFolderPath} created`); + projectFolderPath.value = response.projectFolderPath; }, - }) + }); } return { @@ -310,5 +290,5 @@ export const useAppStore = defineStore("app", () => { createProjectFolder, start_request, stop_request, - } -}) + }; +}); diff --git a/app/stores/feedback.js b/app/stores/feedback.js index 9baf3e5a..d1101281 100644 --- a/app/stores/feedback.js +++ b/app/stores/feedback.js @@ -1,18 +1,17 @@ -import { v4 as uuidv4 } from "uuid" +import { v4 as uuidv4 } from "uuid"; -const MILLISECONDS_IN_SECOND = 1000 -const DEFAULT_FEEDBACKS_TIMEOUT_SECONDS = 10 +const MILLISECONDS_IN_SECOND = 1000; +const DEFAULT_FEEDBACKS_TIMEOUT_SECONDS = 10; export const useFeedbackStore = defineStore("feedback", { state: () => ({ feedbacks: [], server_error: false, - feedbacks_timeout_miliseconds: - DEFAULT_FEEDBACKS_TIMEOUT_SECONDS * MILLISECONDS_IN_SECOND, + feedbacks_timeout_miliseconds: DEFAULT_FEEDBACKS_TIMEOUT_SECONDS * MILLISECONDS_IN_SECOND, }), actions: { async add_error(code, route, name, description) { - const feedbackId = uuidv4() + const feedbackId = uuidv4(); await this.feedbacks.push({ id: feedbackId, type: "error", @@ -20,29 +19,27 @@ export const useFeedbackStore = defineStore("feedback", { route, name, description, - }) + }); setTimeout(() => { - this.delete_feedback(feedbackId) - }, this.feedbacks_timeout_miliseconds) + this.delete_feedback(feedbackId); + }, this.feedbacks_timeout_miliseconds); }, async add_success(description) { - const feedbackId = uuidv4() + const feedbackId = uuidv4(); await this.feedbacks.push({ id: feedbackId, type: "success", description, - }) + }); setTimeout(() => { - this.delete_feedback(feedbackId) - }, this.feedbacks_timeout_miliseconds) + this.delete_feedback(feedbackId); + }, this.feedbacks_timeout_miliseconds); }, - async delete_feedback(feedbackId) { - this.feedbacks = this.feedbacks.filter( - (feedback) => feedback.id !== feedbackId, - ) + delete_feedback(feedbackId) { + this.feedbacks = this.feedbacks.filter((feedback) => feedback.id !== feedbackId); }, - async delete_server_error() { - this.server_error = false + delete_server_error() { + this.server_error = false; }, }, -}) +}); diff --git a/app/stores/geode.js b/app/stores/geode.js index f87a2444..8c736aa1 100644 --- a/app/stores/geode.js +++ b/app/stores/geode.js @@ -1,14 +1,14 @@ -import { Status } from "@ogw_front/utils/status" -import { api_fetch } from "@ogw_internal/utils/api_fetch" -import { appMode } from "@ogw_front/utils/app_mode" -import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" -import { upload_file } from "@ogw_internal/utils/upload_file.js" -import { useAppStore } from "@ogw_front/stores/app" -import { useFeedbackStore } from "@ogw_front/stores/feedback" -import { useInfraStore } from "@ogw_front/stores/infra" +import { Status } from "@ogw_front/utils/status"; +import { api_fetch } from "@ogw_internal/utils/api_fetch"; +import { appMode } from "@ogw_front/utils/app_mode"; +import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json"; +import { upload_file } from "@ogw_internal/utils/upload_file.js"; +import { useAppStore } from "@ogw_front/stores/app"; +import { useFeedbackStore } from "@ogw_front/stores/feedback"; +import { useInfraStore } from "@ogw_front/stores/infra"; -const MILLISECONDS_IN_SECOND = 1000 -const DEFAULT_PING_INTERVAL_SECONDS = 10 +const MILLISECONDS_IN_SECOND = 1000; +const DEFAULT_PING_INTERVAL_SECONDS = 10; export const useGeodeStore = defineStore("geode", { state: () => ({ @@ -19,74 +19,73 @@ export const useGeodeStore = defineStore("geode", { getters: { protocol() { if (useInfraStore().app_mode === appMode.CLOUD) { - return "https" + return "https"; } - return "http" + return "http"; }, port() { if (useInfraStore().app_mode === appMode.CLOUD) { - return "443" + return "443"; } - return this.default_local_port + return this.default_local_port; }, base_url() { - const infraStore = useInfraStore() - let geode_url = `${this.protocol}://${infraStore.domain_name}:${this.port}` + const infraStore = useInfraStore(); + let geode_url = `${this.protocol}://${infraStore.domain_name}:${this.port}`; if (infraStore.app_mode === appMode.CLOUD) { if (infraStore.ID === "") { - throw new Error("ID must not be empty in cloud mode") + throw new Error("ID must not be empty in cloud mode"); } - geode_url += `/${infraStore.ID}/geode` + geode_url += `/${infraStore.ID}/geode`; } - return geode_url + return geode_url; }, is_busy() { - return this.request_counter > 0 + return this.request_counter > 0; }, }, actions: { set_ping() { - this.ping() + this.ping(); setInterval(() => { - this.ping() - }, DEFAULT_PING_INTERVAL_SECONDS * MILLISECONDS_IN_SECOND) + this.ping(); + }, DEFAULT_PING_INTERVAL_SECONDS * MILLISECONDS_IN_SECOND); }, ping() { - const geodeStore = this - const feedbackStore = useFeedbackStore() + const feedbackStore = useFeedbackStore(); return this.request( back_schemas.opengeodeweb_back.ping, {}, { request_error_function: () => { - feedbackStore.$patch({ server_error: true }) - geodeStore.status = Status.NOT_CONNECTED + feedbackStore.$patch({ server_error: true }); + this.status = Status.NOT_CONNECTED; }, response_function: () => { - feedbackStore.$patch({ server_error: false }) - geodeStore.status = Status.CONNECTED + feedbackStore.$patch({ server_error: false }); + this.status = Status.CONNECTED; }, response_error_function: () => { - feedbackStore.$patch({ server_error: true }) - geodeStore.status = Status.NOT_CONNECTED + feedbackStore.$patch({ server_error: true }); + this.status = Status.NOT_CONNECTED; }, }, - ) + ); }, start_request() { - this.request_counter += 1 + this.request_counter += 1; }, stop_request() { - this.request_counter -= 1 + this.request_counter -= 1; }, launch(args) { - console.log("[GEODE] Launching back microservice...", { args }) - const appStore = useAppStore() + console.log("[GEODE] Launching back microservice...", { args }); + const appStore = useAppStore(); - const { BACK_PATH, BACK_COMMAND } = useRuntimeConfig().public + const { BACK_PATH, BACK_COMMAND } = useRuntimeConfig().public; - console.log("[GEODE] BACK_PATH", BACK_PATH) - console.log("[GEODE] BACK_COMMAND", BACK_COMMAND) + console.log("[GEODE] BACK_PATH", BACK_PATH); + console.log("[GEODE] BACK_COMMAND", BACK_COMMAND); const schema = { $id: "/api/app/run_back", methods: ["POST"], @@ -97,30 +96,30 @@ export const useGeodeStore = defineStore("geode", { }, required: ["BACK_PATH", "BACK_COMMAND"], additionalProperties: true, - } + }; const params = { BACK_PATH, BACK_COMMAND, args, - } + }; - console.log("[GEODE] params", params) + console.log("[GEODE] params", params); return appStore.request(schema, params, { response_function: (response) => { - console.log(`[GEODE] Back launched on port ${response.port}`) - this.default_local_port = response.port + console.log(`[GEODE] Back launched on port ${response.port}`); + this.default_local_port = response.port; }, - }) + }); }, connect() { - console.log("[GEODE] Connecting to geode microservice...") - this.set_ping() - return Promise.resolve() + console.log("[GEODE] Connecting to geode microservice..."); + this.set_ping(); + return Promise.resolve(); }, request(schema, params, callbacks = {}) { - console.log("[GEODE] Request:", schema.$id) - const start = Date.now() + console.log("[GEODE] Request:", schema.$id); + const start = Date.now(); return api_fetch( this, @@ -134,16 +133,16 @@ export const useGeodeStore = defineStore("geode", { "in", (Date.now() - start) / MILLISECONDS_IN_SECOND, "s", - ) + ); if (callbacks.response_function) { - await callbacks.response_function(response) + await callbacks.response_function(response); } }, }, - ) + ); }, upload(file, callbacks = {}) { - const route = back_schemas.opengeodeweb_back.upload_file.$id + const route = back_schemas.opengeodeweb_back.upload_file.$id; return upload_file( this, { @@ -153,16 +152,16 @@ export const useGeodeStore = defineStore("geode", { { ...callbacks, response_function: async (response) => { - console.log("[GEODE] Request completed:", route) + console.log("[GEODE] Request completed:", route); if (callbacks.response_function) { - await callbacks.response_function(response) + await callbacks.response_function(response); } }, }, - ) + ); }, }, share: { omit: ["status"], }, -}) +}); diff --git a/app/stores/hybrid_viewer.js b/app/stores/hybrid_viewer.js index 32660a6b..6a6d94a0 100644 --- a/app/stores/hybrid_viewer.js +++ b/app/stores/hybrid_viewer.js @@ -1,137 +1,134 @@ // oxlint-disable-next-line import/no-unassigned-import -import "@kitware/vtk.js/Rendering/Profiles/Geometry" -import { newInstance as vtkActor } from "@kitware/vtk.js/Rendering/Core/Actor" -import { newInstance as vtkGenericRenderWindow } from "@kitware/vtk.js/Rendering/Misc/GenericRenderWindow" -import { newInstance as vtkMapper } from "@kitware/vtk.js/Rendering/Core/Mapper" -import { newInstance as vtkXMLPolyDataReader } from "@kitware/vtk.js/IO/XML/XMLPolyDataReader" +import "@kitware/vtk.js/Rendering/Profiles/Geometry"; +import { newInstance as vtkActor } from "@kitware/vtk.js/Rendering/Core/Actor"; +import { newInstance as vtkGenericRenderWindow } from "@kitware/vtk.js/Rendering/Misc/GenericRenderWindow"; +import { newInstance as vtkMapper } from "@kitware/vtk.js/Rendering/Core/Mapper"; +import { newInstance as vtkXMLPolyDataReader } from "@kitware/vtk.js/IO/XML/XMLPolyDataReader"; -import { Status } from "@ogw_front/utils/status" -import { useDataStore } from "@ogw_front/stores/data" -import { useViewerStore } from "@ogw_front/stores/viewer" -import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" +import { Status } from "@ogw_front/utils/status"; +import { useDataStore } from "@ogw_front/stores/data"; +import { useViewerStore } from "@ogw_front/stores/viewer"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"; -const RGB_MAX = 255 -const BACKGROUND_GREY_VALUE = 180 -const ACTOR_DARK_VALUE = 20 +const RGB_MAX = 255; +const BACKGROUND_GREY_VALUE = 180; +const ACTOR_DARK_VALUE = 20; const BACKGROUND_COLOR = [ BACKGROUND_GREY_VALUE / RGB_MAX, BACKGROUND_GREY_VALUE / RGB_MAX, BACKGROUND_GREY_VALUE / RGB_MAX, -] +]; const ACTOR_COLOR = [ ACTOR_DARK_VALUE / RGB_MAX, ACTOR_DARK_VALUE / RGB_MAX, ACTOR_DARK_VALUE / RGB_MAX, -] -const WHEEL_TIME_OUT_MS = 600 +]; +const WHEEL_TIME_OUT_MS = 600; export const useHybridViewerStore = defineStore("hybridViewer", () => { - const dataStore = useDataStore() - const viewerStore = useViewerStore() - const hybridDb = reactive({}) - const status = ref(Status.NOT_CREATED) - const camera_options = reactive({}) - const genericRenderWindow = reactive({}) - const is_moving = ref(false) - const zScale = ref(1) - let viewStream = undefined - const gridActor = undefined + const dataStore = useDataStore(); + const viewerStore = useViewerStore(); + const hybridDb = reactive({}); + const status = ref(Status.NOT_CREATED); + const camera_options = reactive({}); + const genericRenderWindow = reactive({}); + const is_moving = ref(false); + const zScale = ref(1); + let viewStream = undefined; + const gridActor = undefined; async function initHybridViewer() { if (status.value !== Status.NOT_CREATED) { - return + return; } - status.value = Status.CREATING + status.value = Status.CREATING; genericRenderWindow.value = vtkGenericRenderWindow({ background: BACKGROUND_COLOR, listenWindowResize: false, - }) + }); - const webGLRenderWindow = - genericRenderWindow.value.getApiSpecificRenderWindow() - const imageStyle = webGLRenderWindow.getReferenceByName("bgImage").style - imageStyle.transition = "opacity 0.1s ease-in" - imageStyle.zIndex = 1 + const webGLRenderWindow = genericRenderWindow.value.getApiSpecificRenderWindow(); + const imageStyle = webGLRenderWindow.getReferenceByName("bgImage").style; + imageStyle.transition = "opacity 0.1s ease-in"; + imageStyle.zIndex = 1; - await viewerStore.ws_connect() - viewStream = viewerStore.client.getImageStream().createViewStream("-1") + await viewerStore.ws_connect(); + viewStream = viewerStore.client.getImageStream().createViewStream("-1"); viewStream.onImageReady((event) => { if (is_moving.value) { - return + return; } - webGLRenderWindow.setBackgroundImage(event.image) - imageStyle.opacity = 1 - }) + webGLRenderWindow.setBackgroundImage(event.image); + imageStyle.opacity = 1; + }); - status.value = Status.CREATED + status.value = Status.CREATED; } async function addItem(id) { if (!genericRenderWindow.value) { - return + return; } - const value = await dataStore.item(id) - console.log("hybridViewerStore.addItem", { value }) - const reader = vtkXMLPolyDataReader() - const textEncoder = new TextEncoder() - await reader.parseAsArrayBuffer( - textEncoder.encode(value.binary_light_viewable), - ) - const polydata = reader.getOutputData(0) - const mapper = vtkMapper() - mapper.setInputData(polydata) - const actor = vtkActor() - actor.getProperty().setColor(ACTOR_COLOR) - actor.setMapper(mapper) - const renderer = genericRenderWindow.value.getRenderer() - const renderWindow = genericRenderWindow.value.getRenderWindow() - renderer.addActor(actor) - renderer.resetCamera() - renderWindow.render() - hybridDb[id] = { actor, polydata, mapper } + const value = await dataStore.item(id); + console.log("hybridViewerStore.addItem", { value }); + const reader = vtkXMLPolyDataReader(); + const textEncoder = new TextEncoder(); + await reader.parseAsArrayBuffer(textEncoder.encode(value.binary_light_viewable)); + const polydata = reader.getOutputData(0); + const mapper = vtkMapper(); + mapper.setInputData(polydata); + const actor = vtkActor(); + actor.getProperty().setColor(ACTOR_COLOR); + actor.setMapper(mapper); + const renderer = genericRenderWindow.value.getRenderer(); + const renderWindow = genericRenderWindow.value.getRenderWindow(); + renderer.addActor(actor); + renderer.resetCamera(); + renderWindow.render(); + hybridDb[id] = { actor, polydata, mapper }; } - async function removeItem(id) { + function removeItem(id) { if (!hybridDb[id]) { - return + return; } - const renderer = genericRenderWindow.value.getRenderer() - renderer.removeActor(hybridDb[id].actor) - genericRenderWindow.value.getRenderWindow().render() - delete hybridDb[id] + const renderer = genericRenderWindow.value.getRenderer(); + renderer.removeActor(hybridDb[id].actor); + genericRenderWindow.value.getRenderWindow().render(); + delete hybridDb[id]; } - async function setVisibility(id, visibility) { - hybridDb[id].actor.setVisibility(visibility) - const renderWindow = genericRenderWindow.value.getRenderWindow() - renderWindow.render() + function setVisibility(id, visibility) { + hybridDb[id].actor.setVisibility(visibility); + const renderWindow = genericRenderWindow.value.getRenderWindow(); + renderWindow.render(); } async function setZScaling(z_scale) { - zScale.value = z_scale - const renderer = genericRenderWindow.value.getRenderer() - const actors = renderer.getActors() + zScale.value = z_scale; + const renderer = genericRenderWindow.value.getRenderer(); + const actors = renderer.getActors(); for (const actor of actors) { if (actor !== gridActor) { - const scale = actor.getScale() - actor.setScale(scale[0], scale[1], z_scale) + const scale = actor.getScale(); + actor.setScale(scale[0], scale[1], z_scale); } } - renderer.resetCamera() - genericRenderWindow.value.getRenderWindow().render() - const schema = viewer_schemas?.opengeodeweb_viewer?.viewer?.set_z_scaling + renderer.resetCamera(); + genericRenderWindow.value.getRenderWindow().render(); + const schema = viewer_schemas?.opengeodeweb_viewer?.viewer?.set_z_scaling; if (!schema) { - return + return; } await viewerStore.request(schema, { z_scale, - }) - remoteRender() + }); + remoteRender(); } function syncRemoteCamera() { - console.log("syncRemoteCamera") - const renderer = genericRenderWindow.value.getRenderer() - const camera = renderer.getActiveCamera() + console.log("syncRemoteCamera"); + const renderer = genericRenderWindow.value.getRenderer(); + const camera = renderer.getActiveCamera(); const params = { camera_options: { focal_point: [...camera.getFocalPoint()], @@ -141,93 +138,84 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { clipping_range: [...camera.getClippingRange()], distance: camera.getDistance(), }, - } - viewerStore.request( - viewer_schemas.opengeodeweb_viewer.viewer.update_camera, - params, - { - response_function: () => { - remoteRender() - for (const key in params.camera_options) { - if (Object.hasOwn(params.camera_options, key)) { - camera_options[key] = params.camera_options[key] - } + }; + viewerStore.request(viewer_schemas.opengeodeweb_viewer.viewer.update_camera, params, { + response_function: () => { + remoteRender(); + for (const key in params.camera_options) { + if (Object.hasOwn(params.camera_options, key)) { + camera_options[key] = params.camera_options[key]; } - }, + } }, - ) + }); } function remoteRender() { - return viewerStore.request(viewer_schemas.opengeodeweb_viewer.viewer.render) + return viewerStore.request(viewer_schemas.opengeodeweb_viewer.viewer.render); } function setContainer(container) { - genericRenderWindow.value.setContainer(container.value.$el) - const webGLRenderWindow = - genericRenderWindow.value.getApiSpecificRenderWindow() - webGLRenderWindow.setUseBackgroundImage(true) - const imageStyle = webGLRenderWindow.getReferenceByName("bgImage").style - imageStyle.transition = "opacity 0.1s ease-in" - imageStyle.zIndex = 1 - resize(container.value.$el.offsetWidth, container.value.$el.offsetHeight) - console.log("setContainer", container.value.$el) + genericRenderWindow.value.setContainer(container.value.$el); + const webGLRenderWindow = genericRenderWindow.value.getApiSpecificRenderWindow(); + webGLRenderWindow.setUseBackgroundImage(true); + const imageStyle = webGLRenderWindow.getReferenceByName("bgImage").style; + imageStyle.transition = "opacity 0.1s ease-in"; + imageStyle.zIndex = 1; + resize(container.value.$el.offsetWidth, container.value.$el.offsetHeight); + console.log("setContainer", container.value.$el); useMousePressed({ target: container, onPressed: (event) => { - console.log("onPressed") + console.log("onPressed"); if (event.button === 0) { - is_moving.value = true - event.stopPropagation() - imageStyle.opacity = 0 + is_moving.value = true; + event.stopPropagation(); + imageStyle.opacity = 0; } }, onReleased: () => { if (!is_moving.value) { - return + return; } - is_moving.value = false - console.log("onReleased") - syncRemoteCamera() + is_moving.value = false; + console.log("onReleased"); + syncRemoteCamera(); }, - }) + }); - let wheelEventEndTimeout = undefined + let wheelEventEndTimeout = undefined; useEventListener(container, "wheel", () => { - is_moving.value = true - imageStyle.opacity = 0 - clearTimeout(wheelEventEndTimeout) + is_moving.value = true; + imageStyle.opacity = 0; + clearTimeout(wheelEventEndTimeout); wheelEventEndTimeout = setTimeout(() => { - is_moving.value = false - syncRemoteCamera() - }, WHEEL_TIME_OUT_MS) - }) + is_moving.value = false; + syncRemoteCamera(); + }, WHEEL_TIME_OUT_MS); + }); } async function resize(width, height) { - if ( - viewerStore.status !== Status.CONNECTED || - status.value !== Status.CREATED - ) { - return + if (viewerStore.status !== Status.CONNECTED || status.value !== Status.CREATED) { + return; } - const webGLRenderWindow = - genericRenderWindow.value.getApiSpecificRenderWindow() - const canvas = webGLRenderWindow.getCanvas() - canvas.width = width - canvas.height = height - await nextTick() - webGLRenderWindow.setSize(width, height) - viewStream.setSize(width, height) - const renderWindow = genericRenderWindow.value.getRenderWindow() - renderWindow.render() - remoteRender() + const webGLRenderWindow = genericRenderWindow.value.getApiSpecificRenderWindow(); + const canvas = webGLRenderWindow.getCanvas(); + canvas.width = width; + canvas.height = height; + await nextTick(); + webGLRenderWindow.setSize(width, height); + viewStream.setSize(width, height); + const renderWindow = genericRenderWindow.value.getRenderWindow(); + renderWindow.render(); + remoteRender(); } function exportStores() { - const renderer = genericRenderWindow.value.getRenderer() - const camera = renderer.getActiveCamera() + const renderer = genericRenderWindow.value.getRenderer(); + const camera = renderer.getActiveCamera(); const cameraSnapshot = camera ? { focal_point: [...camera.getFocalPoint()], @@ -237,33 +225,33 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { clipping_range: [...camera.getClippingRange()], distance: camera.getDistance(), } - : camera_options - return { zScale: zScale.value, camera_options: cameraSnapshot } + : camera_options; + return { zScale: zScale.value, camera_options: cameraSnapshot }; } async function importStores(snapshot) { if (!snapshot) { - console.warn("importStores called with undefined snapshot") - return + console.warn("importStores called with undefined snapshot"); + return; } - const z_scale = snapshot.zScale + const z_scale = snapshot.zScale; function applyCamera() { - const { camera_options: snapshot_camera_options } = snapshot + const { camera_options: snapshot_camera_options } = snapshot; if (!snapshot_camera_options) { - return + return; } - const renderer = genericRenderWindow.value.getRenderer() - const camera = renderer.getActiveCamera() + const renderer = genericRenderWindow.value.getRenderer(); + const camera = renderer.getActiveCamera(); - camera.setFocalPoint(...snapshot_camera_options.focal_point) - camera.setViewUp(...snapshot_camera_options.view_up) - camera.setPosition(...snapshot_camera_options.position) - camera.setViewAngle(snapshot_camera_options.view_angle) - camera.setClippingRange(...snapshot_camera_options.clipping_range) + camera.setFocalPoint(...snapshot_camera_options.focal_point); + camera.setViewUp(...snapshot_camera_options.view_up); + camera.setPosition(...snapshot_camera_options.position); + camera.setViewAngle(snapshot_camera_options.view_angle); + camera.setClippingRange(...snapshot_camera_options.clipping_range); - genericRenderWindow.value.getRenderWindow().render() + genericRenderWindow.value.getRenderWindow().render(); const payload = { camera_options: { @@ -273,35 +261,31 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { view_angle: snapshot_camera_options.view_angle, clipping_range: [...snapshot_camera_options.clipping_range], }, - } - return viewerStore.request( - viewer_schemas.opengeodeweb_viewer.viewer.update_camera, - payload, - { - response_function: () => { - remoteRender() - Object.assign(camera_options, payload.camera_options) - }, + }; + return viewerStore.request(viewer_schemas.opengeodeweb_viewer.viewer.update_camera, payload, { + response_function: () => { + remoteRender(); + Object.assign(camera_options, payload.camera_options); }, - ) + }); } if (typeof z_scale === "number") { - await setZScaling(z_scale) - return await applyCamera() + await setZScaling(z_scale); + return await applyCamera(); } - return await applyCamera() + return await applyCamera(); } function clear() { - const renderer = genericRenderWindow.value.getRenderer() - const actors = renderer.getActors() + const renderer = genericRenderWindow.value.getRenderer(); + const actors = renderer.getActors(); for (const actor of actors) { - renderer.removeActor(actor) + renderer.removeActor(actor); } - genericRenderWindow.value.getRenderWindow().render() + genericRenderWindow.value.getRenderWindow().render(); for (const id of Object.keys(hybridDb)) { - delete hybridDb[id] + delete hybridDb[id]; } } @@ -321,5 +305,5 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { clear, exportStores, importStores, - } -}) + }; +}); diff --git a/app/stores/infra.js b/app/stores/infra.js index 5c57239c..8c89c341 100644 --- a/app/stores/infra.js +++ b/app/stores/infra.js @@ -1,9 +1,9 @@ -import { appMode, getAppMode } from "@ogw_front/utils/app_mode" -import { Status } from "@ogw_front/utils/status" -import { useAppStore } from "@ogw_front/stores/app" -import { useLambdaStore } from "@ogw_front/stores/lambda" +import { appMode, getAppMode } from "@ogw_front/utils/app_mode"; +import { Status } from "@ogw_front/utils/status"; +import { useAppStore } from "@ogw_front/stores/app"; +import { useLambdaStore } from "@ogw_front/stores/lambda"; -import { registerRunningExtensions } from "@ogw_front/utils/extension" +import { registerRunningExtensions } from "@ogw_front/utils/extension"; export const useInfraStore = defineStore("infra", { state: () => ({ @@ -16,96 +16,86 @@ export const useInfraStore = defineStore("infra", { getters: { domain_name() { if (this.app_mode === appMode.CLOUD) { - return useRuntimeConfig().public.API_URL + return useRuntimeConfig().public.API_URL; } - return "localhost" + return "localhost"; }, microservices_connected() { - console.log("microservices", this.microservices) - return this.microservices.every( - (store) => store.status === Status.CONNECTED, - ) + console.log("microservices", this.microservices); + return this.microservices.every((store) => store.status === Status.CONNECTED); }, microservices_busy() { - return this.microservices.some((store) => store.is_busy === true) + return this.microservices.some((store) => store.is_busy === true); }, }, actions: { register_microservice(store) { - const store_name = store.$id - console.log("[INFRA] Registering microservice:", store_name) + const store_name = store.$id; + console.log("[INFRA] Registering microservice:", store_name); - if ( - !this.microservices.find( - (microservice) => microservice.$id === store_name, - ) - ) { - this.microservices.push(store) - console.log("[INFRA] Microservice registered:", store_name) + if (!this.microservices.some((microservice) => microservice.$id === store_name)) { + this.microservices.push(store); + console.log("[INFRA] Microservice registered:", store_name); } }, - async create_backend() { - console.log("[INFRA] Starting create_backend - Mode:", this.app_mode) + create_backend() { + console.log("[INFRA] Starting create_backend - Mode:", this.app_mode); console.log( "[INFRA] Registered microservices:", this.microservices.map((store) => store.$id), - ) + ); if (this.status === Status.CREATED) { - return + return; } return navigator.locks.request("infra.create_backend", async () => { - this.status = Status.CREATING + this.status = Status.CREATING; if (this.status === Status.CREATED) { - return + return; } - console.log("[INFRA] Lock granted for create_backend") + console.log("[INFRA] Lock granted for create_backend"); if (this.app_mode === appMode.CLOUD) { - console.log("[INFRA] CLOUD mode - Launching lambda...") - const lambdaStore = useLambdaStore() - this.ID = await lambdaStore.launch() - console.log("[INFRA] Lambda launched successfully") + console.log("[INFRA] CLOUD mode - Launching lambda..."); + const lambdaStore = useLambdaStore(); + this.ID = await lambdaStore.launch(); + console.log("[INFRA] Lambda launched successfully"); } else { - console.log( - `[INFRA] ${this.app_mode} mode - Launching microservices...`, - ) - const appStore = useAppStore() - await appStore.createProjectFolder() + console.log(`[INFRA] ${this.app_mode} mode - Launching microservices...`); + const appStore = useAppStore(); + await appStore.createProjectFolder(); if (this.app_mode === appMode.DESKTOP) { globalThis.electronAPI.project_folder_path({ projectFolderPath: appStore.projectFolderPath, - }) + }); } - const microservices_with_launch = this.microservices.filter( - (store) => store.launch, - ) + const microservices_with_launch = this.microservices.filter((store) => store.launch); const launch_promises = microservices_with_launch.map((store) => store.launch({ projectFolderPath: appStore.projectFolderPath }), - ) - launch_promises.push(registerRunningExtensions()) - await Promise.all(launch_promises) + ); + launch_promises.push(registerRunningExtensions()); + await Promise.all(launch_promises); } - this.status = Status.CREATED - console.log("[INFRA] Backend created successfully") - return this.create_connection() - }) + this.status = Status.CREATED; + console.log("[INFRA] Backend created successfully"); + return this.create_connection(); + }); }, async create_connection() { - console.log("[INFRA] Starting create_connection") + console.log("[INFRA] Starting create_connection"); console.log( "[INFRA] Connecting microservices:", this.microservices.map((store) => store.$id), - ) + ); await Promise.all( this.microservices.map(async (store) => { - await store.connect() - console.log("[INFRA] Microservice connected:", store.$id) + await store.connect(); + console.log("[INFRA] Microservice connected:", store.$id); }), - ) - console.log("[INFRA] All microservices connected") + ); + console.log("[INFRA] All microservices connected"); }, }, share: { omit: ["microservices"], }, -}) +}); diff --git a/app/stores/lambda.js b/app/stores/lambda.js index e634e5de..2fb8609c 100644 --- a/app/stores/lambda.js +++ b/app/stores/lambda.js @@ -1,5 +1,5 @@ -import { Status } from "@ogw_front/utils/status" -import { useFeedbackStore } from "@ogw_front/stores/feedback" +import { Status } from "@ogw_front/utils/status"; +import { useFeedbackStore } from "@ogw_front/stores/feedback"; export const useLambdaStore = defineStore("lambda", { state: () => ({ @@ -7,51 +7,51 @@ export const useLambdaStore = defineStore("lambda", { }), getters: { protocol() { - return "https" + return "https"; }, port() { - return "443" + return "443"; }, base_url() { - const public_runtime_config = useRuntimeConfig().public - const domain_name = public_runtime_config.API_URL - const projectPath = `/${public_runtime_config.PROJECT}` - const url = `${this.protocol}://${domain_name}:${this.port}${public_runtime_config.SITE_BRANCH}${projectPath}/createbackend` - return url + const public_runtime_config = useRuntimeConfig().public; + const domain_name = public_runtime_config.API_URL; + const projectPath = `/${public_runtime_config.PROJECT}`; + const url = `${this.protocol}://${domain_name}:${this.port}${public_runtime_config.SITE_BRANCH}${projectPath}/createbackend`; + return url; }, is_busy() { - return false + return false; }, }, actions: { async launch() { - console.log("[LAMBDA] Launching lambda backend...") - const feedbackStore = useFeedbackStore() + console.log("[LAMBDA] Launching lambda backend..."); + const feedbackStore = useFeedbackStore(); const { data, error } = await useFetch(this.base_url, { method: "POST", - }) + }); if (error.value || !data.value) { - this.status = Status.NOT_CONNECTED - feedbackStore.server_error = true - console.error("[LAMBDA] Failed to launch lambda backend", error.value) - throw new Error("Failed to launch lambda backend") + this.status = Status.NOT_CONNECTED; + feedbackStore.server_error = true; + console.error("[LAMBDA] Failed to launch lambda backend", error.value); + throw new Error("Failed to launch lambda backend"); } - this.status = Status.CONNECTED - const id = data.value.ID + this.status = Status.CONNECTED; + const id = data.value.ID; - console.log("[LAMBDA] Lambda launched, ID:", id) - return id + console.log("[LAMBDA] Lambda launched, ID:", id); + return id; }, - async connect() { - console.log("[LAMBDA] Lambda connected") - this.status = Status.CONNECTED - return Promise.resolve() + connect() { + console.log("[LAMBDA] Lambda connected"); + this.status = Status.CONNECTED; + return Promise.resolve(); }, }, share: { omit: ["status"], }, -}) +}); diff --git a/app/stores/treeview.js b/app/stores/treeview.js index e122e9b0..10e8d551 100644 --- a/app/stores/treeview.js +++ b/app/stores/treeview.js @@ -1,67 +1,64 @@ export const useTreeviewStore = defineStore("treeview", () => { - const PANEL_WIDTH = 300 - - const items = ref([]) - const selection = ref([]) - const components_selection = ref([]) - const isAdditionnalTreeDisplayed = ref(false) - const panelWidth = ref(PANEL_WIDTH) - const model_id = ref("") - const isTreeCollection = ref(false) - const selectedTree = ref(undefined) - const isImporting = ref(false) - const pendingSelectionIds = ref([]) + const PANEL_WIDTH = 300; + + const items = ref([]); + const selection = ref([]); + const components_selection = ref([]); + const isAdditionnalTreeDisplayed = ref(false); + const panelWidth = ref(PANEL_WIDTH); + const model_id = ref(""); + const isTreeCollection = ref(false); + const selectedTree = ref(undefined); + const isImporting = ref(false); + const pendingSelectionIds = ref([]); // /** Functions **/ function addItem(geode_object_type, name, id, viewer_type) { - const child = { title: name, id, viewer_type } + const child = { title: name, id, viewer_type }; for (let i = 0; i < items.value.length; i += 1) { if (items.value[i].title === geode_object_type) { - items.value[i].children.push(child) + items.value[i].children.push(child); items.value[i].children.sort((element1, element2) => element1.title.localeCompare(element2.title, undefined, { numeric: true, sensitivity: "base", }), - ) - selection.value.push(child) - return + ); + selection.value.push(child); + return; } } - items.value.push({ title: geode_object_type, children: [child] }) + items.value.push({ title: geode_object_type, children: [child] }); items.value.sort((element1, element2) => element1.title.localeCompare(element2.title, undefined, { numeric: true, sensitivity: "base", }), - ) - selection.value.push(child) + ); + selection.value.push(child); } function displayAdditionalTree(id) { - isAdditionnalTreeDisplayed.value = true - model_id.value = id + isAdditionnalTreeDisplayed.value = true; + model_id.value = id; } function displayFileTree() { - isAdditionnalTreeDisplayed.value = false + isAdditionnalTreeDisplayed.value = false; } function toggleTreeView() { - isTreeCollection.value = !isTreeCollection.value - console.log( - "Switched to", - isTreeCollection.value ? "TreeCollection" : "TreeComponent", - ) + isTreeCollection.value = !isTreeCollection.value; + console.log("Switched to", isTreeCollection.value ? "TreeCollection" : "TreeComponent"); } function setPanelWidth(width) { - panelWidth.value = width + panelWidth.value = width; } function exportStores() { - const selectionIds = selection.value.map((store) => store.id) + const selectionIds = selection.value.map((store) => store.id); return { isAdditionnalTreeDisplayed: isAdditionnalTreeDisplayed.value, panelWidth: panelWidth.value, @@ -69,76 +66,71 @@ export const useTreeviewStore = defineStore("treeview", () => { isTreeCollection: isTreeCollection.value, selectedTree: selectedTree.value, selectionIds, - } + }; } - async function importStores(snapshot) { - isAdditionnalTreeDisplayed.value = - snapshot?.isAdditionnalTreeDisplayed || false - panelWidth.value = snapshot?.panelWidth || PANEL_WIDTH - model_id.value = snapshot?.model_id || "" - isTreeCollection.value = snapshot?.isTreeCollection || false - selectedTree.value = snapshot?.selectedTree || undefined + function importStores(snapshot) { + isAdditionnalTreeDisplayed.value = snapshot?.isAdditionnalTreeDisplayed || false; + panelWidth.value = snapshot?.panelWidth || PANEL_WIDTH; + model_id.value = snapshot?.model_id || ""; + isTreeCollection.value = snapshot?.isTreeCollection || false; + selectedTree.value = snapshot?.selectedTree || undefined; pendingSelectionIds.value = - snapshot?.selectionIds || - (snapshot?.selection || []).map((store) => store.id) || - [] + snapshot?.selectionIds || (snapshot?.selection || []).map((store) => store.id) || []; } function finalizeImportSelection() { - const ids = pendingSelectionIds.value || [] - const rebuilt = [] - if (!ids.length) { + const ids = pendingSelectionIds.value || []; + const rebuilt = []; + if (ids.length === 0) { for (const group of items.value) { for (const child of group.children) { - rebuilt.push(child) + rebuilt.push(child); } } } else { for (const group of items.value) { for (const child of group.children) { if (ids.includes(child.id)) { - rebuilt.push(child) + rebuilt.push(child); } } } } - selection.value = rebuilt - pendingSelectionIds.value = [] + selection.value = rebuilt; + pendingSelectionIds.value = []; } function removeItem(id) { for (let i = 0; i < items.value.length; i += 1) { - const group = items.value[i] - const childIndex = group.children.findIndex((child) => child.id === id) + const group = items.value[i]; + const childIndex = group.children.findIndex((child) => child.id === id); if (childIndex !== -1) { - group.children.splice(childIndex, 1) + group.children.splice(childIndex, 1); if (group.children.length === 0) { - items.value.splice(i, 1) + items.value.splice(i, 1); } - const selectionIndex = selection.value.findIndex( - (item) => item.id === id, - ) + const selectionIndex = selection.value.findIndex((item) => item.id === id); if (selectionIndex !== -1) { - selection.value.splice(selectionIndex, 1) + selection.value.splice(selectionIndex, 1); } - return + return; } } } function clear() { - items.value = [] - selection.value = [] - components_selection.value = [] - pendingSelectionIds.value = [] - model_id.value = "" - selectedTree.value = undefined + items.value = []; + selection.value = []; + components_selection.value = []; + pendingSelectionIds.value = []; + model_id.value = ""; + selectedTree.value = undefined; } return { @@ -160,5 +152,5 @@ export const useTreeviewStore = defineStore("treeview", () => { importStores, finalizeImportSelection, clear, - } -}) + }; +}); diff --git a/app/stores/viewer.js b/app/stores/viewer.js index bd05ee13..ac623fd9 100644 --- a/app/stores/viewer.js +++ b/app/stores/viewer.js @@ -70,7 +70,10 @@ export const useViewerStore = defineStore( async function set_picked_point(x, y) { const response = await request( schemas.opengeodeweb_viewer.generic.get_point_position, - { x, y }, + { + x, + y, + }, ) const { x: world_x, y: world_y } = response picked_point.value.x = world_x @@ -137,7 +140,7 @@ export const useViewerStore = defineStore( request_counter.value -= 1 } - function launch(args = { projectFolderPath }) { + function launch(args = ({ projectFolderPath } = {})) { console.log("[VIEWER] Launching viewer microservice...", { args }) const appStore = useAppStore() diff --git a/app/utils/local/microservices.js b/app/utils/local/microservices.js index caaab6d5..d2e44a9c 100644 --- a/app/utils/local/microservices.js +++ b/app/utils/local/microservices.js @@ -191,11 +191,11 @@ function killWebsocketMicroservice(microservice) { function killMicroservice(microservice) { if (microservice.type === "back") { return killHttpMicroservice(microservice) - } else if (microservice.type === "viewer") { + } + if (microservice.type === "viewer") { return killWebsocketMicroservice(microservice) - } else { - throw new Error(`Unknown microservice type: ${microservice.type}`) } + throw new Error(`Unknown microservice type: ${microservice.type}`) } function killMicroservices(microservices) { diff --git a/app/utils/local/path.js b/app/utils/local/path.js index bdb474b0..f19bea52 100644 --- a/app/utils/local/path.js +++ b/app/utils/local/path.js @@ -1,79 +1,77 @@ // Node imports -import fs from "node:fs" -import os from "node:os" -import path from "node:path" -import { setTimeout } from "node:timers/promises" +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { setTimeout } from "node:timers/promises"; // Third party imports -import isElectron from "is-electron" -import { rimraf } from "rimraf" -import { v4 as uuidv4 } from "uuid" +import isElectron from "is-electron"; +import { rimraf } from "rimraf"; +import { v4 as uuidv4 } from "uuid"; -const MAX_DELETE_FOLDER_RETRIES = 5 +const MAX_DELETE_FOLDER_RETRIES = 5; function venvScriptPath(microservicePath) { - const venvPath = path.join(microservicePath, "venv") - let scriptPath = "" + const venvPath = path.join(microservicePath, "venv"); + let scriptPath = ""; if (process.platform === "win32") { - scriptPath = path.join(venvPath, "Scripts") + scriptPath = path.join(venvPath, "Scripts"); } else { - scriptPath = path.join(venvPath, "bin") + scriptPath = path.join(venvPath, "bin"); } - return scriptPath + return scriptPath; } async function executablePath(microservicePath) { if (isElectron()) { - const electron = await import("electron") + const electron = await import("electron"); if (electron.app.isPackaged) { - return process.resourcesPath - } else { - return venvScriptPath(microservicePath) + return process.resourcesPath; } - } else { - return venvScriptPath(microservicePath) + return venvScriptPath(microservicePath); } + return venvScriptPath(microservicePath); } function executableName(name) { if (process.platform === "win32") { - return `${name}.exe` + return `${name}.exe`; } - return name + return name; } function createPath(dirPath) { if (!fs.existsSync(dirPath)) { - fs.mkdirSync(dirPath, { recursive: true }) - console.log(`${dirPath} directory created successfully!`) + fs.mkdirSync(dirPath, { recursive: true }); + console.log(`${dirPath} directory created successfully!`); } - return dirPath + return dirPath; } function generateProjectFolderPath(projectName) { - return path.join(os.tmpdir(), projectName.replace(/\//g, "_"), uuidv4()) + return path.join(os.tmpdir(), projectName.replaceAll("/", "_"), uuidv4()); } async function deleteFolderRecursive(folderPath) { if (!fs.existsSync(folderPath)) { - console.log(`Folder ${folderPath} does not exist.`) - return + console.log(`Folder ${folderPath} does not exist.`); + return; } for (let i = 0; i <= MAX_DELETE_FOLDER_RETRIES; i += 1) { try { - console.log(`Deleting folder: ${folderPath}`) + console.log(`Deleting folder: ${folderPath}`); // oxlint-disable-next-line no-await-in-loop - await rimraf(folderPath) - console.log(`Deleted folder: ${folderPath}`) - return + await rimraf(folderPath); + console.log(`Deleted folder: ${folderPath}`); + return; } catch (error) { - console.error(`Error deleting folder ${folderPath}:`, error) + console.error(`Error deleting folder ${folderPath}:`, error); // Wait before retrying - const MILLISECONDS_PER_RETRY = 1000 - const DELAY = MILLISECONDS_PER_RETRY * (i + 1) + const MILLISECONDS_PER_RETRY = 1000; + const DELAY = MILLISECONDS_PER_RETRY * (i + 1); // oxlint-disable-next-line no-await-in-loop - await setTimeout(DELAY) - console.log("Retrying delete folder") + await setTimeout(DELAY); + console.log("Retrying delete folder"); } } } @@ -83,4 +81,4 @@ export { executableName, deleteFolderRecursive, generateProjectFolderPath, -} +}; diff --git a/app/utils/server.js b/app/utils/server.js index 582ecb72..32bde76b 100644 --- a/app/utils/server.js +++ b/app/utils/server.js @@ -1,46 +1,43 @@ // Node imports -import fs from "node:fs" -import path from "node:path" +import fs from "node:fs"; +import path from "node:path"; // Third party imports -import JSZip from "jszip" +import JSZip from "jszip"; -async function unzipFile( - zipFilePath, - outputDir = zipFilePath.replace(/\.[^/.]+$/, ""), // Remove the file extension -) { - console.log("Unzipping file...", zipFilePath, outputDir) +async function unzipFile(zipFilePath, outputDir = zipFilePath.replace(/\.[^/.]+$/, "")) { + console.log("Unzipping file...", zipFilePath, outputDir); try { - const data = await fs.promises.readFile(zipFilePath) - const zip = await JSZip.loadAsync(data) - await fs.promises.mkdir(outputDir, { recursive: true }) - const promises = [] + const data = await fs.promises.readFile(zipFilePath); + const zip = await JSZip.loadAsync(data); + await fs.promises.mkdir(outputDir, { recursive: true }); + const promises = []; for (const [relativePath, zipEntry] of Object.entries(zip.files)) { - const outputPath = path.join(outputDir, relativePath) + const outputPath = path.join(outputDir, relativePath); if (zipEntry.dir) { - promises.push(fs.promises.mkdir(outputPath, { recursive: true })) + promises.push(fs.promises.mkdir(outputPath, { recursive: true })); } else { promises.push( (async () => { - const content = await zipEntry.async("nodebuffer") + const content = await zipEntry.async("nodebuffer"); await fs.promises.mkdir(path.dirname(outputPath), { recursive: true, - }) - await fs.promises.writeFile(outputPath, content) + }); + await fs.promises.writeFile(outputPath, content); })(), - ) + ); } } - await Promise.all(promises) - console.log("Extraction complete!") - return outputDir + await Promise.all(promises); + console.log("Extraction complete!"); + return outputDir; } catch (error) { - console.error("Error unzipping file:", error) - throw error + console.error("Error unzipping file:", error); + throw error; } } -export { unzipFile } +export { unzipFile }; diff --git a/internal/database/database.js b/internal/database/database.js index 84202450..10bf6c1a 100644 --- a/internal/database/database.js +++ b/internal/database/database.js @@ -24,12 +24,11 @@ class Database extends Dexie { await tempDb.open() const currentVersion = tempDb.verno - const currentStores = {} - - currentStores[dataTable.name] = dataTable.schema - currentStores[modelComponentsTable.name] = modelComponentsTable.schema - currentStores[modelComponentsRelationTable.name] = - modelComponentsRelationTable.schema + const currentStores = { + [dataTable.name]: dataTable.schema, + [modelComponentsTable.name]: modelComponentsTable.schema, + [modelComponentsRelationTable.name]: modelComponentsRelationTable.schema, + } for (const table of tempDb.tables) { const keyPath = table.schema.primKey.src diff --git a/internal/stores/data_style/mesh/cells/index.js b/internal/stores/data_style/mesh/cells/index.js index f5d7e7b4..d7562117 100644 --- a/internal/stores/data_style/mesh/cells/index.js +++ b/internal/stores/data_style/mesh/cells/index.js @@ -1,74 +1,64 @@ // Third party imports // Local imports -import { useMeshCellsCellAttributeStyle } from "./cell" -import { useMeshCellsColorStyle } from "./color" -import { useMeshCellsCommonStyle } from "./common" -import { useMeshCellsTexturesStyle } from "./textures" -import { useMeshCellsVertexAttributeStyle } from "./vertex" -import { useMeshCellsVisibilityStyle } from "./visibility" +import { useMeshCellsCellAttributeStyle } from "./cell"; +import { useMeshCellsColorStyle } from "./color"; +import { useMeshCellsCommonStyle } from "./common"; +import { useMeshCellsTexturesStyle } from "./textures"; +import { useMeshCellsVertexAttributeStyle } from "./vertex"; +import { useMeshCellsVisibilityStyle } from "./visibility"; // Local constants export function useMeshCellsStyle() { - const meshCellsCommonStyle = useMeshCellsCommonStyle() - const meshCellsVisibility = useMeshCellsVisibilityStyle() - const meshCellsColorStyle = useMeshCellsColorStyle() - const meshCellsTexturesStore = useMeshCellsTexturesStyle() - const meshCellsVertexAttributeStyle = useMeshCellsVertexAttributeStyle() - const meshCellsCellAttributeStyle = useMeshCellsCellAttributeStyle() + const meshCellsCommonStyle = useMeshCellsCommonStyle(); + const meshCellsVisibility = useMeshCellsVisibilityStyle(); + const meshCellsColorStyle = useMeshCellsColorStyle(); + const meshCellsTexturesStore = useMeshCellsTexturesStyle(); + const meshCellsVertexAttributeStyle = useMeshCellsVertexAttributeStyle(); + const meshCellsCellAttributeStyle = useMeshCellsCellAttributeStyle(); async function setMeshCellsActiveColoring(id, type) { - const coloring = meshCellsCommonStyle.meshCellsColoring(id) - coloring.active = type + const coloring = meshCellsCommonStyle.meshCellsColoring(id); + coloring.active = type; console.log( setMeshCellsActiveColoring.name, { id }, meshCellsCommonStyle.meshCellsActiveColoring(id), - ) + ); if (type === "color") { - return meshCellsColorStyle.setMeshCellsColor( - id, - meshCellsColorStyle.meshCellsColor(id), - ) - } else if (type === "textures") { - const textures = meshCellsTexturesStore.meshCellsTextures(id) + return meshCellsColorStyle.setMeshCellsColor(id, meshCellsColorStyle.meshCellsColor(id)); + } + if (type === "textures") { + const textures = meshCellsTexturesStore.meshCellsTextures(id); if (textures === undefined) { - return Promise.resolve() + return; } - return meshCellsTexturesStore.setMeshCellsTextures(id, textures) - } else if (type === "vertex") { - const name = - meshCellsVertexAttributeStyle.meshCellsVertexAttributeName(id) + return meshCellsTexturesStore.setMeshCellsTextures(id, textures); + } + if (type === "vertex") { + const name = meshCellsVertexAttributeStyle.meshCellsVertexAttributeName(id); if (name === undefined) { - return Promise.resolve() + return; } - return meshCellsVertexAttributeStyle.setMeshCellsVertexAttributeName( - id, - name, - ) - } else if (type === "cell") { - const name = meshCellsCellAttributeStyle.meshCellsCellAttributeName(id) + return meshCellsVertexAttributeStyle.setMeshCellsVertexAttributeName(id, name); + } + if (type === "cell") { + const name = meshCellsCellAttributeStyle.meshCellsCellAttributeName(id); if (name === undefined) { - return Promise.resolve() + return; } - await meshCellsCellAttributeStyle.setMeshCellsCellAttributeName(id, name) - } else { - throw new Error(`Unknown mesh cells coloring type: ${type}`) + await meshCellsCellAttributeStyle.setMeshCellsCellAttributeName(id, name); + return; } + throw new Error(`Unknown mesh cells coloring type: ${type}`); } function applyMeshCellsStyle(id) { return Promise.all([ - meshCellsVisibility.setMeshCellsVisibility( - id, - meshCellsVisibility.meshCellsVisibility(id), - ), - setMeshCellsActiveColoring( - id, - meshCellsCommonStyle.meshCellsActiveColoring(id), - ), - ]) + meshCellsVisibility.setMeshCellsVisibility(id, meshCellsVisibility.meshCellsVisibility(id)), + setMeshCellsActiveColoring(id, meshCellsCommonStyle.meshCellsActiveColoring(id)), + ]); } return { @@ -80,5 +70,5 @@ export function useMeshCellsStyle() { ...meshCellsTexturesStore, ...meshCellsVertexAttributeStyle, ...meshCellsCellAttributeStyle, - } + }; } diff --git a/internal/stores/data_style/mesh/edges/index.js b/internal/stores/data_style/mesh/edges/index.js index 14df9cc6..680cafa5 100644 --- a/internal/stores/data_style/mesh/edges/index.js +++ b/internal/stores/data_style/mesh/edges/index.js @@ -1,78 +1,64 @@ // Third party imports // Local imports -import { useMeshEdgesColorStyle } from "./color" -import { useMeshEdgesCommonStyle } from "./common" -import { useMeshEdgesEdgeAttributeStyle } from "./edge" -import { useMeshEdgesVertexAttributeStyle } from "./vertex" -import { useMeshEdgesVisibilityStyle } from "./visibility" -import { useMeshEdgesWidthStyle } from "./width" +import { useMeshEdgesColorStyle } from "./color"; +import { useMeshEdgesCommonStyle } from "./common"; +import { useMeshEdgesEdgeAttributeStyle } from "./edge"; +import { useMeshEdgesVertexAttributeStyle } from "./vertex"; +import { useMeshEdgesVisibilityStyle } from "./visibility"; +import { useMeshEdgesWidthStyle } from "./width"; // Local constants export function useMeshEdgesStyle() { - const meshEdgesCommonStyle = useMeshEdgesCommonStyle() - const meshEdgesVisibility = useMeshEdgesVisibilityStyle() - const meshEdgesColorStyle = useMeshEdgesColorStyle() - const meshEdgesWidthStyle = useMeshEdgesWidthStyle() - const meshEdgesVertexAttributeStyle = useMeshEdgesVertexAttributeStyle() - const meshEdgesEdgeAttributeStyle = useMeshEdgesEdgeAttributeStyle() + const meshEdgesCommonStyle = useMeshEdgesCommonStyle(); + const meshEdgesVisibility = useMeshEdgesVisibilityStyle(); + const meshEdgesColorStyle = useMeshEdgesColorStyle(); + const meshEdgesWidthStyle = useMeshEdgesWidthStyle(); + const meshEdgesVertexAttributeStyle = useMeshEdgesVertexAttributeStyle(); + const meshEdgesEdgeAttributeStyle = useMeshEdgesEdgeAttributeStyle(); - async function setMeshEdgesActiveColoring(id, type) { - const coloring = meshEdgesCommonStyle.meshEdgesColoring(id) - coloring.active = type + function setMeshEdgesActiveColoring(id, type) { + const coloring = meshEdgesCommonStyle.meshEdgesColoring(id); + coloring.active = type; console.log( setMeshEdgesActiveColoring.name, { id }, meshEdgesCommonStyle.meshEdgesActiveColoring(id), - ) + ); if (type === "color") { - return meshEdgesColorStyle.setMeshEdgesColor( - id, - meshEdgesColorStyle.meshEdgesColor(id), - ) - } else if (type === "textures") { - const textures = meshEdgesTexturesStore.meshEdgesTextures(id) + return meshEdgesColorStyle.setMeshEdgesColor(id, meshEdgesColorStyle.meshEdgesColor(id)); + } + if (type === "textures") { + const textures = meshEdgesTexturesStore.meshEdgesTextures(id); if (textures === undefined) { - return Promise.resolve() + return Promise.resolve(); } - return meshEdgesTexturesStore.setMeshEdgesTextures(id, textures) - } else if (type === "vertex") { - const name = - meshEdgesVertexAttributeStyle.meshEdgesVertexAttributeName(id) + return meshEdgesTexturesStore.setMeshEdgesTextures(id, textures); + } + if (type === "vertex") { + const name = meshEdgesVertexAttributeStyle.meshEdgesVertexAttributeName(id); if (name === undefined) { - return Promise.resolve() + return Promise.resolve(); } - return meshEdgesVertexAttributeStyle.setMeshEdgesVertexAttributeName( - id, - name, - ) - } else if (type === "edge") { - const name = meshEdgesEdgeAttributeStyle.meshEdgesEdgeAttributeName(id) + return meshEdgesVertexAttributeStyle.setMeshEdgesVertexAttributeName(id, name); + } + if (type === "edge") { + const name = meshEdgesEdgeAttributeStyle.meshEdgesEdgeAttributeName(id); if (name === undefined) { - return Promise.resolve() + return Promise.resolve(); } - return meshEdgesEdgeAttributeStyle.setMeshEdgesEdgeAttributeName(id, name) - } else { - throw new Error(`Unknown mesh edges coloring type: ${type}`) + return meshEdgesEdgeAttributeStyle.setMeshEdgesEdgeAttributeName(id, name); } + throw new Error(`Unknown mesh edges coloring type: ${type}`); } function applyMeshEdgesStyle(id) { return Promise.all([ - meshEdgesVisibility.setMeshEdgesVisibility( - id, - meshEdgesVisibility.meshEdgesVisibility(id), - ), - meshEdgesWidthStyle.setMeshEdgesWidth( - id, - meshEdgesWidthStyle.meshEdgesWidth(id), - ), - setMeshEdgesActiveColoring( - id, - meshEdgesCommonStyle.meshEdgesActiveColoring(id), - ), - ]) + meshEdgesVisibility.setMeshEdgesVisibility(id, meshEdgesVisibility.meshEdgesVisibility(id)), + meshEdgesWidthStyle.setMeshEdgesWidth(id, meshEdgesWidthStyle.meshEdgesWidth(id)), + setMeshEdgesActiveColoring(id, meshEdgesCommonStyle.meshEdgesActiveColoring(id)), + ]); } return { @@ -84,5 +70,5 @@ export function useMeshEdgesStyle() { ...meshEdgesWidthStyle, ...meshEdgesVertexAttributeStyle, ...meshEdgesEdgeAttributeStyle, - } + }; } diff --git a/internal/stores/data_style/mesh/points/index.js b/internal/stores/data_style/mesh/points/index.js index 37610f42..7a7bd464 100644 --- a/internal/stores/data_style/mesh/points/index.js +++ b/internal/stores/data_style/mesh/points/index.js @@ -1,63 +1,55 @@ // Third party imports // Local imports -import { useMeshPointsColorStyle } from "./color" -import { useMeshPointsCommonStyle } from "./common" -import { useMeshPointsSizeStyle } from "./size" -import { useMeshPointsVertexAttributeStyle } from "./vertex" -import { useMeshPointsVisibilityStyle } from "./visibility" +import { useMeshPointsColorStyle } from "./color"; +import { useMeshPointsCommonStyle } from "./common"; +import { useMeshPointsSizeStyle } from "./size"; +import { useMeshPointsVertexAttributeStyle } from "./vertex"; +import { useMeshPointsVisibilityStyle } from "./visibility"; // Local constants export function useMeshPointsStyle() { - const meshPointsCommonStyle = useMeshPointsCommonStyle() - const meshPointsVisibility = useMeshPointsVisibilityStyle() - const meshPointsColorStyle = useMeshPointsColorStyle() - const meshPointsSizeStyle = useMeshPointsSizeStyle() - const meshPointsVertexAttributeStyle = useMeshPointsVertexAttributeStyle() + const meshPointsCommonStyle = useMeshPointsCommonStyle(); + const meshPointsVisibility = useMeshPointsVisibilityStyle(); + const meshPointsColorStyle = useMeshPointsColorStyle(); + const meshPointsSizeStyle = useMeshPointsSizeStyle(); + const meshPointsVertexAttributeStyle = useMeshPointsVertexAttributeStyle(); async function setMeshPointsActiveColoring(id, type) { - const coloring = meshPointsCommonStyle.meshPointsColoring(id) - coloring.active = type + const coloring = meshPointsCommonStyle.meshPointsColoring(id); + coloring.active = type; console.log( setMeshPointsActiveColoring.name, { id }, meshPointsCommonStyle.meshPointsActiveColoring(id), - ) + ); if (type === "color") { - return meshPointsColorStyle.setMeshPointsColor( - id, - meshPointsColorStyle.meshPointsColor(id), - ) - } else if (type === "textures") { - const textures = meshPointsTexturesStore.meshPointsTextures(id) + return meshPointsColorStyle.setMeshPointsColor(id, meshPointsColorStyle.meshPointsColor(id)); + } + if (type === "textures") { + const textures = meshPointsTexturesStore.meshPointsTextures(id); if (textures === undefined) { - return Promise.resolve() + return; } - return meshPointsTexturesStore.setMeshPointsTextures(id, textures) - } else if (type === "vertex") { - const name = - meshPointsVertexAttributeStyle.meshPointsVertexAttributeName(id) + return meshPointsTexturesStore.setMeshPointsTextures(id, textures); + } + if (type === "vertex") { + const name = meshPointsVertexAttributeStyle.meshPointsVertexAttributeName(id); if (name === undefined) { - return Promise.resolve() + return; } - return meshPointsVertexAttributeStyle.setMeshPointsVertexAttributeName( - id, - name, - ) - } else if (type === "polygon") { - const name = - meshPointsPolygonAttributeStyleStore.meshPointsPolygonAttributeName(id) + return meshPointsVertexAttributeStyle.setMeshPointsVertexAttributeName(id, name); + } + if (type === "polygon") { + const name = meshPointsPolygonAttributeStyleStore.meshPointsPolygonAttributeName(id); if (name === undefined) { - return Promise.resolve() + return; } - await meshPointsPolygonAttributeStyleStore.setMeshPointsPolygonAttributeName( - id, - name, - ) - } else { - throw new Error(`Unknown mesh points coloring type: ${type}`) + await meshPointsPolygonAttributeStyleStore.setMeshPointsPolygonAttributeName(id, name); + return; } + throw new Error(`Unknown mesh points coloring type: ${type}`); } function applyMeshPointsStyle(id) { @@ -66,15 +58,9 @@ export function useMeshPointsStyle() { id, meshPointsVisibility.meshPointsVisibility(id), ), - meshPointsSizeStyle.setMeshPointsSize( - id, - meshPointsSizeStyle.meshPointsSize(id), - ), - setMeshPointsActiveColoring( - id, - meshPointsCommonStyle.meshPointsActiveColoring(id), - ), - ]) + meshPointsSizeStyle.setMeshPointsSize(id, meshPointsSizeStyle.meshPointsSize(id)), + setMeshPointsActiveColoring(id, meshPointsCommonStyle.meshPointsActiveColoring(id)), + ]); } return { @@ -85,5 +71,5 @@ export function useMeshPointsStyle() { ...meshPointsColorStyle, ...meshPointsSizeStyle, ...meshPointsVertexAttributeStyle, - } + }; } diff --git a/internal/stores/data_style/mesh/polygons/index.js b/internal/stores/data_style/mesh/polygons/index.js index 86c1496b..7f72fe2e 100644 --- a/internal/stores/data_style/mesh/polygons/index.js +++ b/internal/stores/data_style/mesh/polygons/index.js @@ -1,66 +1,60 @@ // Third party imports // Local imports -import { useMeshPolygonsColorStyle } from "./color" -import { useMeshPolygonsCommonStyle } from "./common" -import { useMeshPolygonsPolygonAttributeStyle } from "./polygon" -import { useMeshPolygonsTexturesStyle } from "./textures" -import { useMeshPolygonsVertexAttributeStyle } from "./vertex" -import { useMeshPolygonsVisibilityStyle } from "./visibility" +import { useMeshPolygonsColorStyle } from "./color"; +import { useMeshPolygonsCommonStyle } from "./common"; +import { useMeshPolygonsPolygonAttributeStyle } from "./polygon"; +import { useMeshPolygonsTexturesStyle } from "./textures"; +import { useMeshPolygonsVertexAttributeStyle } from "./vertex"; +import { useMeshPolygonsVisibilityStyle } from "./visibility"; // Local constants export function useMeshPolygonsStyle() { - const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle() - const meshPolygonsVisibility = useMeshPolygonsVisibilityStyle() - const meshPolygonsColorStyle = useMeshPolygonsColorStyle() - const meshPolygonsTexturesStyle = useMeshPolygonsTexturesStyle() - const meshPolygonsVertexAttributeStyle = useMeshPolygonsVertexAttributeStyle() - const meshPolygonsPolygonAttributeStyle = - useMeshPolygonsPolygonAttributeStyle() + const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(); + const meshPolygonsVisibility = useMeshPolygonsVisibilityStyle(); + const meshPolygonsColorStyle = useMeshPolygonsColorStyle(); + const meshPolygonsTexturesStyle = useMeshPolygonsTexturesStyle(); + const meshPolygonsVertexAttributeStyle = useMeshPolygonsVertexAttributeStyle(); + const meshPolygonsPolygonAttributeStyle = useMeshPolygonsPolygonAttributeStyle(); async function setMeshPolygonsActiveColoring(id, type) { - const coloring = meshPolygonsCommonStyle.meshPolygonsColoring(id) - coloring.active = type + const coloring = meshPolygonsCommonStyle.meshPolygonsColoring(id); + coloring.active = type; console.log( setMeshPolygonsActiveColoring.name, { id }, meshPolygonsCommonStyle.meshPolygonsActiveColoring(id), - ) + ); if (type === "color") { return meshPolygonsColorStyle.setMeshPolygonsColor( id, meshPolygonsColorStyle.meshPolygonsColor(id), - ) - } else if (type === "textures") { - const textures = meshPolygonsTexturesStyle.meshPolygonsTextures(id) + ); + } + if (type === "textures") { + const textures = meshPolygonsTexturesStyle.meshPolygonsTextures(id); if (textures === undefined) { - return Promise.resolve() + return; } - return meshPolygonsTexturesStyle.setMeshPolygonsTextures(id, textures) - } else if (type === "vertex") { - const name = - meshPolygonsVertexAttributeStyle.meshPolygonsVertexAttributeName(id) + return meshPolygonsTexturesStyle.setMeshPolygonsTextures(id, textures); + } + if (type === "vertex") { + const name = meshPolygonsVertexAttributeStyle.meshPolygonsVertexAttributeName(id); if (name === undefined) { - return Promise.resolve() + return; } - return meshPolygonsVertexAttributeStyle.setMeshPolygonsVertexAttributeName( - id, - name, - ) - } else if (type === "polygon") { - const name = - meshPolygonsPolygonAttributeStyle.meshPolygonsPolygonAttributeName(id) + return meshPolygonsVertexAttributeStyle.setMeshPolygonsVertexAttributeName(id, name); + } + if (type === "polygon") { + const name = meshPolygonsPolygonAttributeStyle.meshPolygonsPolygonAttributeName(id); if (name === undefined) { - return Promise.resolve() + return; } - await meshPolygonsPolygonAttributeStyle.setMeshPolygonsPolygonAttributeName( - id, - name, - ) - } else { - throw new Error(`Unknown mesh polygons coloring type: ${type}`) + await meshPolygonsPolygonAttributeStyle.setMeshPolygonsPolygonAttributeName(id, name); + return; } + throw new Error(`Unknown mesh polygons coloring type: ${type}`); } function applyMeshPolygonsStyle(id) { @@ -69,11 +63,8 @@ export function useMeshPolygonsStyle() { id, meshPolygonsVisibility.meshPolygonsVisibility(id), ), - setMeshPolygonsActiveColoring( - id, - meshPolygonsCommonStyle.meshPolygonsActiveColoring(id), - ), - ]) + setMeshPolygonsActiveColoring(id, meshPolygonsCommonStyle.meshPolygonsActiveColoring(id)), + ]); } return { @@ -85,5 +76,5 @@ export function useMeshPolygonsStyle() { ...meshPolygonsTexturesStyle, ...meshPolygonsVertexAttributeStyle, ...meshPolygonsPolygonAttributeStyle, - } + }; } diff --git a/internal/stores/data_style/mesh/polyhedra/index.js b/internal/stores/data_style/mesh/polyhedra/index.js index d7580561..421bc59c 100644 --- a/internal/stores/data_style/mesh/polyhedra/index.js +++ b/internal/stores/data_style/mesh/polyhedra/index.js @@ -1,61 +1,51 @@ // Third party imports // Local imports -import { useMeshPolyhedraColorStyle } from "./color" -import { useMeshPolyhedraCommonStyle } from "./common" -import { useMeshPolyhedraPolyhedronAttributeStyle } from "./polyhedron" -import { useMeshPolyhedraVertexAttributeStyle } from "./vertex" -import { useMeshPolyhedraVisibilityStyle } from "./visibility" +import { useMeshPolyhedraColorStyle } from "./color"; +import { useMeshPolyhedraCommonStyle } from "./common"; +import { useMeshPolyhedraPolyhedronAttributeStyle } from "./polyhedron"; +import { useMeshPolyhedraVertexAttributeStyle } from "./vertex"; +import { useMeshPolyhedraVisibilityStyle } from "./visibility"; // Local constants export function useMeshPolyhedraStyle() { - const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle() - const meshPolyhedraVisibility = useMeshPolyhedraVisibilityStyle() - const meshPolyhedraColorStyle = useMeshPolyhedraColorStyle() - const meshPolyhedraVertexAttributeStyle = - useMeshPolyhedraVertexAttributeStyle() - const meshPolyhedraPolyhedronAttributeStyle = - useMeshPolyhedraPolyhedronAttributeStyle() + const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(); + const meshPolyhedraVisibility = useMeshPolyhedraVisibilityStyle(); + const meshPolyhedraColorStyle = useMeshPolyhedraColorStyle(); + const meshPolyhedraVertexAttributeStyle = useMeshPolyhedraVertexAttributeStyle(); + const meshPolyhedraPolyhedronAttributeStyle = useMeshPolyhedraPolyhedronAttributeStyle(); async function setMeshPolyhedraActiveColoring(id, type) { - const coloring = meshPolyhedraCommonStyle.meshPolyhedraColoring(id) - coloring.active = type + const coloring = meshPolyhedraCommonStyle.meshPolyhedraColoring(id); + coloring.active = type; console.log( setMeshPolyhedraActiveColoring.name, { id }, meshPolyhedraCommonStyle.meshPolyhedraActiveColoring(id), - ) + ); if (type === "color") { return meshPolyhedraColorStyle.setMeshPolyhedraColor( id, meshPolyhedraColorStyle.meshPolyhedraColor(id), - ) - } else if (type === "vertex") { - const name = - meshPolyhedraVertexAttributeStyle.meshPolyhedraVertexAttributeName(id) + ); + } + if (type === "vertex") { + const name = meshPolyhedraVertexAttributeStyle.meshPolyhedraVertexAttributeName(id); if (name === undefined) { - return Promise.resolve() + return; } - return meshPolyhedraVertexAttributeStyle.setMeshPolyhedraVertexAttributeName( - id, - name, - ) - } else if (type === "polyhedron") { - const name = - meshPolyhedraPolyhedronAttributeStyle.meshPolyhedraPolyhedronAttributeName( - id, - ) + return meshPolyhedraVertexAttributeStyle.setMeshPolyhedraVertexAttributeName(id, name); + } + if (type === "polyhedron") { + const name = meshPolyhedraPolyhedronAttributeStyle.meshPolyhedraPolyhedronAttributeName(id); if (name === undefined) { - return Promise.resolve() + return; } - await meshPolyhedraPolyhedronAttributeStyle.setMeshPolyhedraPolyhedronAttributeName( - id, - name, - ) - } else { - throw new Error(`Unknown mesh polyhedra coloring type: ${type}`) + await meshPolyhedraPolyhedronAttributeStyle.setMeshPolyhedraPolyhedronAttributeName(id, name); + return; } + throw new Error(`Unknown mesh polyhedra coloring type: ${type}`); } function applyMeshPolyhedraStyle(id) { @@ -64,11 +54,8 @@ export function useMeshPolyhedraStyle() { id, meshPolyhedraVisibility.meshPolyhedraVisibility(id), ), - setMeshPolyhedraActiveColoring( - id, - meshPolyhedraCommonStyle.meshPolyhedraActiveColoring(id), - ), - ]) + setMeshPolyhedraActiveColoring(id, meshPolyhedraCommonStyle.meshPolyhedraActiveColoring(id)), + ]); } return { @@ -79,5 +66,5 @@ export function useMeshPolyhedraStyle() { ...meshPolyhedraColorStyle, ...meshPolyhedraVertexAttributeStyle, ...meshPolyhedraPolyhedronAttributeStyle, - } + }; } diff --git a/internal/stores/data_style/model/index.js b/internal/stores/data_style/model/index.js index 8d5cc543..476cda74 100644 --- a/internal/stores/data_style/model/index.js +++ b/internal/stores/data_style/model/index.js @@ -1,35 +1,35 @@ // Third party imports -import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"; // Local imports -import { useDataStore } from "@ogw_front/stores/data" -import { useDataStyleStateStore } from "@ogw_internal/stores/data_style/state" -import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer" -import { useModelBlocksStyle } from "./blocks" -import { useModelCornersStyle } from "./corners" -import { useModelEdgesStyle } from "./edges" -import { useModelLinesStyle } from "./lines" -import { useModelPointsStyle } from "./points" -import { useModelSurfacesStyle } from "./surfaces" -import { useViewerStore } from "@ogw_front/stores/viewer" +import { useDataStore } from "@ogw_front/stores/data"; +import { useDataStyleStateStore } from "@ogw_internal/stores/data_style/state"; +import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; +import { useModelBlocksStyle } from "./blocks"; +import { useModelCornersStyle } from "./corners"; +import { useModelEdgesStyle } from "./edges"; +import { useModelLinesStyle } from "./lines"; +import { useModelPointsStyle } from "./points"; +import { useModelSurfacesStyle } from "./surfaces"; +import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants -const model_schemas = viewer_schemas.opengeodeweb_viewer.model +const model_schemas = viewer_schemas.opengeodeweb_viewer.model; export function useModelStyle() { - const dataStore = useDataStore() - const dataStyleStateStore = useDataStyleStateStore() - const modelCornersStyleStore = useModelCornersStyle() - const modelBlocksStyleStore = useModelBlocksStyle() - const modelEdgesStyleStore = useModelEdgesStyle() - const modelLinesStyleStore = useModelLinesStyle() - const modelPointsStyleStore = useModelPointsStyle() - const modelSurfacesStyleStore = useModelSurfacesStyle() - const hybridViewerStore = useHybridViewerStore() - const viewerStore = useViewerStore() + const dataStore = useDataStore(); + const dataStyleStateStore = useDataStyleStateStore(); + const modelCornersStyleStore = useModelCornersStyle(); + const modelBlocksStyleStore = useModelBlocksStyle(); + const modelEdgesStyleStore = useModelEdgesStyle(); + const modelLinesStyleStore = useModelLinesStyle(); + const modelPointsStyleStore = useModelPointsStyle(); + const modelSurfacesStyleStore = useModelSurfacesStyle(); + const hybridViewerStore = useHybridViewerStore(); + const viewerStore = useViewerStore(); function modelVisibility(id) { - return dataStyleStateStore.getStyle(id).visibility + return dataStyleStateStore.getStyle(id).visibility; } function setModelVisibility(id, visibility) { return viewerStore.request( @@ -37,63 +37,66 @@ export function useModelStyle() { { id, visibility }, { response_function: () => { - dataStyleStateStore.getStyle(id).visibility = visibility - hybridViewerStore.setVisibility(id, visibility) - console.log(setModelVisibility.name, { id }, modelVisibility(id)) + dataStyleStateStore.getStyle(id).visibility = visibility; + hybridViewerStore.setVisibility(id, visibility); + console.log(setModelVisibility.name, { id }, modelVisibility(id)); }, }, - ) + ); } function visibleMeshComponents(id) { - const visible_mesh_components = ref([]) - const styles = dataStyleStateStore.styles[id] + const visible_mesh_components = ref([]); + const styles = dataStyleStateStore.styles[id]; if (!styles) { - return visible_mesh_components + return visible_mesh_components; } for (const [corner_id, style] of Object.entries(styles.corners || {})) { if (style.visibility) { - visible_mesh_components.value.push(corner_id) + visible_mesh_components.value.push(corner_id); } } for (const [line_id, style] of Object.entries(styles.lines || {})) { if (style.visibility) { - visible_mesh_components.value.push(line_id) + visible_mesh_components.value.push(line_id); } } for (const [surface_id, style] of Object.entries(styles.surfaces || {})) { if (style.visibility) { - visible_mesh_components.value.push(surface_id) + visible_mesh_components.value.push(surface_id); } } for (const [block_id, style] of Object.entries(styles.blocks || {})) { if (style.visibility) { - visible_mesh_components.value.push(block_id) + visible_mesh_components.value.push(block_id); } } - return visible_mesh_components + return visible_mesh_components; } function modelMeshComponentVisibility(id, component_type, component_id) { if (component_type === "Corner") { - return modelCornersStyleStore.modelCornerVisibility(id, component_id) - } else if (component_type === "Line") { - return modelLinesStyleStore.modelLineVisibility(id, component_id) - } else if (component_type === "Surface") { - return modelSurfacesStyleStore.modelSurfaceVisibility(id, component_id) - } else if (component_type === "Block") { - return modelBlocksStyleStore.modelBlockVisibility(id, component_id) - } - throw new Error(`Unknown model component_type: ${component_type}`) + return modelCornersStyleStore.modelCornerVisibility(id, component_id); + } + if (component_type === "Line") { + return modelLinesStyleStore.modelLineVisibility(id, component_id); + } + if (component_type === "Surface") { + return modelSurfacesStyleStore.modelSurfaceVisibility(id, component_id); + } + if (component_type === "Block") { + return modelBlocksStyleStore.modelBlockVisibility(id, component_id); + } + throw new Error(`Unknown model component_type: ${component_type}`); } function modelColor(id) { - return dataStyleStateStore.getStyle(id).color + return dataStyleStateStore.getStyle(id).color; } function setModelColor(id, color) { return viewerStore.request( @@ -101,95 +104,76 @@ export function useModelStyle() { { id, color }, { response_function: () => { - dataStyleStateStore.styles[id].color = color - console.log(setModelColor.name, { id }, modelColor(id)) + dataStyleStateStore.styles[id].color = color; + console.log(setModelColor.name, { id }, modelColor(id)); }, }, - ) + ); } - async function setModelMeshComponentsVisibility( - id, - component_geode_ids, - visibility, - ) { - const component_type = await dataStore.meshComponentType( - id, - component_geode_ids[0], - ) + async function setModelMeshComponentsVisibility(id, component_geode_ids, visibility) { + const component_type = await dataStore.meshComponentType(id, component_geode_ids[0]); if (component_type === "Corner") { - return modelCornersStyleStore.setModelCornersVisibility( - id, - component_geode_ids, - visibility, - ) - } else if (component_type === "Line") { - return modelLinesStyleStore.setModelLinesVisibility( - id, - component_geode_ids, - visibility, - ) - } else if (component_type === "Surface") { + return modelCornersStyleStore.setModelCornersVisibility(id, component_geode_ids, visibility); + } + if (component_type === "Line") { + return modelLinesStyleStore.setModelLinesVisibility(id, component_geode_ids, visibility); + } + if (component_type === "Surface") { return modelSurfacesStyleStore.setModelSurfacesVisibility( id, component_geode_ids, visibility, - ) - } else if (component_type === "Block") { - return modelBlocksStyleStore.setModelBlocksVisibility( - id, - component_geode_ids, - visibility, - ) - } else { - throw new Error(`Unknown model component_type: ${component_type}`) + ); } + if (component_type === "Block") { + return modelBlocksStyleStore.setModelBlocksVisibility(id, component_geode_ids, visibility); + } + throw new Error(`Unknown model component_type: ${component_type}`); } function applyModelStyle(id) { - const style = dataStyleStateStore.getStyle(id) - const promise_array = [] + const style = dataStyleStateStore.getStyle(id); + const promise_array = []; for (const [key, value] of Object.entries(style)) { if (key === "visibility") { - promise_array.push(setModelVisibility(id, value)) + promise_array.push(setModelVisibility(id, value)); } else if (key === "corners") { - promise_array.push(modelCornersStyleStore.applyModelCornersStyle(id)) + promise_array.push(modelCornersStyleStore.applyModelCornersStyle(id)); } else if (key === "lines") { - promise_array.push(modelLinesStyleStore.applyModelLinesStyle(id)) + promise_array.push(modelLinesStyleStore.applyModelLinesStyle(id)); } else if (key === "surfaces") { - promise_array.push(modelSurfacesStyleStore.applyModelSurfacesStyle(id)) + promise_array.push(modelSurfacesStyleStore.applyModelSurfacesStyle(id)); } else if (key === "blocks") { - promise_array.push(modelBlocksStyleStore.applyModelBlocksStyle(id)) + promise_array.push(modelBlocksStyleStore.applyModelBlocksStyle(id)); } else if (key === "points") { - promise_array.push(modelPointsStyleStore.applyModelPointsStyle(id)) + promise_array.push(modelPointsStyleStore.applyModelPointsStyle(id)); } else if (key === "edges") { - promise_array.push(modelEdgesStyleStore.applyModelEdgesStyle(id)) + promise_array.push(modelEdgesStyleStore.applyModelEdgesStyle(id)); } else { - throw new Error(`Unknown model key: ${key}`) + throw new Error(`Unknown model key: ${key}`); } } - return Promise.all(promise_array) + return Promise.all(promise_array); } async function setModelMeshComponentsDefaultStyle(id) { - const item = await dataStore.item(id) - const { mesh_components } = item - const promise_array = [] + const item = await dataStore.item(id); + const { mesh_components } = item; + const promise_array = []; if ("Corner" in mesh_components) { - promise_array.push(modelCornersStyleStore.setModelCornersDefaultStyle(id)) + promise_array.push(modelCornersStyleStore.setModelCornersDefaultStyle(id)); } if ("Line" in mesh_components) { - promise_array.push(modelLinesStyleStore.setModelLinesDefaultStyle(id)) + promise_array.push(modelLinesStyleStore.setModelLinesDefaultStyle(id)); } if ("Surface" in mesh_components) { - promise_array.push( - modelSurfacesStyleStore.setModelSurfacesDefaultStyle(id), - ) + promise_array.push(modelSurfacesStyleStore.setModelSurfacesDefaultStyle(id)); } if ("Block" in mesh_components) { - promise_array.push(modelBlocksStyleStore.setModelBlocksDefaultStyle(id)) + promise_array.push(modelBlocksStyleStore.setModelBlocksDefaultStyle(id)); } - return promise_array + return promise_array; } return { @@ -207,5 +191,5 @@ export function useModelStyle() { ...useModelLinesStyle(), ...useModelPointsStyle(), ...useModelSurfacesStyle(), - } + }; } diff --git a/internal/utils/upload_file.js b/internal/utils/upload_file.js index b62b2900..269802e7 100644 --- a/internal/utils/upload_file.js +++ b/internal/utils/upload_file.js @@ -1,55 +1,50 @@ -import { useFeedbackStore } from "@ogw_front/stores/feedback.js" +import { useFeedbackStore } from "@ogw_front/stores/feedback.js"; -async function upload_file( +function upload_file( microservice, { route, file }, { request_error_function, response_function, response_error_function } = {}, ) { - console.log("[UPLOAD_FILE] Uploading file", { route, file }) - const feedbackStore = useFeedbackStore() + console.log("[UPLOAD_FILE] Uploading file", { route, file }); + const feedbackStore = useFeedbackStore(); if (!(file instanceof File)) { - throw new Error("file must be a instance of File") + throw new Error("file must be a instance of File"); } - const body = new FormData() - body.append("file", file) + const body = new FormData(); + body.append("file", file); const request_options = { method: "PUT", body: body, - } - microservice.start_request() + }; + microservice.start_request(); return $fetch(route, { baseURL: microservice.base_url || "", ...request_options, onRequestError({ error }) { - microservice.stop_request() - feedbackStore.add_error(error.code, route, error.message, error.stack) + microservice.stop_request(); + feedbackStore.add_error(error.code, route, error.message, error.stack); if (request_error_function) { - request_error_function(error) + request_error_function(error); } }, onResponse({ response }) { if (response.ok) { - microservice.stop_request() + microservice.stop_request(); if (response_function) { - response_function(response) + response_function(response); } } }, onResponseError({ response }) { - microservice.stop_request() - feedbackStore.add_error( - response.status, - route, - response.name, - response.description, - ) + microservice.stop_request(); + feedbackStore.add_error(response.status, route, response.name, response.description); if (response_error_function) { - response_error_function(response) + response_error_function(response); } }, - }) + }); } -export { upload_file } +export { upload_file }; diff --git a/server/api/extensions/upload.put.js b/server/api/extensions/upload.put.js index a33ac49e..f6f7b8ab 100644 --- a/server/api/extensions/upload.put.js +++ b/server/api/extensions/upload.put.js @@ -1,35 +1,27 @@ // Node imports -import { finished, pipeline } from "node:stream/promises" -import { Readable } from "node:stream" -import fs from "node:fs" -import path from "node:path" +import { finished, pipeline } from "node:stream/promises"; +import { Readable } from "node:stream"; +import fs from "node:fs"; +import path from "node:path"; // Third party imports -import { - createError, - defineEventHandler, - getRequestHeaders, - getRequestWebStream, -} from "h3" -import StreamZip from "node-stream-zip" -import busboy from "busboy" -import sanitize from "sanitize-filename" +import { createError, defineEventHandler, getRequestHeaders, getRequestWebStream } from "h3"; +import StreamZip from "node-stream-zip"; +import busboy from "busboy"; +import sanitize from "sanitize-filename"; // Local imports -import { - addExtensionToConf, - confFolderPath, -} from "@geode/opengeodeweb-front/app/utils/config.js" +import { addExtensionToConf, confFolderPath } from "@geode/opengeodeweb-front/app/utils/config.js"; -const CODE_201 = 201 -const FILE_SIZE_LIMIT = 107_374_182 // 100 MB +const CODE_201 = 201; +const FILE_SIZE_LIMIT = 107_374_182; export default defineEventHandler(async (event) => { - const projectName = "vease" - const writePromises = [] - const savedFiles = [] + const projectName = "vease"; + const writePromises = []; + const savedFiles = []; - const configFolderPath = confFolderPath(projectName) + const configFolderPath = confFolderPath(projectName); const busboyInstance = busboy({ headers: getRequestHeaders(event), @@ -37,71 +29,65 @@ export default defineEventHandler(async (event) => { fileSize: FILE_SIZE_LIMIT, files: 1, }, - }) + }); busboyInstance.on("file", (fieldname, fileStream, info) => { if (fieldname !== "file") { // Drain & ignore unwanted fields - fileStream.resume() - return + fileStream.resume(); + return; } - const safeFilename = sanitize(info.filename) - const targetPath = path.join(configFolderPath, safeFilename) + const safeFilename = sanitize(info.filename); + const targetPath = path.join(configFolderPath, safeFilename); const writePromise = (async () => { - const writeStream = fs.createWriteStream(targetPath) - await pipeline(fileStream, writeStream) - savedFiles.push(targetPath) - console.log("File written:", targetPath) - })() - - writePromises.push(writePromise) - fileStream.on("limit", () => - busboyInstance.destroy(new Error("File too large")), - ) - }) + const writeStream = fs.createWriteStream(targetPath); + await pipeline(fileStream, writeStream); + savedFiles.push(targetPath); + console.log("File written:", targetPath); + })(); + + writePromises.push(writePromise); + fileStream.on("limit", () => busboyInstance.destroy(new Error("File too large"))); + }); busboyInstance.on("field", (name, value) => { - console.log(`Field ${name}: ${value}`) - }) + console.log(`Field ${name}: ${value}`); + }); - busboyInstance.on("filesLimit", () => - busboyInstance.destroy(new Error("Too many files")), - ) - busboyInstance.on("partsLimit", () => - busboyInstance.destroy(new Error("Too many parts")), - ) + busboyInstance.on("filesLimit", () => busboyInstance.destroy(new Error("Too many files"))); + busboyInstance.on("partsLimit", () => busboyInstance.destroy(new Error("Too many parts"))); - const webStream = getRequestWebStream(event) - Readable.fromWeb(webStream).pipe(busboyInstance) - await finished(busboyInstance) + const webStream = getRequestWebStream(event); + Readable.fromWeb(webStream).pipe(busboyInstance); + await finished(busboyInstance); if (writePromises.length > 0) { - await Promise.all(writePromises) - console.log("All disk writes completed") + await Promise.all(writePromises); + console.log("All disk writes completed"); } if (savedFiles.length === 0) { - throw createError({ statusCode: 400, message: "No file received" }) + throw createError({ statusCode: 400, message: "No file received" }); } await Promise.all( savedFiles.map(async (file) => { - const StreamZipAsync = StreamZip.async + const StreamZipAsync = StreamZip.async; const zip = new StreamZipAsync({ file, storeEntries: true, - }) - const metadataJson = await zip.entryData("metadata.json") - const metadata = JSON.parse(metadataJson) - const { id } = metadata + }); + const metadataJson = await zip.entryData("metadata.json"); + const metadata = JSON.parse(metadataJson); + const { id } = metadata; await addExtensionToConf(projectName, { extensionID: id, extensionPath: file, - }) + }); }), - ) + ); - return { statusCode: CODE_201 } -}) + return { statusCode: CODE_201 }; +}); diff --git a/tests/integration/stores/data_style/mesh/cells.nuxt.test.js b/tests/integration/stores/data_style/mesh/cells.nuxt.test.js index 2a6409d1..75ae5d65 100644 --- a/tests/integration/stores/data_style/mesh/cells.nuxt.test.js +++ b/tests/integration/stores/data_style/mesh/cells.nuxt.test.js @@ -1,181 +1,155 @@ // Third party imports -import { afterEach, beforeEach, describe, expect, test, vi } from "vitest" -import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" with { type: "json" } +import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" with { type: "json" }; // Local imports -import { Status } from "@ogw_front/utils/status" -import { cleanupBackend } from "@ogw_front/utils/local/microservices" -import { setupIntegrationTests } from "@ogw_tests/integration/setup" -import { useDataStyleStore } from "@ogw_front/stores/data_style" -import { useViewerStore } from "@ogw_front/stores/viewer" +import { Status } from "@ogw_front/utils/status"; +import { cleanupBackend } from "@ogw_front/utils/local/microservices"; +import { setupIntegrationTests } from "@ogw_tests/integration/setup"; +import { useDataStyleStore } from "@ogw_front/stores/data_style"; +import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants -const INTERVAL_TIMEOUT = 20_000 -const mesh_cells_schemas = viewer_schemas.opengeodeweb_viewer.mesh.cells -const file_name = "test.og_rgd2d" -const geode_object = "RegularGrid2D" -const vertex_attribute = { name: "points" } -const cell_attribute = { name: "RGB_data" } +const INTERVAL_TIMEOUT = 20_000; +const mesh_cells_schemas = viewer_schemas.opengeodeweb_viewer.mesh.cells; +const file_name = "test.og_rgd2d"; +const geode_object = "RegularGrid2D"; +const vertex_attribute = { name: "points" }; +const cell_attribute = { name: "RGB_data" }; let id = "", - projectFolderPath = "" + projectFolderPath = ""; beforeEach(async () => { - ;({ id, projectFolderPath } = await setupIntegrationTests( - file_name, - geode_object, - )) -}, INTERVAL_TIMEOUT) + ({ id, projectFolderPath } = await setupIntegrationTests(file_name, geode_object)); +}, INTERVAL_TIMEOUT); afterEach(async () => { - console.log("afterEach mesh cells kill", projectFolderPath) - await cleanupBackend(projectFolderPath) -}) + console.log("afterEach mesh cells kill", projectFolderPath); + await cleanupBackend(projectFolderPath); +}); -describe("Mesh cells", async () => { +describe("Mesh cells", () => { describe("Cells visibility", () => { test("Visibility true", async () => { - const dataStyleStore = useDataStyleStore() - const viewerStore = useViewerStore() - const visibility = true - const spy = vi.spyOn(viewerStore, "request") - const result = dataStyleStore.setMeshCellsVisibility(id, visibility) - expect(result).toBeInstanceOf(Promise) - await result + const dataStyleStore = useDataStyleStore(); + const viewerStore = useViewerStore(); + const visibility = true; + const spy = vi.spyOn(viewerStore, "request"); + const result = dataStyleStore.setMeshCellsVisibility(id, visibility); + expect(result).toBeInstanceOf(Promise); + await result; expect(spy).toHaveBeenCalledWith( mesh_cells_schemas.visibility, { id, visibility }, { response_function: expect.any(Function), }, - ) - expect(dataStyleStore.meshCellsVisibility(id)).toBe(visibility) - expect(viewerStore.status).toBe(Status.CONNECTED) - }) - }) + ); + expect(dataStyleStore.meshCellsVisibility(id)).toBe(visibility); + expect(viewerStore.status).toBe(Status.CONNECTED); + }); + }); describe("Cells color", () => { test("Color red", async () => { - const dataStyleStore = useDataStyleStore() - const viewerStore = useViewerStore() - const color = { r: 255, g: 0, b: 0 } - const spy = vi.spyOn(viewerStore, "request") - const result = dataStyleStore.setMeshCellsColor(id, color) - expect(result).toBeInstanceOf(Promise) - await result + const dataStyleStore = useDataStyleStore(); + const viewerStore = useViewerStore(); + const color = { r: 255, g: 0, b: 0 }; + const spy = vi.spyOn(viewerStore, "request"); + const result = dataStyleStore.setMeshCellsColor(id, color); + expect(result).toBeInstanceOf(Promise); + await result; expect(spy).toHaveBeenCalledWith( mesh_cells_schemas.color, { id, color }, { response_function: expect.any(Function), }, - ) - expect(dataStyleStore.meshCellsColor(id)).toStrictEqual(color) - expect(viewerStore.status).toBe(Status.CONNECTED) - }) - }) + ); + expect(dataStyleStore.meshCellsColor(id)).toStrictEqual(color); + expect(viewerStore.status).toBe(Status.CONNECTED); + }); + }); describe("Cells vertex attribute", () => { test("Coloring vertex attribute", async () => { - const dataStyleStore = useDataStyleStore() - const viewerStore = useViewerStore() - const spy = vi.spyOn(viewerStore, "request") - const result = dataStyleStore.setMeshCellsVertexAttributeName( - id, - vertex_attribute.name, - ) - expect(result).toBeInstanceOf(Promise) - await result + const dataStyleStore = useDataStyleStore(); + const viewerStore = useViewerStore(); + const spy = vi.spyOn(viewerStore, "request"); + const result = dataStyleStore.setMeshCellsVertexAttributeName(id, vertex_attribute.name); + expect(result).toBeInstanceOf(Promise); + await result; expect(spy).toHaveBeenCalledWith( mesh_cells_schemas.attribute.vertex.name, { id, ...vertex_attribute }, { response_function: expect.any(Function), }, - ) - expect(dataStyleStore.meshCellsVertexAttributeName(id)).toBe( - vertex_attribute.name, - ) - expect(viewerStore.status).toBe(Status.CONNECTED) - }) - }) + ); + expect(dataStyleStore.meshCellsVertexAttributeName(id)).toBe(vertex_attribute.name); + expect(viewerStore.status).toBe(Status.CONNECTED); + }); + }); describe("Cells cell attribute", () => { test("Coloring cell attribute", async () => { - const dataStyleStore = useDataStyleStore() - const viewerStore = useViewerStore() - const spy = vi.spyOn(viewerStore, "request") - const result = dataStyleStore.setMeshCellsCellAttributeName( - id, - cell_attribute.name, - ) - expect(result).toBeInstanceOf(Promise) - await result + const dataStyleStore = useDataStyleStore(); + const viewerStore = useViewerStore(); + const spy = vi.spyOn(viewerStore, "request"); + const result = dataStyleStore.setMeshCellsCellAttributeName(id, cell_attribute.name); + expect(result).toBeInstanceOf(Promise); + await result; expect(spy).toHaveBeenCalledWith( mesh_cells_schemas.attribute.cell.name, { id, ...cell_attribute }, { response_function: expect.any(Function), }, - ) - expect(dataStyleStore.meshCellsCellAttributeName(id)).toBe( - cell_attribute.name, - ) - expect(viewerStore.status).toBe(Status.CONNECTED) - }) - }) + ); + expect(dataStyleStore.meshCellsCellAttributeName(id)).toBe(cell_attribute.name); + expect(viewerStore.status).toBe(Status.CONNECTED); + }); + }); describe("Cells active coloring", () => { test("test coloring", async () => { - const dataStyleStore = useDataStyleStore() - const viewerStore = useViewerStore() + const dataStyleStore = useDataStyleStore(); + const viewerStore = useViewerStore(); const coloringTypes = [ { name: "color" }, { name: "vertex", - function: () => - dataStyleStore.setMeshCellsVertexAttributeName( - id, - vertex_attribute.name, - ), + function: () => dataStyleStore.setMeshCellsVertexAttributeName(id, vertex_attribute.name), }, { name: "cell", - function: () => - dataStyleStore.setMeshCellsCellAttributeName( - id, - cell_attribute.name, - ), + function: () => dataStyleStore.setMeshCellsCellAttributeName(id, cell_attribute.name), }, - ] + ]; async function testColoring(coloringType, expectedColoringType) { if (coloringType.function) { - await coloringType.function() + await coloringType.function(); } - const result = dataStyleStore.setMeshCellsActiveColoring( - id, - coloringType.name, - ) - expect(result).toBeInstanceOf(Promise) - await result - expect(dataStyleStore.meshCellsActiveColoring(id)).toBe( - expectedColoringType, - ) - expect(viewerStore.status).toBe(Status.CONNECTED) + const result = dataStyleStore.setMeshCellsActiveColoring(id, coloringType.name); + expect(result).toBeInstanceOf(Promise); + await result; + expect(dataStyleStore.meshCellsActiveColoring(id)).toBe(expectedColoringType); + expect(viewerStore.status).toBe(Status.CONNECTED); } - await testColoring(coloringTypes[0], "color") - await testColoring(coloringTypes[1], "vertex") - await testColoring(coloringTypes[2], "cell") - }) - }) + await testColoring(coloringTypes[0], "color"); + await testColoring(coloringTypes[1], "vertex"); + await testColoring(coloringTypes[2], "cell"); + }); + }); test("Cells apply default style", async () => { - const dataStyleStore = useDataStyleStore() - const viewerStore = useViewerStore() - const result = dataStyleStore.applyMeshCellsStyle(id) - expect(result).toBeInstanceOf(Promise) - await result - expect(viewerStore.status).toBe(Status.CONNECTED) - }) -}) + const dataStyleStore = useDataStyleStore(); + const viewerStore = useViewerStore(); + const result = dataStyleStore.applyMeshCellsStyle(id); + expect(result).toBeInstanceOf(Promise); + await result; + expect(viewerStore.status).toBe(Status.CONNECTED); + }); +}); 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 e13f1fe8..c5f12fa3 100644 --- a/tests/integration/stores/data_style/model/surfaces.nuxt.test.js +++ b/tests/integration/stores/data_style/model/surfaces.nuxt.test.js @@ -1,115 +1,94 @@ // Third party imports -import { afterEach, beforeEach, describe, expect, test, vi } from "vitest" -import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" with { type: "json" } +import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" with { type: "json" }; // Local imports -import { Status } from "@ogw_front/utils/status" -import { cleanupBackend } from "@ogw_front/utils/local/microservices" -import { setupIntegrationTests } from "@ogw_tests/integration/setup" -import { useDataStore } from "@ogw_front/stores/data" -import { useDataStyleStore } from "@ogw_front/stores/data_style" -import { useViewerStore } from "@ogw_front/stores/viewer" +import { Status } from "@ogw_front/utils/status"; +import { cleanupBackend } from "@ogw_front/utils/local/microservices"; +import { setupIntegrationTests } from "@ogw_tests/integration/setup"; +import { useDataStore } from "@ogw_front/stores/data"; +import { useDataStyleStore } from "@ogw_front/stores/data_style"; +import { useViewerStore } from "@ogw_front/stores/viewer"; // Local constants -const INTERVAL_TIMEOUT = 20_000 -const model_surfaces_schemas = viewer_schemas.opengeodeweb_viewer.model.surfaces -const file_name = "test.og_brep" -const geode_object = "BRep" +const INTERVAL_TIMEOUT = 20_000; +const model_surfaces_schemas = viewer_schemas.opengeodeweb_viewer.model.surfaces; +const file_name = "test.og_brep"; +const geode_object = "BRep"; let id = "", - projectFolderPath = "" + projectFolderPath = ""; beforeEach(async () => { - ;({ id, projectFolderPath } = await setupIntegrationTests( - file_name, - geode_object, - )) -}, INTERVAL_TIMEOUT) + ({ id, projectFolderPath } = await setupIntegrationTests(file_name, geode_object)); +}, INTERVAL_TIMEOUT); afterEach(async () => { - console.log("afterEach model surfaces kill", projectFolderPath) - await cleanupBackend(projectFolderPath) -}) + console.log("afterEach model surfaces kill", projectFolderPath); + await cleanupBackend(projectFolderPath); +}); describe("model surfaces", () => { describe("surfaces visibility", () => { test("visibility true", async () => { - const dataStyleStore = useDataStyleStore() - const viewerStore = useViewerStore() - const dataStore = useDataStore() - const surface_ids = await dataStore.getSurfacesGeodeIds(id) - const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds( - id, - surface_ids, - ) - const visibility = true - const spy = vi.spyOn(viewerStore, "request") - spy.mockClear() // Clear calls from setup (applyDefaultStyle) - const result = dataStyleStore.setModelSurfacesVisibility( - id, - surface_ids, - visibility, - ) - expect(result).toBeInstanceOf(Promise) - await result + const dataStyleStore = useDataStyleStore(); + const viewerStore = useViewerStore(); + const dataStore = useDataStore(); + const surface_ids = await dataStore.getSurfacesGeodeIds(id); + const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds(id, surface_ids); + const visibility = true; + const spy = vi.spyOn(viewerStore, "request"); + spy.mockClear(); + const result = dataStyleStore.setModelSurfacesVisibility(id, surface_ids, visibility); + expect(result).toBeInstanceOf(Promise); + await result; expect(spy).toHaveBeenCalledWith( model_surfaces_schemas.visibility, { id, block_ids: surface_viewer_ids, visibility }, { response_function: expect.any(Function), }, - ) + ); for (const surface_id of surface_ids) { - expect(dataStyleStore.modelSurfaceVisibility(id, surface_id)).toBe( - visibility, - ) + expect(dataStyleStore.modelSurfaceVisibility(id, surface_id)).toBe(visibility); } - expect(viewerStore.status).toBe(Status.CONNECTED) - }) - }) + expect(viewerStore.status).toBe(Status.CONNECTED); + }); + }); describe("surfaces color", () => { test("color red", async () => { - const dataStyleStore = useDataStyleStore() - const viewerStore = useViewerStore() - const dataStore = useDataStore() - const surface_ids = await dataStore.getSurfacesGeodeIds(id) - const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds( - id, - surface_ids, - ) - const color = { r: 255, g: 0, b: 0 } - const spy = vi.spyOn(viewerStore, "request") - spy.mockClear() // Clear calls from setup (applyDefaultStyle) - const result = dataStyleStore.setModelSurfacesColor( - id, - surface_ids, - color, - ) - expect(result).toBeInstanceOf(Promise) - await result + const dataStyleStore = useDataStyleStore(); + const viewerStore = useViewerStore(); + const dataStore = useDataStore(); + const surface_ids = await dataStore.getSurfacesGeodeIds(id); + const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds(id, surface_ids); + const color = { r: 255, g: 0, b: 0 }; + const spy = vi.spyOn(viewerStore, "request"); + spy.mockClear(); + const result = dataStyleStore.setModelSurfacesColor(id, surface_ids, color); + expect(result).toBeInstanceOf(Promise); + await result; expect(spy).toHaveBeenCalledWith( model_surfaces_schemas.color, { id, block_ids: surface_viewer_ids, color }, { response_function: expect.any(Function), }, - ) + ); for (const surface_id of surface_ids) { - expect(dataStyleStore.modelSurfaceColor(id, surface_id)).toStrictEqual( - color, - ) + expect(dataStyleStore.modelSurfaceColor(id, surface_id)).toStrictEqual(color); } - expect(viewerStore.status).toBe(Status.CONNECTED) - }) - }) + expect(viewerStore.status).toBe(Status.CONNECTED); + }); + }); describe("Surfaces style", () => { test("Surfaces apply style", async () => { - const dataStyleStore = useDataStyleStore() - const viewerStore = useViewerStore() - const result = dataStyleStore.applyModelSurfacesStyle(id) - expect(result).toBeInstanceOf(Promise) - await result - expect(viewerStore.status).toBe(Status.CONNECTED) - }) - }) -}) + const dataStyleStore = useDataStyleStore(); + const viewerStore = useViewerStore(); + const result = dataStyleStore.applyModelSurfacesStyle(id); + expect(result).toBeInstanceOf(Promise); + await result; + expect(viewerStore.status).toBe(Status.CONNECTED); + }); + }); +}); diff --git a/tests/integration/stores/viewer.nuxt.test.js b/tests/integration/stores/viewer.nuxt.test.js index 1e1110f7..86f52826 100644 --- a/tests/integration/stores/viewer.nuxt.test.js +++ b/tests/integration/stores/viewer.nuxt.test.js @@ -1,28 +1,28 @@ // Global imports // Third party imports -import { afterEach, beforeEach, describe, expect, test } from "vitest" -import opengeodeweb_viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" +import { afterEach, beforeEach, describe, expect, test } from "vitest"; +import opengeodeweb_viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"; // Local imports -import { Status } from "@ogw_front/utils/status" -import { cleanupBackend } from "@ogw_front/utils/local/microservices" -import { runMicroservices } from "@ogw_tests/integration/setup" -import { setupActivePinia } from "@ogw_tests/utils" -import { useViewerStore } from "@ogw_front/stores/viewer" +import { Status } from "@ogw_front/utils/status"; +import { cleanupBackend } from "@ogw_front/utils/local/microservices"; +import { runMicroservices } from "@ogw_tests/integration/setup"; +import { setupActivePinia } from "@ogw_tests/utils"; +import { useViewerStore } from "@ogw_front/stores/viewer"; -const CONNECT_TIMEOUT = 25_000 +const CONNECT_TIMEOUT = 25_000; -let projectFolderPath = "" +let projectFolderPath = ""; beforeEach(async () => { - setupActivePinia() - ;({ projectFolderPath } = await runMicroservices()) -}) + setupActivePinia(); + ({ projectFolderPath } = await runMicroservices()); +}); afterEach(async () => { - await cleanupBackend(projectFolderPath) -}) + await cleanupBackend(projectFolderPath); +}); describe("Viewer Store", () => { describe("actions", () => { @@ -30,44 +30,41 @@ describe("Viewer Store", () => { test( "ws_connect", async () => { - const viewerStore = useViewerStore() - await viewerStore.ws_connect() - expect(viewerStore.status).toBe(Status.CONNECTED) + const viewerStore = useViewerStore(); + await viewerStore.ws_connect(); + expect(viewerStore.status).toBe(Status.CONNECTED); }, CONNECT_TIMEOUT, - ) - }) + ); + }); describe("connect", () => { test( "connect", async () => { - const viewerStore = useViewerStore() - await viewerStore.connect() - expect(viewerStore.status).toBe(Status.CONNECTED) + const viewerStore = useViewerStore(); + await viewerStore.connect(); + expect(viewerStore.status).toBe(Status.CONNECTED); }, CONNECT_TIMEOUT, - ) - }) + ); + }); describe("request", () => { test( "request", - async () => { - const schema = - opengeodeweb_viewer_schemas.opengeodeweb_viewer.viewer.render - const viewerStore = useViewerStore() - const timeout = 1 - const params = {} + () => { + const schema = opengeodeweb_viewer_schemas.opengeodeweb_viewer.viewer.render; + const viewerStore = useViewerStore(); + const timeout = 1; + const params = {}; expect(() => viewerStore .request(schema, params, {}, timeout) - .rejects.toThrow( - `${schema.$id}: Timed out after ${timeout}ms, ${schema} ${params}`, - ), - ) + .rejects.toThrow(`${schema.$id}: Timed out after ${timeout}ms, ${schema} ${params}`), + ); }, CONNECT_TIMEOUT, - ) - }) - }) -}) + ); + }); + }); +}); diff --git a/tests/unit/components/FeedBack/Snackers.nuxt.test.js b/tests/unit/components/FeedBack/Snackers.nuxt.test.js index 6b615476..11aa9cb9 100644 --- a/tests/unit/components/FeedBack/Snackers.nuxt.test.js +++ b/tests/unit/components/FeedBack/Snackers.nuxt.test.js @@ -1,19 +1,19 @@ // Third party imports -import * as components from "vuetify/components" -import { describe, expect, test, vi } from "vitest" -import { mount } from "@vue/test-utils" +import * as components from "vuetify/components"; +import { describe, expect, test, vi } from "vitest"; +import { mount } from "@vue/test-utils"; // Local imports -import { setupActivePinia, vuetify } from "@ogw_tests/utils" -import FeedBackSnackers from "@ogw_front/components/FeedBack/Snackers" -import { useFeedbackStore } from "@ogw_front/stores/feedback" +import { setupActivePinia, vuetify } from "@ogw_tests/utils"; +import FeedBackSnackers from "@ogw_front/components/FeedBack/Snackers"; +import { useFeedbackStore } from "@ogw_front/stores/feedback"; -vi.stubGlobal("visualViewport", new EventTarget()) +vi.stubGlobal("visualViewport", new EventTarget()); -describe(FeedBackSnackers, async () => { +describe(FeedBackSnackers, () => { test(`Test delete error`, async () => { - const pinia = setupActivePinia() - const feedbackStore = useFeedbackStore() + const pinia = setupActivePinia(); + const feedbackStore = useFeedbackStore(); feedbackStore.$patch({ feedbacks: [ { @@ -24,7 +24,7 @@ describe(FeedBackSnackers, async () => { description: "test description", }, ], - }) + }); const wrapper = mount( { @@ -39,11 +39,11 @@ describe(FeedBackSnackers, async () => { plugins: [vuetify, pinia], }, }, - ) + ); - expect(feedbackStore.feedbacks.length).toBe(1) - const v_btn = await wrapper.findComponent(components.VBtn) - await v_btn.trigger("click") - expect(feedbackStore.feedbacks.length).toBe(0) - }) -}) + expect(feedbackStore.feedbacks.length).toBe(1); + const v_btn = await wrapper.findComponent(components.VBtn); + await v_btn.trigger("click"); + expect(feedbackStore.feedbacks.length).toBe(0); + }); +}); diff --git a/tests/unit/components/FileSelector.nuxt.test.js b/tests/unit/components/FileSelector.nuxt.test.js index 88afde3a..0ce42285 100644 --- a/tests/unit/components/FileSelector.nuxt.test.js +++ b/tests/unit/components/FileSelector.nuxt.test.js @@ -1,27 +1,27 @@ // Third party imports -import * as components from "vuetify/components" -import { describe, expect, test, vi } from "vitest" -import { mountSuspended, registerEndpoint } from "@nuxt/test-utils/runtime" -import { flushPromises } from "@vue/test-utils" -import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" +import * as components from "vuetify/components"; +import { describe, expect, test, vi } from "vitest"; +import { mountSuspended, registerEndpoint } from "@nuxt/test-utils/runtime"; +import { flushPromises } from "@vue/test-utils"; +import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json"; // Local imports -import { setupActivePinia, vuetify } from "@ogw_tests/utils" -import FileSelector from "@ogw_front/components/FileSelector" -import FileUploader from "@ogw_front/components/FileUploader" -import { useGeodeStore } from "@ogw_front/stores/geode" +import { setupActivePinia, vuetify } from "@ogw_tests/utils"; +import FileSelector from "@ogw_front/components/FileSelector"; +import FileUploader from "@ogw_front/components/FileUploader"; +import { useGeodeStore } from "@ogw_front/stores/geode"; -const EXPECTED_LENGTH = 1 -const FIRST_INDEX = 0 -const SECOND_INDEX = 1 +const EXPECTED_LENGTH = 1; +const FIRST_INDEX = 0; +const SECOND_INDEX = 1; -const allowed_files_schema = schemas.opengeodeweb_back.allowed_files -const upload_file_schema = schemas.opengeodeweb_back.upload_file +const allowed_files_schema = schemas.opengeodeweb_back.allowed_files; +const upload_file_schema = schemas.opengeodeweb_back.upload_file; -describe(FileSelector, async () => { - const pinia = setupActivePinia() - const geodeStore = useGeodeStore() - geodeStore.base_url = "" +describe(FileSelector, () => { + const pinia = setupActivePinia(); + const geodeStore = useGeodeStore(); + geodeStore.base_url = ""; test(`Select file`, async () => { registerEndpoint(allowed_files_schema.$id, { @@ -29,40 +29,40 @@ describe(FileSelector, async () => { handler: () => ({ extensions: ["1", "2", "3"], }), - }) + }); const wrapper = await mountSuspended(FileSelector, { global: { plugins: [vuetify, pinia], }, props: { multiple: false, auto_upload: false }, - }) + }); - const file_uploader = wrapper.findComponent(FileUploader) + const file_uploader = wrapper.findComponent(FileUploader); registerEndpoint(upload_file_schema.$id, { method: upload_file_schema.methods[SECOND_INDEX], handler: () => ({}), - }) + }); - const v_file_input = file_uploader.find('input[type="file"]') - const files = [new File(["fake_file"], "fake_file.txt")] - const auto_upload = false + const v_file_input = file_uploader.find('input[type="file"]'); + const files = [new File(["fake_file"], "fake_file.txt")]; + const auto_upload = false; Object.defineProperty(v_file_input.element, "files", { value: files, writable: true, - }) - await v_file_input.trigger("change") - const v_btn = wrapper.findComponent(components.VBtn) - await v_btn.trigger("click") - await flushPromises() - await flushPromises() - expect(wrapper.emitted()).toHaveProperty("update_values") - expect(wrapper.emitted().update_values).toHaveLength(EXPECTED_LENGTH) + }); + await v_file_input.trigger("change"); + const v_btn = wrapper.findComponent(components.VBtn); + await v_btn.trigger("click"); + await flushPromises(); + await flushPromises(); + expect(wrapper.emitted()).toHaveProperty("update_values"); + expect(wrapper.emitted().update_values).toHaveLength(EXPECTED_LENGTH); expect(wrapper.emitted().update_values[FIRST_INDEX][FIRST_INDEX]).toEqual({ files, auto_upload, - }) - }) + }); + }); describe(FileSelector, () => { registerEndpoint(allowed_files_schema.$id, { @@ -70,14 +70,14 @@ describe(FileSelector, async () => { handler: () => ({ extensions: ["1", "2", "3"], }), - }) + }); registerEndpoint(upload_file_schema.$id, { method: upload_file_schema.methods[SECOND_INDEX], handler: () => ({}), - }) + }); - const files = [new File(["fake_file"], "fake_file.txt")] + const files = [new File(["fake_file"], "fake_file.txt")]; test("auto_upload true", async () => { const wrapper = await mountSuspended(FileSelector, { global: { @@ -88,19 +88,17 @@ describe(FileSelector, async () => { files: files, auto_upload: true, }, - }) + }); - await flushPromises() - expect(wrapper.componentVM.files).toEqual(files) - expect(wrapper.emitted()).toHaveProperty("update_values") - expect(wrapper.emitted().update_values).toHaveLength(EXPECTED_LENGTH) - expect(wrapper.emitted().update_values[FIRST_INDEX][FIRST_INDEX]).toEqual( - { - files, - auto_upload: false, - }, - ) - }) + await flushPromises(); + expect(wrapper.componentVM.files).toEqual(files); + expect(wrapper.emitted()).toHaveProperty("update_values"); + expect(wrapper.emitted().update_values).toHaveLength(EXPECTED_LENGTH); + expect(wrapper.emitted().update_values[FIRST_INDEX][FIRST_INDEX]).toEqual({ + files, + auto_upload: false, + }); + }); test("auto_upload false", async () => { const wrapper = await mountSuspended(FileSelector, { @@ -112,14 +110,14 @@ describe(FileSelector, async () => { files: files, auto_upload: false, }, - }) + }); - await flushPromises() + await flushPromises(); - const file_uploader = wrapper.findComponent(FileUploader) - expect(wrapper.vm.files).toEqual(files) - const upload_files = vi.spyOn(file_uploader.vm, "upload_files") - expect(upload_files).not.toHaveBeenCalled() - }) - }) -}) + const file_uploader = wrapper.findComponent(FileUploader); + expect(wrapper.vm.files).toEqual(files); + const upload_files = vi.spyOn(file_uploader.vm, "upload_files"); + expect(upload_files).not.toHaveBeenCalled(); + }); + }); +}); diff --git a/tests/unit/components/FileUploader.nuxt.test.js b/tests/unit/components/FileUploader.nuxt.test.js index 665dbe99..96c61002 100644 --- a/tests/unit/components/FileUploader.nuxt.test.js +++ b/tests/unit/components/FileUploader.nuxt.test.js @@ -1,60 +1,58 @@ // Third party imports -import * as components from "vuetify/components" -import { describe, expect, test } from "vitest" -import { mountSuspended, registerEndpoint } from "@nuxt/test-utils/runtime" -import { flushPromises } from "@vue/test-utils" -import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" +import * as components from "vuetify/components"; +import { describe, expect, test } from "vitest"; +import { mountSuspended, registerEndpoint } from "@nuxt/test-utils/runtime"; +import { flushPromises } from "@vue/test-utils"; +import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json"; // Local imports -import { setupActivePinia, vuetify } from "@ogw_tests/utils" -import FileUploader from "@ogw_front/components/FileUploader" -import { useGeodeStore } from "@ogw_front/stores/geode" +import { setupActivePinia, vuetify } from "@ogw_tests/utils"; +import FileUploader from "@ogw_front/components/FileUploader"; +import { useGeodeStore } from "@ogw_front/stores/geode"; -const FIRST_INDEX = 0 -const SECOND_INDEX = 1 +const FIRST_INDEX = 0; +const SECOND_INDEX = 1; -const upload_file_schema = schemas.opengeodeweb_back.upload_file +const upload_file_schema = schemas.opengeodeweb_back.upload_file; -describe(FileUploader, async () => { - const pinia = setupActivePinia() - const geodeStore = useGeodeStore() - geodeStore.base_url = "" +describe(FileUploader, () => { + const pinia = setupActivePinia(); + const geodeStore = useGeodeStore(); + geodeStore.base_url = ""; registerEndpoint(upload_file_schema.$id, { method: upload_file_schema.methods[FIRST_INDEX], handler: () => ({}), - }) + }); registerEndpoint(upload_file_schema.$id, { method: upload_file_schema.methods[SECOND_INDEX], handler: () => ({}), - }) + }); - const files = [new File(["fake_file"], "fake_file.txt")] + const files = [new File(["fake_file"], "fake_file.txt")]; - describe(`Upload file`, async () => { + describe(`Upload file`, () => { test(`prop auto_upload false`, async () => { const wrapper = await mountSuspended(FileUploader, { global: { plugins: [vuetify, pinia], }, props: { multiple: false, accept: "*.txt" }, - }) + }); - const v_file_input = wrapper.find('input[type="file"]') + const v_file_input = wrapper.find('input[type="file"]'); Object.defineProperty(v_file_input.element, "files", { value: files, writable: true, - }) - await v_file_input.trigger("change") - const v_btn = wrapper.findComponent(components.VBtn) + }); + await v_file_input.trigger("change"); + const v_btn = wrapper.findComponent(components.VBtn); - await v_btn.trigger("click") - await flushPromises() - await flushPromises() - expect( - wrapper.emitted().files_uploaded[FIRST_INDEX][FIRST_INDEX], - ).toEqual(files) - }) + await v_btn.trigger("click"); + await flushPromises(); + await flushPromises(); + expect(wrapper.emitted().files_uploaded[FIRST_INDEX][FIRST_INDEX]).toEqual(files); + }); test(`prop auto_upload true`, async () => { const wrapper = await mountSuspended(FileUploader, { @@ -62,11 +60,9 @@ describe(FileUploader, async () => { plugins: [vuetify, pinia], }, props: { multiple: false, accept: "*.txt", files, auto_upload: true }, - }) - await flushPromises() - expect( - wrapper.emitted().files_uploaded[FIRST_INDEX][FIRST_INDEX], - ).toEqual(files) - }) - }) -}) + }); + await flushPromises(); + expect(wrapper.emitted().files_uploaded[FIRST_INDEX][FIRST_INDEX]).toEqual(files); + }); + }); +}); diff --git a/tests/unit/components/Inspector/InspectionButton.nuxt.test.js b/tests/unit/components/Inspector/InspectionButton.nuxt.test.js index d4eb3cd0..2d7ea6ad 100644 --- a/tests/unit/components/Inspector/InspectionButton.nuxt.test.js +++ b/tests/unit/components/Inspector/InspectionButton.nuxt.test.js @@ -1,18 +1,18 @@ // Third party imports -import * as components from "vuetify/components" -import { describe, expect, test, vi } from "vitest" -import { flushPromises } from "@vue/test-utils" -import { mountSuspended } from "@nuxt/test-utils/runtime" +import * as components from "vuetify/components"; +import { describe, expect, test, vi } from "vitest"; +import { flushPromises } from "@vue/test-utils"; +import { mountSuspended } from "@nuxt/test-utils/runtime"; // Local imports -import { setupActivePinia, vuetify } from "@ogw_tests/utils" -import InspectorInspectionButton from "@ogw_front/components/Inspector/InspectionButton" -import { useGeodeStore } from "@ogw_front/stores/geode" +import { setupActivePinia, vuetify } from "@ogw_tests/utils"; +import InspectorInspectionButton from "@ogw_front/components/Inspector/InspectionButton"; +import { useGeodeStore } from "@ogw_front/stores/geode"; -describe("Inspector/InspectionButton", async () => { - const pinia = setupActivePinia() - const geodeStore = useGeodeStore() - geodeStore.base_url = "" +describe("Inspector/InspectionButton", () => { + const pinia = setupActivePinia(); + const geodeStore = useGeodeStore(); + geodeStore.base_url = ""; test(`Test with issues`, async () => { const inspection_result = { @@ -30,39 +30,39 @@ describe("Inspector/InspectionButton", async () => { issues: ["issue 1"], }, ], - } + }; geodeStore.request = vi.fn((_schema, params, callbacks) => { if (callbacks?.response_function) { callbacks.response_function({ inspection_result, - }) + }); } return Promise.resolve({ inspection_result, - }) - }) + }); + }); - const geode_object_type = "BRep" - const filename = "test.txt" + const geode_object_type = "BRep"; + const filename = "test.txt"; const wrapper = await mountSuspended(InspectorInspectionButton, { global: { plugins: [vuetify, pinia], }, props: { geode_object_type, filename }, - }) + }); - expect(wrapper.exists()).toBeTruthy() - const v_btn = await wrapper.findComponent(components.VBtn) - await v_btn.trigger("click") - await flushPromises() + expect(wrapper.exists()).toBeTruthy(); + const v_btn = await wrapper.findComponent(components.VBtn); + await v_btn.trigger("click"); + await flushPromises(); - expect(wrapper.emitted()).toHaveProperty("update_values") - expect(wrapper.emitted().update_values).toHaveLength(1) + expect(wrapper.emitted()).toHaveProperty("update_values"); + expect(wrapper.emitted().update_values).toHaveLength(1); expect(wrapper.emitted().update_values[0][0]).toStrictEqual({ inspection_result: [inspection_result], - }) - expect(wrapper.emitted()).toHaveProperty("increment_step") - }) -}) + }); + expect(wrapper.emitted()).toHaveProperty("increment_step"); + }); +}); diff --git a/tests/unit/components/Inspector/ResultPanel.nuxt.test.js b/tests/unit/components/Inspector/ResultPanel.nuxt.test.js index bedbc646..a21047e9 100644 --- a/tests/unit/components/Inspector/ResultPanel.nuxt.test.js +++ b/tests/unit/components/Inspector/ResultPanel.nuxt.test.js @@ -1,12 +1,12 @@ // Third party imports -import { describe, expect, test } from "vitest" -import { mountSuspended } from "@nuxt/test-utils/runtime" +import { describe, expect, test } from "vitest"; +import { mountSuspended } from "@nuxt/test-utils/runtime"; // Local imports -import InspectorResultPanel from "@ogw_front/components/Inspector/ResultPanel" -import { vuetify } from "@ogw_tests/utils" +import InspectorResultPanel from "@ogw_front/components/Inspector/ResultPanel"; +import { vuetify } from "@ogw_tests/utils"; -describe("Inspector/ResultPanel", async () => { +describe("Inspector/ResultPanel", () => { test(`Test with issues`, async () => { const inspection_result = [ { @@ -14,27 +14,24 @@ describe("Inspector/ResultPanel", async () => { nb_issues: 26, children: [], }, - ] + ]; const wrapper = await mountSuspended(InspectorResultPanel, { global: { plugins: [vuetify], }, props: { inspection_result }, - }) + }); - expect(wrapper.exists()).toBeTruthy() - expect(wrapper.componentVM.inspection_result).toStrictEqual( - inspection_result, - ) + expect(wrapper.exists()).toBeTruthy(); + expect(wrapper.componentVM.inspection_result).toStrictEqual(inspection_result); - const child_result_panel_wrapper = - await wrapper.findComponent(InspectorResultPanel) - expect(child_result_panel_wrapper.exists()).toBeTruthy() - expect( - child_result_panel_wrapper.componentVM.inspection_result, - ).toStrictEqual(inspection_result[0].children) - }) + const child_result_panel_wrapper = await wrapper.findComponent(InspectorResultPanel); + expect(child_result_panel_wrapper.exists()).toBeTruthy(); + expect(child_result_panel_wrapper.componentVM.inspection_result).toStrictEqual( + inspection_result[0].children, + ); + }); test(`Test without issues`, async () => { const inspection_result = [ @@ -42,20 +39,18 @@ describe("Inspector/ResultPanel", async () => { title: "Brep inspection", nb_issues: 0, }, - ] + ]; const wrapper = await mountSuspended(InspectorResultPanel, { global: { plugins: [vuetify], }, props: { inspection_result }, - }) + }); - expect(wrapper.exists()).toBeTruthy() + expect(wrapper.exists()).toBeTruthy(); - console.log({ wrapper }) + console.log({ wrapper }); - expect(wrapper.componentVM.inspection_result).toStrictEqual( - inspection_result, - ) - }) -}) + expect(wrapper.componentVM.inspection_result).toStrictEqual(inspection_result); + }); +}); diff --git a/tests/unit/components/Launcher.nuxt.test.js b/tests/unit/components/Launcher.nuxt.test.js index 41e57df6..9f2e5e34 100644 --- a/tests/unit/components/Launcher.nuxt.test.js +++ b/tests/unit/components/Launcher.nuxt.test.js @@ -1,39 +1,37 @@ -import { describe, expect, test, vi } from "vitest" +import { describe, expect, test, vi } from "vitest"; -import Launcher from "@ogw_front/components/Launcher" -import ResizeObserver from "resize-observer-polyfill" -import { flushPromises } from "@vue/test-utils" -import { mountSuspended } from "@nuxt/test-utils/runtime" +import Launcher from "@ogw_front/components/Launcher"; +import ResizeObserver from "resize-observer-polyfill"; +import { flushPromises } from "@vue/test-utils"; +import { mountSuspended } from "@nuxt/test-utils/runtime"; -import { setupActivePinia, vuetify } from "@ogw_tests/utils" -import { useInfraStore } from "@ogw_front/stores/infra" +import { setupActivePinia, vuetify } from "@ogw_tests/utils"; +import { useInfraStore } from "@ogw_front/stores/infra"; // Mock navigator.locks API -const mockLockRequest = vi - .fn() - .mockImplementation(async (name, task) => await task({ name })) +const mockLockRequest = vi.fn().mockImplementation(async (name, task) => await task({ name })); vi.stubGlobal("navigator", { ...navigator, locks: { request: mockLockRequest, }, -}) +}); -globalThis.ResizeObserver = ResizeObserver +globalThis.ResizeObserver = ResizeObserver; -describe(Launcher, async () => { +describe(Launcher, () => { test(`Mount`, async () => { - const pinia = setupActivePinia() - const infraStore = useInfraStore() + const pinia = setupActivePinia(); + const infraStore = useInfraStore(); const wrapper = await mountSuspended(Launcher, { global: { plugins: [vuetify, pinia], }, - }) - expect(wrapper.exists()).toBeTruthy() - await infraStore.$patch({ is_captcha_validated: true }) - await flushPromises() - expect(infraStore.create_backend).toHaveBeenCalled() - }) -}) + }); + expect(wrapper.exists()).toBeTruthy(); + await infraStore.$patch({ is_captcha_validated: true }); + await flushPromises(); + expect(infraStore.create_backend).toHaveBeenCalled(); + }); +}); diff --git a/tests/unit/components/PackagesVersions.nuxt.test.js b/tests/unit/components/PackagesVersions.nuxt.test.js index 7e7a19ef..4546c843 100644 --- a/tests/unit/components/PackagesVersions.nuxt.test.js +++ b/tests/unit/components/PackagesVersions.nuxt.test.js @@ -1,17 +1,17 @@ -import { describe, expect, test } from "vitest" -import { mountSuspended, registerEndpoint } from "@nuxt/test-utils/runtime" +import { describe, expect, test } from "vitest"; +import { mountSuspended, registerEndpoint } from "@nuxt/test-utils/runtime"; -import { setupActivePinia, vuetify } from "@ogw_tests/utils" -import PackagesVersions from "@ogw_front/components/PackagesVersions" -import { useGeodeStore } from "@ogw_front/stores/geode" +import { setupActivePinia, vuetify } from "@ogw_tests/utils"; +import PackagesVersions from "@ogw_front/components/PackagesVersions"; +import { useGeodeStore } from "@ogw_front/stores/geode"; -const FIRST_INDEX = 0 +const FIRST_INDEX = 0; -describe(PackagesVersions, async () => { +describe(PackagesVersions, () => { test(`Mount`, async () => { - const pinia = setupActivePinia() - const geodeStore = useGeodeStore() - geodeStore.base_url = "" + const pinia = setupActivePinia(); + const geodeStore = useGeodeStore(); + geodeStore.base_url = ""; const schema = { $id: "/versions", @@ -19,7 +19,7 @@ describe(PackagesVersions, async () => { type: "object", properties: {}, additionalProperties: false, - } + }; registerEndpoint(schema.$id, { method: schema.methods[FIRST_INDEX], handler: () => ({ @@ -30,13 +30,13 @@ describe(PackagesVersions, async () => { }, ], }), - }) + }); const wrapper = await mountSuspended(PackagesVersions, { global: { plugins: [vuetify, pinia], }, props: { schema }, - }) - expect(wrapper.exists()).toBeTruthy() - }) -}) + }); + expect(wrapper.exists()).toBeTruthy(); + }); +}); diff --git a/tests/unit/components/Step.nuxt.test.js b/tests/unit/components/Step.nuxt.test.js index 7c892f15..289f07fb 100644 --- a/tests/unit/components/Step.nuxt.test.js +++ b/tests/unit/components/Step.nuxt.test.js @@ -1,19 +1,19 @@ -import { computed, reactive, ref, shallowRef } from "vue" -import { describe, expect, test } from "vitest" -import ResizeObserver from "resize-observer-polyfill" -import { mount } from "@vue/test-utils" +import { computed, reactive, ref, shallowRef } from "vue"; +import { describe, expect, test } from "vitest"; +import ResizeObserver from "resize-observer-polyfill"; +import { mount } from "@vue/test-utils"; -import ObjectSelector from "@ogw_front/components/ObjectSelector" -import Step from "@ogw_front/components/Step" +import ObjectSelector from "@ogw_front/components/ObjectSelector"; +import Step from "@ogw_front/components/Step"; -import { vuetify } from "@ogw_tests/utils" +import { vuetify } from "@ogw_tests/utils"; -globalThis.ResizeObserver = ResizeObserver +globalThis.ResizeObserver = ResizeObserver; describe(Step, () => { - test(`BRep`, async () => { - const geode_object_type = ref("BRep") - const files = ref([]) + test(`BRep`, () => { + const geode_object_type = ref("BRep"); + const files = ref([]); const stepper_tree = reactive({ current_step_index: ref(0), geode_object_type, @@ -29,21 +29,20 @@ describe(Step, () => { }, chips: computed(() => { if (geode_object_type.value === "") { - return [] - } else { - return [geode_object_type.value] + return []; } + return [geode_object_type.value]; }), }, ], - }) + }); const wrapper = mount(Step, { global: { plugins: [vuetify], provide: { stepper_tree }, }, props: { step_index: 0 }, - }) - expect(wrapper.exists()).toBeTruthy() - }) -}) + }); + expect(wrapper.exists()).toBeTruthy(); + }); +}); diff --git a/tests/unit/composables/api_fetch.nuxt.test.js b/tests/unit/composables/api_fetch.nuxt.test.js index a620a3a6..d35fd657 100644 --- a/tests/unit/composables/api_fetch.nuxt.test.js +++ b/tests/unit/composables/api_fetch.nuxt.test.js @@ -1,19 +1,19 @@ // Third party imports -import { beforeEach, describe, expect, test } from "vitest" -import { registerEndpoint } from "@nuxt/test-utils/runtime" +import { beforeEach, describe, expect, test } from "vitest"; +import { registerEndpoint } from "@nuxt/test-utils/runtime"; // Local imports -import { setupActivePinia } from "@ogw_tests/utils" -import { useFeedbackStore } from "@ogw_front/stores/feedback" -import { useGeodeStore } from "@ogw_front/stores/geode" +import { setupActivePinia } from "@ogw_tests/utils"; +import { useFeedbackStore } from "@ogw_front/stores/feedback"; +import { useGeodeStore } from "@ogw_front/stores/geode"; -const FIRST_INDEX = 0 +const FIRST_INDEX = 0; describe("geodeStore.request()", () => { - setupActivePinia() - const geodeStore = useGeodeStore() - const feedbackStore = useFeedbackStore() - geodeStore.base_url = "" + setupActivePinia(); + const geodeStore = useGeodeStore(); + const feedbackStore = useFeedbackStore(); + geodeStore.base_url = ""; const schema = { $id: "/test", @@ -26,15 +26,15 @@ describe("geodeStore.request()", () => { }, required: ["test"], additionalProperties: false, - } + }; beforeEach(async () => { - await feedbackStore.$reset() - await geodeStore.$reset() - geodeStore.base_url = "" - }) + await feedbackStore.$reset(); + await geodeStore.$reset(); + geodeStore.base_url = ""; + }); - test("invalid schema", async () => { + test("invalid schema", () => { const invalid_schema = { $id: "/test", type: "object", @@ -46,33 +46,31 @@ describe("geodeStore.request()", () => { }, required: ["test"], additionalProperties: false, - } - const params = { test: "hello" } - expect(() => geodeStore.request(invalid_schema, params)).toThrow( - "data/test must be number", - ) - }) + }; + const params = { test: "hello" }; + expect(() => geodeStore.request(invalid_schema, params)).toThrow("data/test must be number"); + }); - test("invalid params", async () => { - const params = {} + test("invalid params", () => { + const params = {}; expect(() => geodeStore.request(schema, params)).toThrow( "data must have required property 'test'", - ) - }) + ); + }); test("request with callbacks", async () => { - const params = { test: "hello" } - let errorCalled = false + const params = { test: "hello" }; + let errorCalled = false; const callbacks = { - request_error_function: async () => { - errorCalled = true + request_error_function: () => { + errorCalled = true; }, - } + }; registerEndpoint(schema.$id, { method: schema.methods[FIRST_INDEX], handler: () => ({ result: "success" }), - }) - await geodeStore.request(schema, params, callbacks) - expect(errorCalled).toBeFalsy() - }) -}) + }); + await geodeStore.request(schema, params, callbacks); + expect(errorCalled).toBeFalsy(); + }); +}); diff --git a/tests/unit/composables/run_function_when_microservices_connected.nuxt.test.js b/tests/unit/composables/run_function_when_microservices_connected.nuxt.test.js index a46ba4b5..2bfc8bc9 100644 --- a/tests/unit/composables/run_function_when_microservices_connected.nuxt.test.js +++ b/tests/unit/composables/run_function_when_microservices_connected.nuxt.test.js @@ -1,57 +1,57 @@ // Third party imports -import { beforeEach, describe, expect, test, vi } from "vitest" -import { flushPromises } from "@vue/test-utils" +import { beforeEach, describe, expect, test, vi } from "vitest"; +import { flushPromises } from "@vue/test-utils"; // Local imports -import { Status } from "@ogw_front/utils/status" -import { run_function_when_microservices_connected } from "@ogw_front/composables/run_function_when_microservices_connected" -import { setupActivePinia } from "@ogw_tests/utils" -import { useGeodeStore } from "@ogw_front/stores/geode" -import { useInfraStore } from "@ogw_front/stores/infra" -import { useViewerStore } from "@ogw_front/stores/viewer" +import { Status } from "@ogw_front/utils/status"; +import { run_function_when_microservices_connected } from "@ogw_front/composables/run_function_when_microservices_connected"; +import { setupActivePinia } from "@ogw_tests/utils"; +import { useGeodeStore } from "@ogw_front/stores/geode"; +import { useInfraStore } from "@ogw_front/stores/infra"; +import { useViewerStore } from "@ogw_front/stores/viewer"; -const dumb_obj = { dumb_method: () => true } -let infraStore = undefined -let geodeStore = undefined -let viewerStore = undefined +const dumb_obj = { dumb_method: () => true }; +let infraStore = undefined; +let geodeStore = undefined; +let viewerStore = undefined; beforeEach(() => { - setupActivePinia() - infraStore = useInfraStore() - geodeStore = useGeodeStore() - viewerStore = useViewerStore() + setupActivePinia(); + infraStore = useInfraStore(); + geodeStore = useGeodeStore(); + viewerStore = useViewerStore(); // Register microservices in infra store infraStore.register_microservice(geodeStore, { request: vi.fn(), connect: vi.fn(), launch: vi.fn(), - }) + }); infraStore.register_microservice(viewerStore, { request: vi.fn(), connect: vi.fn(), launch: vi.fn(), - }) + }); - geodeStore.$patch({ status: Status.NOT_CONNECTED }) - viewerStore.$patch({ status: Status.NOT_CONNECTED }) -}) + geodeStore.$patch({ status: Status.NOT_CONNECTED }); + viewerStore.$patch({ status: Status.NOT_CONNECTED }); +}); describe("when_microservices_connected_run_function", () => { - test("microservices not connected", async () => { - const spy = vi.spyOn(dumb_obj, "dumb_method") - run_function_when_microservices_connected(dumb_obj.dumb_method) - geodeStore.$patch({ status: Status.NOT_CONNECTED }) - viewerStore.$patch({ status: Status.NOT_CONNECTED }) - expect(spy).not.toHaveBeenCalled() - }) + test("microservices not connected", () => { + const spy = vi.spyOn(dumb_obj, "dumb_method"); + run_function_when_microservices_connected(dumb_obj.dumb_method); + geodeStore.$patch({ status: Status.NOT_CONNECTED }); + viewerStore.$patch({ status: Status.NOT_CONNECTED }); + expect(spy).not.toHaveBeenCalled(); + }); test("microservices connected", async () => { - const spy = vi.spyOn(dumb_obj, "dumb_method") - run_function_when_microservices_connected(dumb_obj.dumb_method) - geodeStore.$patch({ status: Status.CONNECTED }) - viewerStore.$patch({ status: Status.CONNECTED }) - await flushPromises() - expect(spy).toHaveBeenCalledWith() - }) -}) + const spy = vi.spyOn(dumb_obj, "dumb_method"); + run_function_when_microservices_connected(dumb_obj.dumb_method); + geodeStore.$patch({ status: Status.CONNECTED }); + viewerStore.$patch({ status: Status.CONNECTED }); + await flushPromises(); + expect(spy).toHaveBeenCalledWith(); + }); +}); diff --git a/tests/unit/stores/lambda.nuxt.test.js b/tests/unit/stores/lambda.nuxt.test.js index 46a29906..66c9dc2a 100644 --- a/tests/unit/stores/lambda.nuxt.test.js +++ b/tests/unit/stores/lambda.nuxt.test.js @@ -1,132 +1,130 @@ // Third party imports -import { beforeEach, describe, expect, expectTypeOf, test, vi } from "vitest" -import { registerEndpoint } from "@nuxt/test-utils/runtime" +import { beforeEach, describe, expect, expectTypeOf, test, vi } from "vitest"; +import { registerEndpoint } from "@nuxt/test-utils/runtime"; // Local imports -import { Status } from "@ogw_front/utils/status" -import { setupActivePinia } from "@ogw_tests/utils" -import { useFeedbackStore } from "@ogw_front/stores/feedback" -import { useLambdaStore } from "@ogw_front/stores/lambda" +import { Status } from "@ogw_front/utils/status"; +import { setupActivePinia } from "@ogw_tests/utils"; +import { useFeedbackStore } from "@ogw_front/stores/feedback"; +import { useLambdaStore } from "@ogw_front/stores/lambda"; // CONSTANTS -const PORT_443 = "443" -const API_URL = "api.example.com" -const SITE_BRANCH = "/test" -const PROJECT = "project" -const TEST_ID = "test-id-123456" -const STATUS_500 = 500 +const PORT_443 = "443"; +const API_URL = "api.example.com"; +const SITE_BRANCH = "/test"; +const PROJECT = "project"; +const TEST_ID = "test-id-123456"; +const STATUS_500 = 500; -beforeEach(async () => { - setupActivePinia() -}) +beforeEach(() => { + setupActivePinia(); +}); function setupConfig() { - const config = useRuntimeConfig() - config.public.API_URL = API_URL - config.public.SITE_BRANCH = SITE_BRANCH - config.public.PROJECT = PROJECT + const config = useRuntimeConfig(); + config.public.API_URL = API_URL; + config.public.SITE_BRANCH = SITE_BRANCH; + config.public.PROJECT = PROJECT; } describe("Lambda Store", () => { describe("state", () => { test("initial state", () => { - const lambdaStore = useLambdaStore() - expectTypeOf(lambdaStore.status).toBeString() - expect(lambdaStore.status).toBe(Status.NOT_CONNECTED) - }) - }) + const lambdaStore = useLambdaStore(); + expectTypeOf(lambdaStore.status).toBeString(); + expect(lambdaStore.status).toBe(Status.NOT_CONNECTED); + }); + }); describe("getters", () => { describe("protocol", () => { test("test protocol is always https", () => { - const lambdaStore = useLambdaStore() - expect(lambdaStore.protocol).toBe("https") - }) - }) + const lambdaStore = useLambdaStore(); + expect(lambdaStore.protocol).toBe("https"); + }); + }); describe("port", () => { test("test port is always 443", () => { - const lambdaStore = useLambdaStore() - expect(lambdaStore.port).toBe(PORT_443) - }) - }) + const lambdaStore = useLambdaStore(); + expect(lambdaStore.port).toBe(PORT_443); + }); + }); describe("base_url", () => { test("test base_url construction", () => { - setupConfig() - const lambdaStore = useLambdaStore() + setupConfig(); + const lambdaStore = useLambdaStore(); expect(lambdaStore.base_url).toBe( `https://${API_URL}:${PORT_443}${SITE_BRANCH}/${PROJECT}/createbackend`, - ) - }) - }) + ); + }); + }); describe("is_busy", () => { test("test is_busy is always false", () => { - const lambdaStore = useLambdaStore() - expect(lambdaStore.is_busy).toBeFalsy() - }) - }) - }) + const lambdaStore = useLambdaStore(); + expect(lambdaStore.is_busy).toBeFalsy(); + }); + }); + }); describe("actions", () => { describe("launch", () => { - const postFakeCall = vi.fn() + const postFakeCall = vi.fn(); test("successful launch", async () => { - setupConfig() - const lambdaStore = useLambdaStore() - const feedbackStore = useFeedbackStore() + setupConfig(); + const lambdaStore = useLambdaStore(); + const feedbackStore = useFeedbackStore(); - lambdaStore.base_url = "test-base-url" + lambdaStore.base_url = "test-base-url"; registerEndpoint(lambdaStore.base_url, { method: "POST", handler: postFakeCall, - }) + }); postFakeCall.mockImplementation(() => ({ ID: TEST_ID, - })) + })); - const id = await lambdaStore.launch() + const id = await lambdaStore.launch(); - expect(lambdaStore.status).toBe(Status.CONNECTED) - expect(id).toBe(TEST_ID) - expect(feedbackStore.server_error).toBeFalsy() - }) + expect(lambdaStore.status).toBe(Status.CONNECTED); + expect(id).toBe(TEST_ID); + expect(feedbackStore.server_error).toBeFalsy(); + }); test("failed launch - error response", async () => { - setupConfig() - const lambdaStore = useLambdaStore() - const feedbackStore = useFeedbackStore() + setupConfig(); + const lambdaStore = useLambdaStore(); + const feedbackStore = useFeedbackStore(); registerEndpoint(lambdaStore.base_url, { method: "POST", handler: postFakeCall, - }) + }); postFakeCall.mockImplementation(() => { throw createError({ status: STATUS_500, statusMessage: "Internal Server Error", - }) - }) + }); + }); - await expect(lambdaStore.launch()).rejects.toThrow( - "Failed to launch lambda backend", - ) + await expect(lambdaStore.launch()).rejects.toThrow("Failed to launch lambda backend"); - expect(lambdaStore.status).toBe(Status.NOT_CONNECTED) - expect(feedbackStore.server_error).toBeTruthy() - }) - }) + expect(lambdaStore.status).toBe(Status.NOT_CONNECTED); + expect(feedbackStore.server_error).toBeTruthy(); + }); + }); describe("connect", () => { test("successful connect", async () => { - const lambdaStore = useLambdaStore() - await lambdaStore.connect() - expect(lambdaStore.status).toBe(Status.CONNECTED) - }) - }) - }) -}) + const lambdaStore = useLambdaStore(); + await lambdaStore.connect(); + expect(lambdaStore.status).toBe(Status.CONNECTED); + }); + }); + }); +}); From d71bf07cc7b27245d140b5970f2cf383295a49ba Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Thu, 19 Mar 2026 14:16:33 +0100 Subject: [PATCH 02/11] some fixes --- .oxlintrc.json | 4 ++-- app/stores/hybrid_viewer.js | 3 +++ internal/utils/upload_file.js | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.oxlintrc.json b/.oxlintrc.json index 832c2f09..65bd07e8 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -56,7 +56,7 @@ { "max": 50, "skipBlankLines": true, - "skipComments": true, + "skipComments": true } ], "unicorn/no-useless-undefined": "off", @@ -64,7 +64,7 @@ "error", { "skipBlankLines": true, - "skipComments": true, + "skipComments": true } ], "vue/max-props": [ diff --git a/app/stores/hybrid_viewer.js b/app/stores/hybrid_viewer.js index 6a6d94a0..e6c20b3c 100644 --- a/app/stores/hybrid_viewer.js +++ b/app/stores/hybrid_viewer.js @@ -99,6 +99,9 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { } function setVisibility(id, visibility) { + if (!hybridDb[id]) { + return; + } hybridDb[id].actor.setVisibility(visibility); const renderWindow = genericRenderWindow.value.getRenderWindow(); renderWindow.render(); diff --git a/internal/utils/upload_file.js b/internal/utils/upload_file.js index 269802e7..bee87bca 100644 --- a/internal/utils/upload_file.js +++ b/internal/utils/upload_file.js @@ -1,6 +1,6 @@ import { useFeedbackStore } from "@ogw_front/stores/feedback.js"; -function upload_file( +async function upload_file( microservice, { route, file }, { request_error_function, response_function, response_error_function } = {}, @@ -19,7 +19,7 @@ function upload_file( body: body, }; microservice.start_request(); - return $fetch(route, { + return await $fetch(route, { baseURL: microservice.base_url || "", ...request_options, onRequestError({ error }) { From 89c6e4ea106884ec9504cb491a4eb3b8be83ae14 Mon Sep 17 00:00:00 2001 From: MaxNumerique <144453705+MaxNumerique@users.noreply.github.com> Date: Thu, 19 Mar 2026 13:20:02 +0000 Subject: [PATCH 03/11] Apply prepare changes --- .oxlintrc.json | 40 ++- app/stores/app.js | 235 ++++++------ app/stores/feedback.js | 33 +- app/stores/geode.js | 114 +++--- app/stores/hybrid_viewer.js | 336 +++++++++--------- app/stores/infra.js | 98 ++--- app/stores/lambda.js | 50 +-- app/stores/treeview.js | 118 +++--- app/utils/local/path.js | 70 ++-- app/utils/server.js | 45 +-- .../stores/data_style/mesh/cells/index.js | 75 ++-- .../stores/data_style/mesh/edges/index.js | 78 ++-- .../stores/data_style/mesh/points/index.js | 75 ++-- .../stores/data_style/mesh/polygons/index.js | 72 ++-- .../stores/data_style/mesh/polyhedra/index.js | 65 ++-- internal/stores/data_style/model/index.js | 163 +++++---- internal/utils/upload_file.js | 41 ++- server/api/extensions/upload.put.js | 110 +++--- .../stores/data_style/mesh/cells.nuxt.test.js | 204 ++++++----- .../data_style/model/surfaces.nuxt.test.js | 139 +++++--- tests/integration/stores/viewer.nuxt.test.js | 71 ++-- .../components/FeedBack/Snackers.nuxt.test.js | 34 +- .../unit/components/FileSelector.nuxt.test.js | 114 +++--- .../unit/components/FileUploader.nuxt.test.js | 70 ++-- .../Inspector/InspectionButton.nuxt.test.js | 54 +-- .../Inspector/ResultPanel.nuxt.test.js | 47 +-- tests/unit/components/Launcher.nuxt.test.js | 40 ++- .../components/PackagesVersions.nuxt.test.js | 30 +- tests/unit/components/Step.nuxt.test.js | 34 +- tests/unit/composables/api_fetch.nuxt.test.js | 64 ++-- ..._when_microservices_connected.nuxt.test.js | 70 ++-- tests/unit/stores/lambda.nuxt.test.js | 144 ++++---- 32 files changed, 1589 insertions(+), 1344 deletions(-) diff --git a/.oxlintrc.json b/.oxlintrc.json index 65bd07e8..10639b85 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -25,7 +25,22 @@ "eslint/id-length": [ "error", { - "exceptions": ["x", "y", "z", "i", "j", "k", "r", "g", "b", "id", "ID", "fs", "os", "_"], + "exceptions": [ + "x", + "y", + "z", + "i", + "j", + "k", + "r", + "g", + "b", + "id", + "ID", + "fs", + "os", + "_" + ], "min": 3 } ], @@ -51,22 +66,6 @@ "max": 10 } ], - "max-lines-per-function": [ - "warn", - { - "max": 50, - "skipBlankLines": true, - "skipComments": true - } - ], - "unicorn/no-useless-undefined": "off", - "max-lines": [ - "error", - { - "skipBlankLines": true, - "skipComments": true - } - ], "vue/max-props": [ "error", { @@ -106,7 +105,12 @@ } }, { - "files": ["app/plugins/**", "node_scripts/**", "server/**", "*.config.js"], + "files": [ + "app/plugins/**", + "node_scripts/**", + "server/**", + "*.config.js" + ], "rules": { "import/no-default-export": "off" } diff --git a/app/stores/app.js b/app/stores/app.js index c11128ab..5d1a8c0b 100644 --- a/app/stores/app.js +++ b/app/stores/app.js @@ -1,132 +1,143 @@ -import { api_fetch } from "@ogw_internal/utils/api_fetch.js"; -import { upload_file } from "@ogw_internal/utils/upload_file.js"; +import { api_fetch } from "@ogw_internal/utils/api_fetch.js" +import { upload_file } from "@ogw_internal/utils/upload_file.js" export const useAppStore = defineStore("app", () => { - const stores = []; + const stores = [] function registerStore(store) { - const isAlreadyRegistered = stores.some((registeredStore) => registeredStore.$id === store.$id); + const isAlreadyRegistered = stores.some( + (registeredStore) => registeredStore.$id === store.$id, + ) if (isAlreadyRegistered) { - console.log(`[AppStore] Store "${store.$id}" already registered, skipping`); - return; + console.log( + `[AppStore] Store "${store.$id}" already registered, skipping`, + ) + return } - console.log("[AppStore] Registering store", store.$id); - stores.push(store); + console.log("[AppStore] Registering store", store.$id) + stores.push(store) } async function exportStores(params = {}) { - const snapshot = {}; - let exportCount = 0; + const snapshot = {} + let exportCount = 0 - console.log(`[AppStore] Exporting stores, total registered: ${stores.length}`); + console.log( + `[AppStore] Exporting stores, total registered: ${stores.length}`, + ) await Promise.all( stores.map(async (store) => { if (!store.exportStores) { - return; + return } - const storeId = store.$id; + const storeId = store.$id try { - snapshot[storeId] = await store.exportStores(params); - exportCount += 1; + snapshot[storeId] = await store.exportStores(params) + exportCount += 1 } catch (error) { - console.error(`[AppStore] Error exporting store "${storeId}":`, error); + console.error(`[AppStore] Error exporting store "${storeId}":`, error) } }), - ); - console.log(`[AppStore] Exported ${exportCount} stores; snapshot keys:`, Object.keys(snapshot)); - return snapshot; + ) + console.log( + `[AppStore] Exported ${exportCount} stores; snapshot keys:`, + Object.keys(snapshot), + ) + return snapshot } async function importStores(snapshot) { if (!snapshot) { - console.warn("[AppStore] import called with invalid snapshot"); - return; + console.warn("[AppStore] import called with invalid snapshot") + return } - console.log("[AppStore] Import snapshot keys:", Object.keys(snapshot || {})); + console.log("[AppStore] Import snapshot keys:", Object.keys(snapshot || {})) - let importedCount = 0; - const notFoundStores = []; + let importedCount = 0 + const notFoundStores = [] await Promise.all( stores.map(async (store) => { if (!store.importStores) { - return; + return } - const storeId = store.$id; + const storeId = store.$id if (!snapshot[storeId]) { - notFoundStores.push(storeId); - return; + notFoundStores.push(storeId) + return } try { - await store.importStores(snapshot[storeId]); - importedCount += 1; + await store.importStores(snapshot[storeId]) + importedCount += 1 } catch (error) { - console.error(`[AppStore] Error importing store "${storeId}":`, error); + console.error(`[AppStore] Error importing store "${storeId}":`, error) } }), - ); + ) if (notFoundStores.length > 0) { - console.warn(`[AppStore] Stores not found in snapshot: ${notFoundStores.join(", ")}`); + console.warn( + `[AppStore] Stores not found in snapshot: ${notFoundStores.join(", ")}`, + ) } - console.log(`[AppStore] Imported ${importedCount} stores`); + console.log(`[AppStore] Imported ${importedCount} stores`) } - const loadedExtensions = ref(new Map()); - const extensionAPI = ref(undefined); - const codeTransformer = ref(undefined); + const loadedExtensions = ref(new Map()) + const extensionAPI = ref(undefined) + const codeTransformer = ref(undefined) function setExtensionAPI(api) { - extensionAPI.value = api; + extensionAPI.value = api } function setCodeTransformer(transformer) { - codeTransformer.value = transformer; + codeTransformer.value = transformer } function getExtension(id) { - return loadedExtensions.value.get(id); + return loadedExtensions.value.get(id) } async function loadExtension(path, backendPath = "") { try { - let finalURL = path; + let finalURL = path if (codeTransformer.value && path.startsWith("blob:")) { - const response = await fetch(path); - const code = await response.text(); - const transformedCode = codeTransformer.value(code); + const response = await fetch(path) + const code = await response.text() + const transformedCode = codeTransformer.value(code) const newBlob = new Blob([transformedCode], { type: "application/javascript", - }); - finalURL = URL.createObjectURL(newBlob); + }) + finalURL = URL.createObjectURL(newBlob) } // oxlint-disable-next-line no-inline-comments - const extensionModule = await import(/* @vite-ignore */ finalURL); + const extensionModule = await import(/* @vite-ignore */ finalURL) if (finalURL !== path && finalURL.startsWith("blob:")) { - URL.revokeObjectURL(finalURL); + URL.revokeObjectURL(finalURL) } if (!extensionModule.metadata?.id) { - throw new Error("Extension must have metadata.id"); + throw new Error("Extension must have metadata.id") } - const extensionId = extensionModule.metadata.id; + const extensionId = extensionModule.metadata.id if (loadedExtensions.value.has(extensionId)) { - console.warn(`[AppStore] Extension "${extensionId}" is already loaded`); - throw new Error(`Extension "${extensionId}" is already loaded.`); + console.warn(`[AppStore] Extension "${extensionId}" is already loaded`) + throw new Error(`Extension "${extensionId}" is already loaded.`) } if (!extensionAPI.value) { - throw new Error("Extension API not initialized"); + throw new Error("Extension API not initialized") } if (typeof extensionModule.install !== "function") { - throw new TypeError("Extension must export an install function"); + throw new TypeError("Extension must export an install function") } - await extensionModule.install(extensionAPI.value, backendPath); + await extensionModule.install(extensionAPI.value, backendPath) const extensionData = { module: extensionModule, @@ -136,116 +147,126 @@ export const useAppStore = defineStore("app", () => { loadedAt: new Date().toISOString(), metadata: extensionModule.metadata, enabled: true, - }; - loadedExtensions.value.set(extensionId, extensionData); + } + loadedExtensions.value.set(extensionId, extensionData) - console.log(`[AppStore] Extension loaded successfully: ${extensionId}`); - return extensionModule; + console.log(`[AppStore] Extension loaded successfully: ${extensionId}`) + return extensionModule } catch (error) { - console.error(`[AppStore] Failed to load extension from ${path}:`, error); - throw error; + console.error(`[AppStore] Failed to load extension from ${path}:`, error) + throw error } } function getLoadedExtensions() { - return [...loadedExtensions.value.values()]; + return [...loadedExtensions.value.values()] } function unloadExtension(id) { - const extensionData = getExtension(id); + const extensionData = getExtension(id) if (!extensionData) { - return false; + return false } - if (extensionData.module && typeof extensionData.module.uninstall === "function") { + if ( + extensionData.module && + typeof extensionData.module.uninstall === "function" + ) { try { - extensionData.module.uninstall(extensionAPI.value); - console.log(`[AppStore] Extension uninstall called: ${id}`); + extensionData.module.uninstall(extensionAPI.value) + console.log(`[AppStore] Extension uninstall called: ${id}`) } catch (error) { - console.error(`[AppStore] Error calling uninstall for ${id}:`, error); + console.error(`[AppStore] Error calling uninstall for ${id}:`, error) } } - if (extensionAPI.value && typeof extensionAPI.value.unregisterToolsByExtension === "function") { - extensionAPI.value.unregisterToolsByExtension(id); + if ( + extensionAPI.value && + typeof extensionAPI.value.unregisterToolsByExtension === "function" + ) { + extensionAPI.value.unregisterToolsByExtension(id) } - loadedExtensions.value.delete(id); - console.log(`[AppStore] Extension unloaded: ${id}`); - return true; + loadedExtensions.value.delete(id) + console.log(`[AppStore] Extension unloaded: ${id}`) + return true } function toggleExtension(id) { - const extensionData = getExtension(id); + const extensionData = getExtension(id) if (!extensionData) { - return false; + return false } - extensionData.enabled = !extensionData.enabled; - console.log(`[AppStore] Extension ${extensionData.enabled ? "enabled" : "disabled"}: ${id}`); - return extensionData.enabled; + extensionData.enabled = !extensionData.enabled + console.log( + `[AppStore] Extension ${extensionData.enabled ? "enabled" : "disabled"}: ${id}`, + ) + return extensionData.enabled } function setExtensionEnabled(id, enabled) { - const extensionData = getExtension(id); + const extensionData = getExtension(id) if (!extensionData) { - return false; + return false } - extensionData.enabled = enabled; - console.log(`[AppStore] Extension ${enabled ? "enabled" : "disabled"}: ${id}`); - return true; + extensionData.enabled = enabled + console.log( + `[AppStore] Extension ${enabled ? "enabled" : "disabled"}: ${id}`, + ) + return true } function getExtensionEnabled(id) { - return getExtension(id)?.enabled ?? false; + return getExtension(id)?.enabled ?? false } function upload(file, callbacks = {}) { - const route = "/api/extensions/upload"; - const store = useAppStore(); + const route = "/api/extensions/upload" + const store = useAppStore() return upload_file( store, { route, file }, { ...callbacks, response_function: async (response) => { - console.log("[APP] Request completed:", route); + console.log("[APP] Request completed:", route) if (callbacks.response_function) { - await callbacks.response_function(response); + await callbacks.response_function(response) } }, }, - ); + ) } function request(schema, params, callbacks = {}) { - console.log("[APP] Request:", schema.$id); + console.log("[APP] Request:", schema.$id) - const store = useAppStore(); + const store = useAppStore() return api_fetch( store, { schema, params }, { ...callbacks, response_function: async (response) => { - console.log("[APP] Request completed:", schema.$id); + console.log("[APP] Request completed:", schema.$id) if (callbacks.response_function) { - await callbacks.response_function(response); + await callbacks.response_function(response) } }, }, - ); + ) } - const request_counter = ref(0); + const request_counter = ref(0) function start_request() { - request_counter.value += 1; + request_counter.value += 1 } function stop_request() { - request_counter.value -= 1; + request_counter.value -= 1 } - const projectFolderPath = ref(""); + const projectFolderPath = ref("") function createProjectFolder() { - const { PROJECT } = useRuntimeConfig().public; + const { PROJECT } = useRuntimeConfig().public const schema = { $id: "/api/app/project_folder_path", methods: ["POST"], @@ -255,17 +276,17 @@ export const useAppStore = defineStore("app", () => { }, required: ["PROJECT"], additionalProperties: true, - }; - const params = { PROJECT }; + } + const params = { PROJECT } - console.log(createProjectFolder.name, { PROJECT }); + console.log(createProjectFolder.name, { PROJECT }) return request(schema, params, { response_function: (response) => { - console.log(`[APP] ${response.projectFolderPath} created`); - projectFolderPath.value = response.projectFolderPath; + console.log(`[APP] ${response.projectFolderPath} created`) + projectFolderPath.value = response.projectFolderPath }, - }); + }) } return { @@ -290,5 +311,5 @@ export const useAppStore = defineStore("app", () => { createProjectFolder, start_request, stop_request, - }; -}); + } +}) diff --git a/app/stores/feedback.js b/app/stores/feedback.js index d1101281..1996a588 100644 --- a/app/stores/feedback.js +++ b/app/stores/feedback.js @@ -1,17 +1,18 @@ -import { v4 as uuidv4 } from "uuid"; +import { v4 as uuidv4 } from "uuid" -const MILLISECONDS_IN_SECOND = 1000; -const DEFAULT_FEEDBACKS_TIMEOUT_SECONDS = 10; +const MILLISECONDS_IN_SECOND = 1000 +const DEFAULT_FEEDBACKS_TIMEOUT_SECONDS = 10 export const useFeedbackStore = defineStore("feedback", { state: () => ({ feedbacks: [], server_error: false, - feedbacks_timeout_miliseconds: DEFAULT_FEEDBACKS_TIMEOUT_SECONDS * MILLISECONDS_IN_SECOND, + feedbacks_timeout_miliseconds: + DEFAULT_FEEDBACKS_TIMEOUT_SECONDS * MILLISECONDS_IN_SECOND, }), actions: { async add_error(code, route, name, description) { - const feedbackId = uuidv4(); + const feedbackId = uuidv4() await this.feedbacks.push({ id: feedbackId, type: "error", @@ -19,27 +20,29 @@ export const useFeedbackStore = defineStore("feedback", { route, name, description, - }); + }) setTimeout(() => { - this.delete_feedback(feedbackId); - }, this.feedbacks_timeout_miliseconds); + this.delete_feedback(feedbackId) + }, this.feedbacks_timeout_miliseconds) }, async add_success(description) { - const feedbackId = uuidv4(); + const feedbackId = uuidv4() await this.feedbacks.push({ id: feedbackId, type: "success", description, - }); + }) setTimeout(() => { - this.delete_feedback(feedbackId); - }, this.feedbacks_timeout_miliseconds); + this.delete_feedback(feedbackId) + }, this.feedbacks_timeout_miliseconds) }, delete_feedback(feedbackId) { - this.feedbacks = this.feedbacks.filter((feedback) => feedback.id !== feedbackId); + this.feedbacks = this.feedbacks.filter( + (feedback) => feedback.id !== feedbackId, + ) }, delete_server_error() { - this.server_error = false; + this.server_error = false }, }, -}); +}) diff --git a/app/stores/geode.js b/app/stores/geode.js index 8c736aa1..b0c3cd0b 100644 --- a/app/stores/geode.js +++ b/app/stores/geode.js @@ -1,14 +1,14 @@ -import { Status } from "@ogw_front/utils/status"; -import { api_fetch } from "@ogw_internal/utils/api_fetch"; -import { appMode } from "@ogw_front/utils/app_mode"; -import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json"; -import { upload_file } from "@ogw_internal/utils/upload_file.js"; -import { useAppStore } from "@ogw_front/stores/app"; -import { useFeedbackStore } from "@ogw_front/stores/feedback"; -import { useInfraStore } from "@ogw_front/stores/infra"; +import { Status } from "@ogw_front/utils/status" +import { api_fetch } from "@ogw_internal/utils/api_fetch" +import { appMode } from "@ogw_front/utils/app_mode" +import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" +import { upload_file } from "@ogw_internal/utils/upload_file.js" +import { useAppStore } from "@ogw_front/stores/app" +import { useFeedbackStore } from "@ogw_front/stores/feedback" +import { useInfraStore } from "@ogw_front/stores/infra" -const MILLISECONDS_IN_SECOND = 1000; -const DEFAULT_PING_INTERVAL_SECONDS = 10; +const MILLISECONDS_IN_SECOND = 1000 +const DEFAULT_PING_INTERVAL_SECONDS = 10 export const useGeodeStore = defineStore("geode", { state: () => ({ @@ -19,73 +19,73 @@ export const useGeodeStore = defineStore("geode", { getters: { protocol() { if (useInfraStore().app_mode === appMode.CLOUD) { - return "https"; + return "https" } - return "http"; + return "http" }, port() { if (useInfraStore().app_mode === appMode.CLOUD) { - return "443"; + return "443" } - return this.default_local_port; + return this.default_local_port }, base_url() { - const infraStore = useInfraStore(); - let geode_url = `${this.protocol}://${infraStore.domain_name}:${this.port}`; + const infraStore = useInfraStore() + let geode_url = `${this.protocol}://${infraStore.domain_name}:${this.port}` if (infraStore.app_mode === appMode.CLOUD) { if (infraStore.ID === "") { - throw new Error("ID must not be empty in cloud mode"); + throw new Error("ID must not be empty in cloud mode") } - geode_url += `/${infraStore.ID}/geode`; + geode_url += `/${infraStore.ID}/geode` } - return geode_url; + return geode_url }, is_busy() { - return this.request_counter > 0; + return this.request_counter > 0 }, }, actions: { set_ping() { - this.ping(); + this.ping() setInterval(() => { - this.ping(); - }, DEFAULT_PING_INTERVAL_SECONDS * MILLISECONDS_IN_SECOND); + this.ping() + }, DEFAULT_PING_INTERVAL_SECONDS * MILLISECONDS_IN_SECOND) }, ping() { - const feedbackStore = useFeedbackStore(); + const feedbackStore = useFeedbackStore() return this.request( back_schemas.opengeodeweb_back.ping, {}, { request_error_function: () => { - feedbackStore.$patch({ server_error: true }); - this.status = Status.NOT_CONNECTED; + feedbackStore.$patch({ server_error: true }) + this.status = Status.NOT_CONNECTED }, response_function: () => { - feedbackStore.$patch({ server_error: false }); - this.status = Status.CONNECTED; + feedbackStore.$patch({ server_error: false }) + this.status = Status.CONNECTED }, response_error_function: () => { - feedbackStore.$patch({ server_error: true }); - this.status = Status.NOT_CONNECTED; + feedbackStore.$patch({ server_error: true }) + this.status = Status.NOT_CONNECTED }, }, - ); + ) }, start_request() { - this.request_counter += 1; + this.request_counter += 1 }, stop_request() { - this.request_counter -= 1; + this.request_counter -= 1 }, launch(args) { - console.log("[GEODE] Launching back microservice...", { args }); - const appStore = useAppStore(); + console.log("[GEODE] Launching back microservice...", { args }) + const appStore = useAppStore() - const { BACK_PATH, BACK_COMMAND } = useRuntimeConfig().public; + const { BACK_PATH, BACK_COMMAND } = useRuntimeConfig().public - console.log("[GEODE] BACK_PATH", BACK_PATH); - console.log("[GEODE] BACK_COMMAND", BACK_COMMAND); + console.log("[GEODE] BACK_PATH", BACK_PATH) + console.log("[GEODE] BACK_COMMAND", BACK_COMMAND) const schema = { $id: "/api/app/run_back", methods: ["POST"], @@ -96,30 +96,30 @@ export const useGeodeStore = defineStore("geode", { }, required: ["BACK_PATH", "BACK_COMMAND"], additionalProperties: true, - }; + } const params = { BACK_PATH, BACK_COMMAND, args, - }; + } - console.log("[GEODE] params", params); + console.log("[GEODE] params", params) return appStore.request(schema, params, { response_function: (response) => { - console.log(`[GEODE] Back launched on port ${response.port}`); - this.default_local_port = response.port; + console.log(`[GEODE] Back launched on port ${response.port}`) + this.default_local_port = response.port }, - }); + }) }, connect() { - console.log("[GEODE] Connecting to geode microservice..."); - this.set_ping(); - return Promise.resolve(); + console.log("[GEODE] Connecting to geode microservice...") + this.set_ping() + return Promise.resolve() }, request(schema, params, callbacks = {}) { - console.log("[GEODE] Request:", schema.$id); - const start = Date.now(); + console.log("[GEODE] Request:", schema.$id) + const start = Date.now() return api_fetch( this, @@ -133,16 +133,16 @@ export const useGeodeStore = defineStore("geode", { "in", (Date.now() - start) / MILLISECONDS_IN_SECOND, "s", - ); + ) if (callbacks.response_function) { - await callbacks.response_function(response); + await callbacks.response_function(response) } }, }, - ); + ) }, upload(file, callbacks = {}) { - const route = back_schemas.opengeodeweb_back.upload_file.$id; + const route = back_schemas.opengeodeweb_back.upload_file.$id return upload_file( this, { @@ -152,16 +152,16 @@ export const useGeodeStore = defineStore("geode", { { ...callbacks, response_function: async (response) => { - console.log("[GEODE] Request completed:", route); + console.log("[GEODE] Request completed:", route) if (callbacks.response_function) { - await callbacks.response_function(response); + await callbacks.response_function(response) } }, }, - ); + ) }, }, share: { omit: ["status"], }, -}); +}) diff --git a/app/stores/hybrid_viewer.js b/app/stores/hybrid_viewer.js index e6c20b3c..aa2af6c7 100644 --- a/app/stores/hybrid_viewer.js +++ b/app/stores/hybrid_viewer.js @@ -1,137 +1,140 @@ // oxlint-disable-next-line import/no-unassigned-import -import "@kitware/vtk.js/Rendering/Profiles/Geometry"; -import { newInstance as vtkActor } from "@kitware/vtk.js/Rendering/Core/Actor"; -import { newInstance as vtkGenericRenderWindow } from "@kitware/vtk.js/Rendering/Misc/GenericRenderWindow"; -import { newInstance as vtkMapper } from "@kitware/vtk.js/Rendering/Core/Mapper"; -import { newInstance as vtkXMLPolyDataReader } from "@kitware/vtk.js/IO/XML/XMLPolyDataReader"; +import "@kitware/vtk.js/Rendering/Profiles/Geometry" +import { newInstance as vtkActor } from "@kitware/vtk.js/Rendering/Core/Actor" +import { newInstance as vtkGenericRenderWindow } from "@kitware/vtk.js/Rendering/Misc/GenericRenderWindow" +import { newInstance as vtkMapper } from "@kitware/vtk.js/Rendering/Core/Mapper" +import { newInstance as vtkXMLPolyDataReader } from "@kitware/vtk.js/IO/XML/XMLPolyDataReader" -import { Status } from "@ogw_front/utils/status"; -import { useDataStore } from "@ogw_front/stores/data"; -import { useViewerStore } from "@ogw_front/stores/viewer"; -import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"; +import { Status } from "@ogw_front/utils/status" +import { useDataStore } from "@ogw_front/stores/data" +import { useViewerStore } from "@ogw_front/stores/viewer" +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" -const RGB_MAX = 255; -const BACKGROUND_GREY_VALUE = 180; -const ACTOR_DARK_VALUE = 20; +const RGB_MAX = 255 +const BACKGROUND_GREY_VALUE = 180 +const ACTOR_DARK_VALUE = 20 const BACKGROUND_COLOR = [ BACKGROUND_GREY_VALUE / RGB_MAX, BACKGROUND_GREY_VALUE / RGB_MAX, BACKGROUND_GREY_VALUE / RGB_MAX, -]; +] const ACTOR_COLOR = [ ACTOR_DARK_VALUE / RGB_MAX, ACTOR_DARK_VALUE / RGB_MAX, ACTOR_DARK_VALUE / RGB_MAX, -]; -const WHEEL_TIME_OUT_MS = 600; +] +const WHEEL_TIME_OUT_MS = 600 export const useHybridViewerStore = defineStore("hybridViewer", () => { - const dataStore = useDataStore(); - const viewerStore = useViewerStore(); - const hybridDb = reactive({}); - const status = ref(Status.NOT_CREATED); - const camera_options = reactive({}); - const genericRenderWindow = reactive({}); - const is_moving = ref(false); - const zScale = ref(1); - let viewStream = undefined; - const gridActor = undefined; + const dataStore = useDataStore() + const viewerStore = useViewerStore() + const hybridDb = reactive({}) + const status = ref(Status.NOT_CREATED) + const camera_options = reactive({}) + const genericRenderWindow = reactive({}) + const is_moving = ref(false) + const zScale = ref(1) + let viewStream = undefined + const gridActor = undefined async function initHybridViewer() { if (status.value !== Status.NOT_CREATED) { - return; + return } - status.value = Status.CREATING; + status.value = Status.CREATING genericRenderWindow.value = vtkGenericRenderWindow({ background: BACKGROUND_COLOR, listenWindowResize: false, - }); + }) - const webGLRenderWindow = genericRenderWindow.value.getApiSpecificRenderWindow(); - const imageStyle = webGLRenderWindow.getReferenceByName("bgImage").style; - imageStyle.transition = "opacity 0.1s ease-in"; - imageStyle.zIndex = 1; + const webGLRenderWindow = + genericRenderWindow.value.getApiSpecificRenderWindow() + const imageStyle = webGLRenderWindow.getReferenceByName("bgImage").style + imageStyle.transition = "opacity 0.1s ease-in" + imageStyle.zIndex = 1 - await viewerStore.ws_connect(); - viewStream = viewerStore.client.getImageStream().createViewStream("-1"); + await viewerStore.ws_connect() + viewStream = viewerStore.client.getImageStream().createViewStream("-1") viewStream.onImageReady((event) => { if (is_moving.value) { - return; + return } - webGLRenderWindow.setBackgroundImage(event.image); - imageStyle.opacity = 1; - }); + webGLRenderWindow.setBackgroundImage(event.image) + imageStyle.opacity = 1 + }) - status.value = Status.CREATED; + status.value = Status.CREATED } async function addItem(id) { if (!genericRenderWindow.value) { - return; + return } - const value = await dataStore.item(id); - console.log("hybridViewerStore.addItem", { value }); - const reader = vtkXMLPolyDataReader(); - const textEncoder = new TextEncoder(); - await reader.parseAsArrayBuffer(textEncoder.encode(value.binary_light_viewable)); - const polydata = reader.getOutputData(0); - const mapper = vtkMapper(); - mapper.setInputData(polydata); - const actor = vtkActor(); - actor.getProperty().setColor(ACTOR_COLOR); - actor.setMapper(mapper); - const renderer = genericRenderWindow.value.getRenderer(); - const renderWindow = genericRenderWindow.value.getRenderWindow(); - renderer.addActor(actor); - renderer.resetCamera(); - renderWindow.render(); - hybridDb[id] = { actor, polydata, mapper }; + const value = await dataStore.item(id) + console.log("hybridViewerStore.addItem", { value }) + const reader = vtkXMLPolyDataReader() + const textEncoder = new TextEncoder() + await reader.parseAsArrayBuffer( + textEncoder.encode(value.binary_light_viewable), + ) + const polydata = reader.getOutputData(0) + const mapper = vtkMapper() + mapper.setInputData(polydata) + const actor = vtkActor() + actor.getProperty().setColor(ACTOR_COLOR) + actor.setMapper(mapper) + const renderer = genericRenderWindow.value.getRenderer() + const renderWindow = genericRenderWindow.value.getRenderWindow() + renderer.addActor(actor) + renderer.resetCamera() + renderWindow.render() + hybridDb[id] = { actor, polydata, mapper } } function removeItem(id) { if (!hybridDb[id]) { - return; + return } - const renderer = genericRenderWindow.value.getRenderer(); - renderer.removeActor(hybridDb[id].actor); - genericRenderWindow.value.getRenderWindow().render(); - delete hybridDb[id]; + const renderer = genericRenderWindow.value.getRenderer() + renderer.removeActor(hybridDb[id].actor) + genericRenderWindow.value.getRenderWindow().render() + delete hybridDb[id] } function setVisibility(id, visibility) { if (!hybridDb[id]) { - return; + return } - hybridDb[id].actor.setVisibility(visibility); - const renderWindow = genericRenderWindow.value.getRenderWindow(); - renderWindow.render(); + hybridDb[id].actor.setVisibility(visibility) + const renderWindow = genericRenderWindow.value.getRenderWindow() + renderWindow.render() } async function setZScaling(z_scale) { - zScale.value = z_scale; - const renderer = genericRenderWindow.value.getRenderer(); - const actors = renderer.getActors(); + zScale.value = z_scale + const renderer = genericRenderWindow.value.getRenderer() + const actors = renderer.getActors() for (const actor of actors) { if (actor !== gridActor) { - const scale = actor.getScale(); - actor.setScale(scale[0], scale[1], z_scale); + const scale = actor.getScale() + actor.setScale(scale[0], scale[1], z_scale) } } - renderer.resetCamera(); - genericRenderWindow.value.getRenderWindow().render(); - const schema = viewer_schemas?.opengeodeweb_viewer?.viewer?.set_z_scaling; + renderer.resetCamera() + genericRenderWindow.value.getRenderWindow().render() + const schema = viewer_schemas?.opengeodeweb_viewer?.viewer?.set_z_scaling if (!schema) { - return; + return } await viewerStore.request(schema, { z_scale, - }); - remoteRender(); + }) + remoteRender() } function syncRemoteCamera() { - console.log("syncRemoteCamera"); - const renderer = genericRenderWindow.value.getRenderer(); - const camera = renderer.getActiveCamera(); + console.log("syncRemoteCamera") + const renderer = genericRenderWindow.value.getRenderer() + const camera = renderer.getActiveCamera() const params = { camera_options: { focal_point: [...camera.getFocalPoint()], @@ -141,84 +144,93 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { clipping_range: [...camera.getClippingRange()], distance: camera.getDistance(), }, - }; - viewerStore.request(viewer_schemas.opengeodeweb_viewer.viewer.update_camera, params, { - response_function: () => { - remoteRender(); - for (const key in params.camera_options) { - if (Object.hasOwn(params.camera_options, key)) { - camera_options[key] = params.camera_options[key]; + } + viewerStore.request( + viewer_schemas.opengeodeweb_viewer.viewer.update_camera, + params, + { + response_function: () => { + remoteRender() + for (const key in params.camera_options) { + if (Object.hasOwn(params.camera_options, key)) { + camera_options[key] = params.camera_options[key] + } } - } + }, }, - }); + ) } function remoteRender() { - return viewerStore.request(viewer_schemas.opengeodeweb_viewer.viewer.render); + return viewerStore.request(viewer_schemas.opengeodeweb_viewer.viewer.render) } function setContainer(container) { - genericRenderWindow.value.setContainer(container.value.$el); - const webGLRenderWindow = genericRenderWindow.value.getApiSpecificRenderWindow(); - webGLRenderWindow.setUseBackgroundImage(true); - const imageStyle = webGLRenderWindow.getReferenceByName("bgImage").style; - imageStyle.transition = "opacity 0.1s ease-in"; - imageStyle.zIndex = 1; - resize(container.value.$el.offsetWidth, container.value.$el.offsetHeight); - console.log("setContainer", container.value.$el); + genericRenderWindow.value.setContainer(container.value.$el) + const webGLRenderWindow = + genericRenderWindow.value.getApiSpecificRenderWindow() + webGLRenderWindow.setUseBackgroundImage(true) + const imageStyle = webGLRenderWindow.getReferenceByName("bgImage").style + imageStyle.transition = "opacity 0.1s ease-in" + imageStyle.zIndex = 1 + resize(container.value.$el.offsetWidth, container.value.$el.offsetHeight) + console.log("setContainer", container.value.$el) useMousePressed({ target: container, onPressed: (event) => { - console.log("onPressed"); + console.log("onPressed") if (event.button === 0) { - is_moving.value = true; - event.stopPropagation(); - imageStyle.opacity = 0; + is_moving.value = true + event.stopPropagation() + imageStyle.opacity = 0 } }, onReleased: () => { if (!is_moving.value) { - return; + return } - is_moving.value = false; - console.log("onReleased"); - syncRemoteCamera(); + is_moving.value = false + console.log("onReleased") + syncRemoteCamera() }, - }); + }) - let wheelEventEndTimeout = undefined; + let wheelEventEndTimeout = undefined useEventListener(container, "wheel", () => { - is_moving.value = true; - imageStyle.opacity = 0; - clearTimeout(wheelEventEndTimeout); + is_moving.value = true + imageStyle.opacity = 0 + clearTimeout(wheelEventEndTimeout) wheelEventEndTimeout = setTimeout(() => { - is_moving.value = false; - syncRemoteCamera(); - }, WHEEL_TIME_OUT_MS); - }); + is_moving.value = false + syncRemoteCamera() + }, WHEEL_TIME_OUT_MS) + }) } async function resize(width, height) { - if (viewerStore.status !== Status.CONNECTED || status.value !== Status.CREATED) { - return; + if ( + viewerStore.status !== Status.CONNECTED || + status.value !== Status.CREATED + ) { + return } - const webGLRenderWindow = genericRenderWindow.value.getApiSpecificRenderWindow(); - const canvas = webGLRenderWindow.getCanvas(); - canvas.width = width; - canvas.height = height; - await nextTick(); - webGLRenderWindow.setSize(width, height); - viewStream.setSize(width, height); - const renderWindow = genericRenderWindow.value.getRenderWindow(); - renderWindow.render(); - remoteRender(); + const webGLRenderWindow = + genericRenderWindow.value.getApiSpecificRenderWindow() + const canvas = webGLRenderWindow.getCanvas() + canvas.width = width + canvas.height = height + await nextTick() + webGLRenderWindow.setSize(width, height) + viewStream.setSize(width, height) + const renderWindow = genericRenderWindow.value.getRenderWindow() + renderWindow.render() + remoteRender() } function exportStores() { - const renderer = genericRenderWindow.value.getRenderer(); - const camera = renderer.getActiveCamera(); + const renderer = genericRenderWindow.value.getRenderer() + const camera = renderer.getActiveCamera() const cameraSnapshot = camera ? { focal_point: [...camera.getFocalPoint()], @@ -228,33 +240,33 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { clipping_range: [...camera.getClippingRange()], distance: camera.getDistance(), } - : camera_options; - return { zScale: zScale.value, camera_options: cameraSnapshot }; + : camera_options + return { zScale: zScale.value, camera_options: cameraSnapshot } } async function importStores(snapshot) { if (!snapshot) { - console.warn("importStores called with undefined snapshot"); - return; + console.warn("importStores called with undefined snapshot") + return } - const z_scale = snapshot.zScale; + const z_scale = snapshot.zScale function applyCamera() { - const { camera_options: snapshot_camera_options } = snapshot; + const { camera_options: snapshot_camera_options } = snapshot if (!snapshot_camera_options) { - return; + return } - const renderer = genericRenderWindow.value.getRenderer(); - const camera = renderer.getActiveCamera(); + const renderer = genericRenderWindow.value.getRenderer() + const camera = renderer.getActiveCamera() - camera.setFocalPoint(...snapshot_camera_options.focal_point); - camera.setViewUp(...snapshot_camera_options.view_up); - camera.setPosition(...snapshot_camera_options.position); - camera.setViewAngle(snapshot_camera_options.view_angle); - camera.setClippingRange(...snapshot_camera_options.clipping_range); + camera.setFocalPoint(...snapshot_camera_options.focal_point) + camera.setViewUp(...snapshot_camera_options.view_up) + camera.setPosition(...snapshot_camera_options.position) + camera.setViewAngle(snapshot_camera_options.view_angle) + camera.setClippingRange(...snapshot_camera_options.clipping_range) - genericRenderWindow.value.getRenderWindow().render(); + genericRenderWindow.value.getRenderWindow().render() const payload = { camera_options: { @@ -264,31 +276,35 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { view_angle: snapshot_camera_options.view_angle, clipping_range: [...snapshot_camera_options.clipping_range], }, - }; - return viewerStore.request(viewer_schemas.opengeodeweb_viewer.viewer.update_camera, payload, { - response_function: () => { - remoteRender(); - Object.assign(camera_options, payload.camera_options); + } + return viewerStore.request( + viewer_schemas.opengeodeweb_viewer.viewer.update_camera, + payload, + { + response_function: () => { + remoteRender() + Object.assign(camera_options, payload.camera_options) + }, }, - }); + ) } if (typeof z_scale === "number") { - await setZScaling(z_scale); - return await applyCamera(); + await setZScaling(z_scale) + return await applyCamera() } - return await applyCamera(); + return await applyCamera() } function clear() { - const renderer = genericRenderWindow.value.getRenderer(); - const actors = renderer.getActors(); + const renderer = genericRenderWindow.value.getRenderer() + const actors = renderer.getActors() for (const actor of actors) { - renderer.removeActor(actor); + renderer.removeActor(actor) } - genericRenderWindow.value.getRenderWindow().render(); + genericRenderWindow.value.getRenderWindow().render() for (const id of Object.keys(hybridDb)) { - delete hybridDb[id]; + delete hybridDb[id] } } @@ -308,5 +324,5 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => { clear, exportStores, importStores, - }; -}); + } +}) diff --git a/app/stores/infra.js b/app/stores/infra.js index 8c89c341..98ae5473 100644 --- a/app/stores/infra.js +++ b/app/stores/infra.js @@ -1,9 +1,9 @@ -import { appMode, getAppMode } from "@ogw_front/utils/app_mode"; -import { Status } from "@ogw_front/utils/status"; -import { useAppStore } from "@ogw_front/stores/app"; -import { useLambdaStore } from "@ogw_front/stores/lambda"; +import { appMode, getAppMode } from "@ogw_front/utils/app_mode" +import { Status } from "@ogw_front/utils/status" +import { useAppStore } from "@ogw_front/stores/app" +import { useLambdaStore } from "@ogw_front/stores/lambda" -import { registerRunningExtensions } from "@ogw_front/utils/extension"; +import { registerRunningExtensions } from "@ogw_front/utils/extension" export const useInfraStore = defineStore("infra", { state: () => ({ @@ -16,86 +16,96 @@ export const useInfraStore = defineStore("infra", { getters: { domain_name() { if (this.app_mode === appMode.CLOUD) { - return useRuntimeConfig().public.API_URL; + return useRuntimeConfig().public.API_URL } - return "localhost"; + return "localhost" }, microservices_connected() { - console.log("microservices", this.microservices); - return this.microservices.every((store) => store.status === Status.CONNECTED); + console.log("microservices", this.microservices) + return this.microservices.every( + (store) => store.status === Status.CONNECTED, + ) }, microservices_busy() { - return this.microservices.some((store) => store.is_busy === true); + return this.microservices.some((store) => store.is_busy === true) }, }, actions: { register_microservice(store) { - const store_name = store.$id; - console.log("[INFRA] Registering microservice:", store_name); + const store_name = store.$id + console.log("[INFRA] Registering microservice:", store_name) - if (!this.microservices.some((microservice) => microservice.$id === store_name)) { - this.microservices.push(store); - console.log("[INFRA] Microservice registered:", store_name); + if ( + !this.microservices.some( + (microservice) => microservice.$id === store_name, + ) + ) { + this.microservices.push(store) + console.log("[INFRA] Microservice registered:", store_name) } }, create_backend() { - console.log("[INFRA] Starting create_backend - Mode:", this.app_mode); + console.log("[INFRA] Starting create_backend - Mode:", this.app_mode) console.log( "[INFRA] Registered microservices:", this.microservices.map((store) => store.$id), - ); + ) if (this.status === Status.CREATED) { - return; + return } return navigator.locks.request("infra.create_backend", async () => { - this.status = Status.CREATING; + this.status = Status.CREATING if (this.status === Status.CREATED) { - return; + return } - console.log("[INFRA] Lock granted for create_backend"); + console.log("[INFRA] Lock granted for create_backend") if (this.app_mode === appMode.CLOUD) { - console.log("[INFRA] CLOUD mode - Launching lambda..."); - const lambdaStore = useLambdaStore(); - this.ID = await lambdaStore.launch(); - console.log("[INFRA] Lambda launched successfully"); + console.log("[INFRA] CLOUD mode - Launching lambda...") + const lambdaStore = useLambdaStore() + this.ID = await lambdaStore.launch() + console.log("[INFRA] Lambda launched successfully") } else { - console.log(`[INFRA] ${this.app_mode} mode - Launching microservices...`); - const appStore = useAppStore(); - await appStore.createProjectFolder(); + console.log( + `[INFRA] ${this.app_mode} mode - Launching microservices...`, + ) + const appStore = useAppStore() + await appStore.createProjectFolder() if (this.app_mode === appMode.DESKTOP) { globalThis.electronAPI.project_folder_path({ projectFolderPath: appStore.projectFolderPath, - }); + }) } - const microservices_with_launch = this.microservices.filter((store) => store.launch); + const microservices_with_launch = this.microservices.filter( + (store) => store.launch, + ) const launch_promises = microservices_with_launch.map((store) => store.launch({ projectFolderPath: appStore.projectFolderPath }), - ); - launch_promises.push(registerRunningExtensions()); - await Promise.all(launch_promises); + ) + launch_promises.push(registerRunningExtensions()) + await Promise.all(launch_promises) } - this.status = Status.CREATED; - console.log("[INFRA] Backend created successfully"); - return this.create_connection(); - }); + this.status = Status.CREATED + console.log("[INFRA] Backend created successfully") + return this.create_connection() + }) }, async create_connection() { - console.log("[INFRA] Starting create_connection"); + console.log("[INFRA] Starting create_connection") console.log( "[INFRA] Connecting microservices:", this.microservices.map((store) => store.$id), - ); + ) await Promise.all( this.microservices.map(async (store) => { - await store.connect(); - console.log("[INFRA] Microservice connected:", store.$id); + await store.connect() + console.log("[INFRA] Microservice connected:", store.$id) }), - ); - console.log("[INFRA] All microservices connected"); + ) + console.log("[INFRA] All microservices connected") }, }, share: { omit: ["microservices"], }, -}); +}) diff --git a/app/stores/lambda.js b/app/stores/lambda.js index 2fb8609c..d00b0c48 100644 --- a/app/stores/lambda.js +++ b/app/stores/lambda.js @@ -1,5 +1,5 @@ -import { Status } from "@ogw_front/utils/status"; -import { useFeedbackStore } from "@ogw_front/stores/feedback"; +import { Status } from "@ogw_front/utils/status" +import { useFeedbackStore } from "@ogw_front/stores/feedback" export const useLambdaStore = defineStore("lambda", { state: () => ({ @@ -7,51 +7,51 @@ export const useLambdaStore = defineStore("lambda", { }), getters: { protocol() { - return "https"; + return "https" }, port() { - return "443"; + return "443" }, base_url() { - const public_runtime_config = useRuntimeConfig().public; - const domain_name = public_runtime_config.API_URL; - const projectPath = `/${public_runtime_config.PROJECT}`; - const url = `${this.protocol}://${domain_name}:${this.port}${public_runtime_config.SITE_BRANCH}${projectPath}/createbackend`; - return url; + const public_runtime_config = useRuntimeConfig().public + const domain_name = public_runtime_config.API_URL + const projectPath = `/${public_runtime_config.PROJECT}` + const url = `${this.protocol}://${domain_name}:${this.port}${public_runtime_config.SITE_BRANCH}${projectPath}/createbackend` + return url }, is_busy() { - return false; + return false }, }, actions: { async launch() { - console.log("[LAMBDA] Launching lambda backend..."); - const feedbackStore = useFeedbackStore(); + console.log("[LAMBDA] Launching lambda backend...") + const feedbackStore = useFeedbackStore() const { data, error } = await useFetch(this.base_url, { method: "POST", - }); + }) if (error.value || !data.value) { - this.status = Status.NOT_CONNECTED; - feedbackStore.server_error = true; - console.error("[LAMBDA] Failed to launch lambda backend", error.value); - throw new Error("Failed to launch lambda backend"); + this.status = Status.NOT_CONNECTED + feedbackStore.server_error = true + console.error("[LAMBDA] Failed to launch lambda backend", error.value) + throw new Error("Failed to launch lambda backend") } - this.status = Status.CONNECTED; - const id = data.value.ID; + this.status = Status.CONNECTED + const id = data.value.ID - console.log("[LAMBDA] Lambda launched, ID:", id); - return id; + console.log("[LAMBDA] Lambda launched, ID:", id) + return id }, connect() { - console.log("[LAMBDA] Lambda connected"); - this.status = Status.CONNECTED; - return Promise.resolve(); + console.log("[LAMBDA] Lambda connected") + this.status = Status.CONNECTED + return Promise.resolve() }, }, share: { omit: ["status"], }, -}); +}) diff --git a/app/stores/treeview.js b/app/stores/treeview.js index 10e8d551..bccf5063 100644 --- a/app/stores/treeview.js +++ b/app/stores/treeview.js @@ -1,64 +1,67 @@ export const useTreeviewStore = defineStore("treeview", () => { - const PANEL_WIDTH = 300; - - const items = ref([]); - const selection = ref([]); - const components_selection = ref([]); - const isAdditionnalTreeDisplayed = ref(false); - const panelWidth = ref(PANEL_WIDTH); - const model_id = ref(""); - const isTreeCollection = ref(false); - const selectedTree = ref(undefined); - const isImporting = ref(false); - const pendingSelectionIds = ref([]); + const PANEL_WIDTH = 300 + + const items = ref([]) + const selection = ref([]) + const components_selection = ref([]) + const isAdditionnalTreeDisplayed = ref(false) + const panelWidth = ref(PANEL_WIDTH) + const model_id = ref("") + const isTreeCollection = ref(false) + const selectedTree = ref(undefined) + const isImporting = ref(false) + const pendingSelectionIds = ref([]) // /** Functions **/ function addItem(geode_object_type, name, id, viewer_type) { - const child = { title: name, id, viewer_type }; + const child = { title: name, id, viewer_type } for (let i = 0; i < items.value.length; i += 1) { if (items.value[i].title === geode_object_type) { - items.value[i].children.push(child); + items.value[i].children.push(child) items.value[i].children.sort((element1, element2) => element1.title.localeCompare(element2.title, undefined, { numeric: true, sensitivity: "base", }), - ); - selection.value.push(child); - return; + ) + selection.value.push(child) + return } } - items.value.push({ title: geode_object_type, children: [child] }); + items.value.push({ title: geode_object_type, children: [child] }) items.value.sort((element1, element2) => element1.title.localeCompare(element2.title, undefined, { numeric: true, sensitivity: "base", }), - ); - selection.value.push(child); + ) + selection.value.push(child) } function displayAdditionalTree(id) { - isAdditionnalTreeDisplayed.value = true; - model_id.value = id; + isAdditionnalTreeDisplayed.value = true + model_id.value = id } function displayFileTree() { - isAdditionnalTreeDisplayed.value = false; + isAdditionnalTreeDisplayed.value = false } function toggleTreeView() { - isTreeCollection.value = !isTreeCollection.value; - console.log("Switched to", isTreeCollection.value ? "TreeCollection" : "TreeComponent"); + isTreeCollection.value = !isTreeCollection.value + console.log( + "Switched to", + isTreeCollection.value ? "TreeCollection" : "TreeComponent", + ) } function setPanelWidth(width) { - panelWidth.value = width; + panelWidth.value = width } function exportStores() { - const selectionIds = selection.value.map((store) => store.id); + const selectionIds = selection.value.map((store) => store.id) return { isAdditionnalTreeDisplayed: isAdditionnalTreeDisplayed.value, panelWidth: panelWidth.value, @@ -66,71 +69,76 @@ export const useTreeviewStore = defineStore("treeview", () => { isTreeCollection: isTreeCollection.value, selectedTree: selectedTree.value, selectionIds, - }; + } } function importStores(snapshot) { - isAdditionnalTreeDisplayed.value = snapshot?.isAdditionnalTreeDisplayed || false; - panelWidth.value = snapshot?.panelWidth || PANEL_WIDTH; - model_id.value = snapshot?.model_id || ""; - isTreeCollection.value = snapshot?.isTreeCollection || false; - selectedTree.value = snapshot?.selectedTree || undefined; + isAdditionnalTreeDisplayed.value = + snapshot?.isAdditionnalTreeDisplayed || false + panelWidth.value = snapshot?.panelWidth || PANEL_WIDTH + model_id.value = snapshot?.model_id || "" + isTreeCollection.value = snapshot?.isTreeCollection || false + selectedTree.value = snapshot?.selectedTree || undefined pendingSelectionIds.value = - snapshot?.selectionIds || (snapshot?.selection || []).map((store) => store.id) || []; + snapshot?.selectionIds || + (snapshot?.selection || []).map((store) => store.id) || + [] } function finalizeImportSelection() { - const ids = pendingSelectionIds.value || []; - const rebuilt = []; + const ids = pendingSelectionIds.value || [] + const rebuilt = [] if (ids.length === 0) { for (const group of items.value) { for (const child of group.children) { - rebuilt.push(child); + rebuilt.push(child) } } } else { for (const group of items.value) { for (const child of group.children) { if (ids.includes(child.id)) { - rebuilt.push(child); + rebuilt.push(child) } } } } - selection.value = rebuilt; - pendingSelectionIds.value = []; + selection.value = rebuilt + pendingSelectionIds.value = [] } function removeItem(id) { for (let i = 0; i < items.value.length; i += 1) { - const group = items.value[i]; - const childIndex = group.children.findIndex((child) => child.id === id); + const group = items.value[i] + const childIndex = group.children.findIndex((child) => child.id === id) if (childIndex !== -1) { - group.children.splice(childIndex, 1); + group.children.splice(childIndex, 1) if (group.children.length === 0) { - items.value.splice(i, 1); + items.value.splice(i, 1) } - const selectionIndex = selection.value.findIndex((item) => item.id === id); + const selectionIndex = selection.value.findIndex( + (item) => item.id === id, + ) if (selectionIndex !== -1) { - selection.value.splice(selectionIndex, 1); + selection.value.splice(selectionIndex, 1) } - return; + return } } } function clear() { - items.value = []; - selection.value = []; - components_selection.value = []; - pendingSelectionIds.value = []; - model_id.value = ""; - selectedTree.value = undefined; + items.value = [] + selection.value = [] + components_selection.value = [] + pendingSelectionIds.value = [] + model_id.value = "" + selectedTree.value = undefined } return { @@ -152,5 +160,5 @@ export const useTreeviewStore = defineStore("treeview", () => { importStores, finalizeImportSelection, clear, - }; -}); + } +}) diff --git a/app/utils/local/path.js b/app/utils/local/path.js index f19bea52..935cb78e 100644 --- a/app/utils/local/path.js +++ b/app/utils/local/path.js @@ -1,77 +1,77 @@ // Node imports -import fs from "node:fs"; -import os from "node:os"; -import path from "node:path"; -import { setTimeout } from "node:timers/promises"; +import fs from "node:fs" +import os from "node:os" +import path from "node:path" +import { setTimeout } from "node:timers/promises" // Third party imports -import isElectron from "is-electron"; -import { rimraf } from "rimraf"; -import { v4 as uuidv4 } from "uuid"; +import isElectron from "is-electron" +import { rimraf } from "rimraf" +import { v4 as uuidv4 } from "uuid" -const MAX_DELETE_FOLDER_RETRIES = 5; +const MAX_DELETE_FOLDER_RETRIES = 5 function venvScriptPath(microservicePath) { - const venvPath = path.join(microservicePath, "venv"); - let scriptPath = ""; + const venvPath = path.join(microservicePath, "venv") + let scriptPath = "" if (process.platform === "win32") { - scriptPath = path.join(venvPath, "Scripts"); + scriptPath = path.join(venvPath, "Scripts") } else { - scriptPath = path.join(venvPath, "bin"); + scriptPath = path.join(venvPath, "bin") } - return scriptPath; + return scriptPath } async function executablePath(microservicePath) { if (isElectron()) { - const electron = await import("electron"); + const electron = await import("electron") if (electron.app.isPackaged) { - return process.resourcesPath; + return process.resourcesPath } - return venvScriptPath(microservicePath); + return venvScriptPath(microservicePath) } - return venvScriptPath(microservicePath); + return venvScriptPath(microservicePath) } function executableName(name) { if (process.platform === "win32") { - return `${name}.exe`; + return `${name}.exe` } - return name; + return name } function createPath(dirPath) { if (!fs.existsSync(dirPath)) { - fs.mkdirSync(dirPath, { recursive: true }); - console.log(`${dirPath} directory created successfully!`); + fs.mkdirSync(dirPath, { recursive: true }) + console.log(`${dirPath} directory created successfully!`) } - return dirPath; + return dirPath } function generateProjectFolderPath(projectName) { - return path.join(os.tmpdir(), projectName.replaceAll("/", "_"), uuidv4()); + return path.join(os.tmpdir(), projectName.replaceAll("/", "_"), uuidv4()) } async function deleteFolderRecursive(folderPath) { if (!fs.existsSync(folderPath)) { - console.log(`Folder ${folderPath} does not exist.`); - return; + console.log(`Folder ${folderPath} does not exist.`) + return } for (let i = 0; i <= MAX_DELETE_FOLDER_RETRIES; i += 1) { try { - console.log(`Deleting folder: ${folderPath}`); + console.log(`Deleting folder: ${folderPath}`) // oxlint-disable-next-line no-await-in-loop - await rimraf(folderPath); - console.log(`Deleted folder: ${folderPath}`); - return; + await rimraf(folderPath) + console.log(`Deleted folder: ${folderPath}`) + return } catch (error) { - console.error(`Error deleting folder ${folderPath}:`, error); + console.error(`Error deleting folder ${folderPath}:`, error) // Wait before retrying - const MILLISECONDS_PER_RETRY = 1000; - const DELAY = MILLISECONDS_PER_RETRY * (i + 1); + const MILLISECONDS_PER_RETRY = 1000 + const DELAY = MILLISECONDS_PER_RETRY * (i + 1) // oxlint-disable-next-line no-await-in-loop - await setTimeout(DELAY); - console.log("Retrying delete folder"); + await setTimeout(DELAY) + console.log("Retrying delete folder") } } } @@ -81,4 +81,4 @@ export { executableName, deleteFolderRecursive, generateProjectFolderPath, -}; +} diff --git a/app/utils/server.js b/app/utils/server.js index 32bde76b..d5a1559e 100644 --- a/app/utils/server.js +++ b/app/utils/server.js @@ -1,43 +1,46 @@ // Node imports -import fs from "node:fs"; -import path from "node:path"; +import fs from "node:fs" +import path from "node:path" // Third party imports -import JSZip from "jszip"; +import JSZip from "jszip" -async function unzipFile(zipFilePath, outputDir = zipFilePath.replace(/\.[^/.]+$/, "")) { - console.log("Unzipping file...", zipFilePath, outputDir); +async function unzipFile( + zipFilePath, + outputDir = zipFilePath.replace(/\.[^/.]+$/, ""), +) { + console.log("Unzipping file...", zipFilePath, outputDir) try { - const data = await fs.promises.readFile(zipFilePath); - const zip = await JSZip.loadAsync(data); - await fs.promises.mkdir(outputDir, { recursive: true }); - const promises = []; + const data = await fs.promises.readFile(zipFilePath) + const zip = await JSZip.loadAsync(data) + await fs.promises.mkdir(outputDir, { recursive: true }) + const promises = [] for (const [relativePath, zipEntry] of Object.entries(zip.files)) { - const outputPath = path.join(outputDir, relativePath); + const outputPath = path.join(outputDir, relativePath) if (zipEntry.dir) { - promises.push(fs.promises.mkdir(outputPath, { recursive: true })); + promises.push(fs.promises.mkdir(outputPath, { recursive: true })) } else { promises.push( (async () => { - const content = await zipEntry.async("nodebuffer"); + const content = await zipEntry.async("nodebuffer") await fs.promises.mkdir(path.dirname(outputPath), { recursive: true, - }); - await fs.promises.writeFile(outputPath, content); + }) + await fs.promises.writeFile(outputPath, content) })(), - ); + ) } } - await Promise.all(promises); - console.log("Extraction complete!"); - return outputDir; + await Promise.all(promises) + console.log("Extraction complete!") + return outputDir } catch (error) { - console.error("Error unzipping file:", error); - throw error; + console.error("Error unzipping file:", error) + throw error } } -export { unzipFile }; +export { unzipFile } diff --git a/internal/stores/data_style/mesh/cells/index.js b/internal/stores/data_style/mesh/cells/index.js index d7562117..951c220d 100644 --- a/internal/stores/data_style/mesh/cells/index.js +++ b/internal/stores/data_style/mesh/cells/index.js @@ -1,64 +1,77 @@ // Third party imports // Local imports -import { useMeshCellsCellAttributeStyle } from "./cell"; -import { useMeshCellsColorStyle } from "./color"; -import { useMeshCellsCommonStyle } from "./common"; -import { useMeshCellsTexturesStyle } from "./textures"; -import { useMeshCellsVertexAttributeStyle } from "./vertex"; -import { useMeshCellsVisibilityStyle } from "./visibility"; +import { useMeshCellsCellAttributeStyle } from "./cell" +import { useMeshCellsColorStyle } from "./color" +import { useMeshCellsCommonStyle } from "./common" +import { useMeshCellsTexturesStyle } from "./textures" +import { useMeshCellsVertexAttributeStyle } from "./vertex" +import { useMeshCellsVisibilityStyle } from "./visibility" // Local constants export function useMeshCellsStyle() { - const meshCellsCommonStyle = useMeshCellsCommonStyle(); - const meshCellsVisibility = useMeshCellsVisibilityStyle(); - const meshCellsColorStyle = useMeshCellsColorStyle(); - const meshCellsTexturesStore = useMeshCellsTexturesStyle(); - const meshCellsVertexAttributeStyle = useMeshCellsVertexAttributeStyle(); - const meshCellsCellAttributeStyle = useMeshCellsCellAttributeStyle(); + const meshCellsCommonStyle = useMeshCellsCommonStyle() + const meshCellsVisibility = useMeshCellsVisibilityStyle() + const meshCellsColorStyle = useMeshCellsColorStyle() + const meshCellsTexturesStore = useMeshCellsTexturesStyle() + const meshCellsVertexAttributeStyle = useMeshCellsVertexAttributeStyle() + const meshCellsCellAttributeStyle = useMeshCellsCellAttributeStyle() async function setMeshCellsActiveColoring(id, type) { - const coloring = meshCellsCommonStyle.meshCellsColoring(id); - coloring.active = type; + const coloring = meshCellsCommonStyle.meshCellsColoring(id) + coloring.active = type console.log( setMeshCellsActiveColoring.name, { id }, meshCellsCommonStyle.meshCellsActiveColoring(id), - ); + ) if (type === "color") { - return meshCellsColorStyle.setMeshCellsColor(id, meshCellsColorStyle.meshCellsColor(id)); + return meshCellsColorStyle.setMeshCellsColor( + id, + meshCellsColorStyle.meshCellsColor(id), + ) } if (type === "textures") { - const textures = meshCellsTexturesStore.meshCellsTextures(id); + const textures = meshCellsTexturesStore.meshCellsTextures(id) if (textures === undefined) { - return; + return } - return meshCellsTexturesStore.setMeshCellsTextures(id, textures); + return meshCellsTexturesStore.setMeshCellsTextures(id, textures) } if (type === "vertex") { - const name = meshCellsVertexAttributeStyle.meshCellsVertexAttributeName(id); + const name = + meshCellsVertexAttributeStyle.meshCellsVertexAttributeName(id) if (name === undefined) { - return; + return } - return meshCellsVertexAttributeStyle.setMeshCellsVertexAttributeName(id, name); + return meshCellsVertexAttributeStyle.setMeshCellsVertexAttributeName( + id, + name, + ) } if (type === "cell") { - const name = meshCellsCellAttributeStyle.meshCellsCellAttributeName(id); + const name = meshCellsCellAttributeStyle.meshCellsCellAttributeName(id) if (name === undefined) { - return; + return } - await meshCellsCellAttributeStyle.setMeshCellsCellAttributeName(id, name); - return; + await meshCellsCellAttributeStyle.setMeshCellsCellAttributeName(id, name) + return } - throw new Error(`Unknown mesh cells coloring type: ${type}`); + throw new Error(`Unknown mesh cells coloring type: ${type}`) } function applyMeshCellsStyle(id) { return Promise.all([ - meshCellsVisibility.setMeshCellsVisibility(id, meshCellsVisibility.meshCellsVisibility(id)), - setMeshCellsActiveColoring(id, meshCellsCommonStyle.meshCellsActiveColoring(id)), - ]); + meshCellsVisibility.setMeshCellsVisibility( + id, + meshCellsVisibility.meshCellsVisibility(id), + ), + setMeshCellsActiveColoring( + id, + meshCellsCommonStyle.meshCellsActiveColoring(id), + ), + ]) } return { @@ -70,5 +83,5 @@ export function useMeshCellsStyle() { ...meshCellsTexturesStore, ...meshCellsVertexAttributeStyle, ...meshCellsCellAttributeStyle, - }; + } } diff --git a/internal/stores/data_style/mesh/edges/index.js b/internal/stores/data_style/mesh/edges/index.js index 680cafa5..87603b9f 100644 --- a/internal/stores/data_style/mesh/edges/index.js +++ b/internal/stores/data_style/mesh/edges/index.js @@ -1,64 +1,80 @@ // Third party imports // Local imports -import { useMeshEdgesColorStyle } from "./color"; -import { useMeshEdgesCommonStyle } from "./common"; -import { useMeshEdgesEdgeAttributeStyle } from "./edge"; -import { useMeshEdgesVertexAttributeStyle } from "./vertex"; -import { useMeshEdgesVisibilityStyle } from "./visibility"; -import { useMeshEdgesWidthStyle } from "./width"; +import { useMeshEdgesColorStyle } from "./color" +import { useMeshEdgesCommonStyle } from "./common" +import { useMeshEdgesEdgeAttributeStyle } from "./edge" +import { useMeshEdgesVertexAttributeStyle } from "./vertex" +import { useMeshEdgesVisibilityStyle } from "./visibility" +import { useMeshEdgesWidthStyle } from "./width" // Local constants export function useMeshEdgesStyle() { - const meshEdgesCommonStyle = useMeshEdgesCommonStyle(); - const meshEdgesVisibility = useMeshEdgesVisibilityStyle(); - const meshEdgesColorStyle = useMeshEdgesColorStyle(); - const meshEdgesWidthStyle = useMeshEdgesWidthStyle(); - const meshEdgesVertexAttributeStyle = useMeshEdgesVertexAttributeStyle(); - const meshEdgesEdgeAttributeStyle = useMeshEdgesEdgeAttributeStyle(); + const meshEdgesCommonStyle = useMeshEdgesCommonStyle() + const meshEdgesVisibility = useMeshEdgesVisibilityStyle() + const meshEdgesColorStyle = useMeshEdgesColorStyle() + const meshEdgesWidthStyle = useMeshEdgesWidthStyle() + const meshEdgesVertexAttributeStyle = useMeshEdgesVertexAttributeStyle() + const meshEdgesEdgeAttributeStyle = useMeshEdgesEdgeAttributeStyle() function setMeshEdgesActiveColoring(id, type) { - const coloring = meshEdgesCommonStyle.meshEdgesColoring(id); - coloring.active = type; + const coloring = meshEdgesCommonStyle.meshEdgesColoring(id) + coloring.active = type console.log( setMeshEdgesActiveColoring.name, { id }, meshEdgesCommonStyle.meshEdgesActiveColoring(id), - ); + ) if (type === "color") { - return meshEdgesColorStyle.setMeshEdgesColor(id, meshEdgesColorStyle.meshEdgesColor(id)); + return meshEdgesColorStyle.setMeshEdgesColor( + id, + meshEdgesColorStyle.meshEdgesColor(id), + ) } if (type === "textures") { - const textures = meshEdgesTexturesStore.meshEdgesTextures(id); + const textures = meshEdgesTexturesStore.meshEdgesTextures(id) if (textures === undefined) { - return Promise.resolve(); + return Promise.resolve() } - return meshEdgesTexturesStore.setMeshEdgesTextures(id, textures); + return meshEdgesTexturesStore.setMeshEdgesTextures(id, textures) } if (type === "vertex") { - const name = meshEdgesVertexAttributeStyle.meshEdgesVertexAttributeName(id); + const name = + meshEdgesVertexAttributeStyle.meshEdgesVertexAttributeName(id) if (name === undefined) { - return Promise.resolve(); + return Promise.resolve() } - return meshEdgesVertexAttributeStyle.setMeshEdgesVertexAttributeName(id, name); + return meshEdgesVertexAttributeStyle.setMeshEdgesVertexAttributeName( + id, + name, + ) } if (type === "edge") { - const name = meshEdgesEdgeAttributeStyle.meshEdgesEdgeAttributeName(id); + const name = meshEdgesEdgeAttributeStyle.meshEdgesEdgeAttributeName(id) if (name === undefined) { - return Promise.resolve(); + return Promise.resolve() } - return meshEdgesEdgeAttributeStyle.setMeshEdgesEdgeAttributeName(id, name); + return meshEdgesEdgeAttributeStyle.setMeshEdgesEdgeAttributeName(id, name) } - throw new Error(`Unknown mesh edges coloring type: ${type}`); + throw new Error(`Unknown mesh edges coloring type: ${type}`) } function applyMeshEdgesStyle(id) { return Promise.all([ - meshEdgesVisibility.setMeshEdgesVisibility(id, meshEdgesVisibility.meshEdgesVisibility(id)), - meshEdgesWidthStyle.setMeshEdgesWidth(id, meshEdgesWidthStyle.meshEdgesWidth(id)), - setMeshEdgesActiveColoring(id, meshEdgesCommonStyle.meshEdgesActiveColoring(id)), - ]); + meshEdgesVisibility.setMeshEdgesVisibility( + id, + meshEdgesVisibility.meshEdgesVisibility(id), + ), + meshEdgesWidthStyle.setMeshEdgesWidth( + id, + meshEdgesWidthStyle.meshEdgesWidth(id), + ), + setMeshEdgesActiveColoring( + id, + meshEdgesCommonStyle.meshEdgesActiveColoring(id), + ), + ]) } return { @@ -70,5 +86,5 @@ export function useMeshEdgesStyle() { ...meshEdgesWidthStyle, ...meshEdgesVertexAttributeStyle, ...meshEdgesEdgeAttributeStyle, - }; + } } diff --git a/internal/stores/data_style/mesh/points/index.js b/internal/stores/data_style/mesh/points/index.js index 7a7bd464..2cb79d4d 100644 --- a/internal/stores/data_style/mesh/points/index.js +++ b/internal/stores/data_style/mesh/points/index.js @@ -1,55 +1,66 @@ // Third party imports // Local imports -import { useMeshPointsColorStyle } from "./color"; -import { useMeshPointsCommonStyle } from "./common"; -import { useMeshPointsSizeStyle } from "./size"; -import { useMeshPointsVertexAttributeStyle } from "./vertex"; -import { useMeshPointsVisibilityStyle } from "./visibility"; +import { useMeshPointsColorStyle } from "./color" +import { useMeshPointsCommonStyle } from "./common" +import { useMeshPointsSizeStyle } from "./size" +import { useMeshPointsVertexAttributeStyle } from "./vertex" +import { useMeshPointsVisibilityStyle } from "./visibility" // Local constants export function useMeshPointsStyle() { - const meshPointsCommonStyle = useMeshPointsCommonStyle(); - const meshPointsVisibility = useMeshPointsVisibilityStyle(); - const meshPointsColorStyle = useMeshPointsColorStyle(); - const meshPointsSizeStyle = useMeshPointsSizeStyle(); - const meshPointsVertexAttributeStyle = useMeshPointsVertexAttributeStyle(); + const meshPointsCommonStyle = useMeshPointsCommonStyle() + const meshPointsVisibility = useMeshPointsVisibilityStyle() + const meshPointsColorStyle = useMeshPointsColorStyle() + const meshPointsSizeStyle = useMeshPointsSizeStyle() + const meshPointsVertexAttributeStyle = useMeshPointsVertexAttributeStyle() async function setMeshPointsActiveColoring(id, type) { - const coloring = meshPointsCommonStyle.meshPointsColoring(id); - coloring.active = type; + const coloring = meshPointsCommonStyle.meshPointsColoring(id) + coloring.active = type console.log( setMeshPointsActiveColoring.name, { id }, meshPointsCommonStyle.meshPointsActiveColoring(id), - ); + ) if (type === "color") { - return meshPointsColorStyle.setMeshPointsColor(id, meshPointsColorStyle.meshPointsColor(id)); + return meshPointsColorStyle.setMeshPointsColor( + id, + meshPointsColorStyle.meshPointsColor(id), + ) } if (type === "textures") { - const textures = meshPointsTexturesStore.meshPointsTextures(id); + const textures = meshPointsTexturesStore.meshPointsTextures(id) if (textures === undefined) { - return; + return } - return meshPointsTexturesStore.setMeshPointsTextures(id, textures); + return meshPointsTexturesStore.setMeshPointsTextures(id, textures) } if (type === "vertex") { - const name = meshPointsVertexAttributeStyle.meshPointsVertexAttributeName(id); + const name = + meshPointsVertexAttributeStyle.meshPointsVertexAttributeName(id) if (name === undefined) { - return; + return } - return meshPointsVertexAttributeStyle.setMeshPointsVertexAttributeName(id, name); + return meshPointsVertexAttributeStyle.setMeshPointsVertexAttributeName( + id, + name, + ) } if (type === "polygon") { - const name = meshPointsPolygonAttributeStyleStore.meshPointsPolygonAttributeName(id); + const name = + meshPointsPolygonAttributeStyleStore.meshPointsPolygonAttributeName(id) if (name === undefined) { - return; + return } - await meshPointsPolygonAttributeStyleStore.setMeshPointsPolygonAttributeName(id, name); - return; + await meshPointsPolygonAttributeStyleStore.setMeshPointsPolygonAttributeName( + id, + name, + ) + return } - throw new Error(`Unknown mesh points coloring type: ${type}`); + throw new Error(`Unknown mesh points coloring type: ${type}`) } function applyMeshPointsStyle(id) { @@ -58,9 +69,15 @@ export function useMeshPointsStyle() { id, meshPointsVisibility.meshPointsVisibility(id), ), - meshPointsSizeStyle.setMeshPointsSize(id, meshPointsSizeStyle.meshPointsSize(id)), - setMeshPointsActiveColoring(id, meshPointsCommonStyle.meshPointsActiveColoring(id)), - ]); + meshPointsSizeStyle.setMeshPointsSize( + id, + meshPointsSizeStyle.meshPointsSize(id), + ), + setMeshPointsActiveColoring( + id, + meshPointsCommonStyle.meshPointsActiveColoring(id), + ), + ]) } return { @@ -71,5 +88,5 @@ export function useMeshPointsStyle() { ...meshPointsColorStyle, ...meshPointsSizeStyle, ...meshPointsVertexAttributeStyle, - }; + } } diff --git a/internal/stores/data_style/mesh/polygons/index.js b/internal/stores/data_style/mesh/polygons/index.js index 7f72fe2e..73c41b0c 100644 --- a/internal/stores/data_style/mesh/polygons/index.js +++ b/internal/stores/data_style/mesh/polygons/index.js @@ -1,60 +1,69 @@ // Third party imports // Local imports -import { useMeshPolygonsColorStyle } from "./color"; -import { useMeshPolygonsCommonStyle } from "./common"; -import { useMeshPolygonsPolygonAttributeStyle } from "./polygon"; -import { useMeshPolygonsTexturesStyle } from "./textures"; -import { useMeshPolygonsVertexAttributeStyle } from "./vertex"; -import { useMeshPolygonsVisibilityStyle } from "./visibility"; +import { useMeshPolygonsColorStyle } from "./color" +import { useMeshPolygonsCommonStyle } from "./common" +import { useMeshPolygonsPolygonAttributeStyle } from "./polygon" +import { useMeshPolygonsTexturesStyle } from "./textures" +import { useMeshPolygonsVertexAttributeStyle } from "./vertex" +import { useMeshPolygonsVisibilityStyle } from "./visibility" // Local constants export function useMeshPolygonsStyle() { - const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle(); - const meshPolygonsVisibility = useMeshPolygonsVisibilityStyle(); - const meshPolygonsColorStyle = useMeshPolygonsColorStyle(); - const meshPolygonsTexturesStyle = useMeshPolygonsTexturesStyle(); - const meshPolygonsVertexAttributeStyle = useMeshPolygonsVertexAttributeStyle(); - const meshPolygonsPolygonAttributeStyle = useMeshPolygonsPolygonAttributeStyle(); + const meshPolygonsCommonStyle = useMeshPolygonsCommonStyle() + const meshPolygonsVisibility = useMeshPolygonsVisibilityStyle() + const meshPolygonsColorStyle = useMeshPolygonsColorStyle() + const meshPolygonsTexturesStyle = useMeshPolygonsTexturesStyle() + const meshPolygonsVertexAttributeStyle = useMeshPolygonsVertexAttributeStyle() + const meshPolygonsPolygonAttributeStyle = + useMeshPolygonsPolygonAttributeStyle() async function setMeshPolygonsActiveColoring(id, type) { - const coloring = meshPolygonsCommonStyle.meshPolygonsColoring(id); - coloring.active = type; + const coloring = meshPolygonsCommonStyle.meshPolygonsColoring(id) + coloring.active = type console.log( setMeshPolygonsActiveColoring.name, { id }, meshPolygonsCommonStyle.meshPolygonsActiveColoring(id), - ); + ) if (type === "color") { return meshPolygonsColorStyle.setMeshPolygonsColor( id, meshPolygonsColorStyle.meshPolygonsColor(id), - ); + ) } if (type === "textures") { - const textures = meshPolygonsTexturesStyle.meshPolygonsTextures(id); + const textures = meshPolygonsTexturesStyle.meshPolygonsTextures(id) if (textures === undefined) { - return; + return } - return meshPolygonsTexturesStyle.setMeshPolygonsTextures(id, textures); + return meshPolygonsTexturesStyle.setMeshPolygonsTextures(id, textures) } if (type === "vertex") { - const name = meshPolygonsVertexAttributeStyle.meshPolygonsVertexAttributeName(id); + const name = + meshPolygonsVertexAttributeStyle.meshPolygonsVertexAttributeName(id) if (name === undefined) { - return; + return } - return meshPolygonsVertexAttributeStyle.setMeshPolygonsVertexAttributeName(id, name); + return meshPolygonsVertexAttributeStyle.setMeshPolygonsVertexAttributeName( + id, + name, + ) } if (type === "polygon") { - const name = meshPolygonsPolygonAttributeStyle.meshPolygonsPolygonAttributeName(id); + const name = + meshPolygonsPolygonAttributeStyle.meshPolygonsPolygonAttributeName(id) if (name === undefined) { - return; + return } - await meshPolygonsPolygonAttributeStyle.setMeshPolygonsPolygonAttributeName(id, name); - return; + await meshPolygonsPolygonAttributeStyle.setMeshPolygonsPolygonAttributeName( + id, + name, + ) + return } - throw new Error(`Unknown mesh polygons coloring type: ${type}`); + throw new Error(`Unknown mesh polygons coloring type: ${type}`) } function applyMeshPolygonsStyle(id) { @@ -63,8 +72,11 @@ export function useMeshPolygonsStyle() { id, meshPolygonsVisibility.meshPolygonsVisibility(id), ), - setMeshPolygonsActiveColoring(id, meshPolygonsCommonStyle.meshPolygonsActiveColoring(id)), - ]); + setMeshPolygonsActiveColoring( + id, + meshPolygonsCommonStyle.meshPolygonsActiveColoring(id), + ), + ]) } return { @@ -76,5 +88,5 @@ export function useMeshPolygonsStyle() { ...meshPolygonsTexturesStyle, ...meshPolygonsVertexAttributeStyle, ...meshPolygonsPolygonAttributeStyle, - }; + } } diff --git a/internal/stores/data_style/mesh/polyhedra/index.js b/internal/stores/data_style/mesh/polyhedra/index.js index 421bc59c..b60331fb 100644 --- a/internal/stores/data_style/mesh/polyhedra/index.js +++ b/internal/stores/data_style/mesh/polyhedra/index.js @@ -1,51 +1,63 @@ // Third party imports // Local imports -import { useMeshPolyhedraColorStyle } from "./color"; -import { useMeshPolyhedraCommonStyle } from "./common"; -import { useMeshPolyhedraPolyhedronAttributeStyle } from "./polyhedron"; -import { useMeshPolyhedraVertexAttributeStyle } from "./vertex"; -import { useMeshPolyhedraVisibilityStyle } from "./visibility"; +import { useMeshPolyhedraColorStyle } from "./color" +import { useMeshPolyhedraCommonStyle } from "./common" +import { useMeshPolyhedraPolyhedronAttributeStyle } from "./polyhedron" +import { useMeshPolyhedraVertexAttributeStyle } from "./vertex" +import { useMeshPolyhedraVisibilityStyle } from "./visibility" // Local constants export function useMeshPolyhedraStyle() { - const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle(); - const meshPolyhedraVisibility = useMeshPolyhedraVisibilityStyle(); - const meshPolyhedraColorStyle = useMeshPolyhedraColorStyle(); - const meshPolyhedraVertexAttributeStyle = useMeshPolyhedraVertexAttributeStyle(); - const meshPolyhedraPolyhedronAttributeStyle = useMeshPolyhedraPolyhedronAttributeStyle(); + const meshPolyhedraCommonStyle = useMeshPolyhedraCommonStyle() + const meshPolyhedraVisibility = useMeshPolyhedraVisibilityStyle() + const meshPolyhedraColorStyle = useMeshPolyhedraColorStyle() + const meshPolyhedraVertexAttributeStyle = + useMeshPolyhedraVertexAttributeStyle() + const meshPolyhedraPolyhedronAttributeStyle = + useMeshPolyhedraPolyhedronAttributeStyle() async function setMeshPolyhedraActiveColoring(id, type) { - const coloring = meshPolyhedraCommonStyle.meshPolyhedraColoring(id); - coloring.active = type; + const coloring = meshPolyhedraCommonStyle.meshPolyhedraColoring(id) + coloring.active = type console.log( setMeshPolyhedraActiveColoring.name, { id }, meshPolyhedraCommonStyle.meshPolyhedraActiveColoring(id), - ); + ) if (type === "color") { return meshPolyhedraColorStyle.setMeshPolyhedraColor( id, meshPolyhedraColorStyle.meshPolyhedraColor(id), - ); + ) } if (type === "vertex") { - const name = meshPolyhedraVertexAttributeStyle.meshPolyhedraVertexAttributeName(id); + const name = + meshPolyhedraVertexAttributeStyle.meshPolyhedraVertexAttributeName(id) if (name === undefined) { - return; + return } - return meshPolyhedraVertexAttributeStyle.setMeshPolyhedraVertexAttributeName(id, name); + return meshPolyhedraVertexAttributeStyle.setMeshPolyhedraVertexAttributeName( + id, + name, + ) } if (type === "polyhedron") { - const name = meshPolyhedraPolyhedronAttributeStyle.meshPolyhedraPolyhedronAttributeName(id); + const name = + meshPolyhedraPolyhedronAttributeStyle.meshPolyhedraPolyhedronAttributeName( + id, + ) if (name === undefined) { - return; + return } - await meshPolyhedraPolyhedronAttributeStyle.setMeshPolyhedraPolyhedronAttributeName(id, name); - return; + await meshPolyhedraPolyhedronAttributeStyle.setMeshPolyhedraPolyhedronAttributeName( + id, + name, + ) + return } - throw new Error(`Unknown mesh polyhedra coloring type: ${type}`); + throw new Error(`Unknown mesh polyhedra coloring type: ${type}`) } function applyMeshPolyhedraStyle(id) { @@ -54,8 +66,11 @@ export function useMeshPolyhedraStyle() { id, meshPolyhedraVisibility.meshPolyhedraVisibility(id), ), - setMeshPolyhedraActiveColoring(id, meshPolyhedraCommonStyle.meshPolyhedraActiveColoring(id)), - ]); + setMeshPolyhedraActiveColoring( + id, + meshPolyhedraCommonStyle.meshPolyhedraActiveColoring(id), + ), + ]) } return { @@ -66,5 +81,5 @@ export function useMeshPolyhedraStyle() { ...meshPolyhedraColorStyle, ...meshPolyhedraVertexAttributeStyle, ...meshPolyhedraPolyhedronAttributeStyle, - }; + } } diff --git a/internal/stores/data_style/model/index.js b/internal/stores/data_style/model/index.js index 476cda74..502f69d1 100644 --- a/internal/stores/data_style/model/index.js +++ b/internal/stores/data_style/model/index.js @@ -1,35 +1,35 @@ // Third party imports -import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"; +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" // Local imports -import { useDataStore } from "@ogw_front/stores/data"; -import { useDataStyleStateStore } from "@ogw_internal/stores/data_style/state"; -import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer"; -import { useModelBlocksStyle } from "./blocks"; -import { useModelCornersStyle } from "./corners"; -import { useModelEdgesStyle } from "./edges"; -import { useModelLinesStyle } from "./lines"; -import { useModelPointsStyle } from "./points"; -import { useModelSurfacesStyle } from "./surfaces"; -import { useViewerStore } from "@ogw_front/stores/viewer"; +import { useDataStore } from "@ogw_front/stores/data" +import { useDataStyleStateStore } from "@ogw_internal/stores/data_style/state" +import { useHybridViewerStore } from "@ogw_front/stores/hybrid_viewer" +import { useModelBlocksStyle } from "./blocks" +import { useModelCornersStyle } from "./corners" +import { useModelEdgesStyle } from "./edges" +import { useModelLinesStyle } from "./lines" +import { useModelPointsStyle } from "./points" +import { useModelSurfacesStyle } from "./surfaces" +import { useViewerStore } from "@ogw_front/stores/viewer" // Local constants -const model_schemas = viewer_schemas.opengeodeweb_viewer.model; +const model_schemas = viewer_schemas.opengeodeweb_viewer.model export function useModelStyle() { - const dataStore = useDataStore(); - const dataStyleStateStore = useDataStyleStateStore(); - const modelCornersStyleStore = useModelCornersStyle(); - const modelBlocksStyleStore = useModelBlocksStyle(); - const modelEdgesStyleStore = useModelEdgesStyle(); - const modelLinesStyleStore = useModelLinesStyle(); - const modelPointsStyleStore = useModelPointsStyle(); - const modelSurfacesStyleStore = useModelSurfacesStyle(); - const hybridViewerStore = useHybridViewerStore(); - const viewerStore = useViewerStore(); + const dataStore = useDataStore() + const dataStyleStateStore = useDataStyleStateStore() + const modelCornersStyleStore = useModelCornersStyle() + const modelBlocksStyleStore = useModelBlocksStyle() + const modelEdgesStyleStore = useModelEdgesStyle() + const modelLinesStyleStore = useModelLinesStyle() + const modelPointsStyleStore = useModelPointsStyle() + const modelSurfacesStyleStore = useModelSurfacesStyle() + const hybridViewerStore = useHybridViewerStore() + const viewerStore = useViewerStore() function modelVisibility(id) { - return dataStyleStateStore.getStyle(id).visibility; + return dataStyleStateStore.getStyle(id).visibility } function setModelVisibility(id, visibility) { return viewerStore.request( @@ -37,66 +37,66 @@ export function useModelStyle() { { id, visibility }, { response_function: () => { - dataStyleStateStore.getStyle(id).visibility = visibility; - hybridViewerStore.setVisibility(id, visibility); - console.log(setModelVisibility.name, { id }, modelVisibility(id)); + dataStyleStateStore.getStyle(id).visibility = visibility + hybridViewerStore.setVisibility(id, visibility) + console.log(setModelVisibility.name, { id }, modelVisibility(id)) }, }, - ); + ) } function visibleMeshComponents(id) { - const visible_mesh_components = ref([]); - const styles = dataStyleStateStore.styles[id]; + const visible_mesh_components = ref([]) + const styles = dataStyleStateStore.styles[id] if (!styles) { - return visible_mesh_components; + return visible_mesh_components } for (const [corner_id, style] of Object.entries(styles.corners || {})) { if (style.visibility) { - visible_mesh_components.value.push(corner_id); + visible_mesh_components.value.push(corner_id) } } for (const [line_id, style] of Object.entries(styles.lines || {})) { if (style.visibility) { - visible_mesh_components.value.push(line_id); + visible_mesh_components.value.push(line_id) } } for (const [surface_id, style] of Object.entries(styles.surfaces || {})) { if (style.visibility) { - visible_mesh_components.value.push(surface_id); + visible_mesh_components.value.push(surface_id) } } for (const [block_id, style] of Object.entries(styles.blocks || {})) { if (style.visibility) { - visible_mesh_components.value.push(block_id); + visible_mesh_components.value.push(block_id) } } - return visible_mesh_components; + return visible_mesh_components } function modelMeshComponentVisibility(id, component_type, component_id) { if (component_type === "Corner") { - return modelCornersStyleStore.modelCornerVisibility(id, component_id); + return modelCornersStyleStore.modelCornerVisibility(id, component_id) } if (component_type === "Line") { - return modelLinesStyleStore.modelLineVisibility(id, component_id); + return modelLinesStyleStore.modelLineVisibility(id, component_id) } if (component_type === "Surface") { - return modelSurfacesStyleStore.modelSurfaceVisibility(id, component_id); + return modelSurfacesStyleStore.modelSurfaceVisibility(id, component_id) } if (component_type === "Block") { - return modelBlocksStyleStore.modelBlockVisibility(id, component_id); + return modelBlocksStyleStore.modelBlockVisibility(id, component_id) } - throw new Error(`Unknown model component_type: ${component_type}`); + throw new Error(`Unknown model component_type: ${component_type}`) } function modelColor(id) { - return dataStyleStateStore.getStyle(id).color; + return dataStyleStateStore.getStyle(id).color } function setModelColor(id, color) { return viewerStore.request( @@ -104,76 +104,97 @@ export function useModelStyle() { { id, color }, { response_function: () => { - dataStyleStateStore.styles[id].color = color; - console.log(setModelColor.name, { id }, modelColor(id)); + dataStyleStateStore.styles[id].color = color + console.log(setModelColor.name, { id }, modelColor(id)) }, }, - ); + ) } - async function setModelMeshComponentsVisibility(id, component_geode_ids, visibility) { - const component_type = await dataStore.meshComponentType(id, component_geode_ids[0]); + async function setModelMeshComponentsVisibility( + id, + component_geode_ids, + visibility, + ) { + const component_type = await dataStore.meshComponentType( + id, + component_geode_ids[0], + ) if (component_type === "Corner") { - return modelCornersStyleStore.setModelCornersVisibility(id, component_geode_ids, visibility); + return modelCornersStyleStore.setModelCornersVisibility( + id, + component_geode_ids, + visibility, + ) } if (component_type === "Line") { - return modelLinesStyleStore.setModelLinesVisibility(id, component_geode_ids, visibility); + return modelLinesStyleStore.setModelLinesVisibility( + id, + component_geode_ids, + visibility, + ) } if (component_type === "Surface") { return modelSurfacesStyleStore.setModelSurfacesVisibility( id, component_geode_ids, visibility, - ); + ) } if (component_type === "Block") { - return modelBlocksStyleStore.setModelBlocksVisibility(id, component_geode_ids, visibility); + return modelBlocksStyleStore.setModelBlocksVisibility( + id, + component_geode_ids, + visibility, + ) } - throw new Error(`Unknown model component_type: ${component_type}`); + throw new Error(`Unknown model component_type: ${component_type}`) } function applyModelStyle(id) { - const style = dataStyleStateStore.getStyle(id); - const promise_array = []; + const style = dataStyleStateStore.getStyle(id) + const promise_array = [] for (const [key, value] of Object.entries(style)) { if (key === "visibility") { - promise_array.push(setModelVisibility(id, value)); + promise_array.push(setModelVisibility(id, value)) } else if (key === "corners") { - promise_array.push(modelCornersStyleStore.applyModelCornersStyle(id)); + promise_array.push(modelCornersStyleStore.applyModelCornersStyle(id)) } else if (key === "lines") { - promise_array.push(modelLinesStyleStore.applyModelLinesStyle(id)); + promise_array.push(modelLinesStyleStore.applyModelLinesStyle(id)) } else if (key === "surfaces") { - promise_array.push(modelSurfacesStyleStore.applyModelSurfacesStyle(id)); + promise_array.push(modelSurfacesStyleStore.applyModelSurfacesStyle(id)) } else if (key === "blocks") { - promise_array.push(modelBlocksStyleStore.applyModelBlocksStyle(id)); + promise_array.push(modelBlocksStyleStore.applyModelBlocksStyle(id)) } else if (key === "points") { - promise_array.push(modelPointsStyleStore.applyModelPointsStyle(id)); + promise_array.push(modelPointsStyleStore.applyModelPointsStyle(id)) } else if (key === "edges") { - promise_array.push(modelEdgesStyleStore.applyModelEdgesStyle(id)); + promise_array.push(modelEdgesStyleStore.applyModelEdgesStyle(id)) } else { - throw new Error(`Unknown model key: ${key}`); + throw new Error(`Unknown model key: ${key}`) } } - return Promise.all(promise_array); + return Promise.all(promise_array) } async function setModelMeshComponentsDefaultStyle(id) { - const item = await dataStore.item(id); - const { mesh_components } = item; - const promise_array = []; + const item = await dataStore.item(id) + const { mesh_components } = item + const promise_array = [] if ("Corner" in mesh_components) { - promise_array.push(modelCornersStyleStore.setModelCornersDefaultStyle(id)); + promise_array.push(modelCornersStyleStore.setModelCornersDefaultStyle(id)) } if ("Line" in mesh_components) { - promise_array.push(modelLinesStyleStore.setModelLinesDefaultStyle(id)); + promise_array.push(modelLinesStyleStore.setModelLinesDefaultStyle(id)) } if ("Surface" in mesh_components) { - promise_array.push(modelSurfacesStyleStore.setModelSurfacesDefaultStyle(id)); + promise_array.push( + modelSurfacesStyleStore.setModelSurfacesDefaultStyle(id), + ) } if ("Block" in mesh_components) { - promise_array.push(modelBlocksStyleStore.setModelBlocksDefaultStyle(id)); + promise_array.push(modelBlocksStyleStore.setModelBlocksDefaultStyle(id)) } - return promise_array; + return promise_array } return { @@ -191,5 +212,5 @@ export function useModelStyle() { ...useModelLinesStyle(), ...useModelPointsStyle(), ...useModelSurfacesStyle(), - }; + } } diff --git a/internal/utils/upload_file.js b/internal/utils/upload_file.js index bee87bca..e973d4ab 100644 --- a/internal/utils/upload_file.js +++ b/internal/utils/upload_file.js @@ -1,50 +1,55 @@ -import { useFeedbackStore } from "@ogw_front/stores/feedback.js"; +import { useFeedbackStore } from "@ogw_front/stores/feedback.js" async function upload_file( microservice, { route, file }, { request_error_function, response_function, response_error_function } = {}, ) { - console.log("[UPLOAD_FILE] Uploading file", { route, file }); - const feedbackStore = useFeedbackStore(); + console.log("[UPLOAD_FILE] Uploading file", { route, file }) + const feedbackStore = useFeedbackStore() if (!(file instanceof File)) { - throw new Error("file must be a instance of File"); + throw new Error("file must be a instance of File") } - const body = new FormData(); - body.append("file", file); + const body = new FormData() + body.append("file", file) const request_options = { method: "PUT", body: body, - }; - microservice.start_request(); + } + microservice.start_request() return await $fetch(route, { baseURL: microservice.base_url || "", ...request_options, onRequestError({ error }) { - microservice.stop_request(); - feedbackStore.add_error(error.code, route, error.message, error.stack); + microservice.stop_request() + feedbackStore.add_error(error.code, route, error.message, error.stack) if (request_error_function) { - request_error_function(error); + request_error_function(error) } }, onResponse({ response }) { if (response.ok) { - microservice.stop_request(); + microservice.stop_request() if (response_function) { - response_function(response); + response_function(response) } } }, onResponseError({ response }) { - microservice.stop_request(); - feedbackStore.add_error(response.status, route, response.name, response.description); + microservice.stop_request() + feedbackStore.add_error( + response.status, + route, + response.name, + response.description, + ) if (response_error_function) { - response_error_function(response); + response_error_function(response) } }, - }); + }) } -export { upload_file }; +export { upload_file } diff --git a/server/api/extensions/upload.put.js b/server/api/extensions/upload.put.js index f6f7b8ab..a21fd177 100644 --- a/server/api/extensions/upload.put.js +++ b/server/api/extensions/upload.put.js @@ -1,27 +1,35 @@ // Node imports -import { finished, pipeline } from "node:stream/promises"; -import { Readable } from "node:stream"; -import fs from "node:fs"; -import path from "node:path"; +import { finished, pipeline } from "node:stream/promises" +import { Readable } from "node:stream" +import fs from "node:fs" +import path from "node:path" // Third party imports -import { createError, defineEventHandler, getRequestHeaders, getRequestWebStream } from "h3"; -import StreamZip from "node-stream-zip"; -import busboy from "busboy"; -import sanitize from "sanitize-filename"; +import { + createError, + defineEventHandler, + getRequestHeaders, + getRequestWebStream, +} from "h3" +import StreamZip from "node-stream-zip" +import busboy from "busboy" +import sanitize from "sanitize-filename" // Local imports -import { addExtensionToConf, confFolderPath } from "@geode/opengeodeweb-front/app/utils/config.js"; +import { + addExtensionToConf, + confFolderPath, +} from "@geode/opengeodeweb-front/app/utils/config.js" -const CODE_201 = 201; -const FILE_SIZE_LIMIT = 107_374_182; +const CODE_201 = 201 +const FILE_SIZE_LIMIT = 107_374_182 export default defineEventHandler(async (event) => { - const projectName = "vease"; - const writePromises = []; - const savedFiles = []; + const projectName = "vease" + const writePromises = [] + const savedFiles = [] - const configFolderPath = confFolderPath(projectName); + const configFolderPath = confFolderPath(projectName) const busboyInstance = busboy({ headers: getRequestHeaders(event), @@ -29,65 +37,71 @@ export default defineEventHandler(async (event) => { fileSize: FILE_SIZE_LIMIT, files: 1, }, - }); + }) busboyInstance.on("file", (fieldname, fileStream, info) => { if (fieldname !== "file") { // Drain & ignore unwanted fields - fileStream.resume(); - return; + fileStream.resume() + return } - const safeFilename = sanitize(info.filename); - const targetPath = path.join(configFolderPath, safeFilename); + const safeFilename = sanitize(info.filename) + const targetPath = path.join(configFolderPath, safeFilename) const writePromise = (async () => { - const writeStream = fs.createWriteStream(targetPath); - await pipeline(fileStream, writeStream); - savedFiles.push(targetPath); - console.log("File written:", targetPath); - })(); - - writePromises.push(writePromise); - fileStream.on("limit", () => busboyInstance.destroy(new Error("File too large"))); - }); + const writeStream = fs.createWriteStream(targetPath) + await pipeline(fileStream, writeStream) + savedFiles.push(targetPath) + console.log("File written:", targetPath) + })() + + writePromises.push(writePromise) + fileStream.on("limit", () => + busboyInstance.destroy(new Error("File too large")), + ) + }) busboyInstance.on("field", (name, value) => { - console.log(`Field ${name}: ${value}`); - }); + console.log(`Field ${name}: ${value}`) + }) - busboyInstance.on("filesLimit", () => busboyInstance.destroy(new Error("Too many files"))); - busboyInstance.on("partsLimit", () => busboyInstance.destroy(new Error("Too many parts"))); + busboyInstance.on("filesLimit", () => + busboyInstance.destroy(new Error("Too many files")), + ) + busboyInstance.on("partsLimit", () => + busboyInstance.destroy(new Error("Too many parts")), + ) - const webStream = getRequestWebStream(event); - Readable.fromWeb(webStream).pipe(busboyInstance); - await finished(busboyInstance); + const webStream = getRequestWebStream(event) + Readable.fromWeb(webStream).pipe(busboyInstance) + await finished(busboyInstance) if (writePromises.length > 0) { - await Promise.all(writePromises); - console.log("All disk writes completed"); + await Promise.all(writePromises) + console.log("All disk writes completed") } if (savedFiles.length === 0) { - throw createError({ statusCode: 400, message: "No file received" }); + throw createError({ statusCode: 400, message: "No file received" }) } await Promise.all( savedFiles.map(async (file) => { - const StreamZipAsync = StreamZip.async; + const StreamZipAsync = StreamZip.async const zip = new StreamZipAsync({ file, storeEntries: true, - }); - const metadataJson = await zip.entryData("metadata.json"); - const metadata = JSON.parse(metadataJson); - const { id } = metadata; + }) + const metadataJson = await zip.entryData("metadata.json") + const metadata = JSON.parse(metadataJson) + const { id } = metadata await addExtensionToConf(projectName, { extensionID: id, extensionPath: file, - }); + }) }), - ); + ) - return { statusCode: CODE_201 }; -}); + return { statusCode: CODE_201 } +}) diff --git a/tests/integration/stores/data_style/mesh/cells.nuxt.test.js b/tests/integration/stores/data_style/mesh/cells.nuxt.test.js index 75ae5d65..2f110e20 100644 --- a/tests/integration/stores/data_style/mesh/cells.nuxt.test.js +++ b/tests/integration/stores/data_style/mesh/cells.nuxt.test.js @@ -1,155 +1,181 @@ // Third party imports -import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; -import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" with { type: "json" }; +import { afterEach, beforeEach, describe, expect, test, vi } from "vitest" +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" with { type: "json" } // Local imports -import { Status } from "@ogw_front/utils/status"; -import { cleanupBackend } from "@ogw_front/utils/local/microservices"; -import { setupIntegrationTests } from "@ogw_tests/integration/setup"; -import { useDataStyleStore } from "@ogw_front/stores/data_style"; -import { useViewerStore } from "@ogw_front/stores/viewer"; +import { Status } from "@ogw_front/utils/status" +import { cleanupBackend } from "@ogw_front/utils/local/microservices" +import { setupIntegrationTests } from "@ogw_tests/integration/setup" +import { useDataStyleStore } from "@ogw_front/stores/data_style" +import { useViewerStore } from "@ogw_front/stores/viewer" // Local constants -const INTERVAL_TIMEOUT = 20_000; -const mesh_cells_schemas = viewer_schemas.opengeodeweb_viewer.mesh.cells; -const file_name = "test.og_rgd2d"; -const geode_object = "RegularGrid2D"; -const vertex_attribute = { name: "points" }; -const cell_attribute = { name: "RGB_data" }; +const INTERVAL_TIMEOUT = 20_000 +const mesh_cells_schemas = viewer_schemas.opengeodeweb_viewer.mesh.cells +const file_name = "test.og_rgd2d" +const geode_object = "RegularGrid2D" +const vertex_attribute = { name: "points" } +const cell_attribute = { name: "RGB_data" } let id = "", - projectFolderPath = ""; + projectFolderPath = "" beforeEach(async () => { - ({ id, projectFolderPath } = await setupIntegrationTests(file_name, geode_object)); -}, INTERVAL_TIMEOUT); + ;({ id, projectFolderPath } = await setupIntegrationTests( + file_name, + geode_object, + )) +}, INTERVAL_TIMEOUT) afterEach(async () => { - console.log("afterEach mesh cells kill", projectFolderPath); - await cleanupBackend(projectFolderPath); -}); + console.log("afterEach mesh cells kill", projectFolderPath) + await cleanupBackend(projectFolderPath) +}) describe("Mesh cells", () => { describe("Cells visibility", () => { test("Visibility true", async () => { - const dataStyleStore = useDataStyleStore(); - const viewerStore = useViewerStore(); - const visibility = true; - const spy = vi.spyOn(viewerStore, "request"); - const result = dataStyleStore.setMeshCellsVisibility(id, visibility); - expect(result).toBeInstanceOf(Promise); - await result; + const dataStyleStore = useDataStyleStore() + const viewerStore = useViewerStore() + const visibility = true + const spy = vi.spyOn(viewerStore, "request") + const result = dataStyleStore.setMeshCellsVisibility(id, visibility) + expect(result).toBeInstanceOf(Promise) + await result expect(spy).toHaveBeenCalledWith( mesh_cells_schemas.visibility, { id, visibility }, { response_function: expect.any(Function), }, - ); - expect(dataStyleStore.meshCellsVisibility(id)).toBe(visibility); - expect(viewerStore.status).toBe(Status.CONNECTED); - }); - }); + ) + expect(dataStyleStore.meshCellsVisibility(id)).toBe(visibility) + expect(viewerStore.status).toBe(Status.CONNECTED) + }) + }) describe("Cells color", () => { test("Color red", async () => { - const dataStyleStore = useDataStyleStore(); - const viewerStore = useViewerStore(); - const color = { r: 255, g: 0, b: 0 }; - const spy = vi.spyOn(viewerStore, "request"); - const result = dataStyleStore.setMeshCellsColor(id, color); - expect(result).toBeInstanceOf(Promise); - await result; + const dataStyleStore = useDataStyleStore() + const viewerStore = useViewerStore() + const color = { r: 255, g: 0, b: 0 } + const spy = vi.spyOn(viewerStore, "request") + const result = dataStyleStore.setMeshCellsColor(id, color) + expect(result).toBeInstanceOf(Promise) + await result expect(spy).toHaveBeenCalledWith( mesh_cells_schemas.color, { id, color }, { response_function: expect.any(Function), }, - ); - expect(dataStyleStore.meshCellsColor(id)).toStrictEqual(color); - expect(viewerStore.status).toBe(Status.CONNECTED); - }); - }); + ) + expect(dataStyleStore.meshCellsColor(id)).toStrictEqual(color) + expect(viewerStore.status).toBe(Status.CONNECTED) + }) + }) describe("Cells vertex attribute", () => { test("Coloring vertex attribute", async () => { - const dataStyleStore = useDataStyleStore(); - const viewerStore = useViewerStore(); - const spy = vi.spyOn(viewerStore, "request"); - const result = dataStyleStore.setMeshCellsVertexAttributeName(id, vertex_attribute.name); - expect(result).toBeInstanceOf(Promise); - await result; + const dataStyleStore = useDataStyleStore() + const viewerStore = useViewerStore() + const spy = vi.spyOn(viewerStore, "request") + const result = dataStyleStore.setMeshCellsVertexAttributeName( + id, + vertex_attribute.name, + ) + expect(result).toBeInstanceOf(Promise) + await result expect(spy).toHaveBeenCalledWith( mesh_cells_schemas.attribute.vertex.name, { id, ...vertex_attribute }, { response_function: expect.any(Function), }, - ); - expect(dataStyleStore.meshCellsVertexAttributeName(id)).toBe(vertex_attribute.name); - expect(viewerStore.status).toBe(Status.CONNECTED); - }); - }); + ) + expect(dataStyleStore.meshCellsVertexAttributeName(id)).toBe( + vertex_attribute.name, + ) + expect(viewerStore.status).toBe(Status.CONNECTED) + }) + }) describe("Cells cell attribute", () => { test("Coloring cell attribute", async () => { - const dataStyleStore = useDataStyleStore(); - const viewerStore = useViewerStore(); - const spy = vi.spyOn(viewerStore, "request"); - const result = dataStyleStore.setMeshCellsCellAttributeName(id, cell_attribute.name); - expect(result).toBeInstanceOf(Promise); - await result; + const dataStyleStore = useDataStyleStore() + const viewerStore = useViewerStore() + const spy = vi.spyOn(viewerStore, "request") + const result = dataStyleStore.setMeshCellsCellAttributeName( + id, + cell_attribute.name, + ) + expect(result).toBeInstanceOf(Promise) + await result expect(spy).toHaveBeenCalledWith( mesh_cells_schemas.attribute.cell.name, { id, ...cell_attribute }, { response_function: expect.any(Function), }, - ); - expect(dataStyleStore.meshCellsCellAttributeName(id)).toBe(cell_attribute.name); - expect(viewerStore.status).toBe(Status.CONNECTED); - }); - }); + ) + expect(dataStyleStore.meshCellsCellAttributeName(id)).toBe( + cell_attribute.name, + ) + expect(viewerStore.status).toBe(Status.CONNECTED) + }) + }) describe("Cells active coloring", () => { test("test coloring", async () => { - const dataStyleStore = useDataStyleStore(); - const viewerStore = useViewerStore(); + const dataStyleStore = useDataStyleStore() + const viewerStore = useViewerStore() const coloringTypes = [ { name: "color" }, { name: "vertex", - function: () => dataStyleStore.setMeshCellsVertexAttributeName(id, vertex_attribute.name), + function: () => + dataStyleStore.setMeshCellsVertexAttributeName( + id, + vertex_attribute.name, + ), }, { name: "cell", - function: () => dataStyleStore.setMeshCellsCellAttributeName(id, cell_attribute.name), + function: () => + dataStyleStore.setMeshCellsCellAttributeName( + id, + cell_attribute.name, + ), }, - ]; + ] async function testColoring(coloringType, expectedColoringType) { if (coloringType.function) { - await coloringType.function(); + await coloringType.function() } - const result = dataStyleStore.setMeshCellsActiveColoring(id, coloringType.name); - expect(result).toBeInstanceOf(Promise); - await result; - expect(dataStyleStore.meshCellsActiveColoring(id)).toBe(expectedColoringType); - expect(viewerStore.status).toBe(Status.CONNECTED); + const result = dataStyleStore.setMeshCellsActiveColoring( + id, + coloringType.name, + ) + expect(result).toBeInstanceOf(Promise) + await result + expect(dataStyleStore.meshCellsActiveColoring(id)).toBe( + expectedColoringType, + ) + expect(viewerStore.status).toBe(Status.CONNECTED) } - await testColoring(coloringTypes[0], "color"); - await testColoring(coloringTypes[1], "vertex"); - await testColoring(coloringTypes[2], "cell"); - }); - }); + await testColoring(coloringTypes[0], "color") + await testColoring(coloringTypes[1], "vertex") + await testColoring(coloringTypes[2], "cell") + }) + }) test("Cells apply default style", async () => { - const dataStyleStore = useDataStyleStore(); - const viewerStore = useViewerStore(); - const result = dataStyleStore.applyMeshCellsStyle(id); - expect(result).toBeInstanceOf(Promise); - await result; - expect(viewerStore.status).toBe(Status.CONNECTED); - }); -}); + const dataStyleStore = useDataStyleStore() + const viewerStore = useViewerStore() + const result = dataStyleStore.applyMeshCellsStyle(id) + expect(result).toBeInstanceOf(Promise) + await result + expect(viewerStore.status).toBe(Status.CONNECTED) + }) +}) 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 c5f12fa3..11e4fb8b 100644 --- a/tests/integration/stores/data_style/model/surfaces.nuxt.test.js +++ b/tests/integration/stores/data_style/model/surfaces.nuxt.test.js @@ -1,94 +1,115 @@ // Third party imports -import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; -import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" with { type: "json" }; +import { afterEach, beforeEach, describe, expect, test, vi } from "vitest" +import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" with { type: "json" } // Local imports -import { Status } from "@ogw_front/utils/status"; -import { cleanupBackend } from "@ogw_front/utils/local/microservices"; -import { setupIntegrationTests } from "@ogw_tests/integration/setup"; -import { useDataStore } from "@ogw_front/stores/data"; -import { useDataStyleStore } from "@ogw_front/stores/data_style"; -import { useViewerStore } from "@ogw_front/stores/viewer"; +import { Status } from "@ogw_front/utils/status" +import { cleanupBackend } from "@ogw_front/utils/local/microservices" +import { setupIntegrationTests } from "@ogw_tests/integration/setup" +import { useDataStore } from "@ogw_front/stores/data" +import { useDataStyleStore } from "@ogw_front/stores/data_style" +import { useViewerStore } from "@ogw_front/stores/viewer" // Local constants -const INTERVAL_TIMEOUT = 20_000; -const model_surfaces_schemas = viewer_schemas.opengeodeweb_viewer.model.surfaces; -const file_name = "test.og_brep"; -const geode_object = "BRep"; +const INTERVAL_TIMEOUT = 20_000 +const model_surfaces_schemas = viewer_schemas.opengeodeweb_viewer.model.surfaces +const file_name = "test.og_brep" +const geode_object = "BRep" let id = "", - projectFolderPath = ""; + projectFolderPath = "" beforeEach(async () => { - ({ id, projectFolderPath } = await setupIntegrationTests(file_name, geode_object)); -}, INTERVAL_TIMEOUT); + ;({ id, projectFolderPath } = await setupIntegrationTests( + file_name, + geode_object, + )) +}, INTERVAL_TIMEOUT) afterEach(async () => { - console.log("afterEach model surfaces kill", projectFolderPath); - await cleanupBackend(projectFolderPath); -}); + console.log("afterEach model surfaces kill", projectFolderPath) + await cleanupBackend(projectFolderPath) +}) describe("model surfaces", () => { describe("surfaces visibility", () => { test("visibility true", async () => { - const dataStyleStore = useDataStyleStore(); - const viewerStore = useViewerStore(); - const dataStore = useDataStore(); - const surface_ids = await dataStore.getSurfacesGeodeIds(id); - const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds(id, surface_ids); - const visibility = true; - const spy = vi.spyOn(viewerStore, "request"); - spy.mockClear(); - const result = dataStyleStore.setModelSurfacesVisibility(id, surface_ids, visibility); - expect(result).toBeInstanceOf(Promise); - await result; + const dataStyleStore = useDataStyleStore() + const viewerStore = useViewerStore() + const dataStore = useDataStore() + const surface_ids = await dataStore.getSurfacesGeodeIds(id) + const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds( + id, + surface_ids, + ) + const visibility = true + const spy = vi.spyOn(viewerStore, "request") + spy.mockClear() + const result = dataStyleStore.setModelSurfacesVisibility( + id, + surface_ids, + visibility, + ) + expect(result).toBeInstanceOf(Promise) + await result expect(spy).toHaveBeenCalledWith( model_surfaces_schemas.visibility, { id, block_ids: surface_viewer_ids, visibility }, { response_function: expect.any(Function), }, - ); + ) for (const surface_id of surface_ids) { - expect(dataStyleStore.modelSurfaceVisibility(id, surface_id)).toBe(visibility); + expect(dataStyleStore.modelSurfaceVisibility(id, surface_id)).toBe( + visibility, + ) } - expect(viewerStore.status).toBe(Status.CONNECTED); - }); - }); + expect(viewerStore.status).toBe(Status.CONNECTED) + }) + }) describe("surfaces color", () => { test("color red", async () => { - const dataStyleStore = useDataStyleStore(); - const viewerStore = useViewerStore(); - const dataStore = useDataStore(); - const surface_ids = await dataStore.getSurfacesGeodeIds(id); - const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds(id, surface_ids); - const color = { r: 255, g: 0, b: 0 }; - const spy = vi.spyOn(viewerStore, "request"); - spy.mockClear(); - const result = dataStyleStore.setModelSurfacesColor(id, surface_ids, color); - expect(result).toBeInstanceOf(Promise); - await result; + const dataStyleStore = useDataStyleStore() + const viewerStore = useViewerStore() + const dataStore = useDataStore() + const surface_ids = await dataStore.getSurfacesGeodeIds(id) + const surface_viewer_ids = await dataStore.getMeshComponentsViewerIds( + id, + surface_ids, + ) + const color = { r: 255, g: 0, b: 0 } + const spy = vi.spyOn(viewerStore, "request") + spy.mockClear() + const result = dataStyleStore.setModelSurfacesColor( + id, + surface_ids, + color, + ) + expect(result).toBeInstanceOf(Promise) + await result expect(spy).toHaveBeenCalledWith( model_surfaces_schemas.color, { id, block_ids: surface_viewer_ids, color }, { response_function: expect.any(Function), }, - ); + ) for (const surface_id of surface_ids) { - expect(dataStyleStore.modelSurfaceColor(id, surface_id)).toStrictEqual(color); + expect(dataStyleStore.modelSurfaceColor(id, surface_id)).toStrictEqual( + color, + ) } - expect(viewerStore.status).toBe(Status.CONNECTED); - }); - }); + expect(viewerStore.status).toBe(Status.CONNECTED) + }) + }) describe("Surfaces style", () => { test("Surfaces apply style", async () => { - const dataStyleStore = useDataStyleStore(); - const viewerStore = useViewerStore(); - const result = dataStyleStore.applyModelSurfacesStyle(id); - expect(result).toBeInstanceOf(Promise); - await result; - expect(viewerStore.status).toBe(Status.CONNECTED); - }); - }); -}); + const dataStyleStore = useDataStyleStore() + const viewerStore = useViewerStore() + const result = dataStyleStore.applyModelSurfacesStyle(id) + expect(result).toBeInstanceOf(Promise) + await result + expect(viewerStore.status).toBe(Status.CONNECTED) + }) + }) +}) diff --git a/tests/integration/stores/viewer.nuxt.test.js b/tests/integration/stores/viewer.nuxt.test.js index 86f52826..082fb676 100644 --- a/tests/integration/stores/viewer.nuxt.test.js +++ b/tests/integration/stores/viewer.nuxt.test.js @@ -1,28 +1,28 @@ // Global imports // Third party imports -import { afterEach, beforeEach, describe, expect, test } from "vitest"; -import opengeodeweb_viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"; +import { afterEach, beforeEach, describe, expect, test } from "vitest" +import opengeodeweb_viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json" // Local imports -import { Status } from "@ogw_front/utils/status"; -import { cleanupBackend } from "@ogw_front/utils/local/microservices"; -import { runMicroservices } from "@ogw_tests/integration/setup"; -import { setupActivePinia } from "@ogw_tests/utils"; -import { useViewerStore } from "@ogw_front/stores/viewer"; +import { Status } from "@ogw_front/utils/status" +import { cleanupBackend } from "@ogw_front/utils/local/microservices" +import { runMicroservices } from "@ogw_tests/integration/setup" +import { setupActivePinia } from "@ogw_tests/utils" +import { useViewerStore } from "@ogw_front/stores/viewer" -const CONNECT_TIMEOUT = 25_000; +const CONNECT_TIMEOUT = 25_000 -let projectFolderPath = ""; +let projectFolderPath = "" beforeEach(async () => { - setupActivePinia(); - ({ projectFolderPath } = await runMicroservices()); -}); + setupActivePinia() + ;({ projectFolderPath } = await runMicroservices()) +}) afterEach(async () => { - await cleanupBackend(projectFolderPath); -}); + await cleanupBackend(projectFolderPath) +}) describe("Viewer Store", () => { describe("actions", () => { @@ -30,41 +30,44 @@ describe("Viewer Store", () => { test( "ws_connect", async () => { - const viewerStore = useViewerStore(); - await viewerStore.ws_connect(); - expect(viewerStore.status).toBe(Status.CONNECTED); + const viewerStore = useViewerStore() + await viewerStore.ws_connect() + expect(viewerStore.status).toBe(Status.CONNECTED) }, CONNECT_TIMEOUT, - ); - }); + ) + }) describe("connect", () => { test( "connect", async () => { - const viewerStore = useViewerStore(); - await viewerStore.connect(); - expect(viewerStore.status).toBe(Status.CONNECTED); + const viewerStore = useViewerStore() + await viewerStore.connect() + expect(viewerStore.status).toBe(Status.CONNECTED) }, CONNECT_TIMEOUT, - ); - }); + ) + }) describe("request", () => { test( "request", () => { - const schema = opengeodeweb_viewer_schemas.opengeodeweb_viewer.viewer.render; - const viewerStore = useViewerStore(); - const timeout = 1; - const params = {}; + const schema = + opengeodeweb_viewer_schemas.opengeodeweb_viewer.viewer.render + const viewerStore = useViewerStore() + const timeout = 1 + const params = {} expect(() => viewerStore .request(schema, params, {}, timeout) - .rejects.toThrow(`${schema.$id}: Timed out after ${timeout}ms, ${schema} ${params}`), - ); + .rejects.toThrow( + `${schema.$id}: Timed out after ${timeout}ms, ${schema} ${params}`, + ), + ) }, CONNECT_TIMEOUT, - ); - }); - }); -}); + ) + }) + }) +}) diff --git a/tests/unit/components/FeedBack/Snackers.nuxt.test.js b/tests/unit/components/FeedBack/Snackers.nuxt.test.js index 11aa9cb9..fe452f21 100644 --- a/tests/unit/components/FeedBack/Snackers.nuxt.test.js +++ b/tests/unit/components/FeedBack/Snackers.nuxt.test.js @@ -1,19 +1,19 @@ // Third party imports -import * as components from "vuetify/components"; -import { describe, expect, test, vi } from "vitest"; -import { mount } from "@vue/test-utils"; +import * as components from "vuetify/components" +import { describe, expect, test, vi } from "vitest" +import { mount } from "@vue/test-utils" // Local imports -import { setupActivePinia, vuetify } from "@ogw_tests/utils"; -import FeedBackSnackers from "@ogw_front/components/FeedBack/Snackers"; -import { useFeedbackStore } from "@ogw_front/stores/feedback"; +import { setupActivePinia, vuetify } from "@ogw_tests/utils" +import FeedBackSnackers from "@ogw_front/components/FeedBack/Snackers" +import { useFeedbackStore } from "@ogw_front/stores/feedback" -vi.stubGlobal("visualViewport", new EventTarget()); +vi.stubGlobal("visualViewport", new EventTarget()) describe(FeedBackSnackers, () => { test(`Test delete error`, async () => { - const pinia = setupActivePinia(); - const feedbackStore = useFeedbackStore(); + const pinia = setupActivePinia() + const feedbackStore = useFeedbackStore() feedbackStore.$patch({ feedbacks: [ { @@ -24,7 +24,7 @@ describe(FeedBackSnackers, () => { description: "test description", }, ], - }); + }) const wrapper = mount( { @@ -39,11 +39,11 @@ describe(FeedBackSnackers, () => { plugins: [vuetify, pinia], }, }, - ); + ) - expect(feedbackStore.feedbacks.length).toBe(1); - const v_btn = await wrapper.findComponent(components.VBtn); - await v_btn.trigger("click"); - expect(feedbackStore.feedbacks.length).toBe(0); - }); -}); + expect(feedbackStore.feedbacks.length).toBe(1) + const v_btn = await wrapper.findComponent(components.VBtn) + await v_btn.trigger("click") + expect(feedbackStore.feedbacks.length).toBe(0) + }) +}) diff --git a/tests/unit/components/FileSelector.nuxt.test.js b/tests/unit/components/FileSelector.nuxt.test.js index 0ce42285..a1c21ce6 100644 --- a/tests/unit/components/FileSelector.nuxt.test.js +++ b/tests/unit/components/FileSelector.nuxt.test.js @@ -1,27 +1,27 @@ // Third party imports -import * as components from "vuetify/components"; -import { describe, expect, test, vi } from "vitest"; -import { mountSuspended, registerEndpoint } from "@nuxt/test-utils/runtime"; -import { flushPromises } from "@vue/test-utils"; -import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json"; +import * as components from "vuetify/components" +import { describe, expect, test, vi } from "vitest" +import { mountSuspended, registerEndpoint } from "@nuxt/test-utils/runtime" +import { flushPromises } from "@vue/test-utils" +import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" // Local imports -import { setupActivePinia, vuetify } from "@ogw_tests/utils"; -import FileSelector from "@ogw_front/components/FileSelector"; -import FileUploader from "@ogw_front/components/FileUploader"; -import { useGeodeStore } from "@ogw_front/stores/geode"; +import { setupActivePinia, vuetify } from "@ogw_tests/utils" +import FileSelector from "@ogw_front/components/FileSelector" +import FileUploader from "@ogw_front/components/FileUploader" +import { useGeodeStore } from "@ogw_front/stores/geode" -const EXPECTED_LENGTH = 1; -const FIRST_INDEX = 0; -const SECOND_INDEX = 1; +const EXPECTED_LENGTH = 1 +const FIRST_INDEX = 0 +const SECOND_INDEX = 1 -const allowed_files_schema = schemas.opengeodeweb_back.allowed_files; -const upload_file_schema = schemas.opengeodeweb_back.upload_file; +const allowed_files_schema = schemas.opengeodeweb_back.allowed_files +const upload_file_schema = schemas.opengeodeweb_back.upload_file describe(FileSelector, () => { - const pinia = setupActivePinia(); - const geodeStore = useGeodeStore(); - geodeStore.base_url = ""; + const pinia = setupActivePinia() + const geodeStore = useGeodeStore() + geodeStore.base_url = "" test(`Select file`, async () => { registerEndpoint(allowed_files_schema.$id, { @@ -29,40 +29,40 @@ describe(FileSelector, () => { handler: () => ({ extensions: ["1", "2", "3"], }), - }); + }) const wrapper = await mountSuspended(FileSelector, { global: { plugins: [vuetify, pinia], }, props: { multiple: false, auto_upload: false }, - }); + }) - const file_uploader = wrapper.findComponent(FileUploader); + const file_uploader = wrapper.findComponent(FileUploader) registerEndpoint(upload_file_schema.$id, { method: upload_file_schema.methods[SECOND_INDEX], handler: () => ({}), - }); + }) - const v_file_input = file_uploader.find('input[type="file"]'); - const files = [new File(["fake_file"], "fake_file.txt")]; - const auto_upload = false; + const v_file_input = file_uploader.find('input[type="file"]') + const files = [new File(["fake_file"], "fake_file.txt")] + const auto_upload = false Object.defineProperty(v_file_input.element, "files", { value: files, writable: true, - }); - await v_file_input.trigger("change"); - const v_btn = wrapper.findComponent(components.VBtn); - await v_btn.trigger("click"); - await flushPromises(); - await flushPromises(); - expect(wrapper.emitted()).toHaveProperty("update_values"); - expect(wrapper.emitted().update_values).toHaveLength(EXPECTED_LENGTH); + }) + await v_file_input.trigger("change") + const v_btn = wrapper.findComponent(components.VBtn) + await v_btn.trigger("click") + await flushPromises() + await flushPromises() + expect(wrapper.emitted()).toHaveProperty("update_values") + expect(wrapper.emitted().update_values).toHaveLength(EXPECTED_LENGTH) expect(wrapper.emitted().update_values[FIRST_INDEX][FIRST_INDEX]).toEqual({ files, auto_upload, - }); - }); + }) + }) describe(FileSelector, () => { registerEndpoint(allowed_files_schema.$id, { @@ -70,14 +70,14 @@ describe(FileSelector, () => { handler: () => ({ extensions: ["1", "2", "3"], }), - }); + }) registerEndpoint(upload_file_schema.$id, { method: upload_file_schema.methods[SECOND_INDEX], handler: () => ({}), - }); + }) - const files = [new File(["fake_file"], "fake_file.txt")]; + const files = [new File(["fake_file"], "fake_file.txt")] test("auto_upload true", async () => { const wrapper = await mountSuspended(FileSelector, { global: { @@ -88,17 +88,19 @@ describe(FileSelector, () => { files: files, auto_upload: true, }, - }); + }) - await flushPromises(); - expect(wrapper.componentVM.files).toEqual(files); - expect(wrapper.emitted()).toHaveProperty("update_values"); - expect(wrapper.emitted().update_values).toHaveLength(EXPECTED_LENGTH); - expect(wrapper.emitted().update_values[FIRST_INDEX][FIRST_INDEX]).toEqual({ - files, - auto_upload: false, - }); - }); + await flushPromises() + expect(wrapper.componentVM.files).toEqual(files) + expect(wrapper.emitted()).toHaveProperty("update_values") + expect(wrapper.emitted().update_values).toHaveLength(EXPECTED_LENGTH) + expect(wrapper.emitted().update_values[FIRST_INDEX][FIRST_INDEX]).toEqual( + { + files, + auto_upload: false, + }, + ) + }) test("auto_upload false", async () => { const wrapper = await mountSuspended(FileSelector, { @@ -110,14 +112,14 @@ describe(FileSelector, () => { files: files, auto_upload: false, }, - }); + }) - await flushPromises(); + await flushPromises() - const file_uploader = wrapper.findComponent(FileUploader); - expect(wrapper.vm.files).toEqual(files); - const upload_files = vi.spyOn(file_uploader.vm, "upload_files"); - expect(upload_files).not.toHaveBeenCalled(); - }); - }); -}); + const file_uploader = wrapper.findComponent(FileUploader) + expect(wrapper.vm.files).toEqual(files) + const upload_files = vi.spyOn(file_uploader.vm, "upload_files") + expect(upload_files).not.toHaveBeenCalled() + }) + }) +}) diff --git a/tests/unit/components/FileUploader.nuxt.test.js b/tests/unit/components/FileUploader.nuxt.test.js index 96c61002..66cada19 100644 --- a/tests/unit/components/FileUploader.nuxt.test.js +++ b/tests/unit/components/FileUploader.nuxt.test.js @@ -1,35 +1,35 @@ // Third party imports -import * as components from "vuetify/components"; -import { describe, expect, test } from "vitest"; -import { mountSuspended, registerEndpoint } from "@nuxt/test-utils/runtime"; -import { flushPromises } from "@vue/test-utils"; -import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json"; +import * as components from "vuetify/components" +import { describe, expect, test } from "vitest" +import { mountSuspended, registerEndpoint } from "@nuxt/test-utils/runtime" +import { flushPromises } from "@vue/test-utils" +import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" // Local imports -import { setupActivePinia, vuetify } from "@ogw_tests/utils"; -import FileUploader from "@ogw_front/components/FileUploader"; -import { useGeodeStore } from "@ogw_front/stores/geode"; +import { setupActivePinia, vuetify } from "@ogw_tests/utils" +import FileUploader from "@ogw_front/components/FileUploader" +import { useGeodeStore } from "@ogw_front/stores/geode" -const FIRST_INDEX = 0; -const SECOND_INDEX = 1; +const FIRST_INDEX = 0 +const SECOND_INDEX = 1 -const upload_file_schema = schemas.opengeodeweb_back.upload_file; +const upload_file_schema = schemas.opengeodeweb_back.upload_file describe(FileUploader, () => { - const pinia = setupActivePinia(); - const geodeStore = useGeodeStore(); - geodeStore.base_url = ""; + const pinia = setupActivePinia() + const geodeStore = useGeodeStore() + geodeStore.base_url = "" registerEndpoint(upload_file_schema.$id, { method: upload_file_schema.methods[FIRST_INDEX], handler: () => ({}), - }); + }) registerEndpoint(upload_file_schema.$id, { method: upload_file_schema.methods[SECOND_INDEX], handler: () => ({}), - }); + }) - const files = [new File(["fake_file"], "fake_file.txt")]; + const files = [new File(["fake_file"], "fake_file.txt")] describe(`Upload file`, () => { test(`prop auto_upload false`, async () => { @@ -38,21 +38,23 @@ describe(FileUploader, () => { plugins: [vuetify, pinia], }, props: { multiple: false, accept: "*.txt" }, - }); + }) - const v_file_input = wrapper.find('input[type="file"]'); + const v_file_input = wrapper.find('input[type="file"]') Object.defineProperty(v_file_input.element, "files", { value: files, writable: true, - }); - await v_file_input.trigger("change"); - const v_btn = wrapper.findComponent(components.VBtn); + }) + await v_file_input.trigger("change") + const v_btn = wrapper.findComponent(components.VBtn) - await v_btn.trigger("click"); - await flushPromises(); - await flushPromises(); - expect(wrapper.emitted().files_uploaded[FIRST_INDEX][FIRST_INDEX]).toEqual(files); - }); + await v_btn.trigger("click") + await flushPromises() + await flushPromises() + expect( + wrapper.emitted().files_uploaded[FIRST_INDEX][FIRST_INDEX], + ).toEqual(files) + }) test(`prop auto_upload true`, async () => { const wrapper = await mountSuspended(FileUploader, { @@ -60,9 +62,11 @@ describe(FileUploader, () => { plugins: [vuetify, pinia], }, props: { multiple: false, accept: "*.txt", files, auto_upload: true }, - }); - await flushPromises(); - expect(wrapper.emitted().files_uploaded[FIRST_INDEX][FIRST_INDEX]).toEqual(files); - }); - }); -}); + }) + await flushPromises() + expect( + wrapper.emitted().files_uploaded[FIRST_INDEX][FIRST_INDEX], + ).toEqual(files) + }) + }) +}) diff --git a/tests/unit/components/Inspector/InspectionButton.nuxt.test.js b/tests/unit/components/Inspector/InspectionButton.nuxt.test.js index 2d7ea6ad..c556bb71 100644 --- a/tests/unit/components/Inspector/InspectionButton.nuxt.test.js +++ b/tests/unit/components/Inspector/InspectionButton.nuxt.test.js @@ -1,18 +1,18 @@ // Third party imports -import * as components from "vuetify/components"; -import { describe, expect, test, vi } from "vitest"; -import { flushPromises } from "@vue/test-utils"; -import { mountSuspended } from "@nuxt/test-utils/runtime"; +import * as components from "vuetify/components" +import { describe, expect, test, vi } from "vitest" +import { flushPromises } from "@vue/test-utils" +import { mountSuspended } from "@nuxt/test-utils/runtime" // Local imports -import { setupActivePinia, vuetify } from "@ogw_tests/utils"; -import InspectorInspectionButton from "@ogw_front/components/Inspector/InspectionButton"; -import { useGeodeStore } from "@ogw_front/stores/geode"; +import { setupActivePinia, vuetify } from "@ogw_tests/utils" +import InspectorInspectionButton from "@ogw_front/components/Inspector/InspectionButton" +import { useGeodeStore } from "@ogw_front/stores/geode" describe("Inspector/InspectionButton", () => { - const pinia = setupActivePinia(); - const geodeStore = useGeodeStore(); - geodeStore.base_url = ""; + const pinia = setupActivePinia() + const geodeStore = useGeodeStore() + geodeStore.base_url = "" test(`Test with issues`, async () => { const inspection_result = { @@ -30,39 +30,39 @@ describe("Inspector/InspectionButton", () => { issues: ["issue 1"], }, ], - }; + } geodeStore.request = vi.fn((_schema, params, callbacks) => { if (callbacks?.response_function) { callbacks.response_function({ inspection_result, - }); + }) } return Promise.resolve({ inspection_result, - }); - }); + }) + }) - const geode_object_type = "BRep"; - const filename = "test.txt"; + const geode_object_type = "BRep" + const filename = "test.txt" const wrapper = await mountSuspended(InspectorInspectionButton, { global: { plugins: [vuetify, pinia], }, props: { geode_object_type, filename }, - }); + }) - expect(wrapper.exists()).toBeTruthy(); - const v_btn = await wrapper.findComponent(components.VBtn); - await v_btn.trigger("click"); - await flushPromises(); + expect(wrapper.exists()).toBeTruthy() + const v_btn = await wrapper.findComponent(components.VBtn) + await v_btn.trigger("click") + await flushPromises() - expect(wrapper.emitted()).toHaveProperty("update_values"); - expect(wrapper.emitted().update_values).toHaveLength(1); + expect(wrapper.emitted()).toHaveProperty("update_values") + expect(wrapper.emitted().update_values).toHaveLength(1) expect(wrapper.emitted().update_values[0][0]).toStrictEqual({ inspection_result: [inspection_result], - }); - expect(wrapper.emitted()).toHaveProperty("increment_step"); - }); -}); + }) + expect(wrapper.emitted()).toHaveProperty("increment_step") + }) +}) diff --git a/tests/unit/components/Inspector/ResultPanel.nuxt.test.js b/tests/unit/components/Inspector/ResultPanel.nuxt.test.js index a21047e9..caff982b 100644 --- a/tests/unit/components/Inspector/ResultPanel.nuxt.test.js +++ b/tests/unit/components/Inspector/ResultPanel.nuxt.test.js @@ -1,10 +1,10 @@ // Third party imports -import { describe, expect, test } from "vitest"; -import { mountSuspended } from "@nuxt/test-utils/runtime"; +import { describe, expect, test } from "vitest" +import { mountSuspended } from "@nuxt/test-utils/runtime" // Local imports -import InspectorResultPanel from "@ogw_front/components/Inspector/ResultPanel"; -import { vuetify } from "@ogw_tests/utils"; +import InspectorResultPanel from "@ogw_front/components/Inspector/ResultPanel" +import { vuetify } from "@ogw_tests/utils" describe("Inspector/ResultPanel", () => { test(`Test with issues`, async () => { @@ -14,24 +14,27 @@ describe("Inspector/ResultPanel", () => { nb_issues: 26, children: [], }, - ]; + ] const wrapper = await mountSuspended(InspectorResultPanel, { global: { plugins: [vuetify], }, props: { inspection_result }, - }); + }) - expect(wrapper.exists()).toBeTruthy(); - expect(wrapper.componentVM.inspection_result).toStrictEqual(inspection_result); + expect(wrapper.exists()).toBeTruthy() + expect(wrapper.componentVM.inspection_result).toStrictEqual( + inspection_result, + ) - const child_result_panel_wrapper = await wrapper.findComponent(InspectorResultPanel); - expect(child_result_panel_wrapper.exists()).toBeTruthy(); - expect(child_result_panel_wrapper.componentVM.inspection_result).toStrictEqual( - inspection_result[0].children, - ); - }); + const child_result_panel_wrapper = + await wrapper.findComponent(InspectorResultPanel) + expect(child_result_panel_wrapper.exists()).toBeTruthy() + expect( + child_result_panel_wrapper.componentVM.inspection_result, + ).toStrictEqual(inspection_result[0].children) + }) test(`Test without issues`, async () => { const inspection_result = [ @@ -39,18 +42,20 @@ describe("Inspector/ResultPanel", () => { title: "Brep inspection", nb_issues: 0, }, - ]; + ] const wrapper = await mountSuspended(InspectorResultPanel, { global: { plugins: [vuetify], }, props: { inspection_result }, - }); + }) - expect(wrapper.exists()).toBeTruthy(); + expect(wrapper.exists()).toBeTruthy() - console.log({ wrapper }); + console.log({ wrapper }) - expect(wrapper.componentVM.inspection_result).toStrictEqual(inspection_result); - }); -}); + expect(wrapper.componentVM.inspection_result).toStrictEqual( + inspection_result, + ) + }) +}) diff --git a/tests/unit/components/Launcher.nuxt.test.js b/tests/unit/components/Launcher.nuxt.test.js index 9f2e5e34..3f8eaf81 100644 --- a/tests/unit/components/Launcher.nuxt.test.js +++ b/tests/unit/components/Launcher.nuxt.test.js @@ -1,37 +1,39 @@ -import { describe, expect, test, vi } from "vitest"; +import { describe, expect, test, vi } from "vitest" -import Launcher from "@ogw_front/components/Launcher"; -import ResizeObserver from "resize-observer-polyfill"; -import { flushPromises } from "@vue/test-utils"; -import { mountSuspended } from "@nuxt/test-utils/runtime"; +import Launcher from "@ogw_front/components/Launcher" +import ResizeObserver from "resize-observer-polyfill" +import { flushPromises } from "@vue/test-utils" +import { mountSuspended } from "@nuxt/test-utils/runtime" -import { setupActivePinia, vuetify } from "@ogw_tests/utils"; -import { useInfraStore } from "@ogw_front/stores/infra"; +import { setupActivePinia, vuetify } from "@ogw_tests/utils" +import { useInfraStore } from "@ogw_front/stores/infra" // Mock navigator.locks API -const mockLockRequest = vi.fn().mockImplementation(async (name, task) => await task({ name })); +const mockLockRequest = vi + .fn() + .mockImplementation(async (name, task) => await task({ name })) vi.stubGlobal("navigator", { ...navigator, locks: { request: mockLockRequest, }, -}); +}) -globalThis.ResizeObserver = ResizeObserver; +globalThis.ResizeObserver = ResizeObserver describe(Launcher, () => { test(`Mount`, async () => { - const pinia = setupActivePinia(); - const infraStore = useInfraStore(); + const pinia = setupActivePinia() + const infraStore = useInfraStore() const wrapper = await mountSuspended(Launcher, { global: { plugins: [vuetify, pinia], }, - }); - expect(wrapper.exists()).toBeTruthy(); - await infraStore.$patch({ is_captcha_validated: true }); - await flushPromises(); - expect(infraStore.create_backend).toHaveBeenCalled(); - }); -}); + }) + expect(wrapper.exists()).toBeTruthy() + await infraStore.$patch({ is_captcha_validated: true }) + await flushPromises() + expect(infraStore.create_backend).toHaveBeenCalled() + }) +}) diff --git a/tests/unit/components/PackagesVersions.nuxt.test.js b/tests/unit/components/PackagesVersions.nuxt.test.js index 4546c843..518c4718 100644 --- a/tests/unit/components/PackagesVersions.nuxt.test.js +++ b/tests/unit/components/PackagesVersions.nuxt.test.js @@ -1,17 +1,17 @@ -import { describe, expect, test } from "vitest"; -import { mountSuspended, registerEndpoint } from "@nuxt/test-utils/runtime"; +import { describe, expect, test } from "vitest" +import { mountSuspended, registerEndpoint } from "@nuxt/test-utils/runtime" -import { setupActivePinia, vuetify } from "@ogw_tests/utils"; -import PackagesVersions from "@ogw_front/components/PackagesVersions"; -import { useGeodeStore } from "@ogw_front/stores/geode"; +import { setupActivePinia, vuetify } from "@ogw_tests/utils" +import PackagesVersions from "@ogw_front/components/PackagesVersions" +import { useGeodeStore } from "@ogw_front/stores/geode" -const FIRST_INDEX = 0; +const FIRST_INDEX = 0 describe(PackagesVersions, () => { test(`Mount`, async () => { - const pinia = setupActivePinia(); - const geodeStore = useGeodeStore(); - geodeStore.base_url = ""; + const pinia = setupActivePinia() + const geodeStore = useGeodeStore() + geodeStore.base_url = "" const schema = { $id: "/versions", @@ -19,7 +19,7 @@ describe(PackagesVersions, () => { type: "object", properties: {}, additionalProperties: false, - }; + } registerEndpoint(schema.$id, { method: schema.methods[FIRST_INDEX], handler: () => ({ @@ -30,13 +30,13 @@ describe(PackagesVersions, () => { }, ], }), - }); + }) const wrapper = await mountSuspended(PackagesVersions, { global: { plugins: [vuetify, pinia], }, props: { schema }, - }); - expect(wrapper.exists()).toBeTruthy(); - }); -}); + }) + expect(wrapper.exists()).toBeTruthy() + }) +}) diff --git a/tests/unit/components/Step.nuxt.test.js b/tests/unit/components/Step.nuxt.test.js index 289f07fb..e40cca15 100644 --- a/tests/unit/components/Step.nuxt.test.js +++ b/tests/unit/components/Step.nuxt.test.js @@ -1,19 +1,19 @@ -import { computed, reactive, ref, shallowRef } from "vue"; -import { describe, expect, test } from "vitest"; -import ResizeObserver from "resize-observer-polyfill"; -import { mount } from "@vue/test-utils"; +import { computed, reactive, ref, shallowRef } from "vue" +import { describe, expect, test } from "vitest" +import ResizeObserver from "resize-observer-polyfill" +import { mount } from "@vue/test-utils" -import ObjectSelector from "@ogw_front/components/ObjectSelector"; -import Step from "@ogw_front/components/Step"; +import ObjectSelector from "@ogw_front/components/ObjectSelector" +import Step from "@ogw_front/components/Step" -import { vuetify } from "@ogw_tests/utils"; +import { vuetify } from "@ogw_tests/utils" -globalThis.ResizeObserver = ResizeObserver; +globalThis.ResizeObserver = ResizeObserver describe(Step, () => { test(`BRep`, () => { - const geode_object_type = ref("BRep"); - const files = ref([]); + const geode_object_type = ref("BRep") + const files = ref([]) const stepper_tree = reactive({ current_step_index: ref(0), geode_object_type, @@ -29,20 +29,20 @@ describe(Step, () => { }, chips: computed(() => { if (geode_object_type.value === "") { - return []; + return [] } - return [geode_object_type.value]; + return [geode_object_type.value] }), }, ], - }); + }) const wrapper = mount(Step, { global: { plugins: [vuetify], provide: { stepper_tree }, }, props: { step_index: 0 }, - }); - expect(wrapper.exists()).toBeTruthy(); - }); -}); + }) + expect(wrapper.exists()).toBeTruthy() + }) +}) diff --git a/tests/unit/composables/api_fetch.nuxt.test.js b/tests/unit/composables/api_fetch.nuxt.test.js index d35fd657..3e998e9a 100644 --- a/tests/unit/composables/api_fetch.nuxt.test.js +++ b/tests/unit/composables/api_fetch.nuxt.test.js @@ -1,19 +1,19 @@ // Third party imports -import { beforeEach, describe, expect, test } from "vitest"; -import { registerEndpoint } from "@nuxt/test-utils/runtime"; +import { beforeEach, describe, expect, test } from "vitest" +import { registerEndpoint } from "@nuxt/test-utils/runtime" // Local imports -import { setupActivePinia } from "@ogw_tests/utils"; -import { useFeedbackStore } from "@ogw_front/stores/feedback"; -import { useGeodeStore } from "@ogw_front/stores/geode"; +import { setupActivePinia } from "@ogw_tests/utils" +import { useFeedbackStore } from "@ogw_front/stores/feedback" +import { useGeodeStore } from "@ogw_front/stores/geode" -const FIRST_INDEX = 0; +const FIRST_INDEX = 0 describe("geodeStore.request()", () => { - setupActivePinia(); - const geodeStore = useGeodeStore(); - const feedbackStore = useFeedbackStore(); - geodeStore.base_url = ""; + setupActivePinia() + const geodeStore = useGeodeStore() + const feedbackStore = useFeedbackStore() + geodeStore.base_url = "" const schema = { $id: "/test", @@ -26,13 +26,13 @@ describe("geodeStore.request()", () => { }, required: ["test"], additionalProperties: false, - }; + } beforeEach(async () => { - await feedbackStore.$reset(); - await geodeStore.$reset(); - geodeStore.base_url = ""; - }); + await feedbackStore.$reset() + await geodeStore.$reset() + geodeStore.base_url = "" + }) test("invalid schema", () => { const invalid_schema = { @@ -46,31 +46,33 @@ describe("geodeStore.request()", () => { }, required: ["test"], additionalProperties: false, - }; - const params = { test: "hello" }; - expect(() => geodeStore.request(invalid_schema, params)).toThrow("data/test must be number"); - }); + } + const params = { test: "hello" } + expect(() => geodeStore.request(invalid_schema, params)).toThrow( + "data/test must be number", + ) + }) test("invalid params", () => { - const params = {}; + const params = {} expect(() => geodeStore.request(schema, params)).toThrow( "data must have required property 'test'", - ); - }); + ) + }) test("request with callbacks", async () => { - const params = { test: "hello" }; - let errorCalled = false; + const params = { test: "hello" } + let errorCalled = false const callbacks = { request_error_function: () => { - errorCalled = true; + errorCalled = true }, - }; + } registerEndpoint(schema.$id, { method: schema.methods[FIRST_INDEX], handler: () => ({ result: "success" }), - }); - await geodeStore.request(schema, params, callbacks); - expect(errorCalled).toBeFalsy(); - }); -}); + }) + await geodeStore.request(schema, params, callbacks) + expect(errorCalled).toBeFalsy() + }) +}) diff --git a/tests/unit/composables/run_function_when_microservices_connected.nuxt.test.js b/tests/unit/composables/run_function_when_microservices_connected.nuxt.test.js index 2bfc8bc9..74d8474e 100644 --- a/tests/unit/composables/run_function_when_microservices_connected.nuxt.test.js +++ b/tests/unit/composables/run_function_when_microservices_connected.nuxt.test.js @@ -1,57 +1,57 @@ // Third party imports -import { beforeEach, describe, expect, test, vi } from "vitest"; -import { flushPromises } from "@vue/test-utils"; +import { beforeEach, describe, expect, test, vi } from "vitest" +import { flushPromises } from "@vue/test-utils" // Local imports -import { Status } from "@ogw_front/utils/status"; -import { run_function_when_microservices_connected } from "@ogw_front/composables/run_function_when_microservices_connected"; -import { setupActivePinia } from "@ogw_tests/utils"; -import { useGeodeStore } from "@ogw_front/stores/geode"; -import { useInfraStore } from "@ogw_front/stores/infra"; -import { useViewerStore } from "@ogw_front/stores/viewer"; +import { Status } from "@ogw_front/utils/status" +import { run_function_when_microservices_connected } from "@ogw_front/composables/run_function_when_microservices_connected" +import { setupActivePinia } from "@ogw_tests/utils" +import { useGeodeStore } from "@ogw_front/stores/geode" +import { useInfraStore } from "@ogw_front/stores/infra" +import { useViewerStore } from "@ogw_front/stores/viewer" -const dumb_obj = { dumb_method: () => true }; -let infraStore = undefined; -let geodeStore = undefined; -let viewerStore = undefined; +const dumb_obj = { dumb_method: () => true } +let infraStore = undefined +let geodeStore = undefined +let viewerStore = undefined beforeEach(() => { - setupActivePinia(); - infraStore = useInfraStore(); - geodeStore = useGeodeStore(); - viewerStore = useViewerStore(); + setupActivePinia() + infraStore = useInfraStore() + geodeStore = useGeodeStore() + viewerStore = useViewerStore() // Register microservices in infra store infraStore.register_microservice(geodeStore, { request: vi.fn(), connect: vi.fn(), launch: vi.fn(), - }); + }) infraStore.register_microservice(viewerStore, { request: vi.fn(), connect: vi.fn(), launch: vi.fn(), - }); + }) - geodeStore.$patch({ status: Status.NOT_CONNECTED }); - viewerStore.$patch({ status: Status.NOT_CONNECTED }); -}); + geodeStore.$patch({ status: Status.NOT_CONNECTED }) + viewerStore.$patch({ status: Status.NOT_CONNECTED }) +}) describe("when_microservices_connected_run_function", () => { test("microservices not connected", () => { - const spy = vi.spyOn(dumb_obj, "dumb_method"); - run_function_when_microservices_connected(dumb_obj.dumb_method); - geodeStore.$patch({ status: Status.NOT_CONNECTED }); - viewerStore.$patch({ status: Status.NOT_CONNECTED }); - expect(spy).not.toHaveBeenCalled(); - }); + const spy = vi.spyOn(dumb_obj, "dumb_method") + run_function_when_microservices_connected(dumb_obj.dumb_method) + geodeStore.$patch({ status: Status.NOT_CONNECTED }) + viewerStore.$patch({ status: Status.NOT_CONNECTED }) + expect(spy).not.toHaveBeenCalled() + }) test("microservices connected", async () => { - const spy = vi.spyOn(dumb_obj, "dumb_method"); - run_function_when_microservices_connected(dumb_obj.dumb_method); - geodeStore.$patch({ status: Status.CONNECTED }); - viewerStore.$patch({ status: Status.CONNECTED }); - await flushPromises(); - expect(spy).toHaveBeenCalledWith(); - }); -}); + const spy = vi.spyOn(dumb_obj, "dumb_method") + run_function_when_microservices_connected(dumb_obj.dumb_method) + geodeStore.$patch({ status: Status.CONNECTED }) + viewerStore.$patch({ status: Status.CONNECTED }) + await flushPromises() + expect(spy).toHaveBeenCalledWith() + }) +}) diff --git a/tests/unit/stores/lambda.nuxt.test.js b/tests/unit/stores/lambda.nuxt.test.js index 66c9dc2a..48bee410 100644 --- a/tests/unit/stores/lambda.nuxt.test.js +++ b/tests/unit/stores/lambda.nuxt.test.js @@ -1,130 +1,132 @@ // Third party imports -import { beforeEach, describe, expect, expectTypeOf, test, vi } from "vitest"; -import { registerEndpoint } from "@nuxt/test-utils/runtime"; +import { beforeEach, describe, expect, expectTypeOf, test, vi } from "vitest" +import { registerEndpoint } from "@nuxt/test-utils/runtime" // Local imports -import { Status } from "@ogw_front/utils/status"; -import { setupActivePinia } from "@ogw_tests/utils"; -import { useFeedbackStore } from "@ogw_front/stores/feedback"; -import { useLambdaStore } from "@ogw_front/stores/lambda"; +import { Status } from "@ogw_front/utils/status" +import { setupActivePinia } from "@ogw_tests/utils" +import { useFeedbackStore } from "@ogw_front/stores/feedback" +import { useLambdaStore } from "@ogw_front/stores/lambda" // CONSTANTS -const PORT_443 = "443"; -const API_URL = "api.example.com"; -const SITE_BRANCH = "/test"; -const PROJECT = "project"; -const TEST_ID = "test-id-123456"; -const STATUS_500 = 500; +const PORT_443 = "443" +const API_URL = "api.example.com" +const SITE_BRANCH = "/test" +const PROJECT = "project" +const TEST_ID = "test-id-123456" +const STATUS_500 = 500 beforeEach(() => { - setupActivePinia(); -}); + setupActivePinia() +}) function setupConfig() { - const config = useRuntimeConfig(); - config.public.API_URL = API_URL; - config.public.SITE_BRANCH = SITE_BRANCH; - config.public.PROJECT = PROJECT; + const config = useRuntimeConfig() + config.public.API_URL = API_URL + config.public.SITE_BRANCH = SITE_BRANCH + config.public.PROJECT = PROJECT } describe("Lambda Store", () => { describe("state", () => { test("initial state", () => { - const lambdaStore = useLambdaStore(); - expectTypeOf(lambdaStore.status).toBeString(); - expect(lambdaStore.status).toBe(Status.NOT_CONNECTED); - }); - }); + const lambdaStore = useLambdaStore() + expectTypeOf(lambdaStore.status).toBeString() + expect(lambdaStore.status).toBe(Status.NOT_CONNECTED) + }) + }) describe("getters", () => { describe("protocol", () => { test("test protocol is always https", () => { - const lambdaStore = useLambdaStore(); - expect(lambdaStore.protocol).toBe("https"); - }); - }); + const lambdaStore = useLambdaStore() + expect(lambdaStore.protocol).toBe("https") + }) + }) describe("port", () => { test("test port is always 443", () => { - const lambdaStore = useLambdaStore(); - expect(lambdaStore.port).toBe(PORT_443); - }); - }); + const lambdaStore = useLambdaStore() + expect(lambdaStore.port).toBe(PORT_443) + }) + }) describe("base_url", () => { test("test base_url construction", () => { - setupConfig(); - const lambdaStore = useLambdaStore(); + setupConfig() + const lambdaStore = useLambdaStore() expect(lambdaStore.base_url).toBe( `https://${API_URL}:${PORT_443}${SITE_BRANCH}/${PROJECT}/createbackend`, - ); - }); - }); + ) + }) + }) describe("is_busy", () => { test("test is_busy is always false", () => { - const lambdaStore = useLambdaStore(); - expect(lambdaStore.is_busy).toBeFalsy(); - }); - }); - }); + const lambdaStore = useLambdaStore() + expect(lambdaStore.is_busy).toBeFalsy() + }) + }) + }) describe("actions", () => { describe("launch", () => { - const postFakeCall = vi.fn(); + const postFakeCall = vi.fn() test("successful launch", async () => { - setupConfig(); - const lambdaStore = useLambdaStore(); - const feedbackStore = useFeedbackStore(); + setupConfig() + const lambdaStore = useLambdaStore() + const feedbackStore = useFeedbackStore() - lambdaStore.base_url = "test-base-url"; + lambdaStore.base_url = "test-base-url" registerEndpoint(lambdaStore.base_url, { method: "POST", handler: postFakeCall, - }); + }) postFakeCall.mockImplementation(() => ({ ID: TEST_ID, - })); + })) - const id = await lambdaStore.launch(); + const id = await lambdaStore.launch() - expect(lambdaStore.status).toBe(Status.CONNECTED); - expect(id).toBe(TEST_ID); - expect(feedbackStore.server_error).toBeFalsy(); - }); + expect(lambdaStore.status).toBe(Status.CONNECTED) + expect(id).toBe(TEST_ID) + expect(feedbackStore.server_error).toBeFalsy() + }) test("failed launch - error response", async () => { - setupConfig(); - const lambdaStore = useLambdaStore(); - const feedbackStore = useFeedbackStore(); + setupConfig() + const lambdaStore = useLambdaStore() + const feedbackStore = useFeedbackStore() registerEndpoint(lambdaStore.base_url, { method: "POST", handler: postFakeCall, - }); + }) postFakeCall.mockImplementation(() => { throw createError({ status: STATUS_500, statusMessage: "Internal Server Error", - }); - }); + }) + }) - await expect(lambdaStore.launch()).rejects.toThrow("Failed to launch lambda backend"); + await expect(lambdaStore.launch()).rejects.toThrow( + "Failed to launch lambda backend", + ) - expect(lambdaStore.status).toBe(Status.NOT_CONNECTED); - expect(feedbackStore.server_error).toBeTruthy(); - }); - }); + expect(lambdaStore.status).toBe(Status.NOT_CONNECTED) + expect(feedbackStore.server_error).toBeTruthy() + }) + }) describe("connect", () => { test("successful connect", async () => { - const lambdaStore = useLambdaStore(); - await lambdaStore.connect(); - expect(lambdaStore.status).toBe(Status.CONNECTED); - }); - }); - }); -}); + const lambdaStore = useLambdaStore() + await lambdaStore.connect() + expect(lambdaStore.status).toBe(Status.CONNECTED) + }) + }) + }) +}) From 0eb74c0ab0fb3f03809b4c2652a6d35e477955a0 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Thu, 19 Mar 2026 14:28:30 +0100 Subject: [PATCH 04/11] trigger From e5d02b3fd440fc4b17bc91ddb62adf1b60502461 Mon Sep 17 00:00:00 2001 From: MaxNumerique <144453705+MaxNumerique@users.noreply.github.com> Date: Thu, 19 Mar 2026 13:29:18 +0000 Subject: [PATCH 05/11] Apply prepare changes --- .oxlintrc.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.oxlintrc.json b/.oxlintrc.json index 10639b85..9bb203be 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -66,6 +66,22 @@ "max": 10 } ], + "max-lines-per-function": [ + "warn", + { + "max": 50, + "skipBlankLines": true, + "skipComments": true + } + ], + "unicorn/no-useless-undefined": "off", + "max-lines": [ + "error", + { + "skipBlankLines": true, + "skipComments": true + } + ], "vue/max-props": [ "error", { From 7f7e186156c1b371d395377a92c9f0ae90ad3070 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Thu, 19 Mar 2026 14:58:48 +0100 Subject: [PATCH 06/11] revert undefined --- app/stores/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/stores/app.js b/app/stores/app.js index 5d1a8c0b..227cd552 100644 --- a/app/stores/app.js +++ b/app/stores/app.js @@ -97,7 +97,7 @@ export const useAppStore = defineStore("app", () => { return loadedExtensions.value.get(id) } - async function loadExtension(path, backendPath = "") { + async function loadExtension(path, backendPath = undefined) { try { let finalURL = path From 4511a4f4fd10ab0a792f5f96d2107306e8f4e87c Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Fri, 20 Mar 2026 12:49:20 +0100 Subject: [PATCH 07/11] useless async --- app/stores/app.js | 231 +++++++++++++++++++++------------------------- 1 file changed, 105 insertions(+), 126 deletions(-) diff --git a/app/stores/app.js b/app/stores/app.js index ff8f0f6c..c1e26a40 100644 --- a/app/stores/app.js +++ b/app/stores/app.js @@ -1,143 +1,132 @@ -import { api_fetch } from "@ogw_internal/utils/api_fetch.js" -import { upload_file } from "@ogw_internal/utils/upload_file.js" +import { api_fetch } from "@ogw_internal/utils/api_fetch.js"; +import { upload_file } from "@ogw_internal/utils/upload_file.js"; export const useAppStore = defineStore("app", () => { - const stores = [] + const stores = []; function registerStore(store) { - const isAlreadyRegistered = stores.some( - (registeredStore) => registeredStore.$id === store.$id, - ) + const isAlreadyRegistered = stores.some((registeredStore) => registeredStore.$id === store.$id); if (isAlreadyRegistered) { - console.log( - `[AppStore] Store "${store.$id}" already registered, skipping`, - ) - return + console.log(`[AppStore] Store "${store.$id}" already registered, skipping`); + return; } - console.log("[AppStore] Registering store", store.$id) - stores.push(store) + console.log("[AppStore] Registering store", store.$id); + stores.push(store); } async function exportStores(params = {}) { - const snapshot = {} - let exportCount = 0 + const snapshot = {}; + let exportCount = 0; - console.log( - `[AppStore] Exporting stores, total registered: ${stores.length}`, - ) + console.log(`[AppStore] Exporting stores, total registered: ${stores.length}`); await Promise.all( stores.map(async (store) => { if (!store.exportStores) { - return + return; } - const storeId = store.$id + const storeId = store.$id; try { - snapshot[storeId] = await store.exportStores(params) - exportCount += 1 + snapshot[storeId] = await store.exportStores(params); + exportCount += 1; } catch (error) { - console.error(`[AppStore] Error exporting store "${storeId}":`, error) + console.error(`[AppStore] Error exporting store "${storeId}":`, error); } }), - ) - console.log( - `[AppStore] Exported ${exportCount} stores; snapshot keys:`, - Object.keys(snapshot), - ) - return snapshot + ); + console.log(`[AppStore] Exported ${exportCount} stores; snapshot keys:`, Object.keys(snapshot)); + return snapshot; } async function importStores(snapshot) { if (!snapshot) { - console.warn("[AppStore] import called with invalid snapshot") - return + console.warn("[AppStore] import called with invalid snapshot"); + return; } - console.log("[AppStore] Import snapshot keys:", Object.keys(snapshot || {})) + console.log("[AppStore] Import snapshot keys:", Object.keys(snapshot || {})); - let importedCount = 0 - const notFoundStores = [] + let importedCount = 0; + const notFoundStores = []; await Promise.all( stores.map(async (store) => { if (!store.importStores) { - return + return; } - const storeId = store.$id + const storeId = store.$id; if (!snapshot[storeId]) { - notFoundStores.push(storeId) - return + notFoundStores.push(storeId); + return; } try { - await store.importStores(snapshot[storeId]) - importedCount += 1 + await store.importStores(snapshot[storeId]); + importedCount += 1; } catch (error) { - console.error(`[AppStore] Error importing store "${storeId}":`, error) + console.error(`[AppStore] Error importing store "${storeId}":`, error); } }), - ) + ); if (notFoundStores.length > 0) { - console.warn( - `[AppStore] Stores not found in snapshot: ${notFoundStores.join(", ")}`, - ) + console.warn(`[AppStore] Stores not found in snapshot: ${notFoundStores.join(", ")}`); } - console.log(`[AppStore] Imported ${importedCount} stores`) + console.log(`[AppStore] Imported ${importedCount} stores`); } - const loadedExtensions = ref(new Map()) - const extensionAPI = ref(undefined) - const codeTransformer = ref(undefined) + const loadedExtensions = ref(new Map()); + const extensionAPI = ref(undefined); + const codeTransformer = ref(undefined); function setExtensionAPI(api) { - extensionAPI.value = api + extensionAPI.value = api; } function setCodeTransformer(transformer) { - codeTransformer.value = transformer + codeTransformer.value = transformer; } function getExtension(id) { - return loadedExtensions.value.get(id) + return loadedExtensions.value.get(id); } async function loadExtension(path, backendPath = undefined) { try { - let finalURL = path + let finalURL = path; if (codeTransformer.value && path.startsWith("blob:")) { - const response = await fetch(path) - const code = await response.text() - const transformedCode = codeTransformer.value(code) + const response = await fetch(path); + const code = await response.text(); + const transformedCode = codeTransformer.value(code); const newBlob = new Blob([transformedCode], { type: "application/javascript", - }) - finalURL = URL.createObjectURL(newBlob) + }); + finalURL = URL.createObjectURL(newBlob); } // oxlint-disable-next-line no-inline-comments - const extensionModule = await import(/* @vite-ignore */ finalURL) + const extensionModule = await import(/* @vite-ignore */ finalURL); if (finalURL !== path && finalURL.startsWith("blob:")) { - URL.revokeObjectURL(finalURL) + URL.revokeObjectURL(finalURL); } if (!extensionModule.metadata?.id) { - throw new Error("Extension must have metadata.id") + throw new Error("Extension must have metadata.id"); } - const extensionId = extensionModule.metadata.id + const extensionId = extensionModule.metadata.id; if (loadedExtensions.value.has(extensionId)) { - console.warn(`[AppStore] Extension "${extensionId}" is already loaded`) - throw new Error(`Extension "${extensionId}" is already loaded.`) + console.warn(`[AppStore] Extension "${extensionId}" is already loaded`); + throw new Error(`Extension "${extensionId}" is already loaded.`); } if (!extensionAPI.value) { - throw new Error("Extension API not initialized") + throw new Error("Extension API not initialized"); } if (typeof extensionModule.install !== "function") { - throw new TypeError("Extension must export an install function") + throw new TypeError("Extension must export an install function"); } - await extensionModule.install(extensionAPI.value, backendPath) + await extensionModule.install(extensionAPI.value, backendPath); const extensionData = { module: extensionModule, @@ -147,124 +136,114 @@ export const useAppStore = defineStore("app", () => { loadedAt: new Date().toISOString(), metadata: extensionModule.metadata, enabled: true, - } - loadedExtensions.value.set(extensionId, extensionData) + }; + loadedExtensions.value.set(extensionId, extensionData); - console.log(`[AppStore] Extension loaded successfully: ${extensionId}`) - return extensionModule + console.log(`[AppStore] Extension loaded successfully: ${extensionId}`); + return extensionModule; } catch (error) { - console.error(`[AppStore] Failed to load extension from ${path}:`, error) - throw error + console.error(`[AppStore] Failed to load extension from ${path}:`, error); + throw error; } } function getLoadedExtensions() { - return [...loadedExtensions.value.values()] + return [...loadedExtensions.value.values()]; } function unloadExtension(id) { - const extensionData = getExtension(id) + const extensionData = getExtension(id); if (!extensionData) { - return false + return false; } - if ( - extensionData.module && - typeof extensionData.module.uninstall === "function" - ) { + if (extensionData.module && typeof extensionData.module.uninstall === "function") { try { - extensionData.module.uninstall(extensionAPI.value) - console.log(`[AppStore] Extension uninstall called: ${id}`) + extensionData.module.uninstall(extensionAPI.value); + console.log(`[AppStore] Extension uninstall called: ${id}`); } catch (error) { - console.error(`[AppStore] Error calling uninstall for ${id}:`, error) + console.error(`[AppStore] Error calling uninstall for ${id}:`, error); } } - if ( - extensionAPI.value && - typeof extensionAPI.value.unregisterToolsByExtension === "function" - ) { - extensionAPI.value.unregisterToolsByExtension(id) + if (extensionAPI.value && typeof extensionAPI.value.unregisterToolsByExtension === "function") { + extensionAPI.value.unregisterToolsByExtension(id); } - loadedExtensions.value.delete(id) - console.log(`[AppStore] Extension unloaded: ${id}`) - return true + loadedExtensions.value.delete(id); + console.log(`[AppStore] Extension unloaded: ${id}`); + return true; } function toggleExtension(id) { - const extensionData = getExtension(id) + const extensionData = getExtension(id); if (!extensionData) { - return false + return false; } - extensionData.enabled = !extensionData.enabled - console.log( - `[AppStore] Extension ${extensionData.enabled ? "enabled" : "disabled"}: ${id}`, - ) - return extensionData.enabled + extensionData.enabled = !extensionData.enabled; + console.log(`[AppStore] Extension ${extensionData.enabled ? "enabled" : "disabled"}: ${id}`); + return extensionData.enabled; } function setExtensionEnabled(id, enabled) { - const extensionData = getExtension(id) + const extensionData = getExtension(id); if (!extensionData) { - return false + return false; } - extensionData.enabled = enabled - console.log( - `[AppStore] Extension ${enabled ? "enabled" : "disabled"}: ${id}`, - ) - return true + extensionData.enabled = enabled; + console.log(`[AppStore] Extension ${enabled ? "enabled" : "disabled"}: ${id}`); + return true; } function getExtensionEnabled(id) { - return getExtension(id)?.enabled ?? false + return getExtension(id)?.enabled ?? false; } function upload(file, callbacks = {}) { - const route = "/api/extensions/upload" - const store = useAppStore() + const route = "/api/extensions/upload"; + const store = useAppStore(); return upload_file( store, { route, file }, { ...callbacks, response_function: async (response) => { - console.log("[APP] Request completed:", route) + console.log("[APP] Request completed:", route); if (callbacks.response_function) { - await callbacks.response_function(response) + await callbacks.response_function(response); } }, }, - ) + ); } function request(schema, params, callbacks = {}) { - console.log("[APP] Request:", schema.$id) + console.log("[APP] Request:", schema.$id); - const store = useAppStore() + const store = useAppStore(); return api_fetch( store, { schema, params }, { ...callbacks, response_function: async (response) => { - console.log("[APP] Request completed:", schema.$id) + console.log("[APP] Request completed:", schema.$id); if (callbacks.response_function) { - await callbacks.response_function(response) + await callbacks.response_function(response); } }, }, - ) + ); } - const request_counter = ref(0) + const request_counter = ref(0); function start_request() { - request_counter.value += 1 + request_counter.value += 1; } function stop_request() { - request_counter.value -= 1 + request_counter.value -= 1; } - const projectFolderPath = ref("") + const projectFolderPath = ref(""); function createProjectFolder() { const schema = { $id: "/api/app/project_folder_path", @@ -273,18 +252,18 @@ export const useAppStore = defineStore("app", () => { properties: {}, required: [], additionalProperties: true, - } + }; return request( schema, {}, { - response_function: async (response) => { - console.log(`[APP] ${response.projectFolderPath} created`) - projectFolderPath.value = response.projectFolderPath + response_function: (response) => { + console.log(`[APP] ${response.projectFolderPath} created`); + projectFolderPath.value = response.projectFolderPath; }, }, - ) + ); } return { @@ -309,5 +288,5 @@ export const useAppStore = defineStore("app", () => { createProjectFolder, start_request, stop_request, - } -}) + }; +}); From 85c37acdf587cd3f9796e5661587293b61c1637e Mon Sep 17 00:00:00 2001 From: MaxNumerique <144453705+MaxNumerique@users.noreply.github.com> Date: Fri, 20 Mar 2026 11:50:03 +0000 Subject: [PATCH 08/11] Apply prepare changes --- .eslintrc.cjs | 2 +- .oxlintrc.json | 25 +- app/assets/geode_objects.js | 52 +-- app/components/Carousel.vue | 128 +++---- app/components/CrsSelector.vue | 100 +++-- app/components/DeleteDialog.vue | 58 ++- app/components/DragAndDrop.vue | 76 ++-- app/components/ExtensionSelector.vue | 113 +++--- app/components/FeedBack/ErrorBanner.vue | 17 +- app/components/FeedBack/Snackers.vue | 26 +- app/components/FetchingData.vue | 7 +- app/components/FileSelector.vue | 88 ++--- app/components/FileUploader.vue | 141 +++---- app/components/GlassCard.vue | 38 +- app/components/HybridRenderingView.vue | 75 ++-- app/components/InfraConnected.vue | 6 +- app/components/Inspector/InspectionButton.vue | 58 ++- app/components/Inspector/ResultPanel.vue | 37 +- app/components/Launcher.vue | 26 +- app/components/Loading.vue | 132 ++++--- app/components/MissingFilesSelector.vue | 126 +++---- app/components/ObjectSelector.vue | 180 ++++----- app/components/PackagesVersions.vue | 57 ++- app/components/Recaptcha.vue | 128 +++---- app/components/RemoteRenderingView.vue | 210 +++++------ app/components/Screenshot.vue | 78 ++-- app/components/SearchBar.vue | 10 +- app/components/Step.vue | 81 ++-- app/components/Stepper.vue | 64 ++-- app/components/VeaseViewToolbar.vue | 147 ++++---- app/components/ViewToolbar.vue | 86 ++--- app/components/Viewer/BreadCrumb.vue | 48 +-- app/components/Viewer/ContextMenu.vue | 355 +++++++++--------- app/components/Viewer/ContextMenuItem.vue | 222 ++++++----- .../Viewer/EdgedCurve/PointsOptions.vue | 15 +- .../EdgedCurve/SpecificEdgesOptions.vue | 175 ++++----- .../Viewer/Generic/Mesh/CellsOptions.vue | 183 +++++---- .../Viewer/Generic/Mesh/EdgesOptions.vue | 181 ++++----- .../Viewer/Generic/Mesh/PointsOptions.vue | 135 +++---- .../Viewer/Generic/Mesh/PolygonsOptions.vue | 192 +++++----- .../Viewer/Generic/Mesh/PolyhedraOptions.vue | 187 ++++----- .../Viewer/Generic/Model/EdgesOptions.vue | 42 +-- .../Viewer/Generic/Model/PointsOptions.vue | 56 ++- .../Viewer/Grid/2D/CellsOptions.vue | 10 +- .../Viewer/Grid/2D/EdgesOptions.vue | 15 +- .../Viewer/Grid/2D/PointsOptions.vue | 15 +- .../Viewer/Grid/3D/CellsOptions.vue | 10 +- .../Viewer/Grid/3D/EdgesOptions.vue | 15 +- .../Viewer/Grid/3D/FacetsOptions.vue | 10 +- .../Viewer/Grid/3D/PointsOptions.vue | 15 +- .../Viewer/HybridSolid/EdgesOptions.vue | 15 +- .../Viewer/HybridSolid/PointsOptions.vue | 15 +- .../Viewer/HybridSolid/PolygonsOptions.vue | 15 +- .../Viewer/HybridSolid/PolyhedraOptions.vue | 15 +- .../Viewer/Options/AttributeColorBar.vue | 16 +- .../Viewer/Options/AttributeSelector.vue | 151 ++++---- .../Viewer/Options/ColorMapList.vue | 255 ++++++------- .../Viewer/Options/ColorMapPicker.vue | 270 +++++++------ app/components/Viewer/Options/ColorPicker.vue | 18 +- .../Viewer/Options/ColoringTypeSelector.vue | 168 ++++----- app/components/Viewer/Options/TextureItem.vue | 112 +++--- .../Viewer/Options/TexturesSelector.vue | 48 ++- .../Viewer/Options/VisibilitySwitch.vue | 2 +- .../Viewer/PointSet/SpecificPointsOptions.vue | 129 +++---- .../Viewer/PolygonalSurface/EdgesOptions.vue | 15 +- .../Viewer/PolygonalSurface/PointsOptions.vue | 15 +- .../SpecificPolygonsOptions.vue | 186 ++++----- app/components/Viewer/Solid/EdgesOptions.vue | 15 +- app/components/Viewer/Solid/PointsOptions.vue | 15 +- .../Viewer/Solid/PolygonsOptions.vue | 15 +- .../Viewer/Solid/SpecificPolyhedraOptions.vue | 187 ++++----- .../TetrahedralSolid/TetrahedraOptions.vue | 10 +- .../TetrahedralSolid/TrianglesOptions.vue | 10 +- app/components/Viewer/Tree/ObjectTree.vue | 169 ++++----- app/components/Viewer/TreeComponent.vue | 92 +++-- app/components/Viewer/TreeObject.vue | 98 +++-- .../TriangulatedSurface/EdgesOptions.vue | 15 +- .../TriangulatedSurface/PointsOptions.vue | 10 +- .../TriangulatedSurface/TrianglesOptions.vue | 10 +- app/components/Wrapper.vue | 16 +- app/components/ZScaling.vue | 45 +-- app/composables/project_manager.js | 124 +++--- ...n_function_when_microservices_connected.js | 16 +- app/plugins/auto_store_register.js | 24 +- app/stores/data.js | 120 +++--- app/stores/data_style.js | 72 ++-- app/stores/feedback.js | 33 +- app/stores/geode.js | 108 +++--- app/stores/hybrid_viewer.js | 336 ++++++++--------- app/stores/infra.js | 98 +++-- app/stores/lambda.js | 50 +-- app/stores/menu.js | 163 ++++---- app/stores/treeview.js | 118 +++--- app/stores/viewer.js | 197 +++++----- app/utils/colormap.js | 6 +- app/utils/config.js | 38 +- app/utils/default_styles.js | 112 +++--- app/utils/extension.js | 88 ++--- app/utils/file_import_workflow.js | 114 +++--- app/utils/local/app_mode.js | 4 +- app/utils/local/cleanup.js | 134 ++++--- app/utils/local/microservices.js | 132 +++---- app/utils/local/path.js | 35 +- app/utils/local/scripts.js | 44 +-- app/utils/recaptcha.js | 12 +- app/utils/server.js | 45 ++- app/utils/status.js | 4 +- app/utils/treeview.js | 8 +- app/utils/validate_schema.js | 14 +- commitlint.config.js | 4 +- eslint.config.js | 8 +- internal/database/database.js | 75 ++-- internal/database/extended_database.js | 19 +- internal/database/tables/data.js | 5 +- internal/database/tables/model_components.js | 2 +- .../tables/model_components_relation.js | 2 +- internal/stores/data_style/mesh/cells/cell.js | 110 +++--- .../stores/data_style/mesh/cells/color.js | 27 +- .../stores/data_style/mesh/cells/common.js | 12 +- .../stores/data_style/mesh/cells/index.js | 75 ++-- .../stores/data_style/mesh/cells/textures.js | 23 +- .../stores/data_style/mesh/cells/vertex.js | 105 +++--- .../data_style/mesh/cells/visibility.js | 27 +- .../stores/data_style/mesh/edges/color.js | 27 +- .../stores/data_style/mesh/edges/common.js | 12 +- internal/stores/data_style/mesh/edges/edge.js | 110 +++--- .../stores/data_style/mesh/edges/index.js | 78 ++-- .../stores/data_style/mesh/edges/vertex.js | 105 +++--- .../data_style/mesh/edges/visibility.js | 27 +- .../stores/data_style/mesh/edges/width.js | 27 +- internal/stores/data_style/mesh/index.js | 68 ++-- .../stores/data_style/mesh/points/color.js | 27 +- .../stores/data_style/mesh/points/common.js | 12 +- .../stores/data_style/mesh/points/index.js | 75 ++-- .../stores/data_style/mesh/points/size.js | 27 +- .../stores/data_style/mesh/points/vertex.js | 105 +++--- .../data_style/mesh/points/visibility.js | 27 +- .../stores/data_style/mesh/polygons/color.js | 27 +- .../stores/data_style/mesh/polygons/common.js | 12 +- .../stores/data_style/mesh/polygons/index.js | 72 ++-- .../data_style/mesh/polygons/polygon.js | 101 +++-- .../data_style/mesh/polygons/textures.js | 27 +- .../stores/data_style/mesh/polygons/vertex.js | 105 +++--- .../data_style/mesh/polygons/visibility.js | 27 +- .../stores/data_style/mesh/polyhedra/color.js | 27 +- .../data_style/mesh/polyhedra/common.js | 12 +- .../stores/data_style/mesh/polyhedra/index.js | 65 ++-- .../data_style/mesh/polyhedra/polyhedron.js | 90 +++-- .../data_style/mesh/polyhedra/vertex.js | 105 +++--- .../data_style/mesh/polyhedra/visibility.js | 28 +- .../stores/data_style/model/blocks/color.js | 45 ++- .../stores/data_style/model/blocks/common.js | 12 +- .../stores/data_style/model/blocks/index.js | 30 +- .../data_style/model/blocks/visibility.js | 45 ++- .../stores/data_style/model/corners/color.js | 45 ++- .../stores/data_style/model/corners/common.js | 12 +- .../stores/data_style/model/corners/index.js | 32 +- .../data_style/model/corners/visibility.js | 46 ++- .../stores/data_style/model/edges/common.js | 8 +- .../stores/data_style/model/edges/index.js | 14 +- .../data_style/model/edges/visibility.js | 26 +- internal/stores/data_style/model/index.js | 163 ++++---- .../stores/data_style/model/lines/color.js | 45 ++- .../stores/data_style/model/lines/common.js | 12 +- .../stores/data_style/model/lines/index.js | 30 +- .../data_style/model/lines/visibility.js | 45 ++- .../stores/data_style/model/points/common.js | 8 +- .../stores/data_style/model/points/index.js | 18 +- .../stores/data_style/model/points/size.js | 22 +- .../data_style/model/points/visibility.js | 26 +- .../stores/data_style/model/surfaces/color.js | 45 ++- .../data_style/model/surfaces/common.js | 12 +- .../stores/data_style/model/surfaces/index.js | 36 +- .../data_style/model/surfaces/visibility.js | 40 +- internal/stores/data_style/state.js | 22 +- internal/utils/api_fetch.js | 58 ++- internal/utils/upload_file.js | 41 +- internal/utils/viewer_call.js | 59 ++- nuxt.config.js | 18 +- scripts/generate_geode_objects.js | 30 +- server/api/app/kill.post.js | 8 +- server/api/app/project_folder_path.post.js | 22 +- server/api/app/run_back.post.js | 24 +- server/api/app/run_viewer.post.js | 24 +- server/api/extensions/run.post.js | 75 ++-- server/api/extensions/upload.put.js | 110 +++--- tests/integration/setup.js | 96 +++-- .../stores/data_style/mesh/cells.nuxt.test.js | 204 +++++----- .../stores/data_style/mesh/edges.nuxt.test.js | 188 ++++------ .../stores/data_style/mesh/index.nuxt.test.js | 79 ++-- .../data_style/mesh/points.nuxt.test.js | 186 +++++---- .../data_style/mesh/polygons.nuxt.test.js | 202 +++++----- .../data_style/mesh/polyhedra.nuxt.test.js | 186 ++++----- .../data_style/model/blocks.nuxt.test.js | 129 +++---- .../data_style/model/corners.nuxt.test.js | 135 +++---- .../data_style/model/edges.nuxt.test.js | 81 ++-- .../data_style/model/index.nuxt.test.js | 65 ++-- .../data_style/model/lines.nuxt.test.js | 133 +++---- .../data_style/model/points.nuxt.test.js | 107 +++--- .../data_style/model/surfaces.nuxt.test.js | 139 +++---- tests/integration/stores/viewer.nuxt.test.js | 71 ++-- tests/setup_indexeddb.js | 4 +- .../unit/components/CrsSelector.nuxt.test.js | 56 +-- .../components/ExtensionSelector.nuxt.test.js | 68 ++-- .../FeedBack/ErrorsBanner.nuxt.test.js | 46 +-- .../components/FeedBack/Snackers.nuxt.test.js | 34 +- .../unit/components/FileSelector.nuxt.test.js | 114 +++--- .../unit/components/FileUploader.nuxt.test.js | 70 ++-- .../Inspector/InspectionButton.nuxt.test.js | 54 +-- .../Inspector/ResultPanel.nuxt.test.js | 47 ++- tests/unit/components/Launcher.nuxt.test.js | 40 +- .../MissingFilesSelector.nuxt.test.js | 74 ++-- .../components/ObjectSelector.nuxt.test.js | 124 +++--- .../components/PackagesVersions.nuxt.test.js | 30 +- tests/unit/components/Step.nuxt.test.js | 34 +- tests/unit/components/Stepper.nuxt.test.js | 36 +- tests/unit/composables/api_fetch.nuxt.test.js | 64 ++-- .../composables/project_manager.nuxt.test.js | 205 +++++----- ..._when_microservices_connected.nuxt.test.js | 70 ++-- .../unit/composables/upload_file.nuxt.test.js | 56 ++- tests/unit/plugins/project_load.nuxt.test.js | 64 ++-- tests/unit/stores/app.nuxt.test.js | 182 +++++---- tests/unit/stores/feedback.nuxt.test.js | 104 +++-- tests/unit/stores/geode.nuxt.test.js | 226 ++++++----- tests/unit/stores/infra.nuxt.test.js | 296 +++++++-------- tests/unit/stores/lambda.nuxt.test.js | 144 ++++--- tests/unit/stores/treeview.nuxt.test.js | 40 +- tests/unit/stores/viewer.nuxt.test.js | 231 ++++++------ tests/unit/utils/recaptcha.nuxt.test.js | 54 ++- tests/unit/utils/validate_schema.nuxt.test.js | 34 +- tests/utils.js | 22 +- tests/vitest.config.js | 18 +- vuetify_config.js | 4 +- 233 files changed, 7595 insertions(+), 8932 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 8ad75e57..0fae25cc 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -12,4 +12,4 @@ module.exports = { "plugin:vuetify/recommended", "plugin:nuxt/recommended", ], -} +}; diff --git a/.oxlintrc.json b/.oxlintrc.json index 9bb203be..cfed6074 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -25,22 +25,7 @@ "eslint/id-length": [ "error", { - "exceptions": [ - "x", - "y", - "z", - "i", - "j", - "k", - "r", - "g", - "b", - "id", - "ID", - "fs", - "os", - "_" - ], + "exceptions": ["x", "y", "z", "i", "j", "k", "r", "g", "b", "id", "ID", "fs", "os", "_"], "min": 3 } ], @@ -78,6 +63,7 @@ "max-lines": [ "error", { + "max": 310, "skipBlankLines": true, "skipComments": true } @@ -121,12 +107,7 @@ } }, { - "files": [ - "app/plugins/**", - "node_scripts/**", - "server/**", - "*.config.js" - ], + "files": ["app/plugins/**", "node_scripts/**", "server/**", "*.config.js"], "rules": { "import/no-default-export": "off" } diff --git a/app/assets/geode_objects.js b/app/assets/geode_objects.js index 899bf6e9..73538210 100644 --- a/app/assets/geode_objects.js +++ b/app/assets/geode_objects.js @@ -1,28 +1,28 @@ -import BRep from "@ogw_front/assets/img/geode_objects/BRep.svg" -import CrossSection from "@ogw_front/assets/img/geode_objects/CrossSection.svg" -import EdgedCurve2D from "@ogw_front/assets/img/geode_objects/EdgedCurve2D.svg" -import EdgedCurve3D from "@ogw_front/assets/img/geode_objects/EdgedCurve3D.svg" -import Graph from "@ogw_front/assets/img/geode_objects/Graph.svg" -import HybridSolid3D from "@ogw_front/assets/img/geode_objects/HybridSolid3D.svg" -import ImplicitCrossSection from "@ogw_front/assets/img/geode_objects/ImplicitCrossSection.svg" -import ImplicitStructuralModel from "@ogw_front/assets/img/geode_objects/ImplicitStructuralModel.svg" -import LightRegularGrid2D from "@ogw_front/assets/img/geode_objects/LightRegularGrid2D.svg" -import LightRegularGrid3D from "@ogw_front/assets/img/geode_objects/LightRegularGrid3D.svg" -import PointSet2D from "@ogw_front/assets/img/geode_objects/PointSet2D.svg" -import PointSet3D from "@ogw_front/assets/img/geode_objects/PointSet3D.svg" -import PolygonalSurface2D from "@ogw_front/assets/img/geode_objects/PolygonalSurface2D.svg" -import PolygonalSurface3D from "@ogw_front/assets/img/geode_objects/PolygonalSurface3D.svg" -import PolyhedralSolid3D from "@ogw_front/assets/img/geode_objects/PolyhedralSolid3D.svg" -import RasterImage2D from "@ogw_front/assets/img/geode_objects/RasterImage2D.svg" -import RasterImage3D from "@ogw_front/assets/img/geode_objects/RasterImage3D.svg" -import RegularGrid2D from "@ogw_front/assets/img/geode_objects/RegularGrid2D.svg" -import RegularGrid3D from "@ogw_front/assets/img/geode_objects/RegularGrid3D.svg" -import Section from "@ogw_front/assets/img/geode_objects/Section.svg" -import StructuralModel from "@ogw_front/assets/img/geode_objects/StructuralModel.svg" -import TetrahedralSolid3D from "@ogw_front/assets/img/geode_objects/TetrahedralSolid3D.svg" -import TriangulatedSurface2D from "@ogw_front/assets/img/geode_objects/TriangulatedSurface2D.svg" -import TriangulatedSurface3D from "@ogw_front/assets/img/geode_objects/TriangulatedSurface3D.svg" -import VertexSet from "@ogw_front/assets/img/geode_objects/VertexSet.svg" +import BRep from "@ogw_front/assets/img/geode_objects/BRep.svg"; +import CrossSection from "@ogw_front/assets/img/geode_objects/CrossSection.svg"; +import EdgedCurve2D from "@ogw_front/assets/img/geode_objects/EdgedCurve2D.svg"; +import EdgedCurve3D from "@ogw_front/assets/img/geode_objects/EdgedCurve3D.svg"; +import Graph from "@ogw_front/assets/img/geode_objects/Graph.svg"; +import HybridSolid3D from "@ogw_front/assets/img/geode_objects/HybridSolid3D.svg"; +import ImplicitCrossSection from "@ogw_front/assets/img/geode_objects/ImplicitCrossSection.svg"; +import ImplicitStructuralModel from "@ogw_front/assets/img/geode_objects/ImplicitStructuralModel.svg"; +import LightRegularGrid2D from "@ogw_front/assets/img/geode_objects/LightRegularGrid2D.svg"; +import LightRegularGrid3D from "@ogw_front/assets/img/geode_objects/LightRegularGrid3D.svg"; +import PointSet2D from "@ogw_front/assets/img/geode_objects/PointSet2D.svg"; +import PointSet3D from "@ogw_front/assets/img/geode_objects/PointSet3D.svg"; +import PolygonalSurface2D from "@ogw_front/assets/img/geode_objects/PolygonalSurface2D.svg"; +import PolygonalSurface3D from "@ogw_front/assets/img/geode_objects/PolygonalSurface3D.svg"; +import PolyhedralSolid3D from "@ogw_front/assets/img/geode_objects/PolyhedralSolid3D.svg"; +import RasterImage2D from "@ogw_front/assets/img/geode_objects/RasterImage2D.svg"; +import RasterImage3D from "@ogw_front/assets/img/geode_objects/RasterImage3D.svg"; +import RegularGrid2D from "@ogw_front/assets/img/geode_objects/RegularGrid2D.svg"; +import RegularGrid3D from "@ogw_front/assets/img/geode_objects/RegularGrid3D.svg"; +import Section from "@ogw_front/assets/img/geode_objects/Section.svg"; +import StructuralModel from "@ogw_front/assets/img/geode_objects/StructuralModel.svg"; +import TetrahedralSolid3D from "@ogw_front/assets/img/geode_objects/TetrahedralSolid3D.svg"; +import TriangulatedSurface2D from "@ogw_front/assets/img/geode_objects/TriangulatedSurface2D.svg"; +import TriangulatedSurface3D from "@ogw_front/assets/img/geode_objects/TriangulatedSurface3D.svg"; +import VertexSet from "@ogw_front/assets/img/geode_objects/VertexSet.svg"; export const geode_objects = { BRep: { @@ -125,4 +125,4 @@ export const geode_objects = { tooltip: "VertexSet", image: VertexSet, }, -} +}; diff --git a/app/components/Carousel.vue b/app/components/Carousel.vue index 9c37610d..3ed6ae89 100644 --- a/app/components/Carousel.vue +++ b/app/components/Carousel.vue @@ -1,58 +1,54 @@ diff --git a/app/components/CrsSelector.vue b/app/components/CrsSelector.vue index 70712996..a75407f4 100644 --- a/app/components/CrsSelector.vue +++ b/app/components/CrsSelector.vue @@ -1,67 +1,63 @@