|
1 | 1 | <template> |
2 | 2 | <v-row> |
3 | 3 | <v-col class="pa-0"> |
4 | | - <v-file-input |
5 | | - v-model="internal_files" |
6 | | - :multiple="props.multiple" |
7 | | - :label="label" |
8 | | - :accept="props.accept" |
9 | | - :rules="[(value) => !!value || 'The file is mandatory']" |
10 | | - color="primary" |
11 | | - :hide-input="props.mini" |
12 | | - :hide-details="props.mini" |
13 | | - chips |
14 | | - counter |
15 | | - show-size |
16 | | - @click:clear="clear()" |
17 | | - /> |
| 4 | + <v-file-input v-model="internal_files" :multiple="props.multiple" :label="label" :accept="props.accept" |
| 5 | + :rules="[(value) => !!value || 'The file is mandatory']" color="primary" :hide-input="props.mini" |
| 6 | + :hide-details="props.mini" chips counter show-size @click:clear="clear()" /> |
18 | 7 | </v-col> |
19 | 8 | </v-row> |
20 | 9 | <v-row v-if="!props.auto_upload"> |
21 | 10 | <v-col cols="auto"> |
22 | | - <v-btn |
23 | | - color="primary" |
24 | | - :disabled="!internal_files.length && !files_uploaded" |
25 | | - :loading="loading" |
26 | | - class="pa-2" |
27 | | - @click="upload_files" |
28 | | - > |
| 11 | + <v-btn color="primary" :disabled="!internal_files.length && !files_uploaded" :loading="loading" class="pa-2" |
| 12 | + @click="upload_files"> |
29 | 13 | Upload file(s) |
30 | 14 | </v-btn> |
31 | 15 | </v-col> |
32 | 16 | </v-row> |
33 | 17 | </template> |
34 | 18 |
|
35 | 19 | <script setup> |
36 | | - import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" |
37 | | - const schema = schemas.opengeodeweb_back.upload_file |
| 20 | +import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json" |
| 21 | +const schema = schemas.opengeodeweb_back.upload_file |
38 | 22 |
|
39 | | - const emit = defineEmits(["files_uploaded", "decrement_step"]) |
| 23 | +const emit = defineEmits(["files_uploaded", "decrement_step"]) |
40 | 24 |
|
41 | | - const props = defineProps({ |
42 | | - multiple: { type: Boolean, required: true }, |
43 | | - accept: { type: String, required: true }, |
44 | | - files: { type: Array, required: false, default: [] }, |
45 | | - auto_upload: { type: Boolean, required: false, default: false }, |
46 | | - mini: { type: Boolean, required: false, default: false }, |
47 | | - }) |
| 25 | +const props = defineProps({ |
| 26 | + multiple: { type: Boolean, required: true }, |
| 27 | + accept: { type: String, required: true }, |
| 28 | + files: { type: Array, required: false, default: [] }, |
| 29 | + auto_upload: { type: Boolean, required: false, default: false }, |
| 30 | + mini: { type: Boolean, required: false, default: false }, |
| 31 | +}) |
48 | 32 |
|
49 | | - const label = props.multiple |
50 | | - ? "Please select file(s) to import" |
51 | | - : "Please select a file to import" |
52 | | - const internal_files = ref(props.files) |
53 | | - const loading = ref(false) |
54 | | - const files_uploaded = ref(false) |
| 33 | +const label = props.multiple |
| 34 | + ? "Please select file(s) to import" |
| 35 | + : "Please select a file to import" |
| 36 | +const internal_files = ref(props.files) |
| 37 | +const loading = ref(false) |
| 38 | +const files_uploaded = ref(false) |
55 | 39 |
|
56 | | - const toggle_loading = useToggle(loading) |
| 40 | +const toggle_loading = useToggle(loading) |
57 | 41 |
|
58 | | - async function upload_files() { |
59 | | - toggle_loading() |
60 | | - var promise_array = [] |
61 | | - for (const file of internal_files.value) { |
62 | | - const promise = new Promise((resolve, reject) => { |
63 | | - upload_file( |
64 | | - { route: schema.$id, file }, |
65 | | - { |
66 | | - request_error_function: () => { |
67 | | - reject() |
68 | | - }, |
69 | | - response_function: () => { |
70 | | - resolve() |
71 | | - }, |
72 | | - response_error_function: () => { |
73 | | - reject() |
74 | | - }, |
| 42 | +async function upload_files() { |
| 43 | + toggle_loading() |
| 44 | + var promise_array = [] |
| 45 | + for (const file of internal_files.value) { |
| 46 | + const promise = new Promise((resolve, reject) => { |
| 47 | + upload_file( |
| 48 | + { route: schema.$id, file }, |
| 49 | + { |
| 50 | + request_error_function: () => { |
| 51 | + reject() |
75 | 52 | }, |
76 | | - ) |
77 | | - }) |
78 | | - promise_array.push(promise) |
79 | | - } |
80 | | - await Promise.all(promise_array) |
81 | | - files_uploaded.value = true |
82 | | - emit("files_uploaded", internal_files.value) |
83 | | -
|
84 | | - toggle_loading() |
| 53 | + response_function: () => { |
| 54 | + resolve() |
| 55 | + }, |
| 56 | + response_error_function: () => { |
| 57 | + reject() |
| 58 | + }, |
| 59 | + }, |
| 60 | + ) |
| 61 | + }) |
| 62 | + promise_array.push(promise) |
85 | 63 | } |
| 64 | + await Promise.all(promise_array) |
| 65 | + files_uploaded.value = true |
| 66 | + emit("files_uploaded", internal_files.value) |
86 | 67 |
|
87 | | - if (props.files.length) { |
88 | | - internal_files.value = props.files |
89 | | - if (props.auto_upload) { |
90 | | - upload_files() |
91 | | - } |
92 | | - } |
| 68 | + toggle_loading() |
| 69 | +} |
93 | 70 |
|
94 | | - function clear() { |
95 | | - internal_files.value = [] |
96 | | - emit("files_uploaded", internal_files.value) |
| 71 | +if (props.files.length) { |
| 72 | + internal_files.value = props.files |
| 73 | + if (props.auto_upload) { |
| 74 | + upload_files() |
97 | 75 | } |
| 76 | +} |
| 77 | +
|
| 78 | +function clear() { |
| 79 | + internal_files.value = [] |
| 80 | + emit("files_uploaded", internal_files.value) |
| 81 | +} |
98 | 82 |
|
99 | | - watch( |
100 | | - () => props.files, |
101 | | - (newVal) => { |
102 | | - internal_files.value = newVal |
103 | | - }, |
104 | | - { deep: true }, |
105 | | - ) |
| 83 | +watch( |
| 84 | + () => props.files, |
| 85 | + (newVal) => { |
| 86 | + internal_files.value = newVal |
| 87 | + }, |
| 88 | + { deep: true }, |
| 89 | +) |
106 | 90 |
|
107 | | - watch(internal_files, (value) => { |
108 | | - files_uploaded.value = false |
109 | | - if (props.auto_upload) { |
110 | | - if (props.multiple.value == false) { |
111 | | - internal_files.value = [value] |
112 | | - } |
113 | | - upload_files() |
| 91 | +watch(internal_files, (value) => { |
| 92 | + files_uploaded.value = false |
| 93 | + if (props.auto_upload) { |
| 94 | + if (props.multiple.value == false) { |
| 95 | + internal_files.value = [value] |
114 | 96 | } |
115 | | - }) |
| 97 | + upload_files() |
| 98 | + } |
| 99 | +}) |
116 | 100 | </script> |
117 | 101 |
|
118 | 102 | <style scoped> |
119 | | - .div.v-input__details { |
120 | | - display: none; |
121 | | - } |
| 103 | +.div.v-input__details { |
| 104 | + display: none; |
| 105 | +} |
122 | 106 | </style> |
0 commit comments