Add new automatic action to move a task to another column when closed

This commit is contained in:
Frederic Guillot
2016-07-23 18:33:31 -04:00
parent 2a42e0e1aa
commit 9b2a32af78
35 changed files with 236 additions and 39 deletions

View File

@@ -7,7 +7,7 @@ use Kanboard\Event\GenericEvent;
/**
* Base class for automatic actions
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
abstract class Base extends \Kanboard\Core\Base

View File

@@ -5,7 +5,7 @@ namespace Kanboard\Action;
/**
* Create automatically a comment from a webhook
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class CommentCreation extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Add a comment of the triggering event to the task description.
*
* @package action
* @package Kanboard\Action
* @author Oren Ben-Kiki
*/
class CommentCreationMoveTaskColumn extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Set a category automatically according to the color
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignCategoryColor extends Base

View File

@@ -5,7 +5,7 @@ namespace Kanboard\Action;
/**
* Set a category automatically according to a label
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignCategoryLabel extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskLinkModel;
/**
* Set a category automatically according to a task link
*
* @package action
* @package Kanboard\Action
* @author Olivier Maridat
* @author Frederic Guillot
*/

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a color to a specific category
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignColorCategory extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a color to a task
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignColorColumn extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskLinkModel;
/**
* Assign a color to a specific task link
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignColorLink extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a color to a priority
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignColorPriority extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a color to a specific user
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignColorUser extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a task to the logged user
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignCurrentUser extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a task to the logged user on column change
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignCurrentUserColumn extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Set the due date of task
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignDueDateOnCreation extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Assign a task to a specific user
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskAssignSpecificUser extends Base

View File

@@ -5,7 +5,7 @@ namespace Kanboard\Action;
/**
* Assign a task to someone
*
* @package action
* @package Kanboard\Actionv
* @author Frederic Guillot
*/
class TaskAssignUser extends Base

View File

@@ -5,7 +5,7 @@ namespace Kanboard\Action;
/**
* Close automatically a task
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskClose extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Close automatically a task in a specific column
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskCloseColumn extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Close automatically a task after when inactive
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskCloseNoActivity extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Close automatically a task after inactive and in an defined column
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskCloseNoActivityColumn extends Base

View File

@@ -5,7 +5,7 @@ namespace Kanboard\Action;
/**
* Create automatically a task from a webhook
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskCreation extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Duplicate a task to another project
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskDuplicateAnotherProject extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Email a task to someone
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskEmail extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Email a task with no activity
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskEmailNoActivity extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Move a task to another project
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskMoveAnotherProject extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Move a task to another column when an assignee is set
*
* @package action
* @package Kanboard\Action
* @author Francois Ferrand
*/
class TaskMoveColumnAssigned extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Move a task to another column when the category is changed
*
* @package action
* @package Kanboard\Action
* @author Francois Ferrand
*/
class TaskMoveColumnCategoryChange extends Base

View File

@@ -0,0 +1,102 @@
<?php
namespace Kanboard\Action;
use Kanboard\Model\TaskModel;
/**
* Move a task to another column when the task is closed
*
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskMoveColumnClosed extends Base
{
/**
* Get automatic action description
*
* @access public
* @return string
*/
public function getDescription()
{
return t('Move the task to another column when closed');
}
/**
* Get the list of compatible events
*
* @access public
* @return array
*/
public function getCompatibleEvents()
{
return array(
TaskModel::EVENT_CLOSE,
);
}
/**
* Get the required parameter for the action (defined by the user)
*
* @access public
* @return array
*/
public function getActionRequiredParameters()
{
return array(
'dest_column_id' => t('Destination column'),
);
}
/**
* Get the required parameter for the event
*
* @access public
* @return string[]
*/
public function getEventRequiredParameters()
{
return array(
'task_id',
'task' => array(
'project_id',
'column_id',
'swimlane_id',
'is_active',
)
);
}
/**
* Execute the action (move the task to another column)
*
* @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)
{
return $this->taskPositionModel->movePosition(
$data['task']['project_id'],
$data['task']['id'],
$this->getParam('dest_column_id'),
1,
$data['task']['swimlane_id'],
false,
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']['column_id'] != $this->getParam('dest_column_id') && $data['task']['is_active'] == 0;
}
}

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Move a task to another column when an assignee is cleared
*
* @package action
* @package Kanboard\Action
* @author Francois Ferrand
*/
class TaskMoveColumnUnAssigned extends Base

View File

@@ -5,7 +5,7 @@ namespace Kanboard\Action;
/**
* Open automatically a task
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskOpen extends Base

View File

@@ -7,7 +7,7 @@ use Kanboard\Model\TaskModel;
/**
* Set the start date of task
*
* @package action
* @package Kanboard\Action
* @author Frederic Guillot
*/
class TaskUpdateStartDate extends Base

View File

@@ -16,15 +16,16 @@ class TaskPositionModel extends Base
* Move a task to another column or to another position
*
* @access public
* @param integer $project_id Project id
* @param integer $task_id Task id
* @param integer $column_id Column id
* @param integer $position Position (must be >= 1)
* @param integer $swimlane_id Swimlane id
* @param boolean $fire_events Fire events
* @return boolean
* @param integer $project_id Project id
* @param integer $task_id Task id
* @param integer $column_id Column id
* @param integer $position Position (must be >= 1)
* @param integer $swimlane_id Swimlane id
* @param boolean $fire_events Fire events
* @param bool $onlyOpen Do not move closed tasks
* @return bool
*/
public function movePosition($project_id, $task_id, $column_id, $position, $swimlane_id = 0, $fire_events = true)
public function movePosition($project_id, $task_id, $column_id, $position, $swimlane_id = 0, $fire_events = true, $onlyOpen = true)
{
if ($position < 1) {
return false;
@@ -32,7 +33,7 @@ class TaskPositionModel extends Base
$task = $this->taskFinderModel->getById($task_id);
if ($task['is_active'] == TaskModel::STATUS_CLOSED) {
if ($onlyOpen && $task['is_active'] == TaskModel::STATUS_CLOSED) {
return true;
}

View File

@@ -4,6 +4,7 @@ namespace Kanboard\ServiceProvider;
use Kanboard\Action\TaskAssignColorPriority;
use Kanboard\Action\TaskAssignDueDateOnCreation;
use Kanboard\Action\TaskMoveColumnClosed;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Kanboard\Core\Action\ActionManager;
@@ -78,6 +79,7 @@ class ActionProvider implements ServiceProviderInterface
$container['actionManager']->register(new TaskMoveAnotherProject($container));
$container['actionManager']->register(new TaskMoveColumnAssigned($container));
$container['actionManager']->register(new TaskMoveColumnCategoryChange($container));
$container['actionManager']->register(new TaskMoveColumnClosed($container));
$container['actionManager']->register(new TaskMoveColumnUnAssigned($container));
$container['actionManager']->register(new TaskOpen($container));
$container['actionManager']->register(new TaskUpdateStartDate($container));