10
10
<modal :show =" showColumnsModal" @close =" showColumnsModal=false" >
11
11
<template #icon >
12
12
<svg class =" w-8 h-8" viewBox =" 0 0 24 24" fill =" none" xmlns =" http://www.w3.org/2000/svg" >
13
- <path d =" M16 5H8C4.13401 5 1 8.13401 1 12C1 15.866 4.13401 19 8 19H16C19.866 19 23 15.866 23 12C23 8.13401 19.866 5 16 5Z" stroke =" currentColor" stroke-width =" 2" stroke-linecap =" round" stroke-linejoin =" round" />
14
- <path d =" M8 15C9.65685 15 11 13.6569 11 12C11 10.3431 9.65685 9 8 9C6.34315 9 5 10.3431 5 12C5 13.6569 6.34315 15 8 15Z" stroke =" currentColor" stroke-width =" 2" stroke-linecap =" round" stroke-linejoin =" round" />
13
+ <path
14
+ d =" M16 5H8C4.13401 5 1 8.13401 1 12C1 15.866 4.13401 19 8 19H16C19.866 19 23 15.866 23 12C23 8.13401 19.866 5 16 5Z"
15
+ stroke =" currentColor" stroke-width =" 2" stroke-linecap =" round" stroke-linejoin =" round" />
16
+ <path
17
+ d =" M8 15C9.65685 15 11 13.6569 11 12C11 10.3431 9.65685 9 8 9C6.34315 9 5 10.3431 5 12C5 13.6569 6.34315 15 8 15Z"
18
+ stroke =" currentColor" stroke-width =" 2" stroke-linecap =" round" stroke-linejoin =" round" />
15
19
</svg >
16
20
</template >
17
21
<template #title >
24
28
Form Fields
25
29
</h4 >
26
30
<div class =" border border-gray-300 rounded-md" >
27
- <div v-for =" (field,index) in form.properties" :key =" field.id" class =" p-2 border-gray-300 flex items-center" :class =" {'border-t':index!=0}" >
31
+ <div v-for =" (field,index) in form.properties" :key =" field.id" class =" p-2 border-gray-300 flex items-center"
32
+ :class =" {'border-t':index!=0}" >
28
33
<p class =" flex-grow truncate" >
29
- {{ field.name }}
34
+ {{ field.name }}
30
35
</p >
31
- <v-switch v-model =" displayColumns[field.id]" class =" float-right" @update:model-value =" onChangeDisplayColumns" />
36
+ <v-switch v-model =" displayColumns[field.id]" class =" float-right"
37
+ @update:model-value =" onChangeDisplayColumns" />
32
38
</div >
33
39
</div >
34
40
</template >
37
43
Removed Fields
38
44
</h4 >
39
45
<div class =" border border-gray-300 rounded-md" >
40
- <div v-for =" (field,index) in removed_properties" :key =" field.id" class =" p-2 border-gray-300 flex items-center" :class =" {'border-t':index!=0}" >
46
+ <div v-for =" (field,index) in removed_properties" :key =" field.id"
47
+ class =" p-2 border-gray-300 flex items-center" :class =" {'border-t':index!=0}" >
41
48
<p class =" flex-grow truncate" >
42
49
{{ field.name }}
43
50
</p >
44
- <v-switch v-model =" displayColumns[field.id]" class =" float-right" @update:model-value =" onChangeDisplayColumns" />
51
+ <v-switch v-model =" displayColumns[field.id]" class =" float-right"
52
+ @update:model-value =" onChangeDisplayColumns" />
45
53
</div >
46
54
</div >
47
55
</template >
48
56
</div >
49
57
</modal >
50
58
51
- <Loader v-if =" !form || !formInitDone" class =" h-6 w-6 text-nt-blue mx-auto" />
59
+ <Loader v-if =" !form || !formInitDone" class =" h-6 w-6 text-nt-blue mx-auto" />
52
60
<div v-else >
53
61
<div v-if =" form && tableData.length > 0" class =" flex flex-wrap items-end" >
54
62
<div class =" flex-grow" >
55
- <text-input class =" w-64" :form =" searchForm" name =" search" placeholder =" Search..." />
63
+ <text-input class =" w-64" :form =" searchForm" name =" search" placeholder =" Search..." />
56
64
</div >
57
65
<div class =" font-semibold flex gap-4" >
58
66
<p class =" float-right text-xs uppercase mb-2" >
@@ -94,21 +102,22 @@ import Fuse from 'fuse.js'
94
102
import clonedeep from ' clone-deep'
95
103
import VSwitch from ' ../../../forms/components/VSwitch.vue'
96
104
import OpenTable from ' ../../tables/OpenTable.vue'
105
+ import {now } from " @vueuse/core" ;
97
106
98
107
export default {
99
108
name: ' FormSubmissions' ,
100
- components: { OpenTable, VSwitch },
109
+ components: {OpenTable, VSwitch},
101
110
props: {},
102
111
103
- setup () {
112
+ setup () {
104
113
const workingFormStore = useWorkingFormStore ()
105
114
return {
106
115
workingFormStore,
107
116
runtimeConfig: useRuntimeConfig ()
108
117
}
109
118
},
110
119
111
- data () {
120
+ data () {
112
121
return {
113
122
formInitDone: false ,
114
123
isLoading: false ,
@@ -126,20 +135,20 @@ export default {
126
135
},
127
136
computed: {
128
137
form: {
129
- get () {
138
+ get () {
130
139
return this .workingFormStore .content
131
140
},
132
- set (value) {
141
+ set (value ) {
133
142
this .workingFormStore .set (value)
134
143
}
135
144
},
136
- exportUrl () {
145
+ exportUrl () {
137
146
if (! this .form ) {
138
147
return ' '
139
148
}
140
149
return this .runtimeConfig .public .apiBase + ' /open/forms/' + this .form .id + ' /submissions/export'
141
150
},
142
- filteredData () {
151
+ filteredData () {
143
152
if (! this .tableData ) return []
144
153
145
154
const filteredData = clonedeep (this .tableData )
@@ -159,20 +168,20 @@ export default {
159
168
}
160
169
},
161
170
watch: {
162
- ' form.id' () {
171
+ ' form.id' () {
163
172
if (this .form === null ) {
164
173
return
165
174
}
166
175
this .initFormStructure ()
167
176
this .getSubmissionsData ()
168
177
}
169
178
},
170
- mounted () {
179
+ mounted () {
171
180
this .initFormStructure ()
172
181
this .getSubmissionsData ()
173
182
},
174
183
methods: {
175
- initFormStructure () {
184
+ initFormStructure () {
176
185
if (! this .form || ! this .form .properties || this .formInitDone ) {
177
186
return
178
187
}
@@ -183,7 +192,7 @@ export default {
183
192
if (property .id === ' created_at' ) {
184
193
return true
185
194
}
186
- }) ) {
195
+ })) {
187
196
// Add a "created at" column
188
197
this .properties .push ({
189
198
name: ' Created at' ,
@@ -206,7 +215,7 @@ export default {
206
215
})
207
216
}
208
217
},
209
- getSubmissionsData () {
218
+ getSubmissionsData () {
210
219
if (! this .form || this .fullyLoaded ) {
211
220
return
212
221
}
@@ -227,7 +236,7 @@ export default {
227
236
this .isLoading = false
228
237
})
229
238
},
230
- dataChanged () {
239
+ dataChanged () {
231
240
if (this .$refs .shadows ) {
232
241
this .$refs .shadows .toggleShadow ()
233
242
this .$refs .shadows .calcDimensions ()
@@ -236,24 +245,31 @@ export default {
236
245
onColumnUpdated (columns ) {
237
246
this .properties = columns
238
247
},
239
- onChangeDisplayColumns () {
248
+ onChangeDisplayColumns () {
240
249
if (! process .client ) return
241
250
window .localStorage .setItem (' display-columns-formid-' + this .form .id , JSON .stringify (this .displayColumns ))
242
251
this .properties = clonedeep (this .form .properties ).concat (this .removed_properties ).filter ((field ) => {
243
252
return this .displayColumns [field .id ] === true
244
253
})
245
254
},
246
- onDeleteRecord () {
255
+ onDeleteRecord () {
247
256
this .fullyLoaded = false
248
257
this .tableData = []
249
258
this .getSubmissionsData ()
250
259
},
251
260
downloadAsCsv () {
252
- opnFetch (this .exportUrl , { responseType: " blob" })
253
- .then ( blob => {
254
- var file = window .URL .createObjectURL (blob);
255
- window .location .assign (file);
256
- }).catch ((error )=> {
261
+ opnFetch (this .exportUrl , {responseType: " blob" })
262
+ .then (blob => {
263
+ const filename = ` ${ this .form .slug } -${ Date .now ()} -submissions.csv`
264
+ let a = document .createElement (" a" )
265
+ document .body .appendChild (a)
266
+ a .style = " display: none"
267
+ const url = window .URL .createObjectURL (blob)
268
+ a .href = url
269
+ a .download = filename
270
+ a .click ()
271
+ window .URL .revokeObjectURL (url)
272
+ }).catch ((error ) => {
257
273
console .error (error)
258
274
})
259
275
}
0 commit comments