From 8a6f02735b628033a3284d06a9f633bd260e19ef Mon Sep 17 00:00:00 2001 From: Frederic Guillot <fred@kanboard.net> Date: Sun, 15 May 2016 20:09:43 -0400 Subject: Added task creation menu for all projects views --- app/Controller/DashboardController.php | 6 +-- app/Controller/TaskBulk.php | 88 ------------------------------- app/Controller/TaskBulkController.php | 88 +++++++++++++++++++++++++++++++ app/Controller/TaskCreationController.php | 87 ++++++++++++++++++++++++++++++ app/Controller/Taskcreation.php | 87 ------------------------------ 5 files changed, 178 insertions(+), 178 deletions(-) delete mode 100644 app/Controller/TaskBulk.php create mode 100644 app/Controller/TaskBulkController.php create mode 100644 app/Controller/TaskCreationController.php delete mode 100644 app/Controller/Taskcreation.php (limited to 'app/Controller') diff --git a/app/Controller/DashboardController.php b/app/Controller/DashboardController.php index b05cd209..145e0bff 100644 --- a/app/Controller/DashboardController.php +++ b/app/Controller/DashboardController.php @@ -81,9 +81,9 @@ class DashboardController extends BaseController $this->response->html($this->helper->layout->dashboard('dashboard/show', array( 'title' => t('Dashboard'), - 'project_paginator' => $this->getProjectPaginator($user['id'], 'index', 10), - 'task_paginator' => $this->getTaskPaginator($user['id'], 'index', 10), - 'subtask_paginator' => $this->getSubtaskPaginator($user['id'], 'index', 10), + 'project_paginator' => $this->getProjectPaginator($user['id'], 'show', 10), + 'task_paginator' => $this->getTaskPaginator($user['id'], 'show', 10), + 'subtask_paginator' => $this->getSubtaskPaginator($user['id'], 'show', 10), 'user' => $user, ))); } diff --git a/app/Controller/TaskBulk.php b/app/Controller/TaskBulk.php deleted file mode 100644 index d0a1b276..00000000 --- a/app/Controller/TaskBulk.php +++ /dev/null @@ -1,88 +0,0 @@ -<?php - -namespace Kanboard\Controller; - -/** - * Class TaskBulk - * - * @package Kanboard\Controller - */ -class TaskBulk extends BaseController -{ - /** - * Show the form - * - * @param array $values - * @param array $errors - */ - public function show(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - - if (empty($values)) { - $values = array( - 'swimlane_id' => $this->request->getIntegerParam('swimlane_id'), - 'column_id' => $this->request->getIntegerParam('column_id'), - 'project_id' => $project['id'], - ); - } - - $this->response->html($this->template->render('task_bulk/show', array( - 'project' => $project, - 'values' => $values, - 'errors' => $errors, - 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id'], true, false, true), - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($project['id']), - ))); - } - - /** - * Save all tasks in the database - */ - public function save() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - list($valid, $errors) = $this->taskValidator->validateBulkCreation($values); - - if ($valid) { - $this->createTasks($project, $values); - $this->response->redirect($this->helper->url->to( - 'Board', - 'show', - array('project_id' => $project['id']), - 'swimlane-'. $values['swimlane_id'] - ), true); - } else { - $this->show($values, $errors); - } - } - - /** - * Create all tasks - * - * @param array $project - * @param array $values - */ - protected function createTasks(array $project, array $values) - { - $tasks = preg_split('/\r\n|[\r\n]/', $values['tasks']); - - foreach ($tasks as $title) { - $title = trim($title); - - if (! empty($title)) { - $this->taskCreation->create(array( - 'title' => $title, - 'column_id' => $values['column_id'], - 'swimlane_id' => $values['swimlane_id'], - 'category_id' => empty($values['category_id']) ? 0 : $values['category_id'], - 'owner_id' => empty($values['owner_id']) ? 0 : $values['owner_id'], - 'color_id' => $values['color_id'], - 'project_id' => $project['id'], - )); - } - } - } -} diff --git a/app/Controller/TaskBulkController.php b/app/Controller/TaskBulkController.php new file mode 100644 index 00000000..4b4a2594 --- /dev/null +++ b/app/Controller/TaskBulkController.php @@ -0,0 +1,88 @@ +<?php + +namespace Kanboard\Controller; + +/** + * Class TaskBulkController + * + * @package Kanboard\Controller + */ +class TaskBulkController extends BaseController +{ + /** + * Show the form + * + * @param array $values + * @param array $errors + */ + public function show(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + + if (empty($values)) { + $values = array( + 'swimlane_id' => $this->request->getIntegerParam('swimlane_id'), + 'column_id' => $this->request->getIntegerParam('column_id'), + 'project_id' => $project['id'], + ); + } + + $this->response->html($this->template->render('task_bulk/show', array( + 'project' => $project, + 'values' => $values, + 'errors' => $errors, + 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id'], true, false, true), + 'colors_list' => $this->color->getList(), + 'categories_list' => $this->category->getList($project['id']), + ))); + } + + /** + * Save all tasks in the database + */ + public function save() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + list($valid, $errors) = $this->taskValidator->validateBulkCreation($values); + + if ($valid) { + $this->createTasks($project, $values); + $this->response->redirect($this->helper->url->to( + 'Board', + 'show', + array('project_id' => $project['id']), + 'swimlane-'. $values['swimlane_id'] + ), true); + } else { + $this->show($values, $errors); + } + } + + /** + * Create all tasks + * + * @param array $project + * @param array $values + */ + protected function createTasks(array $project, array $values) + { + $tasks = preg_split('/\r\n|[\r\n]/', $values['tasks']); + + foreach ($tasks as $title) { + $title = trim($title); + + if (! empty($title)) { + $this->taskCreation->create(array( + 'title' => $title, + 'column_id' => $values['column_id'], + 'swimlane_id' => $values['swimlane_id'], + 'category_id' => empty($values['category_id']) ? 0 : $values['category_id'], + 'owner_id' => empty($values['owner_id']) ? 0 : $values['owner_id'], + 'color_id' => $values['color_id'], + 'project_id' => $project['id'], + )); + } + } + } +} diff --git a/app/Controller/TaskCreationController.php b/app/Controller/TaskCreationController.php new file mode 100644 index 00000000..2a63ddcc --- /dev/null +++ b/app/Controller/TaskCreationController.php @@ -0,0 +1,87 @@ +<?php + +namespace Kanboard\Controller; + +/** + * Task Creation Controller + * + * @package Kanboard\Controller + * @author Frederic Guillot + */ +class TaskCreationController extends BaseController +{ + /** + * Display a form to create a new task + * + * @access public + * @param array $values + * @param array $errors + * @throws \Kanboard\Core\Controller\PageNotFoundException + */ + public function show(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + $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->color->getDefaultColor(), + 'owner_id' => $this->userSession->getId(), + ); + + $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values)); + $values = $this->hook->merge('controller:task-creation:form:default', $values, array('default_values' => $values)); + } + + $this->response->html($this->template->render('task_creation/show', array( + 'project' => $project, + 'errors' => $errors, + 'values' => $values + array('project_id' => $project['id']), + 'columns_list' => $this->column->getList($project['id']), + 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id'], true, false, true), + 'colors_list' => $this->color->getList(), + 'categories_list' => $this->category->getList($project['id']), + 'swimlanes_list' => $swimlanes_list, + 'title' => $project['name'].' > '.t('New task') + ))); + } + + /** + * Validate and save a new task + * + * @access public + */ + public function save() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + + list($valid, $errors) = $this->taskValidator->validateCreation($values); + + if ($valid && $this->taskCreation->create($values)) { + $this->flash->success(t('Task created successfully.')); + return $this->afterSave($project, $values); + } + + $this->flash->failure(t('Unable to create your task.')); + return $this->show($values, $errors); + } + + private function afterSave(array $project, array &$values) + { + if (isset($values['another_task']) && $values['another_task'] == 1) { + return $this->show(array( + 'owner_id' => $values['owner_id'], + 'color_id' => $values['color_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, + )); + } + + return $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id'])), true); + } +} diff --git a/app/Controller/Taskcreation.php b/app/Controller/Taskcreation.php deleted file mode 100644 index af7d0c80..00000000 --- a/app/Controller/Taskcreation.php +++ /dev/null @@ -1,87 +0,0 @@ -<?php - -namespace Kanboard\Controller; - -/** - * Task Creation controller - * - * @package controller - * @author Frederic Guillot - */ -class Taskcreation extends BaseController -{ - /** - * Display a form to create a new task - * - * @access public - * @param array $values - * @param array $errors - * @throws \Kanboard\Core\Controller\PageNotFoundException - */ - public function create(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - $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->color->getDefaultColor(), - 'owner_id' => $this->userSession->getId(), - ); - - $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values)); - $values = $this->hook->merge('controller:task-creation:form:default', $values, array('default_values' => $values)); - } - - $this->response->html($this->template->render('task_creation/form', array( - 'project' => $project, - 'errors' => $errors, - 'values' => $values + array('project_id' => $project['id']), - 'columns_list' => $this->column->getList($project['id']), - 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id'], true, false, true), - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($project['id']), - 'swimlanes_list' => $swimlanes_list, - 'title' => $project['name'].' > '.t('New task') - ))); - } - - /** - * Validate and save a new task - * - * @access public - */ - public function save() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - - list($valid, $errors) = $this->taskValidator->validateCreation($values); - - if ($valid && $this->taskCreation->create($values)) { - $this->flash->success(t('Task created successfully.')); - return $this->afterSave($project, $values); - } - - $this->flash->failure(t('Unable to create your task.')); - return $this->create($values, $errors); - } - - private function afterSave(array $project, array &$values) - { - if (isset($values['another_task']) && $values['another_task'] == 1) { - return $this->create(array( - 'owner_id' => $values['owner_id'], - 'color_id' => $values['color_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, - )); - } - - return $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id'])), true); - } -} -- cgit v1.2.3