Add wildcard search for task reference field (PR #3119)

This commit is contained in:
Frederic Guillot
2017-05-12 15:55:13 -04:00
parent 630f4ee780
commit 5b7e137f76
5 changed files with 73 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ Version 1.0.44 (unreleased)
Improvements: Improvements:
* Add wildcard search for task reference field
* Improve automated action TaskAssignColorOnDueDate to update task only when necessary * Improve automated action TaskAssignColorOnDueDate to update task only when necessary
Version 1.0.43 (April 30, 2017) Version 1.0.43 (April 30, 2017)

View File

@@ -32,6 +32,11 @@ class TaskReferenceFilter extends BaseFilter implements FilterInterface
*/ */
public function apply() public function apply()
{ {
if (strpos($this->value, '*') >= 0) {
$this->query->like(TaskModel::TABLE.'.reference', str_replace('*', '%', $this->value));
return $this;
}
$this->query->eq(TaskModel::TABLE.'.reference', $this->value); $this->query->eq(TaskModel::TABLE.'.reference', $this->value);
return $this; return $this;
} }

View File

@@ -115,6 +115,7 @@ Attribute: **completed**
The task reference is an external id of your task, by example a ticket number from another software. The task reference is an external id of your task, by example a ticket number from another software.
- Find tasks with a reference: `ref:1234` or `reference:TICKET-1234` - Find tasks with a reference: `ref:1234` or `reference:TICKET-1234`
- Wildcard search: `ref:TICKET-*`
### Search by category ### Search by category

View File

@@ -111,6 +111,7 @@ Değiştirme tarihi sorguları aynı şekilde çalışır.
Görev referansı, görevinizin harici bir kimliği, örneğin başka bir yazılımdan gelen bir bilet numarasıdır. Görev referansı, görevinizin harici bir kimliği, örneğin başka bir yazılımdan gelen bir bilet numarasıdır.
- Görevleri referans ile bulun: `ref:1234` veya `reference:TICKET-1234` - Görevleri referans ile bulun: `ref:1234` veya `reference:TICKET-1234`
- Wildcard search: `ref:TICKET-*`
### Kategoriye göre ara ### Kategoriye göre ara

View File

@@ -0,0 +1,65 @@
<?php
use Kanboard\Filter\TaskReferenceFilter;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
require_once __DIR__.'/../Base.php';
class TaskReferenceFilterTest extends Base
{
public function testWithoutMatch()
{
$taskFinder = new TaskFinderModel($this->container);
$taskCreation = new TaskCreationModel($this->container);
$projectModel = new ProjectModel($this->container);
$query = $taskFinder->getExtendedQuery();
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
$this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));
$filter = new TaskReferenceFilter();
$filter->withQuery($query);
$filter->withValue('aaa-bbb');
$filter->apply();
$this->assertCount(0, $query->findAll());
}
public function testWithExactMatch()
{
$taskFinder = new TaskFinderModel($this->container);
$taskCreation = new TaskCreationModel($this->container);
$projectModel = new ProjectModel($this->container);
$query = $taskFinder->getExtendedQuery();
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
$this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'reference' => 'aaa-bbb')));
$filter = new TaskReferenceFilter();
$filter->withQuery($query);
$filter->withValue('aaa-bbb');
$filter->apply();
$this->assertCount(1, $query->findAll());
}
public function testWithWildCard()
{
$taskFinder = new TaskFinderModel($this->container);
$taskCreation = new TaskCreationModel($this->container);
$projectModel = new ProjectModel($this->container);
$query = $taskFinder->getExtendedQuery();
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
$this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'reference' => 'aaa-bbb')));
$filter = new TaskReferenceFilter();
$filter->withQuery($query);
$filter->withValue('aaa-*');
$filter->apply();
$this->assertCount(1, $query->findAll());
}
}