Skip to content

Commit 84a3df9

Browse files
2 parents 9a32459 + ea58d5f commit 84a3df9

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

components/FileUploader.vue

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,26 @@
22
<v-row>
33
<v-col class="pa-0">
44
<v-file-input
5-
v-model="files"
6-
:multiple="multiple"
5+
v-model="internal_files"
6+
:multiple="props.multiple"
77
:label="label"
8-
:accept="accept"
8+
:accept="props.accept"
99
:rules="[(value) => !!value || 'The file is mandatory']"
1010
color="primary"
11+
:hide-input="props.mini"
12+
:hide-details="props.mini"
1113
chips
1214
counter
1315
show-size
1416
@click:clear="clear()"
1517
/>
1618
</v-col>
1719
</v-row>
18-
<v-row>
20+
<v-row v-if="!props.auto_upload">
1921
<v-col cols="auto">
2022
<v-btn
2123
color="primary"
22-
:disabled="!files.length && !files_uploaded"
24+
:disabled="!internal_files.length && !files_uploaded"
2325
:loading="loading"
2426
class="pa-2"
2527
@click="upload_files"
@@ -41,14 +43,13 @@
4143
accept: { type: String, required: true },
4244
files: { type: Array, required: false, default: [] },
4345
auto_upload: { type: Boolean, required: false, default: false },
46+
mini: { type: Boolean, required: false, default: false },
4447
})
4548
46-
const { multiple, accept } = toRefs(props)
47-
48-
const label = multiple
49+
const label = props.multiple
4950
? "Please select file(s) to import"
5051
: "Please select a file to import"
51-
const files = ref([])
52+
const internal_files = ref([])
5253
const loading = ref(false)
5354
const files_uploaded = ref(false)
5455
@@ -57,7 +58,7 @@
5758
async function upload_files() {
5859
toggle_loading()
5960
var promise_array = []
60-
for (const file of files.value) {
61+
for (const file of internal_files.value) {
6162
const promise = new Promise((resolve, reject) => {
6263
upload_file(
6364
{ route: schema.$id, file },
@@ -78,23 +79,35 @@
7879
}
7980
await Promise.all(promise_array)
8081
files_uploaded.value = true
81-
emit("files_uploaded", files.value)
82+
emit("files_uploaded", internal_files.value)
8283
toggle_loading()
8384
}
8485
8586
if (props.files.length) {
86-
files.value = props.files
87+
internal_files.value = props.files
8788
if (props.auto_upload) {
8889
upload_files()
8990
}
9091
}
9192
9293
function clear() {
93-
files.value = []
94-
emit("files_uploaded", files.value)
94+
internal_files.value = []
95+
emit("files_uploaded", internal_files.value)
9596
}
9697
97-
watch(files, () => {
98+
watch(internal_files, (value) => {
9899
files_uploaded.value = false
100+
if (props.auto_upload) {
101+
if (props.multiple.value == false) {
102+
internal_files.value = [value]
103+
}
104+
upload_files()
105+
}
99106
})
100107
</script>
108+
109+
<style scoped>
110+
.div.v-input__details {
111+
display: none;
112+
}
113+
</style>

test/components/FileSelector.nuxt.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("FileSelector.vue", async () => {
4141
global: {
4242
plugins: [vuetify, pinia],
4343
},
44-
props: { multiple: false, supported_feature: "test" },
44+
props: { multiple: false, supported_feature: "test", auto_upload: false },
4545
})
4646

4747
const file_uploader = wrapper.findComponent(FileUploader)

0 commit comments

Comments
 (0)