From 5c685a2a78aea236153fb051ae9615ff0fe6e4a8 Mon Sep 17 00:00:00 2001 From: dalmond Date: Wed, 17 Aug 2016 12:20:12 +0100 Subject: Automatic Actions now support Swimlanes --- app/Controller/ActionController.php | 1 + app/Controller/ActionCreationController.php | 1 + app/Core/Event/EventManager.php | 1 + app/Model/ActionParameterModel.php | 5 ++++- app/ServiceProvider/ActionProvider.php | 4 ++++ app/Template/action/index.php | 2 ++ app/Template/action_creation/params.php | 7 +++++-- 7 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/Controller/ActionController.php b/app/Controller/ActionController.php index 097640f6..c935125a 100644 --- a/app/Controller/ActionController.php +++ b/app/Controller/ActionController.php @@ -33,6 +33,7 @@ class ActionController extends BaseController 'colors_list' => $this->colorModel->getList(), 'categories_list' => $this->categoryModel->getList($project['id']), 'links_list' => $this->linkModel->getList(0, false), + 'swimlane_list' => $this->swimlaneModel->getList($project['id']), 'title' => t('Automatic actions') ))); } diff --git a/app/Controller/ActionCreationController.php b/app/Controller/ActionCreationController.php index 9b228f28..1629e68f 100644 --- a/app/Controller/ActionCreationController.php +++ b/app/Controller/ActionCreationController.php @@ -84,6 +84,7 @@ class ActionCreationController extends BaseController 'priorities_list' => $this->projectTaskPriorityModel->getPriorities($project), 'project' => $project, 'available_actions' => $this->actionManager->getAvailableActions(), + 'swimlane_list' => $this->swimlaneModel->getList($project['id']), 'events' => $this->actionManager->getCompatibleEvents($values['action_name']), ))); } diff --git a/app/Core/Event/EventManager.php b/app/Core/Event/EventManager.php index 9ae43170..68e81a9e 100644 --- a/app/Core/Event/EventManager.php +++ b/app/Core/Event/EventManager.php @@ -53,6 +53,7 @@ class EventManager TaskModel::EVENT_CREATE_UPDATE => t('Task creation or modification'), TaskModel::EVENT_ASSIGNEE_CHANGE => t('Task assignee change'), TaskModel::EVENT_DAILY_CRONJOB => t('Daily background job for tasks'), + TaskModel::EVENT_MOVE_SWIMLANE => t('Move a task to another swimlane'), ); $events = array_merge($events, $this->events); diff --git a/app/Model/ActionParameterModel.php b/app/Model/ActionParameterModel.php index 9895da0f..d4d45178 100644 --- a/app/Model/ActionParameterModel.php +++ b/app/Model/ActionParameterModel.php @@ -157,7 +157,10 @@ class ActionParameterModel extends Base case 'user_id': case 'owner_id': return $this->projectPermissionModel->isAssignable($project_id, $value) ? $value : false; - default: + case 'swimlane_id': + $column = $this->swimlaneModel->getById($value); + return empty($column) ? false : $this->swimlaneModel->getIdByName($project_id, $column['name']) ?: false; + default: return $value; } } diff --git a/app/ServiceProvider/ActionProvider.php b/app/ServiceProvider/ActionProvider.php index 946fbf41..d46562b7 100644 --- a/app/ServiceProvider/ActionProvider.php +++ b/app/ServiceProvider/ActionProvider.php @@ -36,6 +36,8 @@ use Kanboard\Action\TaskOpen; use Kanboard\Action\TaskUpdateStartDate; use Kanboard\Action\TaskCloseNoActivity; use Kanboard\Action\TaskCloseNoActivityColumn; +use Kanboard\Action\TaskAssignColorSwimlane; +use Kanboard\Action\TaskAssignPrioritySwimlane; /** * Action Provider @@ -86,6 +88,8 @@ class ActionProvider implements ServiceProviderInterface $container['actionManager']->register(new TaskOpen($container)); $container['actionManager']->register(new TaskUpdateStartDate($container)); $container['actionManager']->register(new TaskAssignDueDateOnCreation($container)); + $container['actionManager']->register(new TaskAssignColorSwimlane($container)); + $container['actionManager']->register(new TaskAssignPrioritySwimlane($container)); return $container; } diff --git a/app/Template/action/index.php b/app/Template/action/index.php index 0a94e4f0..7140dc85 100644 --- a/app/Template/action/index.php +++ b/app/Template/action/index.php @@ -54,6 +54,8 @@ text->in($param_value, $categories_list) ?> text->contains($param_name, 'link_id')): ?> text->in($param_value, $links_list) ?> + text->contains($param_name, 'swimlane_id')): ?> + text->in($param_value, $swimlane_list) ?> text->e($param_value) ?> diff --git a/app/Template/action_creation/params.php b/app/Template/action_creation/params.php index fa892177..bcf863d7 100644 --- a/app/Template/action_creation/params.php +++ b/app/Template/action_creation/params.php @@ -41,10 +41,13 @@ text->contains($param_name, 'duration')): ?> form->label($param_desc, $param_name) ?> form->number('params['.$param_name.']', $values) ?> - + text->contains($param_name, 'swimlane_id')): ?> + form->label($param_desc, $param_name) ?> + form->select('params['.$param_name.']', $swimlane_list, $values) ?> + form->label($param_desc, $param_name) ?> form->text('params['.$param_name.']', $values) ?> - +
-- cgit v1.2.3 From e8ec7861af9205898d9ff2d5d7ca76a31224044b Mon Sep 17 00:00:00 2001 From: dalmond Date: Wed, 17 Aug 2016 12:29:53 +0100 Subject: New Automatic Actions: Colour by Swimlane and Priority by Swimlane --- app/Action/TaskAssignColorSwimlane.php | 99 ++++++++++++++++++++++ app/Action/TaskAssignPrioritySwimlane.php | 99 ++++++++++++++++++++++ tests/units/Action/TaskAssignColorSwimlaneTest.php | 66 +++++++++++++++ .../Action/TaskAssignPrioritySwimlaneTest.php | 66 +++++++++++++++ 4 files changed, 330 insertions(+) create mode 100644 app/Action/TaskAssignColorSwimlane.php create mode 100644 app/Action/TaskAssignPrioritySwimlane.php create mode 100644 tests/units/Action/TaskAssignColorSwimlaneTest.php create mode 100644 tests/units/Action/TaskAssignPrioritySwimlaneTest.php diff --git a/app/Action/TaskAssignColorSwimlane.php b/app/Action/TaskAssignColorSwimlane.php new file mode 100644 index 00000000..31f2d25a --- /dev/null +++ b/app/Action/TaskAssignColorSwimlane.php @@ -0,0 +1,99 @@ + t('Swimlane'), + 'color_id' => t('Color'), + ); + } + + /** + * Get the required parameter for the event + * + * @access public + * @return string[] + */ + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'task' => array( + 'project_id', + 'swimlane_id', + ), + ); + } + + /** + * Execute the action (set the task color) + * + * @access public + * @param array $data Event data dictionary + * @return bool True if the action was executed or false when not executed + */ + public function doAction(array $data) + { + $values = array( + 'id' => $data['task_id'], + 'color_id' => $this->getParam('color_id'), + ); + + return $this->taskModificationModel->update($values, false); + } + + /** + * Check if the event data meet the action condition + * + * @access public + * @param array $data Event data dictionary + * @return bool + */ + public function hasRequiredCondition(array $data) + { + return $data['task']['swimlane_id'] == $this->getParam('swimlane_id'); + } +} diff --git a/app/Action/TaskAssignPrioritySwimlane.php b/app/Action/TaskAssignPrioritySwimlane.php new file mode 100644 index 00000000..7eaca7c8 --- /dev/null +++ b/app/Action/TaskAssignPrioritySwimlane.php @@ -0,0 +1,99 @@ + t('Swimlane'), + 'priority' => t('Priority'), + ); + } + + /** + * Get the required parameter for the event + * + * @access public + * @return string[] + */ + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'task' => array( + 'project_id', + 'swimlane_id', + ), + ); + } + + /** + * Execute the action (set the priority) + * + * @access public + * @param array $data Event data dictionary + * @return bool True if the action was executed or false when not executed + */ + public function doAction(array $data) + { + $values = array( + 'id' => $data['task_id'], + 'priority' => $this->getParam('priority'), + ); + + return $this->taskModificationModel->update($values); + } + + /** + * Check if the event data meet the action condition + * + * @access public + * @param array $data Event data dictionary + * @return bool + */ + public function hasRequiredCondition(array $data) + { + return $data['task']['swimlane_id'] == $this->getParam('swimlane_id'); + } +} diff --git a/tests/units/Action/TaskAssignColorSwimlaneTest.php b/tests/units/Action/TaskAssignColorSwimlaneTest.php new file mode 100644 index 00000000..898838da --- /dev/null +++ b/tests/units/Action/TaskAssignColorSwimlaneTest.php @@ -0,0 +1,66 @@ +container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new TaskEvent(array( + 'task_id' => 1, + 'task' => array( + 'project_id' => 1, + 'swimlane_id' => 2, + ) + )); + + $action = new TaskAssignColorSwimlane($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); + $action->setParam('swimlane_id', 2); + + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_SWIMLANE)); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('red', $task['color_id']); + } + + public function testWithWrongCategory() + { + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new TaskEvent(array( + 'task_id' => 1, + 'task' => array( + 'project_id' => 1, + 'swimlane_id' => 3, + ) + )); + + $action = new TaskAssignColorSwimlane($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); + $action->setParam('swimlane_id', 2); + + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_SWIMLANE)); + } +} diff --git a/tests/units/Action/TaskAssignPrioritySwimlaneTest.php b/tests/units/Action/TaskAssignPrioritySwimlaneTest.php new file mode 100644 index 00000000..f7217f5b --- /dev/null +++ b/tests/units/Action/TaskAssignPrioritySwimlaneTest.php @@ -0,0 +1,66 @@ +container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new TaskEvent(array( + 'task_id' => 1, + 'task' => array( + 'project_id' => 1, + 'priority' => 1, + ) + )); + + $action = new TaskAssignPrioritySwimlane($this->container); + $action->setProjectId(1); + $action->setParam('priority', 2); + $action->setParam('swimlane_id', 2); + + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_SWIMLANE)); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['priority']); + } + + public function testWithWrongCategory() + { + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new TaskEvent(array( + 'task_id' => 1, + 'task' => array( + 'project_id' => 1, + 'swimlane_id' => 3, + ) + )); + + $action = new TaskAssignColorColumn($this->container); + $action->setProjectId(1); + $action->setParam('priority', 2); + $action->setParam('swimlane_id', 2); + + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_SWIMLANE)); + } +} -- cgit v1.2.3 From 25bdb03927007a20e6f518987508b39b9588fc97 Mon Sep 17 00:00:00 2001 From: dalmond Date: Wed, 17 Aug 2016 15:58:35 +0100 Subject: Corrected Unit Test --- tests/units/Action/TaskAssignPrioritySwimlaneTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/units/Action/TaskAssignPrioritySwimlaneTest.php b/tests/units/Action/TaskAssignPrioritySwimlaneTest.php index f7217f5b..255d26e3 100644 --- a/tests/units/Action/TaskAssignPrioritySwimlaneTest.php +++ b/tests/units/Action/TaskAssignPrioritySwimlaneTest.php @@ -9,7 +9,7 @@ use Kanboard\Model\ProjectModel; use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignPrioritySwimlane; -class TaskAssignColorColumnTest extends Base +class TaskAssignPrioritySwimlaneTest extends Base { public function testChangeSwimlane() { -- cgit v1.2.3 From 37425d45a621929bfa209f84f101ac8cd42b0d06 Mon Sep 17 00:00:00 2001 From: dalmond Date: Mon, 22 Aug 2016 18:37:34 +0100 Subject: Unit Test Issues Resolved --- tests/units/Action/TaskAssignColorSwimlaneTest.php | 6 +++- .../Action/TaskAssignPrioritySwimlaneTest.php | 32 ++++------------------ 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/tests/units/Action/TaskAssignColorSwimlaneTest.php b/tests/units/Action/TaskAssignColorSwimlaneTest.php index 898838da..811ffac3 100644 --- a/tests/units/Action/TaskAssignColorSwimlaneTest.php +++ b/tests/units/Action/TaskAssignColorSwimlaneTest.php @@ -28,6 +28,10 @@ class TaskAssignColorSwimlaneTest extends Base ) )); + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertNotEquals('red', $task['color_id']); + $action = new TaskAssignColorSwimlane($this->container); $action->setProjectId(1); $action->setParam('color_id', 'red'); @@ -40,7 +44,7 @@ class TaskAssignColorSwimlaneTest extends Base $this->assertEquals('red', $task['color_id']); } - public function testWithWrongCategory() + public function testWithWrongSwimlane() { $projectModel = new ProjectModel($this->container); $taskCreationModel = new TaskCreationModel($this->container); diff --git a/tests/units/Action/TaskAssignPrioritySwimlaneTest.php b/tests/units/Action/TaskAssignPrioritySwimlaneTest.php index 255d26e3..39c833bf 100644 --- a/tests/units/Action/TaskAssignPrioritySwimlaneTest.php +++ b/tests/units/Action/TaskAssignPrioritySwimlaneTest.php @@ -18,13 +18,17 @@ class TaskAssignPrioritySwimlaneTest extends Base $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'priority' => 1))); + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['priority']); + $event = new TaskEvent(array( 'task_id' => 1, 'task' => array( 'project_id' => 1, - 'priority' => 1, + 'swimlane_id' => 2, ) )); @@ -39,28 +43,4 @@ class TaskAssignPrioritySwimlaneTest extends Base $this->assertNotEmpty($task); $this->assertEquals(2, $task['priority']); } - - public function testWithWrongCategory() - { - $projectModel = new ProjectModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); - - $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - - $event = new TaskEvent(array( - 'task_id' => 1, - 'task' => array( - 'project_id' => 1, - 'swimlane_id' => 3, - ) - )); - - $action = new TaskAssignColorColumn($this->container); - $action->setProjectId(1); - $action->setParam('priority', 2); - $action->setParam('swimlane_id', 2); - - $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_SWIMLANE)); - } } -- cgit v1.2.3