2021-01-30 16:17:04 +00:00
|
|
|
<template>
|
|
|
|
<create-edit
|
2021-06-23 23:24:57 +00:00
|
|
|
:title="$t('filters.edit.title')"
|
2021-01-30 16:17:04 +00:00
|
|
|
primary-icon=""
|
2021-06-23 23:24:57 +00:00
|
|
|
:primary-label="$t('misc.save')"
|
2021-01-30 16:17:04 +00:00
|
|
|
@primary="save"
|
2021-06-23 23:24:57 +00:00
|
|
|
:tertary="$t('misc.delete')"
|
2021-01-30 16:17:04 +00:00
|
|
|
@tertary="$router.push({ name: 'filter.list.settings.delete', params: { id: $route.params.listId } })"
|
|
|
|
>
|
|
|
|
<form @submit.prevent="save()">
|
|
|
|
<div class="field">
|
2021-06-23 23:24:57 +00:00
|
|
|
<label class="label" for="title">{{ $t('filters.attributes.title') }}</label>
|
2021-01-30 16:17:04 +00:00
|
|
|
<div class="control">
|
|
|
|
<input
|
|
|
|
:class="{ 'disabled': filterService.loading}"
|
|
|
|
:disabled="filterService.loading"
|
|
|
|
@keyup.enter="save"
|
|
|
|
class="input"
|
|
|
|
id="title"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('filters.attributes.titlePlaceholder')"
|
2021-01-30 16:17:04 +00:00
|
|
|
type="text"
|
|
|
|
v-focus
|
|
|
|
v-model="filter.title"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
2021-06-23 23:24:57 +00:00
|
|
|
<label class="label" for="description">{{ $t('filters.attributes.description') }}</label>
|
2021-01-30 16:17:04 +00:00
|
|
|
<div class="control">
|
|
|
|
<editor
|
|
|
|
:class="{ 'disabled': filterService.loading}"
|
|
|
|
:disabled="filterService.loading"
|
|
|
|
:preview-is-default="false"
|
|
|
|
id="description"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('filters.attributes.descriptionPlaceholder')"
|
2021-01-30 16:17:04 +00:00
|
|
|
v-model="filter.description"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
2021-06-23 23:24:57 +00:00
|
|
|
<label class="label" for="filters">{{ $t('filters.title') }}</label>
|
2021-01-30 16:17:04 +00:00
|
|
|
<div class="control">
|
|
|
|
<filters
|
|
|
|
:class="{ 'disabled': filterService.loading}"
|
|
|
|
:disabled="filterService.loading"
|
|
|
|
class="has-no-shadow has-no-border"
|
|
|
|
v-model="filters"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</create-edit>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-07-25 13:27:15 +00:00
|
|
|
import ErrorComponent from '@/components/misc/error.vue'
|
|
|
|
import LoadingComponent from '@/components/misc/loading.vue'
|
|
|
|
import CreateEdit from '@/components/misc/create-edit.vue'
|
2021-01-30 16:17:04 +00:00
|
|
|
|
|
|
|
import SavedFilterModel from '@/models/savedFilter'
|
|
|
|
import SavedFilterService from '@/services/savedFilter'
|
|
|
|
import ListModel from '@/models/list'
|
2021-07-25 13:27:15 +00:00
|
|
|
import Filters from '@/components/list/partials/filters.vue'
|
2021-01-30 16:17:04 +00:00
|
|
|
import {objectToSnakeCase} from '@/helpers/case'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'filter-settings-edit',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
filter: SavedFilterModel,
|
|
|
|
filterService: SavedFilterService,
|
|
|
|
filters: {
|
|
|
|
sort_by: ['done', 'id'],
|
|
|
|
order_by: ['asc', 'desc'],
|
|
|
|
filter_by: ['done'],
|
|
|
|
filter_value: ['false'],
|
|
|
|
filter_comparator: ['equals'],
|
|
|
|
filter_concat: 'and',
|
|
|
|
filter_include_nulls: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
showDeleteModal: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
CreateEdit,
|
|
|
|
Filters,
|
|
|
|
editor: () => ({
|
2021-07-25 13:27:15 +00:00
|
|
|
component: import('@/components/input/editor.vue'),
|
2021-01-30 16:17:04 +00:00
|
|
|
loading: LoadingComponent,
|
|
|
|
error: ErrorComponent,
|
|
|
|
timeout: 60000,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.filterService = new SavedFilterService()
|
|
|
|
this.loadSavedFilter()
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
// call again the method if the route changes
|
|
|
|
'$route': 'loadSavedFilter',
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
loadSavedFilter() {
|
|
|
|
// We assume the listId in the route is the pseudolist
|
|
|
|
const list = new ListModel({id: this.$route.params.listId})
|
|
|
|
|
|
|
|
this.filter = new SavedFilterModel({id: list.getSavedFilterId()})
|
|
|
|
this.filterService.get(this.filter)
|
|
|
|
.then(r => {
|
|
|
|
this.filter = r
|
|
|
|
this.filters = objectToSnakeCase(this.filter.filters)
|
|
|
|
})
|
2021-06-22 20:07:57 +00:00
|
|
|
.catch(e => this.error(e))
|
2021-01-30 16:17:04 +00:00
|
|
|
},
|
|
|
|
save() {
|
|
|
|
this.filter.filters = this.filters
|
|
|
|
this.filterService.update(this.filter)
|
|
|
|
.then(r => {
|
|
|
|
this.$store.dispatch('namespaces/loadNamespaces')
|
2021-06-23 23:24:57 +00:00
|
|
|
this.success({message: this.$t('filters.attributes.edit.success')})
|
2021-01-30 16:17:04 +00:00
|
|
|
this.filter = r
|
|
|
|
this.filters = objectToSnakeCase(this.filter.filters)
|
2021-02-20 16:24:40 +00:00
|
|
|
this.$router.back()
|
2021-01-30 16:17:04 +00:00
|
|
|
})
|
2021-06-22 20:07:57 +00:00
|
|
|
.catch(e => this.error(e))
|
2021-01-30 16:17:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|