diff --git a/src/components/quick-actions/quick-actions.vue b/src/components/quick-actions/quick-actions.vue index 330e87066..f7cfd814d 100644 --- a/src/components/quick-actions/quick-actions.vue +++ b/src/components/quick-actions/quick-actions.vue @@ -243,7 +243,7 @@ export default { return SEARCH_MODE_ALL } - if (this.query.startsWith('#')) { + if (assignees.length === 0 && text !== '') { return SEARCH_MODE_TASKS } if (assignees.length === 0 && list !== null && text === '' && labels.length === 0) { @@ -270,12 +270,7 @@ export default { return } - let query = this.query - if (this.searchMode === SEARCH_MODE_TASKS) { - query = query.substr(1) - } - - if (query === '' || this.selectedCmd !== null) { + if (this.selectedCmd !== null) { return } @@ -284,8 +279,35 @@ export default { this.taskSearchTimeout = null } + const {text, list, labels} = this.parsedQuery + + const params = { + s: text, + filter_by: [], + filter_value: [], + filter_comparator: [], + } + + if (list !== null) { + const l = this.$store.getters['lists/findListByExactname'](list) + if (l !== null) { + params.filter_by.push('list_id') + params.filter_value.push(l.id) + params.filter_comparator.push('equals') + } + } + + if (labels.length > 0) { + const labelIds = this.$store.getters['labels/getLabelsByExactTitles'](labels).map(l => l.id) + if (labelIds.length > 0) { + params.filter_by.push('labels') + params.filter_value.push(labelIds.join()) + params.filter_comparator.push('in') + } + } + this.taskSearchTimeout = setTimeout(async () => { - const r = await this.taskService.getAll({}, {s: query}) + const r = await this.taskService.getAll({}, params) this.foundTasks = r.map(t => { t.type = TYPE_TASK const list = this.$store.getters['lists/getListById'](t.listId) diff --git a/src/store/modules/labels.js b/src/store/modules/labels.js index 5326483b5..dbc468851 100644 --- a/src/store/modules/labels.js +++ b/src/store/modules/labels.js @@ -1,6 +1,6 @@ import LabelService from '@/services/label' import {setLoading} from '@/store/helper' -import { success } from '@/message' +import {success} from '@/message' import {i18n} from '@/i18n' import {getLabelsByIds, filterLabelsByQuery} from '@/helpers/labels' @@ -45,6 +45,13 @@ export default { filterLabelsByQuery(state) { return (labelsToHide, query) => filterLabelsByQuery(state, labelsToHide, query) }, + getLabelsByExactTitles(state) { + return labelTitles => Object + .values(state.labels) + .filter(({title}) => { + return labelTitles.some(l => l.toLowerCase() === title.toLowerCase()) + }) + }, }, actions: { async loadAllLabels(ctx, {forceLoad} = {}) {