Skip to content

Commit 6a09a61

Browse files
committed
geode store & feedback corrected
1 parent cd6c428 commit 6a09a61

File tree

2 files changed

+85
-73
lines changed

2 files changed

+85
-73
lines changed

stores/feedback.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { v4 as uuidv4 } from "uuid"
22

33

4-
export const use_feedback_store = define("feedback", () => {
4+
export const use_feedback_store = defineStore("feedback", () => {
55
const feedbacks = ref([]);
66
const server_error = ref(false);
77
const feedbacks_timeout_miliseconds = ref(5000);

stores/geode.js

Lines changed: 84 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,91 @@
11
import back_schemas from "@geode/opengeodeweb-back/schemas.json"
22
import Status from "@ogw_f/utils/status.js"
33

4-
export const use_geode_store = defineStore("geode", {
5-
state: () => ({
6-
default_local_port: "5000",
7-
request_counter: 0,
8-
status: Status.NOT_CONNECTED,
9-
}),
10-
getters: {
11-
protocol() {
12-
if (use_infra_store().is_cloud) {
13-
return "https"
14-
}
15-
return "http"
16-
},
17-
port() {
18-
if (use_infra_store().is_cloud) {
19-
return "443"
4+
export const use_geode_store = defineStore("geode", () => {
5+
const default_local_port = "5000";
6+
const request_counter = ref(0);
7+
const status = ref(Status.NOT_CONNECTED);
8+
9+
function getProtocol() {
10+
if (use_infra_store().is_cloud) {
11+
return "https"
12+
}
13+
return "http"
14+
}
15+
16+
function getPort() {
17+
if (use_infra_store().is_cloud) {
18+
return "443"
19+
}
20+
return default_local_port
21+
}
22+
23+
function getBaseUrl() {
24+
const infra_store = use_infra_store()
25+
let geode_url = `${getProtocol()}://${infra_store.domain_name}:${getPort()}`
26+
if (infra_store.is_cloud) {
27+
if (infra_store.ID == "") {
28+
throw new Error("ID must not be empty in cloud mode")
2029
}
21-
return this.default_local_port
22-
},
23-
base_url() {
24-
const infra_store = use_infra_store()
25-
let geode_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
26-
if (infra_store.is_cloud) {
27-
if (infra_store.ID == "") {
28-
throw new Error("ID must not be empty in cloud mode")
29-
}
30-
geode_url += `/${infra_store.ID}/geode`
30+
geode_url += `/${infra_store.ID}/geode`
31+
}
32+
return geode_url
33+
}
34+
35+
const is_busy = computed(() => {
36+
return request_counter.value > 0
37+
});
38+
39+
function ping_task() {
40+
setInterval(() => {
41+
if (status.value == Status.CONNECTED) {
42+
do_ping()
3143
}
32-
return geode_url
33-
},
34-
is_busy() {
35-
return this.request_counter > 0
36-
},
37-
},
38-
actions: {
39-
ping_task() {
40-
setInterval(() => {
41-
if (this.status == Status.CONNECTED) {
42-
this.do_ping()
44+
}, 10 * 1000)
45+
}
46+
47+
async function do_ping() {
48+
const geode_store = this
49+
const feedback_store = use_feedback_store()
50+
return useFetch(back_schemas.opengeodeweb_back.ping.$id, {
51+
baseURL: getBaseUrl(),
52+
method: back_schemas.opengeodeweb_back.ping.methods[0],
53+
body: {},
54+
onRequestError({ error }) {
55+
feedback_store.server_error = true
56+
status.value = Status.NOT_CONNECTED
57+
},
58+
onResponse({ response }) {
59+
if (response.ok) {
60+
feedback_store.server_error = false
61+
status.value = Status.CONNECTED
4362
}
44-
}, 10 * 1000)
45-
},
46-
do_ping() {
47-
const geode_store = this
48-
const feedback_store = use_feedback_store()
49-
return useFetch(back_schemas.opengeodeweb_back.ping.$id, {
50-
baseURL: this.base_url,
51-
method: back_schemas.opengeodeweb_back.ping.methods[0],
52-
body: {},
53-
onRequestError({ error }) {
54-
feedback_store.server_error = true
55-
geode_store.status = Status.NOT_CONNECTED
56-
},
57-
onResponse({ response }) {
58-
if (response.ok) {
59-
feedback_store.server_error = false
60-
geode_store.status = Status.CONNECTED
61-
}
62-
},
63-
onResponseError({ response }) {
64-
feedback_store.server_error = true
65-
geode_store.status = Status.NOT_CONNECTED
66-
},
67-
})
68-
},
69-
start_request() {
70-
this.request_counter++
71-
},
72-
stop_request() {
73-
this.request_counter--
74-
},
75-
},
76-
share: {
77-
omit: ["status"],
78-
},
63+
},
64+
onResponseError({ response }) {
65+
feedback_store.server_error = true
66+
status.value = Status.NOT_CONNECTED
67+
},
68+
})
69+
}
70+
71+
function start_request() {
72+
request_counter.value++
73+
}
74+
75+
function stop_request() {
76+
request_counter.value--
77+
}
78+
79+
return {
80+
request_counter,
81+
status,
82+
getProtocol,
83+
getPort,
84+
getBaseUrl,
85+
is_busy,
86+
ping_task,
87+
do_ping,
88+
start_request,
89+
stop_request,
90+
}
7991
})

0 commit comments

Comments
 (0)