Add new automatic action to update the start date
This commit is contained in:
@@ -8,6 +8,7 @@ use Model\Task;
|
|||||||
* Assign a color to a task
|
* Assign a color to a task
|
||||||
*
|
*
|
||||||
* @package action
|
* @package action
|
||||||
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
class TaskAssignColorColumn extends Base
|
class TaskAssignColorColumn extends Base
|
||||||
{
|
{
|
||||||
|
|||||||
83
app/Action/TaskUpdateStartDate.php
Normal file
83
app/Action/TaskUpdateStartDate.php
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Action;
|
||||||
|
|
||||||
|
use Model\Task;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the start date of task
|
||||||
|
*
|
||||||
|
* @package action
|
||||||
|
* @author Frederic Guillot
|
||||||
|
*/
|
||||||
|
class TaskUpdateStartDate extends Base
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the list of compatible events
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getCompatibleEvents()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
Task::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',
|
||||||
|
'column_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'],
|
||||||
|
'date_started' => time(),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->taskModification->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['column_id'] == $this->getParam('column_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -918,4 +918,5 @@ return array(
|
|||||||
'Show tasks based on the start date' => 'Afficher les tâches en fonction de la date de début',
|
'Show tasks based on the start date' => 'Afficher les tâches en fonction de la date de début',
|
||||||
'Subtasks time tracking' => 'Suivi du temps par rapport aux sous-tâches',
|
'Subtasks time tracking' => 'Suivi du temps par rapport aux sous-tâches',
|
||||||
'User calendar view' => 'Vue en mode utilisateur du calendrier',
|
'User calendar view' => 'Vue en mode utilisateur du calendrier',
|
||||||
|
'Automatically update the start date' => 'Mettre à jour automatiquement la date de début',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -916,4 +916,5 @@ return array(
|
|||||||
// 'Show tasks based on the start date' => '',
|
// 'Show tasks based on the start date' => '',
|
||||||
// 'Subtasks time tracking' => '',
|
// 'Subtasks time tracking' => '',
|
||||||
// 'User calendar view' => '',
|
// 'User calendar view' => '',
|
||||||
|
// 'Automatically update the start date' => '',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ class Action extends Base
|
|||||||
'TaskLogMoveAnotherColumn' => t('Add a comment logging moving the task between columns'),
|
'TaskLogMoveAnotherColumn' => t('Add a comment logging moving the task between columns'),
|
||||||
'TaskAssignUser' => t('Change the assignee based on an external username'),
|
'TaskAssignUser' => t('Change the assignee based on an external username'),
|
||||||
'TaskAssignCategoryLabel' => t('Change the category based on an external label'),
|
'TaskAssignCategoryLabel' => t('Change the category based on an external label'),
|
||||||
|
'TaskUpdateStartDate' => t('Automatically update the start date'),
|
||||||
);
|
);
|
||||||
|
|
||||||
asort($values);
|
asort($values);
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ List of available actions
|
|||||||
- Change the assignee based on an external username
|
- Change the assignee based on an external username
|
||||||
- Change the category based on an external label
|
- Change the category based on an external label
|
||||||
- Create a comment from an external provider
|
- Create a comment from an external provider
|
||||||
|
- Automatically update the start date
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
@@ -71,46 +72,52 @@ Here are some examples used in the real life:
|
|||||||
|
|
||||||
### When I move a task to the column "Done", automatically close this task
|
### When I move a task to the column "Done", automatically close this task
|
||||||
|
|
||||||
- Choose the event: **Move a task to another column**
|
|
||||||
- Choose the action: **Close the task**
|
- Choose the action: **Close the task**
|
||||||
|
- Choose the event: **Move a task to another column**
|
||||||
- Define the action parameter: **Column = Done** (this is the destination column)
|
- Define the action parameter: **Column = Done** (this is the destination column)
|
||||||
|
|
||||||
### When I move a task to the column "To be validated", assign this task to a specific user
|
### When I move a task to the column "To be validated", assign this task to a specific user
|
||||||
|
|
||||||
- Choose the event: **Move a task to another column**
|
|
||||||
- Choose the action: **Assign the task to a specific user**
|
- Choose the action: **Assign the task to a specific user**
|
||||||
|
- Choose the event: **Move a task to another column**
|
||||||
- Define the action parameters: **Column = To be validated** and **User = Bob** (Bob is our tester)
|
- Define the action parameters: **Column = To be validated** and **User = Bob** (Bob is our tester)
|
||||||
|
|
||||||
### When I move a task to the column "Work in progress", assign this task to the current user
|
### When I move a task to the column "Work in progress", assign this task to the current user
|
||||||
|
|
||||||
- Choose the event: **Move a task to another column**
|
|
||||||
- Choose the action: **Assign the task to the person who does the action**
|
- Choose the action: **Assign the task to the person who does the action**
|
||||||
|
- Choose the event: **Move a task to another column**
|
||||||
- Define the action parameter: **Column = Work in progress**
|
- Define the action parameter: **Column = Work in progress**
|
||||||
|
|
||||||
### When a task is completed, duplicate this task to another project
|
### When a task is completed, duplicate this task to another project
|
||||||
|
|
||||||
Let's say we have two projects "Customer orders" and "Production", once the order is validated, swap it to the "Production" project.
|
Let's say we have two projects "Customer orders" and "Production", once the order is validated, swap it to the "Production" project.
|
||||||
|
|
||||||
- Choose the event: **Closing a task**
|
|
||||||
- Choose the action: **Duplicate the task to another project**
|
- Choose the action: **Duplicate the task to another project**
|
||||||
|
- Choose the event: **Closing a task**
|
||||||
- Define the action parameters: **Column = Validated** and **Project = Production**
|
- Define the action parameters: **Column = Validated** and **Project = Production**
|
||||||
|
|
||||||
### When a task is moved to the last column, move the exact same task to another project
|
### When a task is moved to the last column, move the exact same task to another project
|
||||||
|
|
||||||
Let's say we have two projects "Ideas" and "Development", once the idea is validated, swap it to the "Development" project.
|
Let's say we have two projects "Ideas" and "Development", once the idea is validated, swap it to the "Development" project.
|
||||||
|
|
||||||
- Choose the event: **Move a task to another column**
|
|
||||||
- Choose the action: **Move the task to another project**
|
- Choose the action: **Move the task to another project**
|
||||||
|
- Choose the event: **Move a task to another column**
|
||||||
- Define the action parameters: **Column = Validated** and **Project = Development**
|
- Define the action parameters: **Column = Validated** and **Project = Development**
|
||||||
|
|
||||||
### I want to assign automatically a color to the user Bob
|
### I want to assign automatically a color to the user Bob
|
||||||
|
|
||||||
- Choose the event: **Task assignee change**
|
|
||||||
- Choose the action: **Assign a color to a specific user**
|
- Choose the action: **Assign a color to a specific user**
|
||||||
|
- Choose the event: **Task assignee change**
|
||||||
- Define the action parameters: **Color = Green** and **Assignee = Bob**
|
- Define the action parameters: **Color = Green** and **Assignee = Bob**
|
||||||
|
|
||||||
### I want to assign automatically a color to the defined category "Feature Request"
|
### I want to assign automatically a color to the defined category "Feature Request"
|
||||||
|
|
||||||
- Choose the event: **Task creation or modification**
|
|
||||||
- Choose the action: **Assign automatically a color based on a category**
|
- Choose the action: **Assign automatically a color based on a category**
|
||||||
|
- Choose the event: **Task creation or modification**
|
||||||
- Define the action parameters: **Color = Blue** and **Category = Feature Request**
|
- Define the action parameters: **Color = Blue** and **Category = Feature Request**
|
||||||
|
|
||||||
|
### I want to set the start date automatically when the task is moved to the column "Work in progress"
|
||||||
|
|
||||||
|
- Choose the action: **Automatically update the start date**
|
||||||
|
- Choose the event: **Move a task to another column**
|
||||||
|
- Define the action parameters: **Column = Work in progress**
|
||||||
|
|||||||
46
tests/units/ActionTaskUpdateStartDateTest.php
Normal file
46
tests/units/ActionTaskUpdateStartDateTest.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__.'/Base.php';
|
||||||
|
|
||||||
|
use Event\GenericEvent;
|
||||||
|
use Model\Task;
|
||||||
|
use Model\TaskCreation;
|
||||||
|
use Model\TaskFinder;
|
||||||
|
use Model\Project;
|
||||||
|
use Integration\GithubWebhook;
|
||||||
|
|
||||||
|
class ActionTaskUpdateStartDateTest extends Base
|
||||||
|
{
|
||||||
|
public function testExecute()
|
||||||
|
{
|
||||||
|
$action = new Action\TaskUpdateStartDate($this->container, 1, Task::EVENT_MOVE_COLUMN);
|
||||||
|
$action->setParam('column_id', 2);
|
||||||
|
|
||||||
|
// We create a task in the first column
|
||||||
|
$tc = new TaskCreation($this->container);
|
||||||
|
$tf = new TaskFinder($this->container);
|
||||||
|
$p = new Project($this->container);
|
||||||
|
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||||
|
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
|
||||||
|
|
||||||
|
// The start date must be empty
|
||||||
|
$task = $tf->getById(1);
|
||||||
|
$this->assertNotEmpty($task);
|
||||||
|
$this->assertEmpty($task['date_started']);
|
||||||
|
|
||||||
|
// We create an event to move the task to the 2nd column
|
||||||
|
$event = array(
|
||||||
|
'project_id' => 1,
|
||||||
|
'task_id' => 1,
|
||||||
|
'column_id' => 2,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Our event should be executed
|
||||||
|
$this->assertTrue($action->execute(new GenericEvent($event)));
|
||||||
|
|
||||||
|
// Our task should be closed
|
||||||
|
$task = $tf->getById(1);
|
||||||
|
$this->assertNotEmpty($task);
|
||||||
|
$this->assertEquals(time(), $task['date_started'], '', 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user