From 46ed06268dc3d591fb7bb90a5a9a75e77c17b86c Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 17 May 2016 22:25:18 -0400 Subject: Rename subtask controller --- app/Controller/Subtask.php | 176 ----------------------- app/Controller/SubtaskController.php | 177 ++++++++++++++++++++++++ app/Controller/SubtaskRestriction.php | 61 -------- app/Controller/SubtaskRestrictionController.php | 61 ++++++++ app/Controller/SubtaskStatus.php | 72 ---------- app/Controller/SubtaskStatusController.php | 72 ++++++++++ app/Helper/SubtaskHelper.php | 6 +- app/ServiceProvider/AuthenticationProvider.php | 6 +- app/ServiceProvider/RouteProvider.php | 1 - app/Template/subtask/create.php | 2 +- app/Template/subtask/edit.php | 2 +- app/Template/subtask/menu.php | 4 +- app/Template/subtask/remove.php | 2 +- app/Template/subtask/table.php | 6 +- app/Template/subtask_restriction/popover.php | 17 --- app/Template/subtask_restriction/show.php | 17 +++ app/Template/task/dropdown.php | 2 +- app/Template/task/layout.php | 2 +- app/Template/task/sidebar.php | 2 +- 19 files changed, 344 insertions(+), 344 deletions(-) delete mode 100644 app/Controller/Subtask.php create mode 100644 app/Controller/SubtaskController.php delete mode 100644 app/Controller/SubtaskRestriction.php create mode 100644 app/Controller/SubtaskRestrictionController.php delete mode 100644 app/Controller/SubtaskStatus.php create mode 100644 app/Controller/SubtaskStatusController.php delete mode 100644 app/Template/subtask_restriction/popover.php create mode 100644 app/Template/subtask_restriction/show.php (limited to 'app') diff --git a/app/Controller/Subtask.php b/app/Controller/Subtask.php deleted file mode 100644 index dfe4415e..00000000 --- a/app/Controller/Subtask.php +++ /dev/null @@ -1,176 +0,0 @@ -getTask(); - - if (empty($values)) { - $values = array( - 'task_id' => $task['id'], - 'another_subtask' => $this->request->getIntegerParam('another_subtask', 0) - ); - } - - $this->response->html($this->template->render('subtask/create', array( - 'values' => $values, - 'errors' => $errors, - 'users_list' => $this->projectUserRole->getAssignableUsersList($task['project_id']), - 'task' => $task, - ))); - } - - /** - * Validation and creation - * - * @access public - */ - public function save() - { - $task = $this->getTask(); - $values = $this->request->getValues(); - - list($valid, $errors) = $this->subtaskValidator->validateCreation($values); - - if ($valid) { - if ($this->subtask->create($values)) { - $this->flash->success(t('Sub-task added successfully.')); - } else { - $this->flash->failure(t('Unable to create your sub-task.')); - } - - if (isset($values['another_subtask']) && $values['another_subtask'] == 1) { - return $this->create(array('project_id' => $task['project_id'], 'task_id' => $task['id'], 'another_subtask' => 1)); - } - - return $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']), 'subtasks'), true); - } - - return $this->create($values, $errors); - } - - /** - * Edit form - * - * @access public - * @param array $values - * @param array $errors - * @throws AccessForbiddenException - * @throws \Kanboard\Core\Controller\PageNotFoundException - */ - public function edit(array $values = array(), array $errors = array()) - { - $task = $this->getTask(); - $subtask = $this->getSubtask(); - - $this->response->html($this->template->render('subtask/edit', array( - 'values' => empty($values) ? $subtask : $values, - 'errors' => $errors, - 'users_list' => $this->projectUserRole->getAssignableUsersList($task['project_id']), - 'status_list' => $this->subtask->getStatusList(), - 'subtask' => $subtask, - 'task' => $task, - ))); - } - - /** - * Update and validate a subtask - * - * @access public - */ - public function update() - { - $task = $this->getTask(); - $this->getSubtask(); - - $values = $this->request->getValues(); - list($valid, $errors) = $this->subtaskValidator->validateModification($values); - - if ($valid) { - if ($this->subtask->update($values)) { - $this->flash->success(t('Sub-task updated successfully.')); - } else { - $this->flash->failure(t('Unable to update your sub-task.')); - } - - return $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true); - } - - return $this->edit($values, $errors); - } - - /** - * Confirmation dialog before removing a subtask - * - * @access public - */ - public function confirm() - { - $task = $this->getTask(); - $subtask = $this->getSubtask(); - - $this->response->html($this->template->render('subtask/remove', array( - 'subtask' => $subtask, - 'task' => $task, - ))); - } - - /** - * Remove a subtask - * - * @access public - */ - public function remove() - { - $this->checkCSRFParam(); - $task = $this->getTask(); - $subtask = $this->getSubtask(); - - if ($this->subtask->remove($subtask['id'])) { - $this->flash->success(t('Sub-task removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this sub-task.')); - } - - $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true); - } - - /** - * Move subtask position - * - * @access public - */ - public function movePosition() - { - $project_id = $this->request->getIntegerParam('project_id'); - $task_id = $this->request->getIntegerParam('task_id'); - $values = $this->request->getJson(); - - if (! empty($values) && $this->helper->user->hasProjectAccess('Subtask', 'movePosition', $project_id)) { - $result = $this->subtask->changePosition($task_id, $values['subtask_id'], $values['position']); - $this->response->json(array('result' => $result)); - } else { - throw new AccessForbiddenException(); - } - } -} diff --git a/app/Controller/SubtaskController.php b/app/Controller/SubtaskController.php new file mode 100644 index 00000000..830548da --- /dev/null +++ b/app/Controller/SubtaskController.php @@ -0,0 +1,177 @@ +getTask(); + + if (empty($values)) { + $values = array( + 'task_id' => $task['id'], + 'another_subtask' => $this->request->getIntegerParam('another_subtask', 0) + ); + } + + $this->response->html($this->template->render('subtask/create', array( + 'values' => $values, + 'errors' => $errors, + 'users_list' => $this->projectUserRole->getAssignableUsersList($task['project_id']), + 'task' => $task, + ))); + } + + /** + * Validation and creation + * + * @access public + */ + public function save() + { + $task = $this->getTask(); + $values = $this->request->getValues(); + + list($valid, $errors) = $this->subtaskValidator->validateCreation($values); + + if ($valid) { + if ($this->subtask->create($values)) { + $this->flash->success(t('Sub-task added successfully.')); + } else { + $this->flash->failure(t('Unable to create your sub-task.')); + } + + if (isset($values['another_subtask']) && $values['another_subtask'] == 1) { + return $this->create(array('project_id' => $task['project_id'], 'task_id' => $task['id'], 'another_subtask' => 1)); + } + + return $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']), 'subtasks'), true); + } + + return $this->create($values, $errors); + } + + /** + * Edit form + * + * @access public + * @param array $values + * @param array $errors + * @throws AccessForbiddenException + * @throws PageNotFoundException + */ + public function edit(array $values = array(), array $errors = array()) + { + $task = $this->getTask(); + $subtask = $this->getSubtask(); + + $this->response->html($this->template->render('subtask/edit', array( + 'values' => empty($values) ? $subtask : $values, + 'errors' => $errors, + 'users_list' => $this->projectUserRole->getAssignableUsersList($task['project_id']), + 'status_list' => $this->subtask->getStatusList(), + 'subtask' => $subtask, + 'task' => $task, + ))); + } + + /** + * Update and validate a subtask + * + * @access public + */ + public function update() + { + $task = $this->getTask(); + $this->getSubtask(); + + $values = $this->request->getValues(); + list($valid, $errors) = $this->subtaskValidator->validateModification($values); + + if ($valid) { + if ($this->subtask->update($values)) { + $this->flash->success(t('Sub-task updated successfully.')); + } else { + $this->flash->failure(t('Unable to update your sub-task.')); + } + + return $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true); + } + + return $this->edit($values, $errors); + } + + /** + * Confirmation dialog before removing a subtask + * + * @access public + */ + public function confirm() + { + $task = $this->getTask(); + $subtask = $this->getSubtask(); + + $this->response->html($this->template->render('subtask/remove', array( + 'subtask' => $subtask, + 'task' => $task, + ))); + } + + /** + * Remove a subtask + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $task = $this->getTask(); + $subtask = $this->getSubtask(); + + if ($this->subtask->remove($subtask['id'])) { + $this->flash->success(t('Sub-task removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this sub-task.')); + } + + $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true); + } + + /** + * Move subtask position + * + * @access public + */ + public function movePosition() + { + $project_id = $this->request->getIntegerParam('project_id'); + $task_id = $this->request->getIntegerParam('task_id'); + $values = $this->request->getJson(); + + if (! empty($values) && $this->helper->user->hasProjectAccess('SubtaskController', 'movePosition', $project_id)) { + $result = $this->subtask->changePosition($task_id, $values['subtask_id'], $values['position']); + $this->response->json(array('result' => $result)); + } else { + throw new AccessForbiddenException(); + } + } +} diff --git a/app/Controller/SubtaskRestriction.php b/app/Controller/SubtaskRestriction.php deleted file mode 100644 index bfa3031c..00000000 --- a/app/Controller/SubtaskRestriction.php +++ /dev/null @@ -1,61 +0,0 @@ -getTask(); - $subtask = $this->getSubtask(); - - $this->response->html($this->template->render('subtask_restriction/popover', array( - 'status_list' => array( - SubtaskModel::STATUS_TODO => t('Todo'), - SubtaskModel::STATUS_DONE => t('Done'), - ), - 'subtask_inprogress' => $this->subtask->getSubtaskInProgress($this->userSession->getId()), - 'subtask' => $subtask, - 'task' => $task, - ))); - } - - /** - * Change status of the in progress subtask and the other subtask - * - * @access public - */ - public function update() - { - $task = $this->getTask(); - $subtask = $this->getSubtask(); - $values = $this->request->getValues(); - - // Change status of the previous "in progress" subtask - $this->subtask->update(array( - 'id' => $values['id'], - 'status' => $values['status'], - )); - - // Set the current subtask to "in progress" - $this->subtask->update(array( - 'id' => $subtask['id'], - 'status' => SubtaskModel::STATUS_INPROGRESS, - )); - - $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true); - } -} diff --git a/app/Controller/SubtaskRestrictionController.php b/app/Controller/SubtaskRestrictionController.php new file mode 100644 index 00000000..185371e7 --- /dev/null +++ b/app/Controller/SubtaskRestrictionController.php @@ -0,0 +1,61 @@ +getTask(); + $subtask = $this->getSubtask(); + + $this->response->html($this->template->render('subtask_restriction/show', array( + 'status_list' => array( + SubtaskModel::STATUS_TODO => t('Todo'), + SubtaskModel::STATUS_DONE => t('Done'), + ), + 'subtask_inprogress' => $this->subtask->getSubtaskInProgress($this->userSession->getId()), + 'subtask' => $subtask, + 'task' => $task, + ))); + } + + /** + * Change status of the in progress subtask and the other subtask + * + * @access public + */ + public function save() + { + $task = $this->getTask(); + $subtask = $this->getSubtask(); + $values = $this->request->getValues(); + + // Change status of the previous "in progress" subtask + $this->subtask->update(array( + 'id' => $values['id'], + 'status' => $values['status'], + )); + + // Set the current subtask to "in progress" + $this->subtask->update(array( + 'id' => $subtask['id'], + 'status' => SubtaskModel::STATUS_INPROGRESS, + )); + + $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true); + } +} diff --git a/app/Controller/SubtaskStatus.php b/app/Controller/SubtaskStatus.php deleted file mode 100644 index e22e825e..00000000 --- a/app/Controller/SubtaskStatus.php +++ /dev/null @@ -1,72 +0,0 @@ - In Progress -> Done - * - * @access public - */ - public function change() - { - $task = $this->getTask(); - $subtask = $this->getSubtask(); - - $status = $this->subtask->toggleStatus($subtask['id']); - - if ($this->request->getIntegerParam('refresh-table') === 0) { - $subtask['status'] = $status; - $html = $this->helper->subtask->toggleStatus($subtask, $task['project_id']); - } else { - $html = $this->renderTable($task); - } - - $this->response->html($html); - } - - /** - * Start/stop timer for subtasks - * - * @access public - */ - public function timer() - { - $task = $this->getTask(); - $subtask_id = $this->request->getIntegerParam('subtask_id'); - $timer = $this->request->getStringParam('timer'); - - if ($timer === 'start') { - $this->subtaskTimeTracking->logStartTime($subtask_id, $this->userSession->getId()); - } elseif ($timer === 'stop') { - $this->subtaskTimeTracking->logEndTime($subtask_id, $this->userSession->getId()); - $this->subtaskTimeTracking->updateTaskTimeTracking($task['id']); - } - - $this->response->html($this->renderTable($task)); - } - - /** - * Render table - * - * @access private - * @param array $task - * @return string - */ - private function renderTable(array $task) - { - return $this->template->render('subtask/table', array( - 'task' => $task, - 'subtasks' => $this->subtask->getAll($task['id']), - 'editable' => true, - 'redirect' => 'task', - )); - } -} diff --git a/app/Controller/SubtaskStatusController.php b/app/Controller/SubtaskStatusController.php new file mode 100644 index 00000000..e24002dc --- /dev/null +++ b/app/Controller/SubtaskStatusController.php @@ -0,0 +1,72 @@ + In Progress -> Done + * + * @access public + */ + public function change() + { + $task = $this->getTask(); + $subtask = $this->getSubtask(); + + $status = $this->subtask->toggleStatus($subtask['id']); + + if ($this->request->getIntegerParam('refresh-table') === 0) { + $subtask['status'] = $status; + $html = $this->helper->subtask->toggleStatus($subtask, $task['project_id']); + } else { + $html = $this->renderTable($task); + } + + $this->response->html($html); + } + + /** + * Start/stop timer for subtasks + * + * @access public + */ + public function timer() + { + $task = $this->getTask(); + $subtask_id = $this->request->getIntegerParam('subtask_id'); + $timer = $this->request->getStringParam('timer'); + + if ($timer === 'start') { + $this->subtaskTimeTracking->logStartTime($subtask_id, $this->userSession->getId()); + } elseif ($timer === 'stop') { + $this->subtaskTimeTracking->logEndTime($subtask_id, $this->userSession->getId()); + $this->subtaskTimeTracking->updateTaskTimeTracking($task['id']); + } + + $this->response->html($this->renderTable($task)); + } + + /** + * Render table + * + * @access private + * @param array $task + * @return string + */ + private function renderTable(array $task) + { + return $this->template->render('subtask/table', array( + 'task' => $task, + 'subtasks' => $this->subtask->getAll($task['id']), + 'editable' => true, + 'redirect' => 'task', + )); + } +} diff --git a/app/Helper/SubtaskHelper.php b/app/Helper/SubtaskHelper.php index afa3c14e..dac71203 100644 --- a/app/Helper/SubtaskHelper.php +++ b/app/Helper/SubtaskHelper.php @@ -36,18 +36,18 @@ class SubtaskHelper extends Base */ public function toggleStatus(array $subtask, $project_id, $refresh_table = false) { - if (! $this->helper->user->hasProjectAccess('subtask', 'edit', $project_id)) { + if (! $this->helper->user->hasProjectAccess('SubtaskController', 'edit', $project_id)) { return $this->getTitle($subtask); } $params = array('task_id' => $subtask['task_id'], 'subtask_id' => $subtask['id'], 'refresh-table' => (int) $refresh_table); if ($subtask['status'] == 0 && isset($this->sessionStorage->hasSubtaskInProgress) && $this->sessionStorage->hasSubtaskInProgress) { - return $this->helper->url->link($this->getTitle($subtask), 'SubtaskRestriction', 'popover', $params, false, 'popover'); + return $this->helper->url->link($this->getTitle($subtask), 'SubtaskRestrictionController', 'show', $params, false, 'popover'); } $class = 'subtask-toggle-status '.($refresh_table ? 'subtask-refresh-table' : ''); - return $this->helper->url->link($this->getTitle($subtask), 'SubtaskStatus', 'change', $params, false, $class); + return $this->helper->url->link($this->getTitle($subtask), 'SubtaskStatusController', 'change', $params, false, $class); } public function selectTitle(array $values, array $errors = array(), array $attributes = array()) diff --git a/app/ServiceProvider/AuthenticationProvider.php b/app/ServiceProvider/AuthenticationProvider.php index fbc10abf..193929c7 100644 --- a/app/ServiceProvider/AuthenticationProvider.php +++ b/app/ServiceProvider/AuthenticationProvider.php @@ -86,9 +86,9 @@ class AuthenticationProvider implements ServiceProviderInterface $acl->add('ProjectEdit', '*', Role::PROJECT_MANAGER); $acl->add('ProjectFile', '*', Role::PROJECT_MEMBER); $acl->add('Projectuser', '*', Role::PROJECT_MANAGER); - $acl->add('Subtask', '*', Role::PROJECT_MEMBER); - $acl->add('SubtaskRestriction', '*', Role::PROJECT_MEMBER); - $acl->add('SubtaskStatus', '*', Role::PROJECT_MEMBER); + $acl->add('SubtaskController', '*', Role::PROJECT_MEMBER); + $acl->add('SubtaskRestrictionController', '*', Role::PROJECT_MEMBER); + $acl->add('SubtaskStatusController', '*', Role::PROJECT_MEMBER); $acl->add('Swimlane', '*', Role::PROJECT_MANAGER); $acl->add('Task', 'remove', Role::PROJECT_MEMBER); $acl->add('TaskCreationController', '*', Role::PROJECT_MEMBER); diff --git a/app/ServiceProvider/RouteProvider.php b/app/ServiceProvider/RouteProvider.php index 359bd220..2bf3b6db 100644 --- a/app/ServiceProvider/RouteProvider.php +++ b/app/ServiceProvider/RouteProvider.php @@ -100,7 +100,6 @@ class RouteProvider implements ServiceProviderInterface $container['route']->addRoute('project/:project_id/task/:task_id/activity', 'activity', 'task'); $container['route']->addRoute('project/:project_id/task/:task_id/transitions', 'task', 'transitions'); $container['route']->addRoute('project/:project_id/task/:task_id/analytics', 'task', 'analytics'); - $container['route']->addRoute('project/:project_id/task/:task_id/subtasks', 'subtask', 'show'); $container['route']->addRoute('project/:project_id/task/:task_id/time-tracking', 'task', 'timetracking'); // Exports diff --git a/app/Template/subtask/create.php b/app/Template/subtask/create.php index 029fddf5..31b99f90 100644 --- a/app/Template/subtask/create.php +++ b/app/Template/subtask/create.php @@ -2,7 +2,7 @@

-
+ form->csrf() ?> form->hidden('task_id', $values) ?> diff --git a/app/Template/subtask/edit.php b/app/Template/subtask/edit.php index 3c210f60..9e316ea5 100644 --- a/app/Template/subtask/edit.php +++ b/app/Template/subtask/edit.php @@ -2,7 +2,7 @@

- + form->csrf() ?> form->hidden('id', $values) ?> diff --git a/app/Template/subtask/menu.php b/app/Template/subtask/menu.php index aa7b9a53..d5d1bf85 100644 --- a/app/Template/subtask/menu.php +++ b/app/Template/subtask/menu.php @@ -3,11 +3,11 @@