From 5fbeb839dfb696650f7e1886e3de131979110c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 21 Apr 2021 11:47:54 +0200 Subject: [PATCH] Allow searching for filters without a query to match all that have a given filter set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Db/CardMapper.php | 8 ++++++++ src/store/card.js | 23 +++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/Db/CardMapper.php b/lib/Db/CardMapper.php index eda1404c0..be91be481 100644 --- a/lib/Db/CardMapper.php +++ b/lib/Db/CardMapper.php @@ -383,6 +383,10 @@ class CardMapper extends QBMapper implements IPermissionMapper { foreach ($query->getDuedate() as $duedate) { $dueDateColumn = $this->databaseType === 'sqlite3' ? $qb->createFunction('DATETIME(`c`.`duedate`)') : 'c.duedate'; $date = $duedate->getValue(); + if ($date === "") { + $qb->andWhere($qb->expr()->isNotNull('c.duedate')); + continue; + } $supportedFilters = ['overdue', 'today', 'week', 'month', 'none']; if (in_array($date, $supportedFilters, true)) { $currentDate = new DateTime(); @@ -430,6 +434,10 @@ class CardMapper extends QBMapper implements IPermissionMapper { foreach ($query->getAssigned() as $index => $assignment) { $qb->innerJoin('c', 'deck_assigned_users', 'au' . $index, $qb->expr()->eq('c.id', 'au' . $index . '.card_id')); $assignedQueryValue = $assignment->getValue(); + if ($assignedQueryValue === "") { + $qb->andWhere($qb->expr()->isNotNull('au' . $index . '.participant')); + continue; + } $searchUsers = $this->userManager->searchDisplayName($assignment->getValue()); $users = array_filter($searchUsers, function (IUser $user) use ($assignedQueryValue) { return (mb_strtolower($user->getDisplayName()) === mb_strtolower($assignedQueryValue) || $user->getUID() === $assignedQueryValue); diff --git a/src/store/card.js b/src/store/card.js index c3c0c39ca..bc3238dc3 100644 --- a/src/store/card.js +++ b/src/store/card.js @@ -97,19 +97,34 @@ export default { return q } for (const match of matches) { - let [filter, query] = match.indexOf(':') !== -1 ? match.split(/:(.+)/) : [null, match] + let [filter, query] = match.indexOf(':') !== -1 ? match.split(/:(.*)/) : [null, match] + const isEmptyQuery = typeof query === 'undefined' || filterOutQuotes(query) === '' if (filter === 'title') { + if (isEmptyQuery) { + continue + } hasMatch = hasMatch && card.title.toLowerCase().includes(filterOutQuotes(query).toLowerCase()) } else if (filter === 'description') { + if (isEmptyQuery) { + hasMatch = hasMatch && !!card.description + continue + } hasMatch = hasMatch && card.description.toLowerCase().includes(filterOutQuotes(query).toLowerCase()) } else if (filter === 'list') { - const stack = this.getters.stackById(card.stackId) + if (isEmptyQuery) { + continue + } + const stack = getters.stackById(card.stackId) if (!stack) { return false } hasMatch = hasMatch && stack.title.toLowerCase().includes(filterOutQuotes(query).toLowerCase()) } else if (filter === 'tag') { + if (isEmptyQuery) { + hasMatch = hasMatch && card.labels.length > 0 + continue + } hasMatch = hasMatch && card.labels.findIndex((label) => label.title.toLowerCase().includes(filterOutQuotes(query).toLowerCase())) !== -1 } else if (filter === 'date') { const datediffHour = ((new Date(card.duedate) - new Date()) / 3600 / 1000) @@ -158,6 +173,10 @@ export default { } } else if (filter === 'assigned') { + if (isEmptyQuery) { + hasMatch = hasMatch && card.assignedUsers.length > 0 + continue + } hasMatch = hasMatch && card.assignedUsers.findIndex((assignment) => { return assignment.participant.primaryKey.toLowerCase() === filterOutQuotes(query).toLowerCase() || assignment.participant.displayname.toLowerCase() === filterOutQuotes(query).toLowerCase()