diff --git a/src/browse.vue b/src/browse.vue index 195c6ed..6cc6b8c 100644 --- a/src/browse.vue +++ b/src/browse.vue @@ -19,49 +19,56 @@ {{ resource.name }} - + + + +
- - + + +
+ + +
field.searchable).map(field => field.name); + }, + mainDateField() { + const mainDateField = this.tableFields.filter(field => field.dateFilter).map(field => field.name); + return mainDateField.length ? mainDateField[0] : ""; } }, watch: { @@ -377,6 +388,8 @@ export default { this.vuetableQueryParams = _clone(this.appendParams); }, resource() { + this.$refs.Vuetable.resetData(); + this.vuetableQueryParams.q = null; this.getSchema(this.resource); } }, @@ -440,16 +453,22 @@ export default { }, getData(searchOptions) { let params = ""; + const fixedFilters = Object.keys(searchOptions.fixedFilters || {}); + const dateFilters = Object.keys(searchOptions.dates || {}); + let searchableFields = []; searchOptions.text = searchOptions.text.trim(); if (searchOptions.text.length) { if (!searchOptions.filters.length) { - params += this.getParams(this.searchableFields, searchOptions); + searchableFields = this.searchableFields.filter(field => !fixedFilters.includes(field) && !dateFilters.includes(field)); } else { - params += this.getParams(searchOptions.filters, searchOptions); + searchableFields = searchOptions.filters.filter(field => !fixedFilters.includes(field) && !dateFilters.includes(field)); } + params += this.getParams(searchableFields, searchOptions); } + params = this.getFixedFilters(searchOptions, params); + this.vuetableQueryParams.q = `(${params})`; this.refresh(); }, @@ -469,6 +488,29 @@ export default { (this.showActionsDelete || this.showActionsEdit) && this.tableFields.push(this.vuetableActions); }); }, + + getFixedFilters(searchOptions, params) { + let fixedFilters = Object.entries(searchOptions.fixedFilters || {}); + const dateFilters = Object.entries(searchOptions.dates || {}); + let dateValues = ""; + + if (fixedFilters.length || dateFilters.length) { + fixedFilters = fixedFilters.map(([filterName, value]) => `${filterName}:${value}`).join(";"); + if (dateFilters.length && this.mainDateField) { + let dateFilterValue = this.formatDate(searchOptions.dates.start); + if (searchOptions.dates.end) { + dateFilterValue += `,${this.mainDateField}<${this.formatDate(searchOptions.dates.end)}`; + } + dateValues = `${this.mainDateField}>${dateFilterValue}`; + } + params = [params, dateValues, fixedFilters].filter(val => val).join(","); + } + + return params; + }, + formatDate(date) { + return date ? date.toISOString().slice(0, 10) : ""; + }, getSelectedRows() { return this.$refs.Vuetable.selectedTo; }, diff --git a/src/components/resource-actions.vue b/src/components/resource-actions.vue index 0ec1e08..284f4bd 100644 --- a/src/components/resource-actions.vue +++ b/src/components/resource-actions.vue @@ -61,6 +61,7 @@
+