summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Core/Lexer.php4
-rw-r--r--app/Model/TaskFilter.php20
-rw-r--r--docs/search.markdown8
-rw-r--r--tests/units/LexerTest.php30
-rw-r--r--tests/units/TaskFilterTest.php27
5 files changed, 88 insertions, 1 deletions
diff --git a/app/Core/Lexer.php b/app/Core/Lexer.php
index a81965c5..34d85704 100644
--- a/app/Core/Lexer.php
+++ b/app/Core/Lexer.php
@@ -28,6 +28,7 @@ class Lexer
"/^(assignee:)/" => 'T_ASSIGNEE',
"/^(color:)/" => 'T_COLOR',
"/^(due:)/" => 'T_DUE',
+ "/^(status:)/" => 'T_STATUS',
"/^(title:)/" => 'T_TITLE',
"/^(\s+)/" => 'T_WHITESPACE',
'/^([<=>]{0,2}[0-9]{4}-[0-9]{2}-[0-9]{2})/' => 'T_DATE',
@@ -114,10 +115,11 @@ class Lexer
break;
+ case 'T_STATUS':
case 'T_DUE':
$next = next($tokens);
- if ($next !== false && $next['token'] === 'T_DATE') {
+ if ($next !== false && ($next['token'] === 'T_DATE' || $next['token'] === 'T_STRING')) {
$map[$token['token']] = $next['match'];
}
diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php
index c47b059f..6577c9b4 100644
--- a/app/Model/TaskFilter.php
+++ b/app/Model/TaskFilter.php
@@ -53,6 +53,9 @@ class TaskFilter extends Base
case 'T_TITLE':
$this->filterByTitle($value);
break;
+ case 'T_STATUS':
+ $this->filterByStatusName($value);
+ break;
}
}
@@ -297,6 +300,22 @@ class TaskFilter extends Base
}
/**
+ * Filter by status name
+ *
+ * @access public
+ * @param string $status
+ * @return TaskFilter
+ */
+ public function filterByStatusName($status)
+ {
+ if ($status === 'open' || $status === 'closed') {
+ $this->filterByStatus($status === 'open' ? Task::STATUS_OPEN : Task::STATUS_CLOSED);
+ }
+
+ return $this;
+ }
+
+ /**
* Filter by status
*
* @access public
@@ -321,6 +340,7 @@ class TaskFilter extends Base
*/
public function filterByDueDate($date)
{
+ $this->query->neq('date_due', '');
$this->query->neq('date_due', 0);
$this->query->notNull('date_due');
return $this->filterWithOperator('date_due', $date, true);
diff --git a/docs/search.markdown b/docs/search.markdown
index c6d5b76e..338f0052 100644
--- a/docs/search.markdown
+++ b/docs/search.markdown
@@ -12,6 +12,14 @@ This example will returns all tasks assigned to me with a due date for tomorrow
assigne:me due:tomorrow my title
```
+Search by status
+----------------
+
+Attribute: **status**
+
+- Query to find open tasks: `status:open`
+- Query to find closed tasks: `status:closed`
+
Search by assignee
------------------
diff --git a/tests/units/LexerTest.php b/tests/units/LexerTest.php
index 4abe451b..7ba3801c 100644
--- a/tests/units/LexerTest.php
+++ b/tests/units/LexerTest.php
@@ -66,6 +66,36 @@ class LexerTest extends Base
);
}
+ public function testStatusQuery()
+ {
+ $lexer = new Lexer;
+
+ $this->assertEquals(
+ array(array('match' => 'status:', 'token' => 'T_STATUS'), array('match' => 'open', 'token' => 'T_STRING')),
+ $lexer->tokenize('status:open')
+ );
+
+ $this->assertEquals(
+ array(array('match' => 'status:', 'token' => 'T_STATUS'), array('match' => 'closed', 'token' => 'T_STRING')),
+ $lexer->tokenize('status:closed')
+ );
+
+ $this->assertEquals(
+ array('T_STATUS' => 'open'),
+ $lexer->map($lexer->tokenize('status:open'))
+ );
+
+ $this->assertEquals(
+ array('T_STATUS' => 'closed'),
+ $lexer->map($lexer->tokenize('status:closed'))
+ );
+
+ $this->assertEquals(
+ array(),
+ $lexer->map($lexer->tokenize('status: '))
+ );
+ }
+
public function testDueDateQuery()
{
$lexer = new Lexer;
diff --git a/tests/units/TaskFilterTest.php b/tests/units/TaskFilterTest.php
index 4e2366e5..4f826cd2 100644
--- a/tests/units/TaskFilterTest.php
+++ b/tests/units/TaskFilterTest.php
@@ -26,6 +26,33 @@ class TaskFilterTest extends Base
$this->assertEmpty($tf->search('search something')->findAll());
}
+ public function testSearchWithStatus()
+ {
+ $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' => 'my task title is awesome')));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing')));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'is_active' => 0)));
+
+ $tf->search('status:open');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(2, $tasks);
+
+ $tf->search('status:plop');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(3, $tasks);
+
+ $tf->search('status:closed');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ }
+
public function testSearchWithDueDate()
{
$dp = new DateParser($this->container);