Change a category directly from the board

This commit is contained in:
Frédéric Guillot 2014-09-03 14:25:17 -07:00
parent d68ff648b1
commit 749136361e
16 changed files with 150 additions and 37 deletions

View File

@ -51,39 +51,27 @@ class Board extends Base
*
* @access public
*/
public function assign()
public function changeAssignee()
{
$task = $this->task->getById($this->request->getIntegerParam('task_id'));
$task = $this->getTask();
$project = $this->project->getById($task['project_id']);
$projects = $this->project->getListByStatus(ProjectModel::ACTIVE);
if ($this->acl->isRegularUser()) {
$projects = $this->project->filterListByAccess($projects, $this->acl->getUserId());
}
if (! $project) $this->notfound();
$this->checkProjectPermissions($project['id']);
$projects = $this->project->getAvailableList($this->acl->getUserId());
$params = array(
'errors' => array(),
'values' => $task,
'users_list' => $this->project->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_assign', array(
'errors' => array(),
'values' => $task,
'users_list' => $this->project->getUsersList($project['id']),
'projects' => $projects,
'current_project_id' => $project['id'],
'current_project_name' => $project['name'],
)));
$this->response->html($this->template->load('board_assignee', $params));
}
else {
$this->response->html($this->template->layout('board_assign', array(
'errors' => array(),
'values' => $task,
'users_list' => $this->project->getUsersList($project['id']),
'projects' => $projects,
'current_project_id' => $project['id'],
'current_project_name' => $project['name'],
$this->response->html($this->template->layout('board_assignee', $params + array(
'menu' => 'boards',
'title' => t('Change assignee').' - '.$task['title'],
)));
@ -95,7 +83,7 @@ class Board extends Base
*
* @access public
*/
public function assignTask()
public function updateAssignee()
{
$values = $this->request->getValues();
$this->checkProjectPermissions($values['project_id']);
@ -112,6 +100,60 @@ class Board extends Base
$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->project->getAvailableList($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->task->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

View File

@ -466,4 +466,6 @@ return array(
// 'No external authentication enabled.' => '',
// 'Password modified successfully.' => '',
// 'Unable to change the password.' => '',
// 'Change category for the task "%s"' => '',
// 'Change category' => '',
);

View File

@ -466,4 +466,6 @@ return array(
// 'No external authentication enabled.' => '',
// 'Password modified successfully.' => '',
// 'Unable to change the password.' => '',
// 'Change category for the task "%s"' => '',
// 'Change category' => '',
);

View File

@ -466,4 +466,6 @@ return array(
// 'No external authentication enabled.' => '',
// 'Password modified successfully.' => '',
// 'Unable to change the password.' => '',
// 'Change category for the task "%s"' => '',
// 'Change category' => '',
);

View File

@ -466,4 +466,6 @@ return array(
'No external authentication enabled.' => 'Aucune authentication externe activée.',
'Password modified successfully.' => 'Mot de passe changé avec succès.',
'Unable to change the password.' => 'Impossible de changer le mot de passe.',
'Change category for the task "%s"' => 'Changer la catégorie pour la tâche « %s »',
'Change category' => 'Changer de catégorie',
);

View File

@ -466,4 +466,6 @@ return array(
// 'No external authentication enabled.' => '',
// 'Password modified successfully.' => '',
// 'Unable to change the password.' => '',
// 'Change category for the task "%s"' => '',
// 'Change category' => '',
);

View File

@ -466,4 +466,6 @@ return array(
// 'No external authentication enabled.' => '',
// 'Password modified successfully.' => '',
// 'Unable to change the password.' => '',
// 'Change category for the task "%s"' => '',
// 'Change category' => '',
);

View File

@ -466,4 +466,6 @@ return array(
// 'No external authentication enabled.' => '',
// 'Password modified successfully.' => '',
// 'Unable to change the password.' => '',
// 'Change category for the task "%s"' => '',
// 'Change category' => '',
);

View File

@ -466,4 +466,6 @@ return array(
// 'No external authentication enabled.' => '',
// 'Password modified successfully.' => '',
// 'Unable to change the password.' => '',
// 'Change category for the task "%s"' => '',
// 'Change category' => '',
);

View File

@ -466,4 +466,6 @@ return array(
// 'No external authentication enabled.' => '',
// 'Password modified successfully.' => '',
// 'Unable to change the password.' => '',
// 'Change category for the task "%s"' => '',
// 'Change category' => '',
);

View File

@ -30,7 +30,7 @@ class Acl extends Base
*/
private $user_actions = array(
'app' => array('index'),
'board' => array('index', 'show', 'assign', 'assigntask', 'save', 'check'),
'board' => array('index', 'show', 'save', 'check', 'changeassignee', 'updateassignee', 'changecategory', 'updatecategory'),
'project' => array('tasks', 'index', 'forbidden', 'search', 'export', 'show'),
'user' => array('index', 'edit', 'forbidden', 'logout', 'index', 'show', 'external', 'unlinkgoogle', 'unlinkgithub', 'sessions', 'removesession', 'last', 'notifications', 'password'),
'comment' => array('create', 'save', 'confirm', 'remove', 'update', 'edit', 'forbidden'),

View File

@ -704,6 +704,30 @@ class Task extends Base
);
}
/**
* Validate category change
*
* @access public
* @param array $values Form values
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
*/
public function validateCategoryModification(array $values)
{
$v = new Validator($values, array(
new Validators\Required('id', t('The id is required')),
new Validators\Integer('id', t('This value must be an integer')),
new Validators\Required('project_id', t('The project is required')),
new Validators\Integer('project_id', t('This value must be an integer')),
new Validators\Required('category_id', t('This value is required')),
new Validators\Integer('category_id', t('This value must be an integer')),
));
return array(
$v->execute(),
$v->getErrors()
);
}
/**
* Validate project modification
*

View File

@ -1,14 +1,12 @@
<section id="main">
<div class="page-header board">
<h2>
<?= t('Project "%s"', $current_project_name) ?>
</h2>
<h2><?= t('Project "%s"', $current_project_name) ?></h2>
</div>
<section>
<h3><?= t('Change assignee for the task "%s"', $values['title']) ?></h3>
<form method="post" action="?controller=board&amp;action=assignTask" autocomplete="off">
<form method="post" action="?controller=board&amp;action=updateAssignee" autocomplete="off">
<?= Helper\form_csrf() ?>
<?= Helper\form_hidden('id', $values) ?>
<?= Helper\form_hidden('project_id', $values) ?>

View File

@ -0,0 +1,24 @@
<section id="main">
<div class="page-header board">
<h2><?= t('Project "%s"', $current_project_name) ?></h2>
</div>
<section>
<h3><?= t('Change category for the task "%s"', $values['title']) ?></h3>
<form method="post" action="?controller=board&amp;action=updateCategory" autocomplete="off">
<?= Helper\form_csrf() ?>
<?= Helper\form_hidden('id', $values) ?>
<?= Helper\form_hidden('project_id', $values) ?>
<?= Helper\form_label(t('Category'), 'category_id') ?>
<?= Helper\form_select('category_id', $categories_list, $values, $errors) ?><br/>
<div class="form-actions">
<input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/>
<?= t('or') ?> <a href="?controller=board&amp;action=show&amp;project_id=<?= $values['project_id'] ?>"><?= t('cancel') ?></a>
</div>
</form>
</section>
</section>

View File

@ -23,11 +23,13 @@
<a class="task-edit-popover" href="?controller=task&amp;action=edit&amp;task_id=<?= $task['id'] ?>" title="<?= t('Edit this task') ?>">#<?= $task['id'] ?></a> -
<span class="task-board-user">
<?php if (! empty($task['owner_id'])): ?>
<a class="assignee-popover" href="?controller=board&amp;action=assign&amp;task_id=<?= $task['id'] ?>" title="<?= t('Change assignee') ?>"><?= t('Assigned to %s', $task['assignee_name'] ?: $task['assignee_username']) ?></a>
<?php else: ?>
<a class="assignee-popover" href="?controller=board&amp;action=assign&amp;task_id=<?= $task['id'] ?>" title="<?= t('Change assignee') ?>" class="task-board-nobody"><?= t('Nobody assigned') ?></a>
<?php endif ?>
<a class="assignee-popover" href="?controller=board&amp;action=changeAssignee&amp;task_id=<?= $task['id'] ?>" title="<?= t('Change assignee') ?>">
<?php if (! empty($task['owner_id'])): ?>
<?= t('Assigned to %s', $task['assignee_name'] ?: $task['assignee_username']) ?></a>
<?php else: ?>
<?= t('Nobody assigned') ?>
<?php endif ?>
</a>
</span>
<?php if ($task['score']): ?>
@ -44,7 +46,9 @@
<?php if ($task['category_id']): ?>
<div class="task-board-category-container">
<span class="task-board-category">
<?= Helper\in_list($task['category_id'], $categories) ?>
<a class="category-popover" href="?controller=board&amp;action=changeCategory&amp;task_id=<?= $task['id'] ?>" title="<?= t('Change category') ?>">
<?= Helper\in_list($task['category_id'], $categories) ?>
</a>
</span>
</div>
<?php endif ?>

View File

@ -92,6 +92,9 @@ Kanboard.Board = (function() {
// Assignee change
$(".assignee-popover").click(Kanboard.Popover);
// Category change
$(".category-popover").click(Kanboard.Popover);
// Task edit popover
$(".task-edit-popover").click(function(e) {
Kanboard.Popover(e, Kanboard.Task.Init);