diff --git a/src/components/list/partials/filters.vue b/src/components/list/partials/filters.vue index b2f54f30f..1b64102bc 100644 --- a/src/components/list/partials/filters.vue +++ b/src/components/list/partials/filters.vue @@ -132,24 +132,7 @@
- - - +
@@ -205,10 +188,12 @@ import Multiselect from '@/components/input/multiselect' import UserService from '@/services/user' import ListService from '@/services/list' import NamespaceService from '@/services/namespace' +import EditLabels from '@/components/tasks/partials/editLabels' export default { name: 'filters', components: { + EditLabels, PrioritySelect, Fancycheckbox, flatPickr, @@ -319,9 +304,12 @@ export default { this.prepareSingleValue('percent_done', 'percentDone', 'usePercentDone', true) this.prepareDate('reminders') this.prepareRelatedObjectFilter('users', 'assignees') - this.prepareRelatedObjectFilter('labels', 'labels', 'label') this.prepareRelatedObjectFilter('lists', 'list_id') this.prepareRelatedObjectFilter('namespace') + + this.prepareSingleValue('labels') + const labelIds = (typeof this.filters.labels === 'string' ? this.filters.labels : '').split(',').map(i => parseInt(i)) + this.labels = (Object.values(this.$store.state.labels.labels).filter(l => labelIds.includes(l.id)) ?? []) }, removePropertyFromFilter(propertyName) { // Because of the way arrays work, we can only ever remove one element at once. diff --git a/src/components/tasks/partials/editLabels.vue b/src/components/tasks/partials/editLabels.vue index 232139f1a..fddcf18bd 100644 --- a/src/components/tasks/partials/editLabels.vue +++ b/src/components/tasks/partials/editLabels.vue @@ -55,7 +55,8 @@ export default { }, taskId: { type: Number, - required: true, + required: false, + default: () => 0, }, disabled: { default: false, @@ -100,9 +101,19 @@ export default { this.query = query }, addLabel(label, showNotification = true) { + const bubble = () => { + this.$emit('input', this.labels) + this.$emit('change', this.labels) + } + + if (this.taskId === 0) { + bubble() + return + } + this.$store.dispatch('tasks/addLabel', {label: label, taskId: this.taskId}) .then(() => { - this.$emit('input', this.labels) + bubble() if (showNotification) { this.success({message: this.$t('task.label.addSuccess')}) } @@ -112,15 +123,24 @@ export default { }) }, removeLabel(label) { + const removeFromState = () => { + for (const l in this.labels) { + if (this.labels[l].id === label.id) { + this.labels.splice(l, 1) + } + } + this.$emit('input', this.labels) + this.$emit('change', this.labels) + } + + if (this.taskId === 0) { + removeFromState() + return + } + this.$store.dispatch('tasks/removeLabel', {label: label, taskId: this.taskId}) .then(() => { - // Remove the label from the list - for (const l in this.labels) { - if (this.labels[l].id === label.id) { - this.labels.splice(l, 1) - } - } - this.$emit('input', this.labels) + removeFromState() this.success({message: this.$t('task.label.removeSuccess')}) }) .catch(e => { @@ -128,6 +148,10 @@ export default { }) }, createAndAddLabel(title) { + if (this.taskId === 0) { + return + } + const newLabel = new LabelModel({title: title}) this.$store.dispatch('labels/createLabel', newLabel) .then(r => {