From 8c41cd54a885f36bce8fedcfc77d7785f65b3cba Mon Sep 17 00:00:00 2001 From: konrad Date: Sat, 19 Dec 2020 21:39:25 +0000 Subject: [PATCH] Add task filter for assignees (#349) Rearrange filter Add task filter for assignees Co-authored-by: kolaente Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/349 Co-Authored-By: konrad Co-Committed-By: konrad --- src/components/list/partials/filters.vue | 146 ++++++++++++++++++----- 1 file changed, 119 insertions(+), 27 deletions(-) diff --git a/src/components/list/partials/filters.vue b/src/components/list/partials/filters.vue index 3be7bb50c..a2374802c 100644 --- a/src/components/list/partials/filters.vue +++ b/src/components/list/partials/filters.vue @@ -18,18 +18,6 @@ -
- -
- -
-
@@ -46,6 +34,34 @@
+
+ +
+ + + Enable Filter By Percent Done + +
+
+
+ +
+ +
+
@@ -82,20 +98,37 @@ />
+
- -
- - Assignees +
+ - Enable Filter By Percent Done - + +
@@ -106,11 +139,16 @@ import Fancycheckbox from '../../input/fancycheckbox' import flatPickr from 'vue-flatpickr-component' import 'flatpickr/dist/flatpickr.css' +import Multiselect from 'vue-multiselect' import {formatISO} from 'date-fns' +import differenceWith from 'lodash/differenceWith' + import PrioritySelect from '@/components/tasks/partials/prioritySelect' import PercentDoneSelect from '@/components/tasks/partials/percentDoneSelect' +import UserService from '../../../services/user' + export default { name: 'filters', components: { @@ -118,6 +156,7 @@ export default { Fancycheckbox, flatPickr, PercentDoneSelect, + Multiselect, }, data() { return { @@ -141,6 +180,7 @@ export default { percentDone: 0, usePercentDone: false, reminders: '', + assignees: '', }, flatPickerConfig: { altFormat: 'j M Y H:i', @@ -150,8 +190,15 @@ export default { time_24hr: true, mode: 'range', }, + + userService: UserService, + foundUsers: [], + users: [], } }, + created() { + this.userService = new UserService() + }, mounted() { this.params = this.value this.filters.requireAllFilters = this.params.filter_concat === 'and' @@ -254,8 +301,8 @@ export default { this.filters[variableName] = `${start.getFullYear()}-${start.getMonth() + 1}-${start.getDate()} to ${end.getFullYear()}-${end.getMonth() + 1}-${end.getDate()}` } }, - setSingleValueFilter(filterName, variableName, useVariableName) { - if (!this.filters[useVariableName]) { + setSingleValueFilter(filterName, variableName, useVariableName = '', comparator = 'equals') { + if (useVariableName !== '' && !this.filters[useVariableName]) { this.removePropertyFromFilter(filterName) return } @@ -270,7 +317,7 @@ export default { if (!found) { this.params.filter_by.push(filterName) - this.params.filter_comparator.push('equals') + this.params.filter_comparator.push(comparator) this.params.filter_value.push(this.filters[variableName]) } @@ -367,6 +414,51 @@ export default { prepareReminders() { this.prepareDate('reminders', 'reminders') }, + clearUsers() { + this.$set(this, 'foundUsers', []) + }, + findUser(query) { + + if(query === '') { + this.clearUsers() + } + + this.userService.getAll({}, {s: query}) + .then(response => { + // Filter the results to not include users who are already assigneid + this.$set(this, 'foundUsers', differenceWith(response, this.users, (first, second) => { + return first.id === second.id + })) + }) + .catch(e => { + this.error(e, this) + }) + }, + addUser() { + this.$nextTick(() => { + this.changeAssigneeFilter() + }) + }, + removeUser() { + this.$nextTick(() => { + this.changeAssigneeFilter() + }) + }, + changeAssigneeFilter() { + if(this.users.length === 0) { + this.removePropertyFromFilter('assignees') + this.change() + return + } + + let userIDs = [] + this.users.forEach(u => { + userIDs.push(u.id) + }) + + this.$set(this.filters, 'assignees', userIDs.join(',')) + this.setSingleValueFilter('assignees', 'assignees', '', 'in') + }, }, }