Skip to content

Commit 869dbd4

Browse files
2 parents 689fc03 + c1bf4fb commit 869dbd4

19 files changed

+261
-208
lines changed

components/Launcher.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,25 @@
1111
<h4 class="pb-3">Please complete the recaptcha to launch the app</h4>
1212
<Recaptcha :site_key="site_key" />
1313
</v-col>
14-
<v-col v-else-if="!is_running && is_connexion_launched">
14+
<v-col v-else-if="infra_store.status == Status.CREATING">
1515
<Loading />
1616
</v-col>
1717
</v-row>
1818
</v-container>
1919
</template>
2020

2121
<script setup>
22+
import Status from "@/utils/status.js"
23+
2224
const viewer_store = use_viewer_store()
2325
const infra_store = use_infra_store()
24-
const { is_captcha_validated, is_connexion_launched, is_running } =
25-
storeToRefs(infra_store)
26+
const { is_captcha_validated } = storeToRefs(infra_store)
2627
2728
const site_key = useRuntimeConfig().public.RECAPTCHA_SITE_KEY
2829
2930
watch(is_captcha_validated, async (value) => {
3031
if (value === true && process.client) {
31-
await infra_store.create_connexion()
32+
await infra_store.create_backend()
3233
await viewer_store.ws_connect()
3334
}
3435
})

components/PackagesVersions.vue

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

2121
<script setup>
22-
const infra_store = use_infra_store()
23-
const { is_running } = storeToRefs(infra_store)
22+
import Status from "@/utils/status.js"
2423
2524
const props = defineProps({
2625
schema: { type: Object, required: true },
2726
})
28-
const { schema } = props
2927
28+
const geode_store = use_geode_store()
3029
const packages_versions = ref([])
3130
3231
async function get_packages_versions() {
3332
const array_promise = []
3433
3534
const promise = new Promise((resolve, reject) => {
3635
api_fetch(
37-
{ schema },
36+
{ schema: props.schema },
3837
{
3938
request_error_function: () => {
4039
reject()
@@ -53,8 +52,8 @@
5352
await Promise.all(array_promise)
5453
}
5554
56-
watch(is_running, () => {
57-
get_packages_versions()
55+
watch(geode_store.status, (value) => {
56+
if (value == Status.CONNECTED) get_packages_versions()
5857
})
5958
6059
await get_packages_versions()

components/RemoteRenderingView.vue

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@
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 viewer_store = use_viewer_store()
29-
const { client, is_running, picking_mode } = storeToRefs(viewer_store)
30-
3130
const viewer = ref(null)
3231
const { width, height } = useElementSize(viewer)
3332
3433
const { width: windowWidth, height: windowHeight } = useWindowSize()
3534
3635
function get_x_y(event) {
37-
if (picking_mode.value === true) {
36+
if (viewer_store.picking_mode.value === true) {
3837
const { offsetX, offsetY } = event
3938
viewer_store.set_picked_point(offsetX, offsetY)
4039
viewer_call({
@@ -70,7 +69,7 @@
7069
resize()
7170
})
7271
73-
watch(picking_mode, (value) => {
72+
watch(viewer_store.picking_mode, (value) => {
7473
const cursor = value ? "crosshair" : "pointer"
7574
view.getCanvasView().setCursor(cursor)
7675
})
@@ -79,7 +78,7 @@
7978
resize()
8079
})
8180
82-
watch(client, () => {
81+
watch(viewer_store.client, () => {
8382
connect()
8483
})
8584
@@ -91,10 +90,10 @@
9190
})
9291
9392
function connect() {
94-
if (!is_running.value) {
93+
if (!viewer_store.status !== Status.CONNECTED) {
9594
return
9695
}
97-
const session = client.value.getConnection().getSession()
96+
const session = viewer_store.client.value.getConnection().getSession()
9897
view.setSession(session)
9998
view.setViewId(viewId.value)
10099
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: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
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: () => ({
67
ID: useStorage("ID", ""),
78
is_captcha_validated: false,
8-
is_connexion_launched: false,
9+
status: Status.NOT_CREATED,
910
}),
1011
getters: {
1112
is_cloud() {
@@ -34,47 +35,53 @@ export const use_infra_store = defineStore("infra", {
3435
"/createbackend"
3536
return url
3637
},
37-
is_running() {
38-
return use_geode_store().is_running && use_viewer_store().is_running
38+
microservices_connected() {
39+
return (
40+
use_geode_store().status == Status.CONNECTED &&
41+
use_viewer_store().status == Status.CONNECTED
42+
)
3943
},
40-
is_busy() {
44+
microservices_busy() {
4145
return use_geode_store().is_busy || use_viewer_store().is_busy
4246
},
4347
},
4448
actions: {
45-
async create_connexion() {
46-
if (this.is_connexion_launched) {
47-
return
48-
}
49-
this.is_connexion_launched = true
50-
return this.create_backend()
51-
},
5249
async create_backend() {
53-
const geode_store = use_geode_store()
54-
const viewer_store = use_viewer_store()
55-
const feedback_store = use_feedback_store()
56-
57-
if (isElectron()) {
58-
const back_port = await window.electronAPI.run_back(geode_store.port)
59-
geode_store.$patch({ default_local_port: back_port })
60-
const viewer_port = await window.electronAPI.run_viewer(
61-
viewer_store.port,
62-
)
63-
viewer_store.$patch({ default_local_port: viewer_port })
64-
} else {
65-
const { data, error } = await useFetch(this.lambda_url, {
66-
method: "POST",
67-
})
68-
if (data.value !== null) {
50+
if (this.status === Status.CREATED) return
51+
navigator.locks.request("infra.create_backend", async (lock) => {
52+
this.status = Status.CREATING
53+
if (this.status === Status.CREATED) return
54+
console.log("LOCK GRANTED !", lock)
55+
const geode_store = use_geode_store()
56+
const viewer_store = use_viewer_store()
57+
const feedback_store = use_feedback_store()
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 (error.value || !data.value) {
70+
this.status = Status.NOT_CREATED
71+
feedback_store.server_error = true
72+
return
73+
}
6974
this.ID = data.value.ID
7075
localStorage.setItem("ID", data.value.ID)
71-
} else {
72-
feedback_store.server_error = true
73-
return
7476
}
75-
}
76-
geode_store.$patch({ is_running: true })
77-
return geode_store.ping_task()
77+
this.status = Status.CREATED
78+
return this.create_connection()
79+
})
80+
},
81+
async create_connection() {
82+
await use_viewer_store().ws_connect()
83+
await use_geode_store().do_ping()
84+
return
7885
},
7986
},
8087
})

0 commit comments

Comments
 (0)