Add two automatic actions for subtasks

- Action to create a subtask assigned to the creator and start the timer
- Action to stop the timer of subtasks
This commit is contained in:
Frédéric Guillot 2017-12-06 18:31:43 -08:00
parent 0060fb9d5c
commit 230eddcc69
33 changed files with 303 additions and 6 deletions

View File

@ -0,0 +1,102 @@
<?php
namespace Kanboard\Action;
use Kanboard\Model\TaskModel;
use Kanboard\Model\SubtaskModel;
/**
* Stop the timer of all subtasks when moving a task to another column.
*
* @package Kanboard\Action
* @author Frederic Guillot
*/
class StopSubtaskTimerMoveTaskColumn extends Base
{
/**
* Get automatic action description
*
* @access public
* @return string
*/
public function getDescription()
{
return t('Stop the timer of all subtasks when moving a task to another column');
}
/**
* Get the list of compatible events
*
* @access public
* @return array
*/
public function getCompatibleEvents()
{
return array(
TaskModel::EVENT_MOVE_COLUMN,
);
}
/**
* Get the required parameter for the action (defined by the user)
*
* @access public
* @return array
*/
public function getActionRequiredParameters()
{
return array(
'column_id' => t('Column'),
);
}
/**
* Get the required parameter for the event
*
* @access public
* @return string[]
*/
public function getEventRequiredParameters()
{
return array(
'task_id',
'task' => array(
'id',
'column_id',
'project_id',
),
);
}
/**
* Execute the action (append to the task description).
*
* @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)
{
$subtasks = $this->subtaskModel->getAll($data['task']['id']);
$results = array();
foreach ($subtasks as $subtask) {
$results[] = $this->subtaskModel->update(array('id' => $subtask['id'], 'status' => SubtaskModel::STATUS_DONE));
$results[] = $this->subtaskTimeTrackingModel->logEndTime($subtask['id'], $subtask['user_id']);
}
return !in_array(false, $results, true);
}
/**
* 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('column_id');
}
}

View File

@ -0,0 +1,107 @@
<?php
namespace Kanboard\Action;
use Kanboard\Model\TaskModel;
use Kanboard\Model\SubtaskModel;
/**
* Create a subtask and activate the timer when moving a task to another column.
*
* @package Kanboard\Action
* @author Frederic Guillot
*/
class SubtaskTimerMoveTaskColumn extends Base
{
/**
* Get automatic action description
*
* @access public
* @return string
*/
public function getDescription()
{
return t('Add a subtask and activate the timer when moving a task to another column');
}
/**
* Get the list of compatible events
*
* @access public
* @return array
*/
public function getCompatibleEvents()
{
return array(
TaskModel::EVENT_MOVE_COLUMN,
);
}
/**
* Get the required parameter for the action (defined by the user)
*
* @access public
* @return array
*/
public function getActionRequiredParameters()
{
return array(
'column_id' => t('Column'),
'subtask' => t('Subtask Title'),
);
}
/**
* Get the required parameter for the event
*
* @access public
* @return string[]
*/
public function getEventRequiredParameters()
{
return array(
'task_id',
'task' => array(
'id',
'column_id',
'project_id',
'creator_id',
),
);
}
/**
* Execute the action (append to the task description).
*
* @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)
{
$subtaskID = $this->subtaskModel->create(array(
'title' => $this->getParam('subtask'),
'user_id' => $data['task']['creator_id'],
'task_id' => $data['task']['id'],
'status' => SubtaskModel::STATUS_INPROGRESS,
));
if ($subtaskID !== false) {
return $this->subtaskTimeTrackingModel->toggleTimer($subtaskID, $data['task']['creator_id'], SubtaskModel::STATUS_INPROGRESS);
}
return 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('column_id');
}
}

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
'Time Spent' => 'Zeitaufwand',
'External Link' => 'externer Link',
'This feature enable the iCal feed, RSS feed and the public board view.' => 'Diese Funktion aktiviert den iCal Feed, RSS Feed und die öffentliche Board-Ansicht',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
'Time Spent' => 'Temps passé',
'External Link' => 'Lien externe',
'This feature enable the iCal feed, RSS feed and the public board view.' => 'Cette fonctionalité active l\'abonnement iCal, le flux RSS et la vue publique du tableau.',
'Stop the timer of all subtasks when moving a task to another column' => 'Arrêter le minuteur de toutes les sous-tâches lorsque la tâche est déplaçée dans une autre colonne',
'Subtask Title' => 'Titre de la sous-tâche',
'Add a subtask and activate the timer when moving a task to another column' => 'Ajouter une sous-tâche et activer le minuteur lorsque la tâche est déplaçé dans une autre colonne',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1015,12 +1015,6 @@ return array(
'Add a new action' => 'Thêm một hành động mới',
'Import from another project' => 'Nhập khẩu từ một dự án khác',
'There is no action at the moment.' => 'Hiện tại không có hành động nào.',
// 'Example: https://example.kanboard.org/ (used to generate absolute URLs)' => '',
// 'Actions duplicated successfully.' => '',
// 'Unable to duplicate actions.' => '',
// 'Add a new action' => '',
// 'Import from another project' => '',
// 'There is no action at the moment.' => '',
'Import actions from another project' => 'Nhập khẩu các hành động từ một dự án khác',
'There is no available project.' => 'Không có dự án sẵn có.',
'Local File' => 'Local File',
@ -1373,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -1367,4 +1367,7 @@ return array(
// 'Time Spent' => '',
// 'External Link' => '',
// 'This feature enable the iCal feed, RSS feed and the public board view.' => '',
// 'Stop the timer of all subtasks when moving a task to another column' => '',
// 'Subtask Title' => '',
// 'Add a subtask and activate the timer when moving a task to another column' => '',
);

View File

@ -41,6 +41,8 @@ use Kanboard\Action\TaskCloseNoActivityColumn;
use Kanboard\Action\TaskCloseNotMovedColumn;
use Kanboard\Action\TaskAssignColorSwimlane;
use Kanboard\Action\TaskAssignPrioritySwimlane;
use Kanboard\Action\SubtaskTimerMoveTaskColumn;
use Kanboard\Action\StopSubtaskTimerMoveTaskColumn;
/**
* Action Provider
@ -96,6 +98,8 @@ class ActionProvider implements ServiceProviderInterface
$container['actionManager']->register(new TaskAssignColorSwimlane($container));
$container['actionManager']->register(new TaskAssignPrioritySwimlane($container));
$container['actionManager']->register(new TaskAssignColorOnDueDate($container));
$container['actionManager']->register(new SubtaskTimerMoveTaskColumn($container));
$container['actionManager']->register(new StopSubtaskTimerMoveTaskColumn($container));
return $container;
}