From bb040cfb78d53696edd63bf256d0fd8ba3ccdbfa Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 30 Jan 2016 22:25:16 -0500 Subject: Simplify code to handle ajax popover and redirects --- app/Controller/Taskcreation.php | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'app/Controller/Taskcreation.php') diff --git a/app/Controller/Taskcreation.php b/app/Controller/Taskcreation.php index 49ccea7f..dc942594 100644 --- a/app/Controller/Taskcreation.php +++ b/app/Controller/Taskcreation.php @@ -18,22 +18,18 @@ class Taskcreation extends Base public function create(array $values = array(), array $errors = array()) { $project = $this->getProject(); - $method = $this->request->isAjax() ? 'render' : 'layout'; $swimlanes_list = $this->swimlane->getList($project['id'], false, true); if (empty($values)) { $values = array( 'swimlane_id' => $this->request->getIntegerParam('swimlane_id', key($swimlanes_list)), 'column_id' => $this->request->getIntegerParam('column_id'), - 'color_id' => $this->request->getStringParam('color_id', $this->color->getDefaultColor()), - 'owner_id' => $this->request->getIntegerParam('owner_id'), - 'another_task' => $this->request->getIntegerParam('another_task'), + 'color_id' => $this->color->getDefaultColor(), ); } - $this->response->html($this->template->$method('task_creation/form', array( + $this->response->html($this->template->render('task_creation/form', array( 'project' => $project, - 'ajax' => $this->request->isAjax(), 'errors' => $errors, 'values' => $values + array('project_id' => $project['id']), 'columns_list' => $this->board->getColumnsList($project['id']), @@ -61,25 +57,26 @@ class Taskcreation extends Base if ($valid && $this->taskCreation->create($values)) { $this->flash->success(t('Task created successfully.')); - $this->afterSave($project, $values); - } else { - $this->flash->failure(t('Unable to create your task.')); + return $this->afterSave($project, $values); } + $this->flash->failure(t('Unable to create your task.')); $this->create($values, $errors); } private function afterSave(array $project, array &$values) { if (isset($values['another_task']) && $values['another_task'] == 1) { - unset($values['title']); - unset($values['description']); - - if (! $this->request->isAjax()) { - $this->response->redirect($this->helper->url->to('taskcreation', 'create', $values)); - } - } else { - $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id']))); + return $this->create(array( + 'owner_id' => $values['owner_id'], + 'color_id' => $values['color_id'], + 'category_id' => $values['category_id'], + 'column_id' => $values['column_id'], + 'swimlane_id' => isset($values['swimlane_id']) ? $values['swimlane_id'] : 0, + 'another_task' => 1, + )); } + + $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id']))); } } -- cgit v1.2.3 From 3279768c1cff1534f435a080c4765f8a45290a4e Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 31 Jan 2016 10:36:46 -0500 Subject: Have a new task assigned to the creator by default instead of "no assignee" --- ChangeLog | 1 + app/Controller/Taskcreation.php | 1 + 2 files changed, 2 insertions(+) (limited to 'app/Controller/Taskcreation.php') diff --git a/ChangeLog b/ChangeLog index 031ab02c..84c10aee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,7 @@ New features: Improvements: +* Have a new task assigned to the creator by default instead of "no assignee" * Show progress for task links in board tooltips * Simplify code to handle ajax popover and redirects diff --git a/app/Controller/Taskcreation.php b/app/Controller/Taskcreation.php index dc942594..ed2ac1b9 100644 --- a/app/Controller/Taskcreation.php +++ b/app/Controller/Taskcreation.php @@ -25,6 +25,7 @@ class Taskcreation extends Base 'swimlane_id' => $this->request->getIntegerParam('swimlane_id', key($swimlanes_list)), 'column_id' => $this->request->getIntegerParam('column_id'), 'color_id' => $this->color->getDefaultColor(), + 'owner_id' => $this->userSession->getId(), ); } -- cgit v1.2.3 From d8e452d375493a70186866b876c0617bb3269e5f Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 31 Jan 2016 11:50:28 -0500 Subject: Move task form elements to Task helper --- ChangeLog | 1 + app/Controller/Gantt.php | 3 +- app/Controller/Taskcreation.php | 2 - app/Helper/Task.php | 82 +++++++++++++++++++++++++++- app/Template/board/popover_category.php | 3 +- app/Template/gantt/task_creation.php | 27 +++------ app/Template/task_creation/form.php | 29 ++-------- app/Template/task_modification/edit_task.php | 15 +---- 8 files changed, 100 insertions(+), 62 deletions(-) (limited to 'app/Controller/Taskcreation.php') diff --git a/ChangeLog b/ChangeLog index 967117b0..8868d410 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,7 @@ Improvements: * Have a new task assigned to the creator by default instead of "no assignee" * Show progress for task links in board tooltips * Simplify code to handle ajax popover and redirects +* Move task form elements to Task helper Version 1.0.24 -------------- diff --git a/app/Controller/Gantt.php b/app/Controller/Gantt.php index ac0e6fad..f312130c 100644 --- a/app/Controller/Gantt.php +++ b/app/Controller/Gantt.php @@ -103,6 +103,7 @@ class Gantt extends Base $project = $this->getProject(); $this->response->html($this->template->render('gantt/task_creation', array( + 'project' => $project, 'errors' => $errors, 'values' => $values + array( 'project_id' => $project['id'], @@ -113,8 +114,6 @@ class Gantt extends Base 'colors_list' => $this->color->getList(), 'categories_list' => $this->category->getList($project['id']), 'swimlanes_list' => $this->swimlane->getList($project['id'], false, true), - 'date_format' => $this->config->get('application_date_format'), - 'date_formats' => $this->dateParser->getAvailableFormats(), 'title' => $project['name'].' > '.t('New task') ))); } diff --git a/app/Controller/Taskcreation.php b/app/Controller/Taskcreation.php index ed2ac1b9..396d5f6f 100644 --- a/app/Controller/Taskcreation.php +++ b/app/Controller/Taskcreation.php @@ -38,8 +38,6 @@ class Taskcreation extends Base 'colors_list' => $this->color->getList(), 'categories_list' => $this->category->getList($project['id']), 'swimlanes_list' => $swimlanes_list, - 'date_format' => $this->config->get('application_date_format'), - 'date_formats' => $this->dateParser->getAvailableFormats(), 'title' => $project['name'].' > '.t('New task') ))); } diff --git a/app/Helper/Task.php b/app/Helper/Task.php index 06f7d58e..57ad6c91 100644 --- a/app/Helper/Task.php +++ b/app/Helper/Task.php @@ -51,7 +51,43 @@ class Task extends Base $html = $this->helper->form->label(t('Assignee'), 'owner_id'); $html .= $this->helper->form->select('owner_id', $users, $values, $errors, $attributes); - $html .= ''.t('Me').''; + $html .= ' '.t('Me').''; + + return $html; + } + + public function selectCategory(array $categories, array $values, array $errors = array(), array $attributes = array(), $allow_one_item = false) + { + $attributes = array_merge(array('tabindex="4"'), $attributes); + $html = ''; + + if (! (! $allow_one_item && count($categories) === 1 && key($categories) == 0)) { + $html .= $this->helper->form->label(t('Category'), 'category_id'); + $html .= $this->helper->form->select('category_id', $categories, $values, $errors, $attributes); + } + + return $html; + } + + public function selectSwimlane(array $swimlanes, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="5"'), $attributes); + $html = ''; + + if (! (count($swimlanes) === 1 && key($swimlanes) == 0)) { + $html .= $this->helper->form->label(t('Swimlane'), 'swimlane_id'); + $html .= $this->helper->form->select('swimlane_id', $swimlanes, $values, $errors, $attributes); + } + + return $html; + } + + public function selectColumn(array $columns, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="6"'), $attributes); + + $html = $this->helper->form->label(t('Column'), 'column_id'); + $html .= $this->helper->form->select('column_id', $columns, $values, $errors, $attributes); return $html; } @@ -72,6 +108,50 @@ class Task extends Base return $html; } + public function selectScore(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="8"'), $attributes); + + $html = $this->helper->form->label(t('Complexity'), 'score'); + $html .= $this->helper->form->number('score', $values, $errors, $attributes); + + return $html; + } + + public function selectTimeEstimate(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="9"'), $attributes); + + $html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); + $html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } + + public function selectStartDate(array $values, array $errors = array(), array $attributes = array()) + { + $placeholder = $this->helper->text->in($this->config->get('application_date_format'), $this->dateParser->getAvailableFormats()); + $attributes = array_merge(array('tabindex="10"', 'placeholder="'.$placeholder.'"'), $attributes); + + $html = $this->helper->form->label(t('Start Date'), 'date_started'); + $html .= $this->helper->form->text('date_started', $values, $errors, $attributes, 'form-date'); + + return $html; + } + + public function selectDueDate(array $values, array $errors = array(), array $attributes = array()) + { + $placeholder = $this->helper->text->in($this->config->get('application_date_format'), $this->dateParser->getAvailableFormats()); + $attributes = array_merge(array('tabindex="11"', 'placeholder="'.$placeholder.'"'), $attributes); + + $html = $this->helper->form->label(t('Due Date'), 'date_due'); + $html .= $this->helper->form->text('date_due', $values, $errors, $attributes, 'form-date'); + $html .= '
'.t('Others formats accepted: %s and %s', date('Y-m-d'), date('Y_m_d')).'
'; + + return $html; + } + public function formatPriority(array $project, array $task) { $html = ''; diff --git a/app/Template/board/popover_category.php b/app/Template/board/popover_category.php index 224ce8d1..e65593cd 100644 --- a/app/Template/board/popover_category.php +++ b/app/Template/board/popover_category.php @@ -9,8 +9,7 @@ form->hidden('id', $values) ?> form->hidden('project_id', $values) ?> - form->label(t('Category'), 'category_id') ?> - form->select('category_id', $categories_list, $values, array(), array('autofocus')) ?>
+ task->selectCategory($categories_list, $values, array(), array('autofocus'), true) ?>
diff --git a/app/Template/gantt/task_creation.php b/app/Template/gantt/task_creation.php index 7997e231..a08f41b4 100644 --- a/app/Template/gantt/task_creation.php +++ b/app/Template/gantt/task_creation.php @@ -33,26 +33,13 @@
- form->label(t('Assignee'), 'owner_id') ?> - form->select('owner_id', $users_list, $values, $errors, array('tabindex="3"')) ?>
- - form->label(t('Category'), 'category_id') ?> - form->select('category_id', $categories_list, $values, $errors, array('tabindex="4"')) ?>
- - - form->label(t('Swimlane'), 'swimlane_id') ?> - form->select('swimlane_id', $swimlanes_list, $values, $errors, array('tabindex="5"')) ?>
- - - form->label(t('Complexity'), 'score') ?> - form->number('score', $values, $errors, array('tabindex="6"')) ?>
- - form->label(t('Start Date'), 'date_started') ?> - form->text('date_started', $values, $errors, array('placeholder="'.$this->text->in($date_format, $date_formats).'"', 'tabindex="7"'), 'form-date') ?> - - form->label(t('Due Date'), 'date_due') ?> - form->text('date_due', $values, $errors, array('placeholder="'.$this->text->in($date_format, $date_formats).'"', 'tabindex="8"'), 'form-date') ?>
-
+ task->selectAssignee($users_list, $values, $errors) ?> + task->selectCategory($categories_list, $values, $errors) ?> + task->selectSwimlane($swimlanes_list, $values, $errors) ?> + task->selectPriority($project, $values) ?> + task->selectScore($values, $errors) ?> + task->selectStartDate($values, $errors) ?> + task->selectDueDate($values, $errors) ?>
diff --git a/app/Template/task_creation/form.php b/app/Template/task_creation/form.php index a814219b..b222f00f 100644 --- a/app/Template/task_creation/form.php +++ b/app/Template/task_creation/form.php @@ -47,31 +47,14 @@
form->hidden('project_id', $values) ?> - task->selectAssignee($users_list, $values, $errors) ?> - - form->label(t('Category'), 'category_id') ?> - form->select('category_id', $categories_list, $values, $errors, array('tabindex="4"')) ?> - - - form->label(t('Swimlane'), 'swimlane_id') ?> - form->select('swimlane_id', $swimlanes_list, $values, $errors, array('tabindex="5"')) ?> - - - form->label(t('Column'), 'column_id') ?> - form->select('column_id', $columns_list, $values, $errors, array('tabindex="6"')) ?> - + task->selectCategory($categories_list, $values, $errors) ?> + task->selectSwimlane($swimlanes_list, $values, $errors) ?> + task->selectColumn($columns_list, $values, $errors) ?> task->selectPriority($project, $values) ?> - - form->label(t('Complexity'), 'score') ?> - form->number('score', $values, $errors, array('tabindex="9"')) ?> - - form->label(t('Original estimate'), 'time_estimated') ?> - form->numeric('time_estimated', $values, $errors, array('tabindex="10"')) ?> - - form->label(t('Due Date'), 'date_due') ?> - form->text('date_due', $values, $errors, array('placeholder="'.$this->text->in($date_format, $date_formats).'"', 'tabindex="11"'), 'form-date') ?> -
+ task->selectScore($values, $errors) ?> + task->selectTimeEstimate($values, $errors) ?> + task->selectDueDate($values, $errors) ?>
diff --git a/app/Template/task_modification/edit_task.php b/app/Template/task_modification/edit_task.php index 1daa318c..fe7fb009 100644 --- a/app/Template/task_modification/edit_task.php +++ b/app/Template/task_modification/edit_task.php @@ -43,20 +43,11 @@
form->hidden('id', $values) ?> form->hidden('project_id', $values) ?> - task->selectAssignee($users_list, $values, $errors) ?> - - form->label(t('Category'), 'category_id') ?> - form->select('category_id', $categories_list, $values, $errors, array('tabindex="4"')) ?> - - form->label(t('Complexity'), 'score') ?> - form->number('score', $values, $errors, array('tabindex="6"')) ?> - + task->selectCategory($categories_list, $values, $errors) ?> task->selectPriority($project, $values) ?> - - form->label(t('Due Date'), 'date_due') ?> - form->text('date_due', $values, $errors, array('placeholder="'.$this->text->in($date_format, $date_formats).'"', 'tabindex="8"'), 'form-date') ?> -
+ task->selectScore($values, $errors) ?> + task->selectDueDate($values, $errors) ?>
-- cgit v1.2.3 From eaf2b0949be390dea6ec8b035773c7061eac4531 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Mon, 1 Feb 2016 19:27:28 -0500 Subject: Add new merge hook to override default form values --- app/Controller/Gantt.php | 14 +++++++++----- app/Controller/Taskcreation.php | 2 ++ app/Controller/Taskmodification.php | 1 + doc/plugin-hooks.markdown | 20 ++++++++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) (limited to 'app/Controller/Taskcreation.php') diff --git a/app/Controller/Gantt.php b/app/Controller/Gantt.php index b1dc2b7e..2d1edc08 100644 --- a/app/Controller/Gantt.php +++ b/app/Controller/Gantt.php @@ -101,14 +101,18 @@ class Gantt extends Base { $project = $this->getProject(); + $values = $values + array( + 'project_id' => $project['id'], + 'column_id' => $this->board->getFirstColumn($project['id']), + 'position' => 1 + ); + + $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values)); + $this->response->html($this->template->render('gantt/task_creation', array( 'project' => $project, 'errors' => $errors, - 'values' => $values + array( - 'project_id' => $project['id'], - 'column_id' => $this->board->getFirstColumn($project['id']), - 'position' => 1 - ), + 'values' => $values, 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id'], true, false, true), 'colors_list' => $this->color->getList(), 'categories_list' => $this->category->getList($project['id']), diff --git a/app/Controller/Taskcreation.php b/app/Controller/Taskcreation.php index 396d5f6f..6f5253eb 100644 --- a/app/Controller/Taskcreation.php +++ b/app/Controller/Taskcreation.php @@ -27,6 +27,8 @@ class Taskcreation extends Base 'color_id' => $this->color->getDefaultColor(), 'owner_id' => $this->userSession->getId(), ); + + $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values)); } $this->response->html($this->template->render('task_creation/form', array( diff --git a/app/Controller/Taskmodification.php b/app/Controller/Taskmodification.php index dc368390..cae1d8ee 100644 --- a/app/Controller/Taskmodification.php +++ b/app/Controller/Taskmodification.php @@ -100,6 +100,7 @@ class Taskmodification extends Base if (empty($values)) { $values = $task; + $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values)); } $this->dateParser->format($values, array('date_due')); diff --git a/doc/plugin-hooks.markdown b/doc/plugin-hooks.markdown index 6e9718d9..eac027c2 100644 --- a/doc/plugin-hooks.markdown +++ b/doc/plugin-hooks.markdown @@ -58,8 +58,28 @@ class Plugin extends Base } ``` +Example to override default values for task forms: + +```php +class Plugin extends Base +{ + public function initialize() + { + $this->hook->on('controller:task:form:default', function (array $default_values) { + return empty($default_values['score']) ? array('score' => 4) : array(); + }); + } +} +``` + List of merging hooks: +#### controller:task:form:default + +- Override default values for task forms +- Arguments: + - `$default_values`: actual default values (array) + #### controller:calendar:project:events - Add more events to the project calendar -- cgit v1.2.3 From 12aaec03b19a07635f59b00f532c92c37ac1df5f Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 4 Feb 2016 21:42:46 -0500 Subject: Fix php notice, see #1777 --- app/Controller/Taskcreation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/Controller/Taskcreation.php') diff --git a/app/Controller/Taskcreation.php b/app/Controller/Taskcreation.php index 6f5253eb..e661587c 100644 --- a/app/Controller/Taskcreation.php +++ b/app/Controller/Taskcreation.php @@ -71,7 +71,7 @@ class Taskcreation extends Base return $this->create(array( 'owner_id' => $values['owner_id'], 'color_id' => $values['color_id'], - 'category_id' => $values['category_id'], + 'category_id' => isset($values['category_id']) ? $values['category_id'] : 0, 'column_id' => $values['column_id'], 'swimlane_id' => isset($values['swimlane_id']) ? $values['swimlane_id'] : 0, 'another_task' => 1, -- cgit v1.2.3