Allow search by task id
This commit is contained in:
@@ -40,6 +40,7 @@ class Lexer
|
|||||||
'/^(yesterday|tomorrow|today)/' => 'T_DATE',
|
'/^(yesterday|tomorrow|today)/' => 'T_DATE',
|
||||||
'/^("(.*?)")/' => 'T_STRING',
|
'/^("(.*?)")/' => 'T_STRING',
|
||||||
"/^(\w+)/" => 'T_STRING',
|
"/^(\w+)/" => 'T_STRING',
|
||||||
|
"/^(#\d+)/" => 'T_STRING',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ class TaskFilter extends Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter by title
|
* Filter by title or id if the string is like #123 or an integer
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $title
|
* @param string $title
|
||||||
@@ -181,7 +181,16 @@ class TaskFilter extends Base
|
|||||||
*/
|
*/
|
||||||
public function filterByTitle($title)
|
public function filterByTitle($title)
|
||||||
{
|
{
|
||||||
$this->query->ilike(Task::TABLE.'.title', '%'.$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);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->query->ilike(Task::TABLE.'.title', '%'.$title.'%');
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ This example will returns all tasks assigned to me with a due date for tomorrow
|
|||||||
assigne:me due:tomorrow my title
|
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 status
|
Search by status
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
|||||||
@@ -340,6 +340,11 @@ class LexerTest extends Base
|
|||||||
$lexer->map($lexer->tokenize('my title '))
|
$lexer->map($lexer->tokenize('my title '))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array('T_TITLE' => '#123'),
|
||||||
|
$lexer->map($lexer->tokenize('#123'))
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(),
|
array(),
|
||||||
$lexer->map($lexer->tokenize('color:assignee:'))
|
$lexer->map($lexer->tokenize('color:assignee:'))
|
||||||
|
|||||||
@@ -27,6 +27,47 @@ class TaskFilterTest extends Base
|
|||||||
$this->assertEmpty($tf->search('search something')->findAll());
|
$this->assertEmpty($tf->search('search something')->findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSearchById()
|
||||||
|
{
|
||||||
|
$p = new Project($this->container);
|
||||||
|
$tc = new TaskCreation($this->container);
|
||||||
|
$tf = new TaskFilter($this->container);
|
||||||
|
|
||||||
|
$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')));
|
||||||
|
|
||||||
|
$tf->search('#2');
|
||||||
|
$tasks = $tf->findAll();
|
||||||
|
$this->assertNotEmpty($tasks);
|
||||||
|
$this->assertCount(1, $tasks);
|
||||||
|
$this->assertEquals('task2', $tasks[0]['title']);
|
||||||
|
|
||||||
|
$tf->search('1');
|
||||||
|
$tasks = $tf->findAll();
|
||||||
|
$this->assertNotEmpty($tasks);
|
||||||
|
$this->assertCount(1, $tasks);
|
||||||
|
$this->assertEquals('task1', $tasks[0]['title']);
|
||||||
|
|
||||||
|
$tf->search('something');
|
||||||
|
$tasks = $tf->findAll();
|
||||||
|
$this->assertEmpty($tasks);
|
||||||
|
|
||||||
|
$tf->search('#');
|
||||||
|
$tasks = $tf->findAll();
|
||||||
|
$this->assertEmpty($tasks);
|
||||||
|
|
||||||
|
$tf->search('#abcd');
|
||||||
|
$tasks = $tf->findAll();
|
||||||
|
$this->assertEmpty($tasks);
|
||||||
|
|
||||||
|
$tf->search('task1');
|
||||||
|
$tasks = $tf->findAll();
|
||||||
|
$this->assertNotEmpty($tasks);
|
||||||
|
$this->assertCount(1, $tasks);
|
||||||
|
$this->assertEquals('task1', $tasks[0]['title']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSearchWithReference()
|
public function testSearchWithReference()
|
||||||
{
|
{
|
||||||
$p = new Project($this->container);
|
$p = new Project($this->container);
|
||||||
|
|||||||
Reference in New Issue
Block a user