diff options
Diffstat (limited to 'app/Controller/Board.php')
-rw-r--r-- | app/Controller/Board.php | 501 |
1 files changed, 213 insertions, 288 deletions
diff --git a/app/Controller/Board.php b/app/Controller/Board.php index d49ad021..2b633d82 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -2,10 +2,6 @@ namespace Controller; -use Model\Project as ProjectModel; -use Model\User as UserModel; -use Core\Security; - /** * Board controller * @@ -15,133 +11,6 @@ use Core\Security; class Board extends Base { /** - * Move a column down or up - * - * @access public - */ - public function moveColumn() - { - $this->checkCSRFParam(); - $project = $this->getProjectManagement(); - $column_id = $this->request->getIntegerParam('column_id'); - $direction = $this->request->getStringParam('direction'); - - if ($direction === 'up' || $direction === 'down') { - $this->board->{'move'.$direction}($project['id'], $column_id); - } - - $this->response->redirect('?controller=board&action=edit&project_id='.$project['id']); - } - - /** - * Change a task assignee directly from the board - * - * @access public - */ - public function changeAssignee() - { - $task = $this->getTask(); - $project = $this->project->getById($task['project_id']); - $projects = $this->projectPermission->getAllowedProjects($this->acl->getUserId()); - $params = array( - 'errors' => array(), - 'values' => $task, - 'users_list' => $this->projectPermission->getUsersList($project['id']), - 'projects' => $projects, - 'current_project_id' => $project['id'], - 'current_project_name' => $project['name'], - ); - - if ($this->request->isAjax()) { - - $this->response->html($this->template->load('board_assignee', $params)); - } - else { - - $this->response->html($this->template->layout('board_assignee', $params + array( - 'menu' => 'boards', - 'title' => t('Change assignee').' - '.$task['title'], - ))); - } - } - - /** - * Validate an assignee modification - * - * @access public - */ - public function updateAssignee() - { - $values = $this->request->getValues(); - $this->checkProjectPermissions($values['project_id']); - - list($valid,) = $this->taskValidator->validateAssigneeModification($values); - - if ($valid && $this->task->update($values)) { - $this->session->flash(t('Task updated successfully.')); - } - else { - $this->session->flashError(t('Unable to update your task.')); - } - - $this->response->redirect('?controller=board&action=show&project_id='.$values['project_id']); - } - - /** - * Change a task category directly from the board - * - * @access public - */ - public function changeCategory() - { - $task = $this->getTask(); - $project = $this->project->getById($task['project_id']); - $projects = $this->projectPermission->getAllowedProjects($this->acl->getUserId()); - $params = array( - 'errors' => array(), - 'values' => $task, - 'categories_list' => $this->category->getList($project['id']), - 'projects' => $projects, - 'current_project_id' => $project['id'], - 'current_project_name' => $project['name'], - ); - - if ($this->request->isAjax()) { - - $this->response->html($this->template->load('board_category', $params)); - } - else { - - $this->response->html($this->template->layout('board_category', $params + array( - 'menu' => 'boards', - 'title' => t('Change category').' - '.$task['title'], - ))); - } - } - - /** - * Validate a category modification - * - * @access public - */ - public function updateCategory() - { - $values = $this->request->getValues(); - $this->checkProjectPermissions($values['project_id']); - - list($valid,) = $this->taskValidator->validateCategoryModification($values); - - if ($valid && $this->task->update($values)) { - $this->session->flash(t('Task updated successfully.')); - } - else { - $this->session->flashError(t('Unable to update your task.')); - } - - $this->response->redirect('?controller=board&action=show&project_id='.$values['project_id']); - } - - /** * Display the public version of a board * Access checked by a simple token, no user login, read only, auto-refresh * @@ -153,19 +22,25 @@ class Board extends Base $project = $this->project->getByToken($token); // Token verification - if (! $project) { + if (empty($project)) { $this->forbidden(true); } + list($categories_listing, $categories_description) = $this->category->getBoardCategories($project['id']); + // Display the board with a specific layout - $this->response->html($this->template->layout('board_public', array( + $this->response->html($this->template->layout('board/public', array( 'project' => $project, - 'columns' => $this->board->get($project['id']), - 'categories' => $this->category->getList($project['id'], false), + 'swimlanes' => $this->board->getBoard($project['id']), + 'categories_listing' => $categories_listing, + 'categories_description' => $categories_description, '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'), ))); } @@ -176,16 +51,16 @@ class Board extends Base */ public function index() { - $last_seen_project_id = $this->user->getLastSeenProjectId(); - $favorite_project_id = $this->user->getFavoriteProjectId(); + $last_seen_project_id = $this->userSession->getLastSeenProjectId(); + $favorite_project_id = $this->userSession->getFavoriteProjectId(); $project_id = $last_seen_project_id ?: $favorite_project_id; if (! $project_id) { - $projects = $this->projectPermission->getAllowedProjects($this->acl->getUserId()); + $projects = $this->projectPermission->getAllowedProjects($this->userSession->getId()); if (empty($projects)) { - if ($this->acl->isAdminUser()) { + if ($this->userSession->isAdmin()) { $this->redirectNoProject(); } @@ -207,23 +82,24 @@ class Board extends Base public function show($project_id = 0) { $project = $this->getProject($project_id); - $projects = $this->projectPermission->getAllowedProjects($this->acl->getUserId()); + $projects = $this->projectPermission->getAllowedProjects($this->userSession->getId()); $board_selector = $projects; unset($board_selector[$project['id']]); - $this->user->storeLastSeenProjectId($project['id']); + $this->userSession->storeLastSeenProjectId($project['id']); + + list($categories_listing, $categories_description) = $this->category->getBoardCategories($project['id']); - $this->response->html($this->template->layout('board_index', array( - 'users' => $this->projectPermission->getUsersList($project['id'], true, true), - 'filters' => array('user_id' => UserModel::EVERYBODY_ID), + $this->response->html($this->template->layout('board/index', array( + 'users' => $this->projectPermission->getMemberList($project['id'], true, true), 'projects' => $projects, - 'current_project_id' => $project['id'], - 'current_project_name' => $project['name'], - 'board' => $this->board->get($project['id']), - 'categories' => $this->category->getList($project['id'], true, true), - 'menu' => 'boards', + 'project' => $project, + 'swimlanes' => $this->board->getBoard($project['id']), + 'categories_listing' => $categories_listing, + 'categories_description' => $categories_description, 'title' => $project['name'], + 'description' => $project['description'], 'board_selector' => $board_selector, 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), 'board_highlight_period' => $this->config->get('board_highlight_period'), @@ -231,215 +107,264 @@ class Board extends Base } /** - * Display a form to edit a board + * Save the board (Ajax request made by the drag and drop) * * @access public */ - public function edit() + public function save() { - $project = $this->getProjectManagement(); - $columns = $this->board->getColumns($project['id']); - $values = array(); + $project_id = $this->request->getIntegerParam('project_id'); - foreach ($columns as $column) { - $values['title['.$column['id'].']'] = $column['title']; - $values['task_limit['.$column['id'].']'] = $column['task_limit'] ?: null; + if (! $project_id || ! $this->request->isAjax()) { + return $this->response->status(403); } - $this->response->html($this->projectLayout('board_edit', array( - 'errors' => array(), - 'values' => $values + array('project_id' => $project['id']), - 'columns' => $columns, - 'project' => $project, - 'menu' => 'projects', - 'title' => t('Edit board') - ))); + if (! $this->projectPermission->isUserAllowed($project_id, $this->userSession->getId())) { + $this->response->text('Forbidden', 403); + } + + $values = $this->request->getJson(); + + $result =$this->taskPosition->movePosition( + $project_id, + $values['task_id'], + $values['column_id'], + $values['position'], + $values['swimlane_id'] + ); + + if (! $result) { + return $this->response->status(400); + } + + list($categories_listing, $categories_description) = $this->category->getBoardCategories($project_id); + + $this->response->html( + $this->template->render('board/show', array( + 'project' => $this->project->getById($project_id), + 'swimlanes' => $this->board->getBoard($project_id), + 'categories_listing' => $categories_listing, + 'categories_description' => $categories_description, + 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), + 'board_highlight_period' => $this->config->get('board_highlight_period'), + )), + 201 + ); } /** - * Validate and update a board + * Check if the board have been changed * * @access public */ - public function update() + public function check() { - $project = $this->getProjectManagement(); - $columns = $this->board->getColumns($project['id']); - $data = $this->request->getValues(); - $values = $columns_list = array(); - - foreach ($columns as $column) { - $columns_list[$column['id']] = $column['title']; - $values['title['.$column['id'].']'] = isset($data['title'][$column['id']]) ? $data['title'][$column['id']] : ''; - $values['task_limit['.$column['id'].']'] = isset($data['task_limit'][$column['id']]) ? $data['task_limit'][$column['id']] : 0; + if (! $this->request->isAjax()) { + return $this->response->status(403); } - list($valid, $errors) = $this->board->validateModification($columns_list, $values); + $project_id = $this->request->getIntegerParam('project_id'); + $timestamp = $this->request->getIntegerParam('timestamp'); - if ($valid) { + if (! $this->projectPermission->isUserAllowed($project_id, $this->userSession->getId())) { + $this->response->text('Forbidden', 403); + } - if ($this->board->update($data)) { - $this->session->flash(t('Board updated successfully.')); - $this->response->redirect('?controller=board&action=edit&project_id='.$project['id']); - } - else { - $this->session->flashError(t('Unable to update this board.')); - } + if (! $this->project->isModifiedSince($project_id, $timestamp)) { + return $this->response->status(304); } - $this->response->html($this->projectLayout('board_edit', array( - 'errors' => $errors, - 'values' => $values + array('project_id' => $project['id']), - 'columns' => $columns, - 'project' => $project, - 'menu' => 'projects', - 'title' => t('Edit board') - ))); + list($categories_listing, $categories_description) = $this->category->getBoardCategories($project_id); + + $this->response->html( + $this->template->render('board/show', array( + 'project' => $this->project->getById($project_id), + 'swimlanes' => $this->board->getBoard($project_id), + 'categories_listing' => $categories_listing, + 'categories_description' => $categories_description, + 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), + 'board_highlight_period' => $this->config->get('board_highlight_period'), + )) + ); } /** - * Validate and add a new column + * Get links on mouseover * * @access public */ - public function add() + public function tasklinks() { - $project = $this->getProjectManagement(); - $columns = $this->board->getColumnsList($project['id']); - $data = $this->request->getValues(); - $values = array(); - - foreach ($columns as $column_id => $column_title) { - $values['title['.$column_id.']'] = $column_title; - } - - list($valid, $errors) = $this->board->validateCreation($data); + $task = $this->getTask(); + $this->response->html($this->template->render('board/tasklinks', array( + 'links' => $this->taskLink->getAll($task['id']), + 'task' => $task, + ))); + } - if ($valid) { + /** + * Get subtasks on mouseover + * + * @access public + */ + public function subtasks() + { + $task = $this->getTask(); + $this->response->html($this->template->render('board/subtasks', array( + 'subtasks' => $this->subtask->getAll($task['id']), + 'task' => $task, + ))); + } - if ($this->board->addColumn($project['id'], $data['title'])) { - $this->session->flash(t('Board updated successfully.')); - $this->response->redirect('?controller=board&action=edit&project_id='.$project['id']); - } - else { - $this->session->flashError(t('Unable to update this board.')); - } - } + /** + * Display all attachments during the task mouseover + * + * @access public + */ + public function attachments() + { + $task = $this->getTask(); - $this->response->html($this->projectLayout('board_edit', array( - 'errors' => $errors, - 'values' => $values + $data, - 'columns' => $columns, - 'project' => $project, - 'menu' => 'projects', - 'title' => t('Edit board') + $this->response->html($this->template->render('board/files', array( + 'files' => $this->file->getAllDocuments($task['id']), + 'images' => $this->file->getAllImages($task['id']), + 'task' => $task, ))); } /** - * Remove a column + * Display comments during a task mouseover * * @access public */ - public function remove() + public function comments() { - $project = $this->getProjectManagement(); + $task = $this->getTask(); - if ($this->request->getStringParam('remove') === 'yes') { + $this->response->html($this->template->render('board/comments', array( + 'comments' => $this->comment->getAll($task['id']) + ))); + } - $this->checkCSRFParam(); - $column = $this->board->getColumn($this->request->getIntegerParam('column_id')); + /** + * Display task description + * + * @access public + */ + public function description() + { + $task = $this->getTask(); - if ($column && $this->board->removeColumn($column['id'])) { - $this->session->flash(t('Column removed successfully.')); - } else { - $this->session->flashError(t('Unable to remove this column.')); - } + $this->response->html($this->template->render('board/description', array( + 'task' => $task + ))); + } - $this->response->redirect('?controller=board&action=edit&project_id='.$project['id']); - } + /** + * Change a task assignee directly from the board + * + * @access public + */ + public function changeAssignee() + { + $task = $this->getTask(); + $project = $this->project->getById($task['project_id']); - $this->response->html($this->projectLayout('board_remove', array( - 'column' => $this->board->getColumn($this->request->getIntegerParam('column_id')), + $this->response->html($this->template->render('board/assignee', array( + 'values' => $task, + 'users_list' => $this->projectPermission->getMemberList($project['id']), 'project' => $project, - 'menu' => 'projects', - 'title' => t('Remove a column from a board') ))); } /** - * Save the board (Ajax request made by the drag and drop) + * Validate an assignee modification * * @access public */ - public function save() + public function updateAssignee() { - $project_id = $this->request->getIntegerParam('project_id'); + $values = $this->request->getValues(); - if ($project_id > 0 && $this->request->isAjax()) { + list($valid,) = $this->taskValidator->validateAssigneeModification($values); - if (! $this->projectPermission->isUserAllowed($project_id, $this->acl->getUserId())) { - $this->response->status(401); - } + if ($valid && $this->taskModification->update($values)) { + $this->session->flash(t('Task updated successfully.')); + } + else { + $this->session->flashError(t('Unable to update your task.')); + } - $values = $this->request->getValues(); + $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $values['project_id']))); + } - if ($this->task->movePosition($project_id, $values['task_id'], $values['column_id'], $values['position'])) { + /** + * Change a task category directly from the board + * + * @access public + */ + public function changeCategory() + { + $task = $this->getTask(); + $project = $this->project->getById($task['project_id']); - $this->response->html( - $this->template->load('board_show', array( - 'current_project_id' => $project_id, - 'board' => $this->board->get($project_id), - 'categories' => $this->category->getList($project_id, false), - 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), - 'board_highlight_period' => $this->config->get('board_highlight_period'), - )), - 201 - ); - } - else { + $this->response->html($this->template->render('board/category', array( + 'values' => $task, + 'categories_list' => $this->category->getList($project['id']), + 'project' => $project, + ))); + } - $this->response->status(400); - } + /** + * Validate a category modification + * + * @access public + */ + public function updateCategory() + { + $values = $this->request->getValues(); + + list($valid,) = $this->taskValidator->validateCategoryModification($values); + + if ($valid && $this->taskModification->update($values)) { + $this->session->flash(t('Task updated successfully.')); } else { - $this->response->status(401); + $this->session->flashError(t('Unable to update your task.')); } + + $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $values['project_id']))); } /** - * Check if the board have been changed + * Screenshot popover * * @access public */ - public function check() + public function screenshot() { - if ($this->request->isAjax()) { + $task = $this->getTask(); - $project_id = $this->request->getIntegerParam('project_id'); - $timestamp = $this->request->getIntegerParam('timestamp'); + $this->response->html($this->template->render('file/screenshot', array( + 'task' => $task, + 'redirect' => 'board', + ))); + } - if ($project_id > 0 && ! $this->projectPermission->isUserAllowed($project_id, $this->acl->getUserId())) { - $this->response->text('Not Authorized', 401); - } + /** + * Get recurrence information on mouseover + * + * @access public + */ + public function recurrence() + { + $task = $this->getTask(); - if ($this->project->isModifiedSince($project_id, $timestamp)) { - $this->response->html( - $this->template->load('board_show', array( - 'current_project_id' => $project_id, - 'board' => $this->board->get($project_id), - 'categories' => $this->category->getList($project_id, false), - 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), - 'board_highlight_period' => $this->config->get('board_highlight_period'), - )) - ); - } - else { - $this->response->status(304); - } - } - else { - $this->response->status(401); - } + $this->response->html($this->template->render('task/recurring_info', array( + 'task' => $task, + 'recurrence_trigger_list' => $this->task->getRecurrenceTriggerList(), + 'recurrence_timeframe_list' => $this->task->getRecurrenceTimeframeList(), + 'recurrence_basedate_list' => $this->task->getRecurrenceBasedateList(), + ))); } } |