From 8d12e2fe736a72d6ad69807ac853a7e325c8cbf3 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 28 May 2016 14:05:57 -0400 Subject: Split board controller into multiple classes --- app/Controller/Board.php | 192 ------------------------------ app/Controller/BoardAjaxController.php | 140 ++++++++++++++++++++++ app/Controller/BoardPopoverController.php | 2 +- app/Controller/BoardViewController.php | 65 ++++++++++ app/Controller/TaskBulkController.php | 2 +- app/Controller/TaskCreationController.php | 2 +- app/Controller/TaskPopoverController.php | 4 +- app/Controller/TaskViewController.php | 2 +- 8 files changed, 211 insertions(+), 198 deletions(-) delete mode 100644 app/Controller/Board.php create mode 100644 app/Controller/BoardAjaxController.php create mode 100644 app/Controller/BoardViewController.php (limited to 'app/Controller') diff --git a/app/Controller/Board.php b/app/Controller/Board.php deleted file mode 100644 index 0f6b3b14..00000000 --- a/app/Controller/Board.php +++ /dev/null @@ -1,192 +0,0 @@ -request->getStringParam('token'); - $project = $this->project->getByToken($token); - - // Token verification - if (empty($project)) { - throw AccessForbiddenException::getInstance()->withoutLayout(); - } - - // Display the board with a specific layout - $this->response->html($this->helper->layout->app('board/view_public', array( - 'project' => $project, - 'swimlanes' => $this->board->getBoard($project['id']), - 'title' => $project['name'], - 'description' => $project['description'], - 'no_layout' => true, - 'not_editable' => true, - 'board_public_refresh_interval' => $this->config->get('board_public_refresh_interval'), - 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), - 'board_highlight_period' => $this->config->get('board_highlight_period'), - ))); - } - - /** - * Show a board for a given project - * - * @access public - */ - public function show() - { - $project = $this->getProject(); - $search = $this->helper->projectHeader->getSearchQuery($project); - - $this->response->html($this->helper->layout->app('board/view_private', array( - 'project' => $project, - 'title' => $project['name'], - 'description' => $this->helper->projectHeader->getDescription($project), - 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), - 'board_highlight_period' => $this->config->get('board_highlight_period'), - 'swimlanes' => $this->taskLexer - ->build($search) - ->format(BoardFormatter::getInstance($this->container)->setProjectId($project['id'])) - ))); - } - - /** - * Save the board (Ajax request made by the drag and drop) - * - * @access public - */ - public function save() - { - $project_id = $this->request->getIntegerParam('project_id'); - - if (! $project_id || ! $this->request->isAjax()) { - throw new AccessForbiddenException(); - } - - $values = $this->request->getJson(); - - $result =$this->taskPosition->movePosition( - $project_id, - $values['task_id'], - $values['column_id'], - $values['position'], - $values['swimlane_id'] - ); - - if (! $result) { - $this->response->status(400); - } else { - $this->response->html($this->renderBoard($project_id), 201); - } - } - - /** - * Check if the board have been changed - * - * @access public - */ - public function check() - { - $project_id = $this->request->getIntegerParam('project_id'); - $timestamp = $this->request->getIntegerParam('timestamp'); - - if (! $project_id || ! $this->request->isAjax()) { - $this->response->status(403); - } elseif (! $this->project->isModifiedSince($project_id, $timestamp)) { - $this->response->status(304); - } else { - $this->response->html($this->renderBoard($project_id)); - } - } - - /** - * Reload the board with new filters - * - * @access public - */ - public function reload() - { - $project_id = $this->request->getIntegerParam('project_id'); - - if (! $project_id || ! $this->request->isAjax()) { - throw new AccessForbiddenException(); - } - - $values = $this->request->getJson(); - $this->userSession->setFilters($project_id, empty($values['search']) ? '' : $values['search']); - - $this->response->html($this->renderBoard($project_id)); - } - - /** - * Enable collapsed mode - * - * @access public - */ - public function collapse() - { - $this->changeDisplayMode(true); - } - - /** - * Enable expanded mode - * - * @access public - */ - public function expand() - { - $this->changeDisplayMode(false); - } - - /** - * Change display mode - * - * @access private - * @param boolean $mode - */ - private function changeDisplayMode($mode) - { - $project_id = $this->request->getIntegerParam('project_id'); - $this->userSession->setBoardDisplayMode($project_id, $mode); - - if ($this->request->isAjax()) { - $this->response->html($this->renderBoard($project_id)); - } else { - $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project_id))); - } - } - - /** - * Render board - * - * @access private - * @param integer $project_id - * @return string - */ - private function renderBoard($project_id) - { - return $this->template->render('board/table_container', array( - 'project' => $this->project->getById($project_id), - 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), - 'board_highlight_period' => $this->config->get('board_highlight_period'), - 'swimlanes' => $this->taskLexer - ->build($this->userSession->getFilters($project_id)) - ->format(BoardFormatter::getInstance($this->container)->setProjectId($project_id)) - )); - } -} diff --git a/app/Controller/BoardAjaxController.php b/app/Controller/BoardAjaxController.php new file mode 100644 index 00000000..d4714699 --- /dev/null +++ b/app/Controller/BoardAjaxController.php @@ -0,0 +1,140 @@ +request->getIntegerParam('project_id'); + + if (! $project_id || ! $this->request->isAjax()) { + throw new AccessForbiddenException(); + } + + $values = $this->request->getJson(); + + $result =$this->taskPosition->movePosition( + $project_id, + $values['task_id'], + $values['column_id'], + $values['position'], + $values['swimlane_id'] + ); + + if (! $result) { + $this->response->status(400); + } else { + $this->response->html($this->renderBoard($project_id), 201); + } + } + + /** + * Check if the board have been changed + * + * @access public + */ + public function check() + { + $project_id = $this->request->getIntegerParam('project_id'); + $timestamp = $this->request->getIntegerParam('timestamp'); + + if (! $project_id || ! $this->request->isAjax()) { + throw new AccessForbiddenException(); + } elseif (! $this->project->isModifiedSince($project_id, $timestamp)) { + $this->response->status(304); + } else { + $this->response->html($this->renderBoard($project_id)); + } + } + + /** + * Reload the board with new filters + * + * @access public + */ + public function reload() + { + $project_id = $this->request->getIntegerParam('project_id'); + + if (! $project_id || ! $this->request->isAjax()) { + throw new AccessForbiddenException(); + } + + $values = $this->request->getJson(); + $this->userSession->setFilters($project_id, empty($values['search']) ? '' : $values['search']); + + $this->response->html($this->renderBoard($project_id)); + } + + /** + * Enable collapsed mode + * + * @access public + */ + public function collapse() + { + $this->changeDisplayMode(true); + } + + /** + * Enable expanded mode + * + * @access public + */ + public function expand() + { + $this->changeDisplayMode(false); + } + + /** + * Change display mode + * + * @access private + * @param boolean $mode + */ + private function changeDisplayMode($mode) + { + $project_id = $this->request->getIntegerParam('project_id'); + $this->userSession->setBoardDisplayMode($project_id, $mode); + + if ($this->request->isAjax()) { + $this->response->html($this->renderBoard($project_id)); + } else { + $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project_id))); + } + } + + /** + * Render board + * + * @access protected + * @param integer $project_id + * @return string + */ + protected function renderBoard($project_id) + { + return $this->template->render('board/table_container', array( + 'project' => $this->project->getById($project_id), + 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), + 'board_highlight_period' => $this->config->get('board_highlight_period'), + 'swimlanes' => $this->taskLexer + ->build($this->userSession->getFilters($project_id)) + ->format(BoardFormatter::getInstance($this->container)->setProjectId($project_id)) + )); + } +} diff --git a/app/Controller/BoardPopoverController.php b/app/Controller/BoardPopoverController.php index b204af39..2c2e5dc6 100644 --- a/app/Controller/BoardPopoverController.php +++ b/app/Controller/BoardPopoverController.php @@ -42,6 +42,6 @@ class BoardPopoverController extends BaseController $this->taskStatus->closeTasksBySwimlaneAndColumn($values['swimlane_id'], $values['column_id']); $this->flash->success(t('All tasks of the column "%s" and the swimlane "%s" have been closed successfully.', $this->column->getColumnTitleById($values['column_id']), $this->swimlane->getNameById($values['swimlane_id']) ?: t($project['default_swimlane']))); - $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id']))); + $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id']))); } } diff --git a/app/Controller/BoardViewController.php b/app/Controller/BoardViewController.php new file mode 100644 index 00000000..3c96af73 --- /dev/null +++ b/app/Controller/BoardViewController.php @@ -0,0 +1,65 @@ +request->getStringParam('token'); + $project = $this->project->getByToken($token); + + if (empty($project)) { + throw AccessForbiddenException::getInstance()->withoutLayout(); + } + + $this->response->html($this->helper->layout->app('board/view_public', array( + 'project' => $project, + 'swimlanes' => $this->board->getBoard($project['id']), + 'title' => $project['name'], + 'description' => $project['description'], + 'no_layout' => true, + 'not_editable' => true, + 'board_public_refresh_interval' => $this->config->get('board_public_refresh_interval'), + 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), + 'board_highlight_period' => $this->config->get('board_highlight_period'), + ))); + } + + /** + * Show a board for a given project + * + * @access public + */ + public function show() + { + $project = $this->getProject(); + $search = $this->helper->projectHeader->getSearchQuery($project); + + $this->response->html($this->helper->layout->app('board/view_private', array( + 'project' => $project, + 'title' => $project['name'], + 'description' => $this->helper->projectHeader->getDescription($project), + 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), + 'board_highlight_period' => $this->config->get('board_highlight_period'), + 'swimlanes' => $this->taskLexer + ->build($search) + ->format(BoardFormatter::getInstance($this->container)->setProjectId($project['id'])) + ))); + } +} diff --git a/app/Controller/TaskBulkController.php b/app/Controller/TaskBulkController.php index c0214ea7..528ae7a3 100644 --- a/app/Controller/TaskBulkController.php +++ b/app/Controller/TaskBulkController.php @@ -50,7 +50,7 @@ class TaskBulkController extends BaseController if ($valid) { $this->createTasks($project, $values); $this->response->redirect($this->helper->url->to( - 'Board', + 'BoardViewController', 'show', array('project_id' => $project['id']), 'swimlane-'. $values['swimlane_id'] diff --git a/app/Controller/TaskCreationController.php b/app/Controller/TaskCreationController.php index 2a63ddcc..b7af6d87 100644 --- a/app/Controller/TaskCreationController.php +++ b/app/Controller/TaskCreationController.php @@ -82,6 +82,6 @@ class TaskCreationController extends BaseController )); } - return $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id'])), true); + return $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id'])), true); } } diff --git a/app/Controller/TaskPopoverController.php b/app/Controller/TaskPopoverController.php index 9bac2206..9916a5d1 100644 --- a/app/Controller/TaskPopoverController.php +++ b/app/Controller/TaskPopoverController.php @@ -44,7 +44,7 @@ class TaskPopoverController extends BaseController $this->flash->failure(t('Unable to update your task.')); } - $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $values['project_id'])), true); + $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $values['project_id'])), true); } /** @@ -81,7 +81,7 @@ class TaskPopoverController extends BaseController $this->flash->failure(t('Unable to update your task.')); } - $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $values['project_id'])), true); + $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $values['project_id'])), true); } /** diff --git a/app/Controller/TaskViewController.php b/app/Controller/TaskViewController.php index 833d42a4..6d3cc5c5 100644 --- a/app/Controller/TaskViewController.php +++ b/app/Controller/TaskViewController.php @@ -166,7 +166,7 @@ class TaskViewController extends BaseController $this->flash->failure(t('Unable to remove this task.')); } - return $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id'])), true); + return $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $task['project_id'])), true); } return $this->response->html($this->template->render('task/remove', array( -- cgit v1.2.3