Add reference hooks
This commit is contained in:
@@ -3,6 +3,7 @@ Version 1.0.33 (unreleased)
|
|||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
|
* Add "reference" hooks
|
||||||
* Show project name in task forms
|
* Show project name in task forms
|
||||||
* Convert vanilla CSS to SASS
|
* Convert vanilla CSS to SASS
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class LexerBuilder
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->lexer = new Lexer;
|
$this->lexer = new Lexer();
|
||||||
$this->queryBuilder = new QueryBuilder();
|
$this->queryBuilder = new QueryBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,4 +96,21 @@ class Hook
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook with reference
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $hook
|
||||||
|
* @param mixed $param
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function reference($hook, &$param)
|
||||||
|
{
|
||||||
|
foreach ($this->getListeners($hook) as $listener) {
|
||||||
|
$listener($param);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $param;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,13 @@ class BoardFormatter extends BaseFormatter implements FormatterInterface
|
|||||||
{
|
{
|
||||||
$swimlanes = $this->swimlaneModel->getSwimlanes($this->projectId);
|
$swimlanes = $this->swimlaneModel->getSwimlanes($this->projectId);
|
||||||
$columns = $this->columnModel->getAll($this->projectId);
|
$columns = $this->columnModel->getAll($this->projectId);
|
||||||
|
|
||||||
|
if (empty($swimlanes) || empty($columns)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->hook->reference('formatter:board:query', $this->query);
|
||||||
|
|
||||||
$tasks = $this->query
|
$tasks = $this->query
|
||||||
->eq(TaskModel::TABLE.'.project_id', $this->projectId)
|
->eq(TaskModel::TABLE.'.project_id', $this->projectId)
|
||||||
->asc(TaskModel::TABLE.'.position')
|
->asc(TaskModel::TABLE.'.position')
|
||||||
@@ -52,10 +59,6 @@ class BoardFormatter extends BaseFormatter implements FormatterInterface
|
|||||||
$task_ids = array_column($tasks, 'id');
|
$task_ids = array_column($tasks, 'id');
|
||||||
$tags = $this->taskTagModel->getTagsByTasks($task_ids);
|
$tags = $this->taskTagModel->getTagsByTasks($task_ids);
|
||||||
|
|
||||||
if (empty($swimlanes) || empty($columns)) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
return BoardSwimlaneFormatter::getInstance($this->container)
|
return BoardSwimlaneFormatter::getInstance($this->container)
|
||||||
->withSwimlanes($swimlanes)
|
->withSwimlanes($swimlanes)
|
||||||
->withColumns($columns)
|
->withColumns($columns)
|
||||||
|
|||||||
@@ -26,11 +26,14 @@ class SubtaskPagination extends Base
|
|||||||
*/
|
*/
|
||||||
public function getDashboardPaginator($user_id, $method, $max)
|
public function getDashboardPaginator($user_id, $method, $max)
|
||||||
{
|
{
|
||||||
|
$query = $this->subtaskModel->getUserQuery($user_id, array(SubtaskModel::STATUS_TODO, SubtaskModel::STATUS_INPROGRESS));
|
||||||
|
$this->hook->reference('pagination:dashboard:subtask:query', $query);
|
||||||
|
|
||||||
return $this->paginator
|
return $this->paginator
|
||||||
->setUrl('DashboardController', $method, array('pagination' => 'subtasks', 'user_id' => $user_id))
|
->setUrl('DashboardController', $method, array('pagination' => 'subtasks', 'user_id' => $user_id))
|
||||||
->setMax($max)
|
->setMax($max)
|
||||||
->setOrder(TaskModel::TABLE.'.id')
|
->setOrder(TaskModel::TABLE.'.id')
|
||||||
->setQuery($this->subtaskModel->getUserQuery($user_id, array(SubtaskModel::STATUS_TODO, SubtaskModel::STATUS_INPROGRESS)))
|
->setQuery($query)
|
||||||
->calculateOnlyIf($this->request->getStringParam('pagination') === 'subtasks');
|
->calculateOnlyIf($this->request->getStringParam('pagination') === 'subtasks');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,11 +25,14 @@ class TaskPagination extends Base
|
|||||||
*/
|
*/
|
||||||
public function getDashboardPaginator($user_id, $method, $max)
|
public function getDashboardPaginator($user_id, $method, $max)
|
||||||
{
|
{
|
||||||
|
$query = $this->taskFinderModel->getUserQuery($user_id);
|
||||||
|
$this->hook->reference('pagination:dashboard:task:query', $query);
|
||||||
|
|
||||||
return $this->paginator
|
return $this->paginator
|
||||||
->setUrl('DashboardController', $method, array('pagination' => 'tasks', 'user_id' => $user_id))
|
->setUrl('DashboardController', $method, array('pagination' => 'tasks', 'user_id' => $user_id))
|
||||||
->setMax($max)
|
->setMax($max)
|
||||||
->setOrder(TaskModel::TABLE.'.id')
|
->setOrder(TaskModel::TABLE.'.id')
|
||||||
->setQuery($this->taskFinderModel->getUserQuery($user_id))
|
->setQuery($query)
|
||||||
->calculateOnlyIf($this->request->getStringParam('pagination') === 'tasks');
|
->calculateOnlyIf($this->request->getStringParam('pagination') === 'tasks');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,6 +115,31 @@ List of asset Hooks:
|
|||||||
- `template:layout:css`
|
- `template:layout:css`
|
||||||
- `template:layout:js`
|
- `template:layout:js`
|
||||||
|
|
||||||
|
|
||||||
|
Reference hooks
|
||||||
|
---------------
|
||||||
|
|
||||||
|
Reference hooks are passing a variable by reference.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$this->hook->on('formatter:board:query', function (\PicoDb\Table &query) {
|
||||||
|
$query->eq('color_id', 'red');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
The code above will show only tasks in red on the board.
|
||||||
|
|
||||||
|
List of reference hooks:
|
||||||
|
|
||||||
|
| Hook | Description |
|
||||||
|
|--------------------------------------------|---------------------------------------------------------------|
|
||||||
|
| `formatter:board:query` | Alter database query before rendering board |
|
||||||
|
| `pagination:dashboard:task:query` | Alter database query for tasks pagination on the dashboard |
|
||||||
|
| `pagination:dashboard:subtask:query` | Alter database query for subtasks pagination on the dashboard |
|
||||||
|
|
||||||
|
|
||||||
Template Hooks
|
Template Hooks
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
|||||||
@@ -8,89 +8,103 @@ class HookTest extends Base
|
|||||||
{
|
{
|
||||||
public function testGetListeners()
|
public function testGetListeners()
|
||||||
{
|
{
|
||||||
$h = new Hook;
|
$hook = new Hook;
|
||||||
$this->assertEmpty($h->getListeners('myhook'));
|
$this->assertEmpty($hook->getListeners('myhook'));
|
||||||
|
|
||||||
$h->on('myhook', 'A');
|
$hook->on('myhook', 'A');
|
||||||
$h->on('myhook', 'B');
|
$hook->on('myhook', 'B');
|
||||||
|
|
||||||
$this->assertEquals(array('A', 'B'), $h->getListeners('myhook'));
|
$this->assertEquals(array('A', 'B'), $hook->getListeners('myhook'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExists()
|
public function testExists()
|
||||||
{
|
{
|
||||||
$h = new Hook;
|
$hook = new Hook;
|
||||||
$this->assertFalse($h->exists('myhook'));
|
$this->assertFalse($hook->exists('myhook'));
|
||||||
|
|
||||||
$h->on('myhook', 'A');
|
$hook->on('myhook', 'A');
|
||||||
|
|
||||||
$this->assertTrue($h->exists('myhook'));
|
$this->assertTrue($hook->exists('myhook'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMergeWithNoBinding()
|
public function testMergeWithNoBinding()
|
||||||
{
|
{
|
||||||
$h = new Hook;
|
$hook = new Hook;
|
||||||
$values = array('A', 'B');
|
$values = array('A', 'B');
|
||||||
|
|
||||||
$result = $h->merge('myhook', $values, array('p' => 'c'));
|
$result = $hook->merge('myhook', $values, array('p' => 'c'));
|
||||||
$this->assertEquals($values, $result);
|
$this->assertEquals($values, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMergeWithBindings()
|
public function testMergeWithBindings()
|
||||||
{
|
{
|
||||||
$h = new Hook;
|
$hook = new Hook;
|
||||||
$values = array('A', 'B');
|
$values = array('A', 'B');
|
||||||
$expected = array('A', 'B', 'c', 'D');
|
$expected = array('A', 'B', 'c', 'D');
|
||||||
|
|
||||||
$h->on('myhook', function ($p) {
|
$hook->on('myhook', function ($p) {
|
||||||
return array($p);
|
return array($p);
|
||||||
});
|
});
|
||||||
|
|
||||||
$h->on('myhook', function () {
|
$hook->on('myhook', function () {
|
||||||
return array('D');
|
return array('D');
|
||||||
});
|
});
|
||||||
|
|
||||||
$result = $h->merge('myhook', $values, array('p' => 'c'));
|
$result = $hook->merge('myhook', $values, array('p' => 'c'));
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($expected, $values);
|
$this->assertEquals($expected, $values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMergeWithBindingButReturningBadData()
|
public function testMergeWithBindingButReturningBadData()
|
||||||
{
|
{
|
||||||
$h = new Hook;
|
$hook = new Hook;
|
||||||
$values = array('A', 'B');
|
$values = array('A', 'B');
|
||||||
$expected = array('A', 'B');
|
$expected = array('A', 'B');
|
||||||
|
|
||||||
$h->on('myhook', function () {
|
$hook->on('myhook', function () {
|
||||||
return 'string';
|
return 'string';
|
||||||
});
|
});
|
||||||
|
|
||||||
$result = $h->merge('myhook', $values);
|
$result = $hook->merge('myhook', $values);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$this->assertEquals($expected, $values);
|
$this->assertEquals($expected, $values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFirstWithNoBinding()
|
public function testFirstWithNoBinding()
|
||||||
{
|
{
|
||||||
$h = new Hook;
|
$hook = new Hook;
|
||||||
|
|
||||||
$result = $h->first('myhook', array('p' => 2));
|
$result = $hook->first('myhook', array('p' => 2));
|
||||||
$this->assertEquals(null, $result);
|
$this->assertEquals(null, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFirstWithMultipleBindings()
|
public function testFirstWithMultipleBindings()
|
||||||
{
|
{
|
||||||
$h = new Hook;
|
$hook = new Hook;
|
||||||
|
|
||||||
$h->on('myhook', function ($p) {
|
$hook->on('myhook', function ($p) {
|
||||||
return $p + 1;
|
return $p + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
$h->on('myhook', function ($p) {
|
$hook->on('myhook', function ($p) {
|
||||||
return $p;
|
return $p;
|
||||||
});
|
});
|
||||||
|
|
||||||
$result = $h->first('myhook', array('p' => 3));
|
$result = $hook->first('myhook', array('p' => 3));
|
||||||
$this->assertEquals(4, $result);
|
$this->assertEquals(4, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHookWithReference()
|
||||||
|
{
|
||||||
|
$hook = new Hook();
|
||||||
|
|
||||||
|
$hook->on('myhook', function (&$p) {
|
||||||
|
$p = 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
$param = 123;
|
||||||
|
$result = $hook->reference('myhook', $param);
|
||||||
|
$this->assertSame(2, $result);
|
||||||
|
$this->assertSame(2, $param);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user