From 79335aaedf1ba1bba17204ea6d8af482bf7a9f68 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 20 Dec 2020 12:41:47 +0000 Subject: [PATCH] Add task filter for labels (#350) Add task filter for labels Co-authored-by: kolaente Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/350 Co-Authored-By: konrad Co-Committed-By: konrad --- src/components/list/partials/filters.vue | 105 ++++++++++++++++++++++- 1 file changed, 102 insertions(+), 3 deletions(-) diff --git a/src/components/list/partials/filters.vue b/src/components/list/partials/filters.vue index a2374802c..d3b4d5b50 100644 --- a/src/components/list/partials/filters.vue +++ b/src/components/list/partials/filters.vue @@ -131,6 +131,47 @@ + +
+ +
+ + + + +
+
@@ -147,7 +188,8 @@ import differenceWith from 'lodash/differenceWith' import PrioritySelect from '@/components/tasks/partials/prioritySelect' import PercentDoneSelect from '@/components/tasks/partials/percentDoneSelect' -import UserService from '../../../services/user' +import UserService from '@/services/user' +import LabelService from '@/services/label' export default { name: 'filters', @@ -194,10 +236,15 @@ export default { userService: UserService, foundUsers: [], users: [], + + labelService: LabelService, + foundLabels: [], + labels: [], } }, created() { this.userService = new UserService() + this.labelService = new LabelService() }, mounted() { this.params = this.value @@ -419,7 +466,7 @@ export default { }, findUser(query) { - if(query === '') { + if (query === '') { this.clearUsers() } @@ -445,7 +492,7 @@ export default { }) }, changeAssigneeFilter() { - if(this.users.length === 0) { + if (this.users.length === 0) { this.removePropertyFromFilter('assignees') this.change() return @@ -459,6 +506,58 @@ export default { this.$set(this.filters, 'assignees', userIDs.join(',')) this.setSingleValueFilter('assignees', 'assignees', '', 'in') }, + clearLabels() { + this.$set(this, 'foundLabels', []) + }, + findLabels(query) { + + if (query === '') { + this.clearLabels() + } + + this.labelService.getAll({}, {s: query}) + .then(response => { + // Filter the results to not include labels already selected + this.$set(this, 'foundLabels', differenceWith(response, this.labels, (first, second) => { + return first.id === second.id + })) + }) + .catch(e => { + this.error(e, this) + }) + }, + addLabel() { + this.$nextTick(() => { + this.changeLabelFilter() + }) + }, + removeLabel(label) { + this.$nextTick(() => { + for (const l in this.labels) { + if (this.labels[l].id === label.id) { + this.labels.splice(l, 1) + } + break + } + + this.changeLabelFilter() + }) + }, + changeLabelFilter() { + if (this.labels.length === 0) { + this.removePropertyFromFilter('labels') + this.change() + return + } + + let labelIDs = [] + this.labels.forEach(u => { + labelIDs.push(u.id) + }) + + this.$set(this.filters, 'labels', labelIDs.join(',')) + this.setSingleValueFilter('labels', 'labels', '', 'in') + }, }, }