feat: use task parsing to search for tasks

This commit is contained in:
kolaente 2021-11-03 21:35:16 +01:00
parent 912746ac08
commit 82fb6a2a52
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 38 additions and 9 deletions

View File

@ -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)

View File

@ -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} = {}) {