From 7348605327441e46ee5ef0c7ba16f65df39629b9 Mon Sep 17 00:00:00 2001 From: Julien Nahum Date: Tue, 30 Jan 2024 09:42:33 +0100 Subject: [PATCH] Fix submissions download --- .../open/forms/components/FormSubmissions.vue | 74 +++++++++++-------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/client/components/open/forms/components/FormSubmissions.vue b/client/components/open/forms/components/FormSubmissions.vue index 63ee58b..9e545e9 100644 --- a/client/components/open/forms/components/FormSubmissions.vue +++ b/client/components/open/forms/components/FormSubmissions.vue @@ -10,8 +10,12 @@ @@ -37,22 +43,24 @@ Removed Fields
-
+

{{ field.name }}

- +
- +
- +

@@ -94,13 +102,14 @@ import Fuse from 'fuse.js' import clonedeep from 'clone-deep' import VSwitch from '../../../forms/components/VSwitch.vue' import OpenTable from '../../tables/OpenTable.vue' +import {now} from "@vueuse/core"; export default { name: 'FormSubmissions', - components: { OpenTable, VSwitch }, + components: {OpenTable, VSwitch}, props: {}, - setup () { + setup() { const workingFormStore = useWorkingFormStore() return { workingFormStore, @@ -108,7 +117,7 @@ export default { } }, - data () { + data() { return { formInitDone: false, isLoading: false, @@ -126,20 +135,20 @@ export default { }, computed: { form: { - get () { + get() { return this.workingFormStore.content }, - set (value) { + set(value) { this.workingFormStore.set(value) } }, - exportUrl () { + exportUrl() { if (!this.form) { return '' } return this.runtimeConfig.public.apiBase + '/open/forms/' + this.form.id + '/submissions/export' }, - filteredData () { + filteredData() { if (!this.tableData) return [] const filteredData = clonedeep(this.tableData) @@ -159,7 +168,7 @@ export default { } }, watch: { - 'form.id' () { + 'form.id'() { if (this.form === null) { return } @@ -167,12 +176,12 @@ export default { this.getSubmissionsData() } }, - mounted () { + mounted() { this.initFormStructure() this.getSubmissionsData() }, methods: { - initFormStructure () { + initFormStructure() { if (!this.form || !this.form.properties || this.formInitDone) { return } @@ -183,7 +192,7 @@ export default { if (property.id === 'created_at') { return true } - }) ) { + })) { // Add a "created at" column this.properties.push({ name: 'Created at', @@ -206,7 +215,7 @@ export default { }) } }, - getSubmissionsData () { + getSubmissionsData() { if (!this.form || this.fullyLoaded) { return } @@ -227,7 +236,7 @@ export default { this.isLoading = false }) }, - dataChanged () { + dataChanged() { if (this.$refs.shadows) { this.$refs.shadows.toggleShadow() this.$refs.shadows.calcDimensions() @@ -236,24 +245,31 @@ export default { onColumnUpdated(columns) { this.properties = columns }, - onChangeDisplayColumns () { + onChangeDisplayColumns() { if (!process.client) return window.localStorage.setItem('display-columns-formid-' + this.form.id, JSON.stringify(this.displayColumns)) this.properties = clonedeep(this.form.properties).concat(this.removed_properties).filter((field) => { return this.displayColumns[field.id] === true }) }, - onDeleteRecord () { + onDeleteRecord() { this.fullyLoaded = false this.tableData = [] this.getSubmissionsData() }, downloadAsCsv() { - opnFetch(this.exportUrl, { responseType: "blob" }) - .then( blob => { - var file = window.URL.createObjectURL(blob); - window.location.assign(file); - }).catch((error)=>{ + opnFetch(this.exportUrl, {responseType: "blob"}) + .then(blob => { + const filename = `${this.form.slug}-${Date.now()}-submissions.csv` + let a = document.createElement("a") + document.body.appendChild(a) + a.style = "display: none" + const url = window.URL.createObjectURL(blob) + a.href = url + a.download = filename + a.click() + window.URL.revokeObjectURL(url) + }).catch((error) => { console.error(error) }) }