Skip to content

Commit 3cb3a07

Browse files
Merge pull request #137 from Geode-solutions/next
Next
2 parents 60807b4 + 652fa23 commit 3cb3a07

34 files changed

+948
-479
lines changed

components/Errors/Banner.vue renamed to components/FeedBack/ErrorBanner.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<v-banner
3-
v-if="server_error"
3+
v-if="feedback_store.server_error"
44
elevation="2"
5-
style="background-color: grey; z-index: 100"
5+
style="background-color: grey; z-index: 9999"
66
position="fixed"
77
>
88
<v-row>
@@ -33,7 +33,7 @@
3333
size="20"
3434
color="grey"
3535
class=".align-center"
36-
@click="errors_store.delete_server_error()"
36+
@click="feedback_store.delete_server_error()"
3737
>
3838
<v-icon icon="mdi-close" size="20" color="white" />
3939
</v-btn>
@@ -43,8 +43,7 @@
4343
</template>
4444

4545
<script setup>
46-
const errors_store = use_errors_store()
47-
const { server_error } = storeToRefs(errors_store)
46+
const feedback_store = use_feedback_store()
4847
4948
function reload() {
5049
window.location.reload()

components/Errors/Snackers.vue renamed to components/FeedBack/Snackers.vue

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<template>
22
<v-snackbar
3-
v-for="(error, index) in errors"
4-
:key="index"
3+
v-for="(feedback, index) in feedback_store.feedbacks"
4+
:key="feedback"
55
v-model="show"
66
:style="{ 'margin-bottom': calc_margin(index) }"
7-
color="error"
7+
:color="feedback.type"
88
location="bottom right"
99
transition="slide-x-reverse-transition"
10-
max-width="30%"
10+
max-width="200px"
1111
height="20px"
1212
>
1313
<v-row dense class="flex-nowrap">
1414
<v-col cols="auto">
15-
<v-tooltip location="left">
15+
<v-tooltip v-if="feedback.type === 'error'" location="left">
1616
<span>
17-
error: {{ error.code }} {{ error.name }}<br />
18-
ressource: {{ error.route }}
17+
error: {{ feedback.code }} {{ feedback.name }}<br />
18+
ressource: {{ feedback.route }}
1919
<br />
2020
</span>
2121
<template #activator="{ props }">
@@ -24,16 +24,21 @@
2424
</v-icon>
2525
</template>
2626
</v-tooltip>
27+
<v-tooltip v-else-if="feedback.type === 'success'" location="left">
28+
<v-icon color="white" class="justify-right">
29+
mdi-check-circle-outline
30+
</v-icon>
31+
</v-tooltip>
2732
</v-col>
2833
<v-col cols="9" class="text-no-wrap overflow-hidden">
2934
<v-tooltip location="top">
3035
<span>
31-
{{ error.description }}
36+
{{ feedback.description }}
3237
<br />
3338
</span>
3439
<template #activator="{ props }">
3540
<div v-bind="props">
36-
{{ error.description }}
41+
{{ feedback.description }}
3742
</div>
3843
</template>
3944
</v-tooltip>
@@ -44,8 +49,8 @@
4449
icon
4550
variant="flat"
4651
size="20"
47-
color="error"
48-
@click="errors_store.delete_error(index)"
52+
:color="feedback.type"
53+
@click="feedback_store.delete_feedback(index)"
4954
>
5055
<v-icon icon="mdi-close" size="20" color="white" />
5156
</v-btn>
@@ -55,9 +60,7 @@
5560
</template>
5661

5762
<script setup>
58-
const errors_store = use_errors_store()
59-
const { errors } = storeToRefs(errors_store)
60-
63+
const feedback_store = use_feedback_store()
6164
const show = true
6265
6366
function calc_margin(index) {

components/FileSelector.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<FetchingData v-if="loading" />
33
<FileUploader
44
v-else
5-
v-bind="{ multiple, accept }"
5+
v-bind="{ multiple, accept, files }"
66
@files_uploaded="files_uploaded_event"
77
/>
88
</template>
@@ -20,6 +20,7 @@
2020
const props = defineProps({
2121
multiple: { type: Boolean, required: true },
2222
supported_feature: { type: String, required: false, default: null },
23+
files: { type: Array, required: false, default: [] },
2324
})
2425
2526
const { multiple, supported_feature } = props
@@ -51,6 +52,5 @@
5152
)
5253
toggle_loading()
5354
}
54-
5555
await get_allowed_files()
5656
</script>

