diff --git a/client/components/open/components/RecordOperations.vue b/client/components/open/components/RecordOperations.vue index b3f7b981..86e95ff0 100644 --- a/client/components/open/components/RecordOperations.vue +++ b/client/components/open/components/RecordOperations.vue @@ -1,46 +1,20 @@ + + \ No newline at end of file diff --git a/client/components/open/forms/components/FormSubmissions.vue b/client/components/open/forms/components/FormSubmissions.vue index 15afcf98..9f909f84 100644 --- a/client/components/open/forms/components/FormSubmissions.vue +++ b/client/components/open/forms/components/FormSubmissions.vue @@ -8,89 +8,16 @@ Form Submissions - - + - - - -
- - -
-
+ :form="form" + :columns="properties" + v-model:display-columns="displayColumns" + v-model:wrap-columns="wrapColumns" + @close="showColumnsModal = false" + @update:columns="onColumnUpdated" + />
@@ -111,26 +38,22 @@ />
-
-

- Display columns -

-

- Export as CSV -

-

- -

+
+ +
@@ -147,6 +70,7 @@ ref="table" class="max-h-full" :columns="properties" + :wrap-columns="wrapColumns" :data="filteredData" :loading="isLoading" :scroll-parent="parentPage" @@ -164,20 +88,24 @@ import Fuse from 'fuse.js' import clonedeep from 'clone-deep' import OpenTable from '../../tables/OpenTable.vue' +import FormColumnsSettingsModal from './FormColumnsSettingsModal.vue' export default { name: 'FormSubmissions', - components: {OpenTable}, + components: { OpenTable, FormColumnsSettingsModal }, props: {}, setup() { const workingFormStore = useWorkingFormStore() const recordStore = useRecordsStore() + const form = storeToRefs(workingFormStore).content + const tableData = storeToRefs(recordStore).getAll + return { workingFormStore, recordStore, - form: storeToRefs(workingFormStore).content, - tableData: storeToRefs(recordStore).getAll, + form, + tableData, runtimeConfig: useRuntimeConfig(), slug: useRoute().params.slug } @@ -188,14 +116,15 @@ export default { fullyLoaded: false, showColumnsModal: false, properties: [], - removed_properties: [], - displayColumns: {}, exportLoading: false, searchForm: useForm({ search: '' }), + displayColumns: {}, + wrapColumns: {}, } }, + computed: { parentPage() { if (import.meta.server) { @@ -203,11 +132,6 @@ export default { } return window }, - candidatesProperties() { - return clonedeep(this.form.properties).filter((field) => { - return !['nf-text', 'nf-code', 'nf-page-break', 'nf-divider', 'nf-image'].includes(field.type) - }) - }, exportUrl() { if (!this.form) { return '' @@ -234,8 +158,9 @@ export default { return fuse.search(this.searchForm.search).map((res) => { return res.item }) - } + }, }, + watch: { 'form.id'() { this.onFormChange() @@ -244,46 +169,19 @@ export default { this.dataChanged() } }, + mounted() { this.onFormChange() }, + methods: { onFormChange() { if (this.form === null || this.form.slug !== this.slug) { return } this.fullyLoaded = false - this.initFormStructure() this.getSubmissionsData() }, - initFormStructure() { - // check if form properties already has a created_at column - if (!this.properties.find((property) => { - if (property.id === 'created_at') { - return true - } - })) { - // Add a "created at" column - this.candidatesProperties.push({ - name: 'Created at', - id: 'created_at', - type: 'date', - width: 140 - }) - } - this.properties = this.candidatesProperties - this.removed_properties = (this.form.removed_properties) ? clonedeep(this.form.removed_properties) : [] - // Get display columns from local storage - const tmpColumns = window.localStorage.getItem('display-columns-formid-' + this.form.id) - if (tmpColumns !== null && tmpColumns) { - this.displayColumns = JSON.parse(tmpColumns) - this.onChangeDisplayColumns() - } else { - this.properties.forEach((field) => { - this.displayColumns[field.id] = true - }) - } - }, getSubmissionsData() { if (this.fullyLoaded) { return @@ -328,13 +226,6 @@ export default { onColumnUpdated(columns) { this.properties = columns }, - onChangeDisplayColumns() { - if (!import.meta.client) return - window.localStorage.setItem('display-columns-formid-' + this.form.id, JSON.stringify(this.displayColumns)) - this.properties = clonedeep(this.candidatesProperties).concat(this.removed_properties).filter((field) => { - return this.displayColumns[field.id] === true - }) - }, onUpdateRecord(submission) { this.recordStore.save(submission) this.dataChanged() @@ -355,16 +246,16 @@ export default { columns: this.displayColumns } }).then(blob => { - const filename = `${this.form.slug}-${Date.now()}-submissions.csv` - const 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) => { + const filename = `${this.form.slug}-${Date.now()}-submissions.csv` + const 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) }).finally(() => { this.exportLoading = false diff --git a/client/components/open/tables/OpenTable.vue b/client/components/open/tables/OpenTable.vue index 301593bf..6fd0df47 100644 --- a/client/components/open/tables/OpenTable.vue +++ b/client/components/open/tables/OpenTable.vue @@ -74,6 +74,7 @@ { 'border-b': index !== data.length - 1, 'border-r': colIndex !== columns.length - 1 || hasActions, + 'whitespace-normal break-words': wrapColumns[col.id] === true, }, colClasses(col), ]" @@ -90,13 +91,15 @@ class="n-table-cell border-gray-100 dark:border-gray-900 text-sm p-2 border-b" style="width: 100px" > - +
+ +
[], }, + wrapColumns: { + type: Object, + default: () => {}, + }, data: { type: Array, default: () => [],