Display project name for task auto-complete fields

This commit is contained in:
Frederic Guillot 2016-07-14 13:46:06 -04:00
parent 9496dfdb6d
commit 6e35d8f22a
No known key found for this signature in database
GPG Key ID: 92D77191BA7FBC99
3 changed files with 42 additions and 2 deletions

View File

@ -9,6 +9,7 @@ New features:
Improvements:
* Display project name for task auto-complete fields
* Make search attributes not case sensitive
* Display TOTP issuer for 2FA
* Make sure that the table schema_version use InnoDB for Mysql

View File

@ -3,6 +3,7 @@
namespace Kanboard\Formatter;
use Kanboard\Core\Filter\FormatterInterface;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskModel;
/**
@ -21,11 +22,15 @@ class TaskAutoCompleteFormatter extends BaseFormatter implements FormatterInterf
*/
public function format()
{
$tasks = $this->query->columns(TaskModel::TABLE.'.id', TaskModel::TABLE.'.title')->findAll();
$tasks = $this->query->columns(
TaskModel::TABLE.'.id',
TaskModel::TABLE.'.title',
ProjectModel::TABLE.'.name AS project_name'
)->asc(TaskModel::TABLE.'.id')->findAll();
foreach ($tasks as &$task) {
$task['value'] = $task['title'];
$task['label'] = '#'.$task['id'].' - '.$task['title'];
$task['label'] = $task['project_name'].' > #'.$task['id'].' '.$task['title'];
}
return $tasks;

View File

@ -0,0 +1,34 @@
<?php
use Kanboard\Formatter\TaskAutoCompleteFormatter;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
require_once __DIR__.'/../Base.php';
class TaskAutoCompleteFormatterTest extends Base
{
public function testFormat()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'My Project')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task 1', 'project_id' => 1)));
$this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task 2', 'project_id' => 1)));
$tasks = TaskAutoCompleteFormatter::getInstance($this->container)
->withQuery($taskFinderModel->getExtendedQuery())
->format();
$this->assertCount(2, $tasks);
$this->assertEquals('My Project > #1 Task 1', $tasks[0]['label']);
$this->assertEquals('Task 1', $tasks[0]['value']);
$this->assertEquals(1, $tasks[0]['id']);
$this->assertEquals('My Project > #2 Task 2', $tasks[1]['label']);
$this->assertEquals('Task 2', $tasks[1]['value']);
$this->assertEquals(2, $tasks[1]['id']);
}
}