add spreadsheet download

pull/250/head
Pete Matsyburka 2 years ago
parent 014835f90d
commit 11bdc522cd

@ -160,52 +160,62 @@
</div> </div>
<div <div
v-else v-else
class="flex h-52 w-full"
@dragover.prevent
@drop.prevent="onDropFiles"
> >
<label <div
class="w-full relative hover:bg-base-200/30 rounded-md border border-2 border-base-content/10 border-dashed" class="flex h-52 w-full"
for="import_list_file" @dragover.prevent
:class="{ 'opacity-50': isLoading }" @drop.prevent="onDropFiles"
> >
<div class="absolute top-0 right-0 left-0 bottom-0 flex items-center justify-center"> <label
<div class="flex flex-col items-center"> class="w-full relative bg-base-200/20 hover:bg-base-200/30 rounded-md border border-2 border-base-content/10 border-dashed"
<IconInnerShadowTop for="import_list_file"
v-if="isLoading" :class="{ 'opacity-50': isLoading }"
class="animate-spin" >
:width="40" <div class="absolute top-0 right-0 left-0 bottom-0 flex items-center justify-center">
:height="40" <div class="flex flex-col items-center">
/> <IconInnerShadowTop
<IconCloudUpload v-if="isLoading"
v-else class="animate-spin"
:width="40" :width="40"
:height="40" :height="40"
/> />
<div <IconCloudUpload
class="font-medium text-lg mb-1" v-else
> :width="40"
Upload CSV or XLSX Spreadsheet :height="40"
</div> />
<div class="text-sm"> <div
<span class="font-medium">Click to Upload</span> or drag and drop files. class="font-medium text-lg mb-1"
>
Upload CSV or XLSX Spreadsheet
</div>
<div class="text-sm">
<span class="font-medium">Click to Upload</span> or drag and drop files.
</div>
</div> </div>
</div> </div>
</div> <form
<form ref="form"
ref="form" class="hidden"
class="hidden"
>
<input
id="import_list_file"
ref="input"
type="file"
name="file"
accept=".xlsx, .xls, .csv"
@change="onSelectFile"
> >
</form> <input
</label> id="import_list_file"
ref="input"
type="file"
name="file"
accept=".xlsx, .xls, .csv"
@change="onSelectFile"
>
</form>
</label>
</div>
<div class="text-center mt-2">
Or <a
:download="`${template.name}.csv`"
:href="`data:text/csv;base64,${csvBase64}`"
class="link font-medium"
>download</a> a spreadsheet to fill and import
</div>
</div> </div>
</div> </div>
</template> </template>
@ -274,6 +284,25 @@ export default {
return submissions return submissions
}, },
csvBase64 () {
const rows = []
this.submitters.forEach((submitter) => {
this.selectFieldsForSubmitter(submitter).forEach((field) => {
rows.push(this.submitters.length > 1 ? `${submitter.name} - ${field.name}` : field.name)
})
})
const csv = rows.map(item => {
if (/[",\n]/.test(item)) {
return `"${item.replace(/"/g, '""')}"`
} else {
return item
}
}).join(',')
return window.btoa(csv + '\n' + rows.map(() => '').join(',') + '\n')
},
submitters () { submitters () {
return this.template.submitters return this.template.submitters
}, },

Loading…
Cancel
Save