diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-08-19 21:25:19 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-08-19 21:25:19 -0400 |
commit | 5b888a23454e369ebf383c3003497038ae2fbf5d (patch) | |
tree | e3e1c5f722eb36e3c39d654e41ac4ee082f715b8 | |
parent | 1983fc5f7afa20b5ddba0ad1fb63fb92f563deb6 (diff) |
Add search in task title when using an integer only input
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | app/Model/TaskFilter.php | 10 | ||||
-rw-r--r-- | docs/search.markdown | 5 | ||||
-rw-r--r-- | tests/units/TaskFilterTest.php | 7 |
4 files changed, 16 insertions, 7 deletions
@@ -17,6 +17,7 @@ New features: Improvements: +* Add search in task title when using an integer only input * Show all tasks when using no search criteria * Add column vertical scrolling * Set dynamically column height based on viewport size diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php index e8926b52..cede59e3 100644 --- a/app/Model/TaskFilter.php +++ b/app/Model/TaskFilter.php @@ -242,11 +242,11 @@ class TaskFilter extends Base */ public function filterByTitle($title) { - if (strlen($title) > 1 && $title{0} === '#' && ctype_digit(substr($title, 1))) { - $this->query->eq(Task::TABLE.'.id', substr($title, 1)); - } - else if (ctype_digit($title)) { - $this->query->eq(Task::TABLE.'.id', $title); + if (ctype_digit($title) || (strlen($title) > 1 && $title{0} === '#' && ctype_digit(substr($title, 1)))) { + $this->query->beginOr(); + $this->query->eq(Task::TABLE.'.id', str_replace('#', '', $title)); + $this->query->ilike(Task::TABLE.'.title', '%'.$title.'%'); + $this->query->closeOr(); } else { $this->query->ilike(Task::TABLE.'.title', '%'.$title.'%'); diff --git a/docs/search.markdown b/docs/search.markdown index c269b5c1..34a20bc6 100644 --- a/docs/search.markdown +++ b/docs/search.markdown @@ -15,8 +15,9 @@ assigne:me due:tomorrow my title Search by task id or title -------------------------- -- Search by task id: `#123` or `123` -- Search by task title: anything that don't match any search attributes mentioned below +- Search by task id: `#123` +- Search by task id and task title: `123` +- Search by task title: anything that don't match any search attributes Search by status ---------------- diff --git a/tests/units/TaskFilterTest.php b/tests/units/TaskFilterTest.php index 504aa5c2..80d5ee4c 100644 --- a/tests/units/TaskFilterTest.php +++ b/tests/units/TaskFilterTest.php @@ -107,6 +107,7 @@ class TaskFilterTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1'))); $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2'))); + $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task 43'))); $tf->search('#2'); $tasks = $tf->findAll(); @@ -137,6 +138,12 @@ class TaskFilterTest extends Base $this->assertNotEmpty($tasks); $this->assertCount(1, $tasks); $this->assertEquals('task1', $tasks[0]['title']); + + $tf->search('43'); + $tasks = $tf->findAll(); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('task 43', $tasks[0]['title']); } public function testSearchWithReference() |