Skip to content

Commit 15d2217

Browse files
Merge pull request #62 from Geode-solutions/feat/is_saveable
Feat/is saveable
2 parents 13dc582 + 7b211d6 commit 15d2217

File tree

9 files changed

+5012
-3254
lines changed

9 files changed

+5012
-3254
lines changed

assets/schemas/ExtensionSelector.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
"properties": {
66
"input_geode_object": {
77
"type": "string"
8+
},
9+
"filename": {
10+
"type": "string"
811
}
912
},
10-
"required": ["input_geode_object"],
13+
"required": ["input_geode_object", "filename"],
1114
"additionalProperties": false
1215
}

components/ExtensionSelector.vue

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
11
<template>
22
<FetchingData v-if="loading" />
33
<v-row
4-
v-for="item in geode_objects_and_output_extensions"
5-
:key="item.geode_object"
4+
v-for="(
5+
output_extensions, output_geode_object
6+
) in geode_objects_and_output_extensions"
7+
:key="output_geode_object"
68
class="justify-left"
79
>
810
<v-card class="card ma-2 pa-2" width="100%">
9-
<v-tooltip :text="`Export as a ${item.geode_object}`" location="bottom">
11+
<v-tooltip :text="`Export as a ${output_geode_object}`" location="bottom">
1012
<template v-slot:activator="{ props }">
1113
<v-card-title v-bind="props">
12-
{{ item.geode_object }}
14+
{{ output_geode_object }}
1315
</v-card-title>
1416
</template>
1517
</v-tooltip>
1618
<v-card-text>
1719
<v-row>
1820
<v-col
19-
v-for="output in item.outputs"
20-
:key="output.extension"
21+
v-for="(extension, output_extension) in output_extensions"
22+
:key="output_extension"
2123
cols="auto"
2224
class="pa-0"
2325
>
2426
<v-tooltip
25-
:disabled="output.is_saveable"
27+
:disabled="extension.is_saveable"
2628
text="Data not saveable with this file extension"
2729
location="bottom"
2830
>
2931
<template v-slot:activator="{ props }">
3032
<span v-bind="props">
3133
<v-card
3234
class="card ma-2"
33-
:color="output.is_saveable ? 'primary' : 'grey'"
35+
:color="extension.is_saveable ? 'primary' : 'grey'"
3436
hover
35-
@click="set_variables(item.geode_object, output.extension)"
36-
:disabled="!output.is_saveable"
37+
@click="
38+
set_variables(output_geode_object, output_extension)
39+
"
40+
:disabled="!extension.is_saveable"
3741
>
3842
<v-card-title align="center">
39-
{{ output.extension }}
43+
{{ output_extension }}
4044
</v-card-title>
4145
</v-card>
4246
</span>
@@ -50,6 +54,7 @@
5054
</template>
5155