components/FileUploader.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
const props = defineProps({
4040
multiple: { type: Boolean, required: true },
4141
accept: { type: String, required: true },
42+
files: { type: Array, required: false, default: [] },
4243
})
44+
4345
const { multiple, accept } = toRefs(props)
4446
4547
const label = multiple ? "Please select file(s)" : "Please select a file"
@@ -77,6 +79,11 @@
7779
toggle_loading()
7880
}
7981
82+
if (props.files.length) {
83+
files.value = props.files
84+
upload_files()
85+
}
86+
8087
function clear() {
8188
files.value = []
8289
emit("files_uploaded", files.value)

composables/api_fetch.js

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@ export function api_fetch(
44
{ schema, params },
55
{ request_error_function, response_function, response_error_function } = {},
66
) {
7-
const errors_store = use_errors_store()
7+
const feedback_store = use_feedback_store()
88
const geode_store = use_geode_store()
99

1010
const body = params || {}
1111

1212
const { valid, error } = validate_schema(schema, body)
1313

1414
if (!valid) {
15-
errors_store.add_error({
16-
code: 400,
17-
route: schema.$id,
18-
name: "Bad request",
19-
description: error,
20-
})
15+
feedback_store.add_error(400, schema.$id, "Bad request", error)
2116
throw new Error(schema.$id.concat(": ", error))
2217
}
2318

@@ -34,41 +29,46 @@ export function api_fetch(
3429
if (schema.max_retry) {
3530
request_options.max_retry = schema.max_retry
3631
}
37-
return useFetch(schema.$id, {
38-
baseURL: geode_store.base_url,
39-
...request_options,
40-
onRequestError({ error }) {
41-
geode_store.stop_request()
42-
errors_store.add_error({
43-
code: error.code,
44-
route: schema.$id,
45-
name: error.message,
46-
description: error.stack,
47-
})
48-
if (request_error_function) {
49-
request_error_function(error)
50-
}
51-
},
52-
onResponse({ response }) {
53-
if (response.ok) {
54-
geode_store.stop_request()
55-
if (response_function) {
56-
response_function(response)
32+
return new Promise((resolve, reject) => {
33+
useFetch(schema.$id, {
34+
baseURL: geode_store.base_url,
35+
...request_options,
36+
async onRequestError({ error }) {
37+
await geode_store.stop_request()
38+
await feedback_store.add_error(
39+
error.code,
40+
schema.$id,
41+
error.message,
42+
error.stack,
43+
)
44+
if (request_error_function) {
45+
await request_error_function(error)
46+
}
47+
reject(error)
48+
},
49+
async onResponse({ response }) {
50+
if (response.ok) {
51+
await geode_store.stop_request()
52+
if (response_function) {
53+
await response_function(response)
54+
}
55+
resolve(response)
5756
}
58-
}
59-
},
60-
onResponseError({ response }) {
61-
geode_store.stop_request()
62-
errors_store.add_error({
63-
code: response.status,
64-
route: schema.$id,
65-
name: response._data.name,
66-
description: response._data.description,
67-
})
68-
if (response_error_function) {
69-
response_error_function(response)
70-
}
71-
},
57+
},
58+
async onResponseError({ response }) {
59+
await geode_store.stop_request()
60+
await feedback_store.add_error(
61+
response.status,
62+
schema.$id,
63+
response._data.name,
64+
response._data.description,
65+
)
66+
if (response_error_function) {
67+
await response_error_function(response)
68+
}
69+
reject(response)
70+
},
71+
})
7272
})
7373
}
7474

composables/upload_file.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export async function upload_file(
22
{ route, file },
33
{ request_error_function, response_function, response_error_function } = {},
44
) {
5-
const errors_store = use_errors_store()
5+
const feedback_store = use_feedback_store()
66
const geode_store = use_geode_store()
77
if (!(file instanceof File)) {
88
throw new Error("file must be a instance of File")
@@ -22,12 +22,7 @@ export async function upload_file(
2222
...request_options,
2323
onRequestError({ error }) {
2424
geode_store.stop_request()
25-
errors_store.add_error({
26-
code: error.code,
27-
route: route,
28-
name: error.message,
29-
description: error.stack,
30-
})
25+
feedback_store.add_error(error.code, route, error.message, error.stack)
3126
if (request_error_function) {
3227
request_error_function(error)
3328
}
@@ -42,12 +37,12 @@ export async function upload_file(
4237
},
4338
onResponseError({ response }) {
4439
geode_store.stop_request()
45-
errors_store.add_error({
46-
code: response.status,
47-
route: route,
48-
name: response._data.name,
49-
description: response._data.description,
50-
})
40+
feedback_store.add_error(
41+
response.status,
42+
route,
43+
response._data.name,
44+
response._data.description,
45+
)
5146
if (response_error_function) {
5247
response_error_function(response)
5348
}

composables/viewer_call.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@ export function viewer_call(
22
{ schema, params = {} },
33
{ request_error_function, response_function, response_error_function } = {},
44
) {
5-
const errors_store = use_errors_store()
5+
const feedback_store = use_feedback_store()
66
const viewer_store = use_viewer_store()
77

88
const { valid, error } = validate_schema(schema, params)
99

1010
if (!valid) {
11-
errors_store.add_error({
12-
code: 400,
13-
route: schema.route,
14-
name: "Bad request",
15-
description: error,
16-
})
11+
feedback_store.add_error(400, schema.route, "Bad request", error)
1712
throw new Error(schema.route.concat(": ", error))
1813
}
1914

@@ -41,12 +36,12 @@ export function viewer_call(
4136
},
4237
)
4338
.catch((error) => {
44-
errors_store.add_error({
45-
code: error.code,
46-
route: schema.route,
47-
name: error.message,
48-
description: error.message,
49-
})
39+
feedback_store.add_error(
40+
error.code,
41+
schema.route,
42+
error.message,
43+
error.message,
44+
)
5045
if (response_error_function) {
5146
response_error_function(error)
5247
}

nuxt.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export default defineNuxtConfig({
99
},
1010
},
1111

12-
modules: [["@pinia/nuxt", { autoImports: ["defineStore"] }], "@vueuse/nuxt"],
12+
modules: [
13+
["@pinia/nuxt", { autoImports: ["defineStore", "storeToRefs"] }],
14+
"@vueuse/nuxt",
15+
],
1316
imports: {
1417
dirs: ["stores"],
1518
},

0 commit comments

Comments
 (0)