From ea9d402587d6fbcb39080a5d9a26e94ff4575443 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 11 Apr 2015 17:38:41 -0400 Subject: Add column controller --- app/Controller/Board.php | 303 ++++++++++--------------------------- app/Controller/Column.php | 170 +++++++++++++++++++++ app/Model/Acl.php | 2 +- app/Template/board/edit.php | 82 ---------- app/Template/board/edit_column.php | 42 ----- app/Template/board/remove.php | 15 -- app/Template/column/edit.php | 42 +++++ app/Template/column/index.php | 82 ++++++++++ app/Template/column/remove.php | 15 ++ app/Template/project/sidebar.php | 2 +- 10 files changed, 387 insertions(+), 368 deletions(-) create mode 100644 app/Controller/Column.php delete mode 100644 app/Template/board/edit.php delete mode 100644 app/Template/board/edit_column.php delete mode 100644 app/Template/board/remove.php create mode 100644 app/Template/column/edit.php create mode 100644 app/Template/column/index.php create mode 100644 app/Template/column/remove.php (limited to 'app') diff --git a/app/Controller/Board.php b/app/Controller/Board.php index 47248fa2..89272393 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -10,101 +10,6 @@ namespace Controller; */ class Board extends Base { - /** - * Move a column down or up - * - * @access public - */ - public function moveColumn() - { - $this->checkCSRFParam(); - $project = $this->getProject(); - $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']); - - $this->response->html($this->template->render('board/assignee', array( - 'values' => $task, - 'users_list' => $this->projectPermission->getMemberList($project['id']), - 'project' => $project, - ))); - } - - /** - * Validate an assignee modification - * - * @access public - */ - public function updateAssignee() - { - $values = $this->request->getValues(); - - list($valid,) = $this->taskValidator->validateAssigneeModification($values); - - if ($valid && $this->taskModification->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']); - - $this->response->html($this->template->render('board/category', array( - 'values' => $task, - 'categories_list' => $this->category->getList($project['id']), - 'project' => $project, - ))); - } - - /** - * 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->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 @@ -201,138 +106,6 @@ class Board extends Base ))); } - /** - * Display a form to edit a board - * - * @access public - */ - public function edit(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - $columns = $this->board->getColumns($project['id']); - - foreach ($columns as $column) { - $values['title['.$column['id'].']'] = $column['title']; - $values['description['.$column['id'].']'] = $column['description']; - $values['task_limit['.$column['id'].']'] = $column['task_limit'] ?: null; - } - - $this->response->html($this->projectLayout('board/edit', array( - 'errors' => $errors, - 'values' => $values + array('project_id' => $project['id']), - 'columns' => $columns, - 'project' => $project, - 'title' => t('Edit board') - ))); - } - - /** - * Display a form to edit a board - * - * @access public - */ - public function editColumn(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - $column = $this->board->getColumn($this->request->getIntegerParam('column_id')); - - $this->response->html($this->projectLayout('board/edit_column', array( - 'errors' => $errors, - 'values' => $values ?: $column, - 'project' => $project, - 'column' => $column, - 'title' => t('Edit column "%s"', $column['title']) - ))); - } - - /** - * Validate and update a column - * - * @access public - */ - public function updateColumn() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - - list($valid, $errors) = $this->board->validateModification($values); - - if ($valid) { - - if ($this->board->updateColumn($values['id'], $values['title'], $values['task_limit'], $values['description'])) { - $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.')); - } - } - - $this->editcolumn($values, $errors); - } - - /** - * Validate and add a new column - * - * @access public - */ - public function add() - { - $project = $this->getProject(); - $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); - - if ($valid) { - - if ($this->board->addColumn($project['id'], $data['title'], $data['task_limit'], $data['description'])) { - $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.')); - } - } - - $this->edit($values, $errors); - } - - /** - * Remove a column - * - * @access public - */ - public function remove() - { - $project = $this->getProject(); - - if ($this->request->getStringParam('remove') === 'yes') { - - $this->checkCSRFParam(); - $column = $this->board->getColumn($this->request->getIntegerParam('column_id')); - - if (! empty($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->redirect('?controller=board&action=edit&project_id='.$project['id']); - } - - $this->response->html($this->projectLayout('board/remove', array( - 'column' => $this->board->getColumn($this->request->getIntegerParam('column_id')), - 'project' => $project, - 'title' => t('Remove a column from a board') - ))); - } - /** * Save the board (Ajax request made by the drag and drop) * @@ -486,4 +259,80 @@ class Board extends Base 'task' => $task ))); } + + /** + * 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->template->render('board/assignee', array( + 'values' => $task, + 'users_list' => $this->projectPermission->getMemberList($project['id']), + 'project' => $project, + ))); + } + + /** + * Validate an assignee modification + * + * @access public + */ + public function updateAssignee() + { + $values = $this->request->getValues(); + + list($valid,) = $this->taskValidator->validateAssigneeModification($values); + + if ($valid && $this->taskModification->update($values)) { + $this->session->flash(t('Task updated successfully.')); + } + else { + $this->session->flashError(t('Unable to update your task.')); + } + + $this->response->redirect($this->helper->url('board', 'show', array('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']); + + $this->response->html($this->template->render('board/category', array( + 'values' => $task, + 'categories_list' => $this->category->getList($project['id']), + 'project' => $project, + ))); + } + + /** + * 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->session->flashError(t('Unable to update your task.')); + } + + $this->response->redirect($this->helper->url('board', 'show', array('project_id' => $values['project_id']))); + } } diff --git a/app/Controller/Column.php b/app/Controller/Column.php new file mode 100644 index 00000000..69ca5dd2 --- /dev/null +++ b/app/Controller/Column.php @@ -0,0 +1,170 @@ +getProject(); + $columns = $this->board->getColumns($project['id']); + + foreach ($columns as $column) { + $values['title['.$column['id'].']'] = $column['title']; + $values['description['.$column['id'].']'] = $column['description']; + $values['task_limit['.$column['id'].']'] = $column['task_limit'] ?: null; + } + + $this->response->html($this->projectLayout('column/index', array( + 'errors' => $errors, + 'values' => $values + array('project_id' => $project['id']), + 'columns' => $columns, + 'project' => $project, + 'title' => t('Edit board') + ))); + } + + /** + * Validate and add a new column + * + * @access public + */ + public function create() + { + $project = $this->getProject(); + $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); + + if ($valid) { + + if ($this->board->addColumn($project['id'], $data['title'], $data['task_limit'], $data['description'])) { + $this->session->flash(t('Board updated successfully.')); + $this->response->redirect($this->helper->url('column', 'index', array('project_id' => $project['id']))); + } + else { + $this->session->flashError(t('Unable to update this board.')); + } + } + + $this->index($values, $errors); + } + + /** + * Display a form to edit a column + * + * @access public + */ + public function edit(array $values = array(), array $errors = array()) + { + $project = $this->getProject(); + $column = $this->board->getColumn($this->request->getIntegerParam('column_id')); + + $this->response->html($this->projectLayout('column/edit', array( + 'errors' => $errors, + 'values' => $values ?: $column, + 'project' => $project, + 'column' => $column, + 'title' => t('Edit column "%s"', $column['title']) + ))); + } + + /** + * Validate and update a column + * + * @access public + */ + public function update() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + + list($valid, $errors) = $this->board->validateModification($values); + + if ($valid) { + + if ($this->board->updateColumn($values['id'], $values['title'], $values['task_limit'], $values['description'])) { + $this->session->flash(t('Board updated successfully.')); + $this->response->redirect($this->helper->url('column', 'index', array('project_id' => $project['id']))); + } + else { + $this->session->flashError(t('Unable to update this board.')); + } + } + + $this->edit($values, $errors); + } + + /** + * Move a column up or down + * + * @access public + */ + public function move() + { + $this->checkCSRFParam(); + $project = $this->getProject(); + $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($this->helper->url('column', 'index', array('project_id' => $project['id']))); + } + + /** + * Confirm column suppression + * + * @access public + */ + public function confirm() + { + $project = $this->getProject(); + + $this->response->html($this->projectLayout('column/remove', array( + 'column' => $this->board->getColumn($this->request->getIntegerParam('column_id')), + 'project' => $project, + 'title' => t('Remove a column from a board') + ))); + } + + /** + * Remove a column + * + * @access public + */ + public function remove() + { + $project = $this->getProject(); + $this->checkCSRFParam(); + $column = $this->board->getColumn($this->request->getIntegerParam('column_id')); + + if (! empty($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->redirect($this->helper->url('column', 'index', array('project_id' => $project['id']))); + } +} diff --git a/app/Model/Acl.php b/app/Model/Acl.php index 403c45d0..cc4d0528 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -51,8 +51,8 @@ class Acl extends Base private $manager_acl = array( 'action' => '*', 'analytic' => '*', - 'board' => array('movecolumn', 'edit', 'editcolumn', 'updatecolumn', 'add', 'remove'), 'category' => '*', + 'column' => '*', 'export' => array('tasks', 'subtasks', 'summary'), 'project' => array('edit', 'update', 'share', 'integration', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'), 'swimlane' => '*', diff --git a/app/Template/board/edit.php b/app/Template/board/edit.php deleted file mode 100644 index a6df1000..00000000 --- a/app/Template/board/edit.php +++ /dev/null @@ -1,82 +0,0 @@ - - -

- - - - - - - - - - - - - -
e($column['title']) ?> - - '> - - - - e($column['task_limit']) ?> -
    -
  • - a(t('Edit'), 'board', 'editColumn', array('project_id' => $project['id'], 'column_id' => $column['id'])) ?> -
  • - -
  • - a(t('Move Up'), 'board', 'moveColumn', array('project_id' => $project['id'], 'column_id' => $column['id'], 'direction' => 'up'), true) ?> -
  • - - -
  • - a(t('Move Down'), 'board', 'moveColumn', array('project_id' => $project['id'], 'column_id' => $column['id'], 'direction' => 'down'), true) ?> -
  • - -
  • - a(t('Remove'), 'board', 'remove', array('project_id' => $project['id'], 'column_id' => $column['id'])) ?> -
  • -
-
- -

-
- - formCsrf() ?> - - formHidden('project_id', $values) ?> - - formLabel(t('Title'), 'title') ?> - formText('title', $values, $errors, array('required', 'maxlength="50"')) ?> - - formLabel(t('Task limit'), 'task_limit') ?> - formNumber('task_limit', $values, $errors) ?> - - formLabel(t('Description'), 'description') ?> - -
-
- formTextarea('description', $values, $errors) ?> -
-
-
-
-
    -
  • - -
  • -
  • - -
  • -
-
-
- -
- -
-
\ No newline at end of file diff --git a/app/Template/board/edit_column.php b/app/Template/board/edit_column.php deleted file mode 100644 index ef76b180..00000000 --- a/app/Template/board/edit_column.php +++ /dev/null @@ -1,42 +0,0 @@ - - -
- - formCsrf() ?> - - formHidden('id', $values) ?> - formHidden('project_id', $values) ?> - - formLabel(t('Title'), 'title') ?> - formText('title', $values, $errors, array('autofocus', 'required', 'maxlength="50"')) ?> - - formLabel(t('Task limit'), 'task_limit') ?> - formNumber('task_limit', $values, $errors) ?> - - formLabel(t('Description'), 'description') ?> - -
- -
- formTextarea('description', $values, $errors) ?> -
-
-
-
-
    -
  • - -
  • -
  • - -
  • -
-
-
- -
- -
-
\ No newline at end of file diff --git a/app/Template/board/remove.php b/app/Template/board/remove.php deleted file mode 100644 index 4b0370eb..00000000 --- a/app/Template/board/remove.php +++ /dev/null @@ -1,15 +0,0 @@ - - -
-

- - -

- -
- a(t('Yes'), 'board', 'remove', array('project_id' => $project['id'], 'column_id' => $column['id'], 'remove' => 'yes'), true, 'btn btn-red') ?> - a(t('cancel'), 'board', 'edit', array('project_id' => $project['id'])) ?> -
-
\ No newline at end of file diff --git a/app/Template/column/edit.php b/app/Template/column/edit.php new file mode 100644 index 00000000..7e16c326 --- /dev/null +++ b/app/Template/column/edit.php @@ -0,0 +1,42 @@ + + +
+ + formCsrf() ?> + + formHidden('id', $values) ?> + formHidden('project_id', $values) ?> + + formLabel(t('Title'), 'title') ?> + formText('title', $values, $errors, array('autofocus', 'required', 'maxlength="50"')) ?> + + formLabel(t('Task limit'), 'task_limit') ?> + formNumber('task_limit', $values, $errors) ?> + + formLabel(t('Description'), 'description') ?> + +
+ +
+ formTextarea('description', $values, $errors) ?> +
+
+
+
+
    +
  • + +
  • +
  • + +
  • +
+
+
+ +
+ +
+
\ No newline at end of file diff --git a/app/Template/column/index.php b/app/Template/column/index.php new file mode 100644 index 00000000..d55aa3a8 --- /dev/null +++ b/app/Template/column/index.php @@ -0,0 +1,82 @@ + + +

+ + + + + + + + + + + + + +
e($column['title']) ?> + + '> + + + + e($column['task_limit']) ?> +
    +
  • + a(t('Edit'), 'column', 'edit', array('project_id' => $project['id'], 'column_id' => $column['id'])) ?> +
  • + +
  • + a(t('Move Up'), 'column', 'move', array('project_id' => $project['id'], 'column_id' => $column['id'], 'direction' => 'up'), true) ?> +
  • + + +
  • + a(t('Move Down'), 'column', 'move', array('project_id' => $project['id'], 'column_id' => $column['id'], 'direction' => 'down'), true) ?> +
  • + +
  • + a(t('Remove'), 'column', 'confirm', array('project_id' => $project['id'], 'column_id' => $column['id'])) ?> +
  • +
+
+ +

+
+ + formCsrf() ?> + + formHidden('project_id', $values) ?> + + formLabel(t('Title'), 'title') ?> + formText('title', $values, $errors, array('required', 'maxlength="50"')) ?> + + formLabel(t('Task limit'), 'task_limit') ?> + formNumber('task_limit', $values, $errors) ?> + + formLabel(t('Description'), 'description') ?> + +
+
+ formTextarea('description', $values, $errors) ?> +
+
+
+
+
    +
  • + +
  • +
  • + +
  • +
+
+
+ +
+ +
+
\ No newline at end of file diff --git a/app/Template/column/remove.php b/app/Template/column/remove.php new file mode 100644 index 00000000..3dcbd62f --- /dev/null +++ b/app/Template/column/remove.php @@ -0,0 +1,15 @@ + + +
+

+ + +

+ +
+ a(t('Yes'), 'column', 'remove', array('project_id' => $project['id'], 'column_id' => $column['id'], 'remove' => 'yes'), true, 'btn btn-red') ?> + a(t('cancel'), 'column', 'index', array('project_id' => $project['id'])) ?> +
+
\ No newline at end of file diff --git a/app/Template/project/sidebar.php b/app/Template/project/sidebar.php index 47458144..31e3ff04 100644 --- a/app/Template/project/sidebar.php +++ b/app/Template/project/sidebar.php @@ -16,7 +16,7 @@ a(t('Edit project'), 'project', 'edit', array('project_id' => $project['id'])) ?>
  • - a(t('Edit board'), 'board', 'edit', array('project_id' => $project['id'])) ?> + a(t('Edit board'), 'column', 'index', array('project_id' => $project['id'])) ?>
  • a(t('Category management'), 'category', 'index', array('project_id' => $project['id'])) ?> -- cgit v1.2.3