5256
<script setup>
57+
import _ from "lodash"
5358
import schema from "@/assets/schemas/ExtensionSelector.json"
5459
5560
const emit = defineEmits([
@@ -60,33 +65,65 @@
6065
6166
const props = defineProps({
6267
input_geode_object: { type: String, required: true },
68+
filenames: { type: Array, required: true },
6369
})
64-
const { input_geode_object } = props
65-
66-
const geode_objects_and_output_extensions = ref([])
70+
const { input_geode_object, filenames } = props
71+
const geode_objects_and_output_extensions = ref({})
6772
const loading = ref(false)
6873
6974
const toggle_loading = useToggle(loading)
7075
7176
async function get_output_file_extensions() {
7277
toggle_loading()
73-
const params = { input_geode_object }
74-
await api_fetch(
75-
{ schema, params },
76-
{
77-
response_function: (response) => {
78-
geode_objects_and_output_extensions.value =
79-
response._data.geode_objects_and_output_extensions
80-
},
81-
},
82-
)
78+
geode_objects_and_output_extensions.vaue = {}
79+
var promise_array = []
80+
for (const filename of filenames) {
81+
const params = { input_geode_object, filename }
82+
const promise = new Promise((resolve, reject) => {
83+
api_fetch(
84+
{ schema, params },
85+
{
86+
request_error_function: () => {
87+
reject()
88+
},
89+
response_function: (response) => {
90+
const data = response._data.geode_objects_and_output_extensions
91+
if (_.isEmpty(geode_objects_and_output_extensions.value)) {
92+
geode_objects_and_output_extensions.value = data
93+
} else {
94+
for (const [geode_object, geode_object_value] of Object.entries(
95+
data,
96+
)) {
97+
for (const [
98+
output_extension,
99+
output_extension_value,
100+
] of Object.entries(geode_object_value)) {
101+
if (!output_extension_value["is_saveable"]) {
102+
geode_objects_and_output_extensions.value[geode_object][
103+
output_extension
104+
]["is_saveable"] = false
105+
}
106+
}
107+
}
108+
}
109+
resolve()
110+
},
111+
response_error_function: () => {
112+
reject()
113+
},
114+
},
115+
)
116+
})
117+
promise_array.push(promise)
118+
}
119+
await Promise.all(promise_array)
83120
toggle_loading()
84121
}
85122
86-
function set_variables(geode_object, output_extension) {
87-
if (geode_object != "" && output_extension != "") {
123+
function set_variables(output_geode_object, output_extension) {
124+
if (output_geode_object != "" && output_extension != "") {
88125
const keys_values_object = {
89-
output_geode_object: geode_object,
126+
output_geode_object,
90127
output_extension,
91128
}
92129
emit("update_values", keys_values_object)

components/FileUploader.vue

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,29 @@
4949
5050
async function upload_files() {
5151
toggle_loading()
52-
await upload_file(
53-
{ route, files: multiple ? files.value : [files.value[0]] },
54-
{
55-
response_function: () => {
56-
files_uploaded.value = true
57-
emit("files_uploaded", files.value)
58-
},
59-
},
60-
)
52+
var promise_array = []
53+
for (const file of files.value) {
54+
const promise = new Promise((resolve, reject) => {
55+
upload_file(
56+
{ route, file },
57+
{
58+
request_error_function: () => {
59+
reject()
60+
},
61+
response_function: () => {
62+
resolve()
63+
},
64+
response_error_function: () => {
65+
reject()
66+
},
67+
},
68+
)
69+
})
70+
promise_array.push(promise)
71+
}
72+
await Promise.all(promise_array)
73+
files_uploaded.value = true
74+
emit("files_uploaded", files.value)
6175
toggle_loading()
6276
}
6377

components/MissingFilesSelector.vue

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454
const props = defineProps({
5555
multiple: { type: Boolean, required: true },
5656
input_geode_object: { type: String, required: true },
57-
files: { type: Array, required: true },
57+
filenames: { type: Array, required: true },
5858
route: { type: String, required: true },
5959
})
6060
61-
const { multiple, input_geode_object, files, route } = props
61+
const { multiple, input_geode_object, filenames, route } = props
6262
6363
const accept = ref("")
6464
const loading = ref(false)
@@ -73,39 +73,51 @@
7373
}
7474
7575
async function missing_files() {
76+
toggle_loading()
7677
has_missing_files.value = false
7778
mandatory_files.value = []
7879
additional_files.value = []
79-
toggle_loading()
80-
for (const file of files) {
81-
const params = { input_geode_object, filename: file.name }
82-
await api_fetch(
83-
{ schema, params },
84-
{
85-
response_function: (response) => {
86-
has_missing_files.value = response._data.has_missing_files
87-
mandatory_files.value = [].concat(
88-
mandatory_files.value,
89-
response._data.mandatory_files,
90-
)
91-
additional_files.value = [].concat(
92-
additional_files.value,
93-
response._data.additional_files,
94-
)
95-
const files_list = [].concat(
96-
mandatory_files.value,
97-
additional_files.value,
98-
)
99-
accept.value = files_list
100-
.map((filename) => "." + filename.split(".").pop())
101-
.join(",")
102-
if (!has_missing_files.value) {
103-
console.log("MISSING FILESSELECTOR increment_step")
104-
emit("increment_step")
105-
}
80+
var promise_array = []
81+
82+
for (const filename of filenames) {
83+
const params = { input_geode_object, filename }
84+
const promise = new Promise((resolve, reject) => {
85+
api_fetch(
86+
{ schema, params },
87+
{
88+
request_error_function: () => {
89+
reject()
90+
},
91+
response_function: (response) => {
92+
has_missing_files.value = response._data.has_missing_files
93+
? true
94+
: has_missing_files.value
95+
mandatory_files.value = [].concat(
96+
mandatory_files.value,
97+
response._data.mandatory_files,
98+
)
99+
additional_files.value = [].concat(
100+
additional_files.value,
101+
response._data.additional_files,
102+
)
103+
resolve()
104+
},
105+
response_error_function: () => {
106+
reject()
107+
},
106108
},
107-
},
108-
)
109+
)
110+
})
111+
promise_array.push(promise)
112+
}
113+
await Promise.all(promise_array)
114+
if (!has_missing_files.value) {
115+
emit("increment_step")
116+
} else {
117+
accept.value = []
118+
.concat(mandatory_files.value, additional_files.value)
119+
.map((filename) => "." + filename.split(".").pop())
120+
.join(",")
109121
}
110122
toggle_loading()
111123
}

components/ObjectSelector.vue

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,62 @@
3131
</template>
3232

3333
<script setup>
34+
import { toRaw } from "vue"
3435
import geode_objects from "@/assets/geode_objects"
3536
import schema from "@/assets/schemas/ObjectSelector.json"
3637
3738
const emit = defineEmits(["update_values", "increment_step"])
3839
3940
const props = defineProps({
40-
files: { type: Array, required: true },
41+
filenames: { type: Array, required: true },
4142
key: { type: String, required: false, default: null },
4243
})
4344
44-
const { files, key } = props
45+
const { filenames, key } = props
4546
4647
const loading = ref(false)
4748
const allowed_objects = ref([])
4849
4950
const toggle_loading = useToggle(loading)
5051
5152
async function get_allowed_objects() {
52-
const params = { filename: files[0].name, key }
5353
toggle_loading()
54-
await api_fetch(
55-
{ schema, params },
56-
{
57-
response_function: (response) => {
58-
allowed_objects.value = response._data.allowed_objects
59-
},
60-
},
61-
)
54+
allowed_objects.value = []
55+
var promise_array = []
56+
for (const filename of filenames) {
57+
const params = { filename, key }
58+
const promise = new Promise((resolve, reject) => {
59+
api_fetch(
60+
{ schema, params },
61+
{
62+
request_error_function: () => {
63+
reject()
64+
},
65+
response_function: (response) => {
66+
if (allowed_objects.value.length == 0) {
67+
allowed_objects.value = response._data.allowed_objects
68+
} else {
69+
allowed_objects.value = toRaw(allowed_objects.value).filter(
70+
(value) => response._data.allowed_objects.includes(value),
71+
)
72+
}
73+
resolve()
74+
},
75+
response_error_function: () => {
76+
reject()
77+
},
78+
},
79+
)
80+
})
81+
promise_array.push(promise)
82+
}
83+
await Promise.all(promise_array)
6284
toggle_loading()
6385
}
6486
65-
function set_geode_object(geode_object) {
66-
if (geode_object != "") {
67-
emit("update_values", { input_geode_object: geode_object })
87+
function set_geode_object(input_geode_object) {
88+
if (input_geode_object != "") {
89+
emit("update_values", { input_geode_object })
6890
emit("increment_step")
6991
}
7092
}

components/Step.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@
6363
}
6464
6565
function update_values_event(keys_values_object) {
66-
console.log("update_values_event", keys_values_object)
6766
for (const [key, value] of Object.entries(keys_values_object)) {
68-
console.log(key, value)
6967
stepper_tree[key] = value
7068
}
7169
}

composables/upload_file.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
export function upload_file(
2-
{ route, files },
2+
{ route, file },
33
{ request_error_function, response_function, response_error_function } = {},
44
) {
55
const errors_store = use_errors_store()
66
const geode_store = use_geode_store()
77

88
const body = new FormData()
9-
for (let i = 0; i < files.length; i++) {
10-
body.append("content", files[i])
11-
}
9+
body.append("file", file)
1210

1311
const request_options = {
1412
method: "PUT",

0 commit comments

Comments
 (0)