Skip to content

Commit 200f504

Browse files
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWeb-Front into fix/refactor_watches
2 parents 4b74caf + 869dbd4 commit 200f504

18 files changed

+293
-225
lines changed

components/PackagesVersions.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@
1919
</template>
2020

2121
<script setup>
22+
import Status from "@/utils/status.js"
23+
2224
const props = defineProps({
2325
schema: { type: Object, required: true },
2426
})
25-
const { schema } = props
2627
28+
const geode_store = use_geode_store()
2729
const packages_versions = ref([])
2830
2931
async function get_packages_versions() {
3032
const array_promise = []
3133
3234
const promise = new Promise((resolve, reject) => {
3335
api_fetch(
34-
{ schema },
36+
{ schema: props.schema },
3537
{
3638
request_error_function: () => {
3739
reject()

components/RemoteRenderingView.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import vtkRemoteView from "@kitware/vtk.js/Rendering/Misc/RemoteView"
2525
import { useElementSize, useWindowSize } from "@vueuse/core"
2626
import viewer_schemas from "@geode/opengeodeweb-viewer/schemas.json"
27+
import Status from "@/utils/status.js"
2728
2829
const props = defineProps({
2930
viewId: { type: String, default: "-1" },
@@ -36,7 +37,7 @@
3637
const { width: windowWidth, height: windowHeight } = useWindowSize()
3738
3839
function get_x_y(event) {
39-
if (picking_mode.value === true) {
40+
if (viewer_store.picking_mode.value === true) {
4041
const { offsetX, offsetY } = event
4142
viewer_store.set_picked_point(offsetX, offsetY)
4243
viewer_call({
@@ -96,10 +97,10 @@
9697
)
9798
9899
function connect() {
99-
if (!is_running.value) {
100+
if (!viewer_store.status !== Status.CONNECTED) {
100101
return
101102
}
102-
const session = client.value.getConnection().getSession()
103+
const session = viewer_store.client.value.getConnection().getSession()
103104
view.setSession(session)
104105
view.setViewId(props.viewId)
105106
connected.value = true

components/Wrapper.vue

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<template>
22
<v-container>
33
<v-row class="flex-column">
4-
<v-col v-if="!is_running">
5-
<Launcher />
6-
</v-col>
7-
<v-col v-if="is_running">
8-
<Stepper />
9-
</v-col>
10-
<v-col v-if="is_running">
11-
<PackagesVersions :schema="versions_schema" />
12-
</v-col>
4+
<template v-if="!infra_store.microservices_connected">
5+
<v-col>
6+
<Launcher />
7+
</v-col>
8+
</template>
9+
<template v-else>
10+
<v-col>
11+
<Stepper />
12+
</v-col>
13+
<v-col> <PackagesVersions :schema="versions_schema" /> </v-col>
14+
</template>
1315
</v-row>
1416
</v-container>
1517
</template>
1618

1719
<script setup>
1820
const infra_store = use_infra_store()
19-
const { is_running } = storeToRefs(infra_store)
2021
2122
const props = defineProps({
2223
versions_schema: { type: Object, required: true },

composables/run_function_when_infra_running.js

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function run_function_when_microservices_connected(function_to_run) {
2+
const infra_store = use_infra_store()
3+
const { microservices_connected } = storeToRefs(infra_store)
4+
if (microservices_connected.value) {
5+
function_to_run()
6+
} else {
7+
watch(microservices_connected, (value) => {
8+
if (value) {
9+
function_to_run()
10+
}
11+
})
12+
}
13+
}
14+
15+
export default run_function_when_microservices_connected

nuxt.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default defineNuxtConfig({
3939
"ajv",
4040
"fast-deep-equal",
4141
"globalthis",
42+
"h3",
4243
"is-electron",
4344
"js-file-download",
4445
"lodash",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"@nuxt/test-utils": "^3.15.1",
1111
"@pinia/testing": "^0.1.7",
1212
"@vitejs/plugin-vue": "^5.2.1",
13+
"@vitest/coverage-v8": "^3.0.8",
1314
"@vue/test-utils": "^2.4.6",
1415
"eslint": "^8.57.0",
1516
"eslint-plugin-import": "^2.29.1",

stores/geode.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import back_schemas from "@geode/opengeodeweb-back/schemas.json"
2+
import Status from "@/utils/status.js"
23

34
export const use_geode_store = defineStore("geode", {
45
state: () => ({
56
default_local_port: "5000",
67
request_counter: 0,
7-
is_running: false,
8+
status: Status.NOT_CONNECTED,
89
}),
910
getters: {
1011
protocol() {
@@ -37,7 +38,7 @@ export const use_geode_store = defineStore("geode", {
3738
actions: {
3839
ping_task() {
3940
setInterval(() => {
40-
if (this.is_running) {
41+
if (this.status == Status.CONNECTED) {
4142
this.do_ping()
4243
}
4344
}, 10 * 1000)
@@ -48,19 +49,20 @@ export const use_geode_store = defineStore("geode", {
4849
return useFetch(back_schemas.opengeodeweb_back.ping.$id, {
4950
baseURL: this.base_url,
5051
method: back_schemas.opengeodeweb_back.ping.methods[0],
52+
body: {},
5153
onRequestError({ error }) {
5254
feedback_store.server_error = true
53-
geode_store.is_running = false
55+
geode_store.status = Status.NOT_CONNECTED
5456
},
5557
onResponse({ response }) {
5658
if (response.ok) {
5759
feedback_store.server_error = false
58-
geode_store.is_running = true
60+
geode_store.status = Status.CONNECTED
5961
}
6062
},
6163
onResponseError({ response }) {
6264
feedback_store.server_error = true
63-
geode_store.is_running = false
65+
geode_store.status = Status.NOT_CONNECTED
6466
},
6567
})
6668
},
@@ -71,4 +73,7 @@ export const use_geode_store = defineStore("geode", {
7173
this.request_counter--
7274
},
7375
},
76+
share: {
77+
omit: ["status"],
78+
},
7479
})

stores/infra.js

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useStorage } from "@vueuse/core"
22
import isElectron from "is-electron"
3+
import Status from "@/utils/status.js"
34

45
export const use_infra_store = defineStore("infra", {
56
state: () => ({
@@ -35,47 +36,53 @@ export const use_infra_store = defineStore("infra", {
3536
"/createbackend"
3637
return url
3738
},
38-
is_running() {
39-
return use_geode_store().is_running && use_viewer_store().is_running
39+
microservices_connected() {
40+
return (
41+
use_geode_store().status == Status.CONNECTED &&
42+
use_viewer_store().status == Status.CONNECTED
43+
)
4044
},
41-
is_busy() {
45+
microservices_busy() {
4246
return use_geode_store().is_busy || use_viewer_store().is_busy
4347
},
4448
},
4549
actions: {
46-
async create_connexion() {
47-
if (this.is_connexion_launched) {
48-
return
49-
}
50-
this.is_connexion_launched = true
51-
return this.create_backend()
52-
},
5350
async create_backend() {
54-
const geode_store = use_geode_store()
55-
const viewer_store = use_viewer_store()
56-
const feedback_store = use_feedback_store()
57-
58-
if (isElectron()) {
59-
const back_port = await window.electronAPI.run_back(geode_store.port)
60-
geode_store.$patch({ default_local_port: back_port })
61-
const viewer_port = await window.electronAPI.run_viewer(
62-
viewer_store.port,
63-
)
64-
viewer_store.$patch({ default_local_port: viewer_port })
65-
} else {
66-
const { data, error } = await useFetch(this.lambda_url, {
67-
method: "POST",
68-
})
69-
if (data.value !== null) {
51+
if (this.status === Status.CREATED) return
52+
navigator.locks.request("infra.create_backend", async (lock) => {
53+
this.status = Status.CREATING
54+
if (this.status === Status.CREATED) return
55+
console.log("LOCK GRANTED !", lock)
56+
const geode_store = use_geode_store()
57+
const viewer_store = use_viewer_store()
58+
const feedback_store = use_feedback_store()
59+
if (isElectron()) {
60+
const back_port = await window.electronAPI.run_back(geode_store.port)
61+
geode_store.$patch({ default_local_port: back_port })
62+
const viewer_port = await window.electronAPI.run_viewer(
63+
viewer_store.port,
64+
)
65+
viewer_store.$patch({ default_local_port: viewer_port })
66+
} else {
67+
const { data, error } = await useFetch(this.lambda_url, {
68+
method: "POST",
69+
})
70+
if (error.value || !data.value) {
71+
this.status = Status.NOT_CREATED
72+
feedback_store.server_error = true
73+
return
74+
}
7075
this.ID = data.value.ID
7176
localStorage.setItem("ID", data.value.ID)
72-
} else {
73-
feedback_store.server_error = true
74-
return
7577
}
76-
}
77-
geode_store.$patch({ is_running: true })
78-
return geode_store.ping_task()
78+
this.status = Status.CREATED
79+
return this.create_connection()
80+
})
81+
},
82+
async create_connection() {
83+
await use_viewer_store().ws_connect()
84+
await use_geode_store().do_ping()
85+
return
7986
},
8087
},
8188
})

0 commit comments

Comments
 (0)