diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Action/TaskAssignColorPriority.php | 95 | ||||
-rw-r--r-- | app/Controller/ActionCreation.php | 1 | ||||
-rw-r--r-- | app/Model/Project.php | 15 | ||||
-rw-r--r-- | app/ServiceProvider/ActionProvider.php | 2 | ||||
-rw-r--r-- | app/Template/action_creation/params.php | 5 |
5 files changed, 116 insertions, 2 deletions
diff --git a/app/Action/TaskAssignColorPriority.php b/app/Action/TaskAssignColorPriority.php new file mode 100644 index 00000000..2e24f9ef --- /dev/null +++ b/app/Action/TaskAssignColorPriority.php @@ -0,0 +1,95 @@ +<?php + +namespace Kanboard\Action; + +use Kanboard\Model\Task; + +/** + * Assign a color to a priority + * + * @package action + * @author Frederic Guillot + */ +class TaskAssignColorPriority extends Base +{ + /** + * Get automatic action description + * + * @access public + * @return string + */ + public function getDescription() + { + return t('Assign automatically a color based on a priority'); + } + + /** + * Get the list of compatible events + * + * @access public + * @return array + */ + public function getCompatibleEvents() + { + return array( + Task::EVENT_CREATE_UPDATE, + ); + } + + /** + * Get the required parameter for the action (defined by the user) + * + * @access public + * @return array + */ + public function getActionRequiredParameters() + { + return array( + 'color_id' => t('Color'), + 'priority' => t('Priority'), + ); + } + + /** + * Get the required parameter for the event + * + * @access public + * @return string[] + */ + public function getEventRequiredParameters() + { + return array( + 'task_id', + 'priority', + ); + } + + /** + * Execute the action (change 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->taskModification->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['priority'] == $this->getParam('priority'); + } +} diff --git a/app/Controller/ActionCreation.php b/app/Controller/ActionCreation.php index 24a12d92..61b7b5e2 100644 --- a/app/Controller/ActionCreation.php +++ b/app/Controller/ActionCreation.php @@ -81,6 +81,7 @@ class ActionCreation extends Base 'colors_list' => $this->color->getList(), 'categories_list' => $this->category->getList($project['id']), 'links_list' => $this->link->getList(0, false), + 'priorities_list' => $this->project->getPriorities($project), 'project' => $project, 'available_actions' => $this->actionManager->getAvailableActions(), 'events' => $this->actionManager->getCompatibleEvents($values['action_name']), diff --git a/app/Model/Project.php b/app/Model/Project.php index 6e3c2326..9843a54c 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -201,7 +201,7 @@ class Project extends Base * Get all projects with all its data for a given status * * @access public - * @param integer $status Proejct status: self::ACTIVE or self:INACTIVE + * @param integer $status Project status: self::ACTIVE or self:INACTIVE * @return array */ public function getAllByStatus($status) @@ -245,6 +245,19 @@ class Project extends Base } /** + * Get Priority range from a project + * + * @access public + * @param array $project + * @return array + */ + public function getPriorities(array $project) + { + $range = range($project['priority_start'], $project['priority_end']); + return array_combine($range, $range); + } + + /** * Gather some task metrics for a given project * * @access public diff --git a/app/ServiceProvider/ActionProvider.php b/app/ServiceProvider/ActionProvider.php index 3692f190..7c92f3ce 100644 --- a/app/ServiceProvider/ActionProvider.php +++ b/app/ServiceProvider/ActionProvider.php @@ -2,6 +2,7 @@ namespace Kanboard\ServiceProvider; +use Kanboard\Action\TaskAssignColorPriority; use Pimple\Container; use Pimple\ServiceProviderInterface; use Kanboard\Core\Action\ActionManager; @@ -59,6 +60,7 @@ class ActionProvider implements ServiceProviderInterface $container['actionManager']->register(new TaskAssignColorColumn($container)); $container['actionManager']->register(new TaskAssignColorLink($container)); $container['actionManager']->register(new TaskAssignColorUser($container)); + $container['actionManager']->register(new TaskAssignColorPriority($container)); $container['actionManager']->register(new TaskAssignCurrentUser($container)); $container['actionManager']->register(new TaskAssignCurrentUserColumn($container)); $container['actionManager']->register(new TaskAssignSpecificUser($container)); diff --git a/app/Template/action_creation/params.php b/app/Template/action_creation/params.php index 59ff6ce9..46ca52a4 100644 --- a/app/Template/action_creation/params.php +++ b/app/Template/action_creation/params.php @@ -35,6 +35,9 @@ <?php elseif ($this->text->contains($param_name, 'link_id')): ?> <?= $this->form->label($param_desc, $param_name) ?> <?= $this->form->select('params['.$param_name.']', $links_list, $values) ?> + <?php elseif ($param_name === 'priority'): ?> + <?= $this->form->label($param_desc, $param_name) ?> + <?= $this->form->select('params['.$param_name.']', $priorities_list, $values) ?> <?php elseif ($this->text->contains($param_name, 'duration')): ?> <?= $this->form->label($param_desc, $param_name) ?> <?= $this->form->number('params['.$param_name.']', $values) ?> @@ -49,4 +52,4 @@ <?= t('or') ?> <?= $this->url->link(t('cancel'), 'action', 'index', array('project_id' => $project['id']), false, 'close-popover') ?> </div> -</form>
\ No newline at end of file +</form> |