Improve group controllers and views

This commit is contained in:
Frederic Guillot 2016-05-16 20:19:07 -04:00
parent de8ce875f4
commit abdf6f9780
19 changed files with 207 additions and 213 deletions

View File

@ -5,12 +5,12 @@ namespace Kanboard\Controller;
use Kanboard\Formatter\GroupAutoCompleteFormatter;
/**
* Group Helper
* Group Ajax Controller
*
* @package controller
* @author Frederic Guillot
* @package Kanboard\Controller
* @author Frederic Guillot
*/
class GroupHelper extends BaseController
class GroupAjaxController extends BaseController
{
/**
* Group auto-completion (Ajax)

View File

@ -0,0 +1,49 @@
<?php
namespace Kanboard\Controller;
/**
* Class GroupCreationController
*
* @package Kanboard\Controller
* @author Frederic Guillot
*/
class GroupCreationController extends BaseController
{
/**
* Display a form to create a new group
*
* @access public
* @param array $values
* @param array $errors
*/
public function show(array $values = array(), array $errors = array())
{
$this->response->html($this->template->render('group_creation/show', array(
'errors' => $errors,
'values' => $values,
)));
}
/**
* Validate and save a new group
*
* @access public
*/
public function save()
{
$values = $this->request->getValues();
list($valid, $errors) = $this->groupValidator->validateCreation($values);
if ($valid) {
if ($this->group->create($values['name']) !== false) {
$this->flash->success(t('Group created successfully.'));
return $this->response->redirect($this->helper->url->to('GroupListController', 'index'), true);
} else {
$this->flash->failure(t('Unable to create your group.'));
}
}
return $this->show($values, $errors);
}
}

View File

@ -5,10 +5,10 @@ namespace Kanboard\Controller;
/**
* Group Controller
*
* @package controller
* @author Frederic Guillot
* @package Kanboard\Controller
* @author Frederic Guillot
*/
class Group extends BaseController
class GroupListController extends BaseController
{
/**
* List all groups
@ -18,7 +18,7 @@ class Group extends BaseController
public function index()
{
$paginator = $this->paginator
->setUrl('group', 'index')
->setUrl('GroupListController', 'index')
->setMax(30)
->setOrder('name')
->setQuery($this->group->getQuery())
@ -41,7 +41,7 @@ class Group extends BaseController
$group = $this->group->getById($group_id);
$paginator = $this->paginator
->setUrl('group', 'users', array('group_id' => $group_id))
->setUrl('GroupListController', 'users', array('group_id' => $group_id))
->setMax(30)
->setOrder('username')
->setQuery($this->groupMember->getQuery($group_id))
@ -54,86 +54,6 @@ class Group extends BaseController
)));
}
/**
* Display a form to create a new group
*
* @access public
* @param array $values
* @param array $errors
*/
public function create(array $values = array(), array $errors = array())
{
$this->response->html($this->helper->layout->app('group/create', array(
'errors' => $errors,
'values' => $values,
'title' => t('New group')
)));
}
/**
* Validate and save a new group
*
* @access public
*/
public function save()
{
$values = $this->request->getValues();
list($valid, $errors) = $this->groupValidator->validateCreation($values);
if ($valid) {
if ($this->group->create($values['name']) !== false) {
$this->flash->success(t('Group created successfully.'));
return $this->response->redirect($this->helper->url->to('group', 'index'));
} else {
$this->flash->failure(t('Unable to create your group.'));
}
}
return $this->create($values, $errors);
}
/**
* Display a form to update a group
*
* @access public
* @param array $values
* @param array $errors
*/
public function edit(array $values = array(), array $errors = array())
{
if (empty($values)) {
$values = $this->group->getById($this->request->getIntegerParam('group_id'));
}
$this->response->html($this->helper->layout->app('group/edit', array(
'errors' => $errors,
'values' => $values,
'title' => t('Edit group')
)));
}
/**
* Validate and save a group
*
* @access public
*/
public function update()
{
$values = $this->request->getValues();
list($valid, $errors) = $this->groupValidator->validateModification($values);
if ($valid) {
if ($this->group->update($values) !== false) {
$this->flash->success(t('Group updated successfully.'));
return $this->response->redirect($this->helper->url->to('group', 'index'));
} else {
$this->flash->failure(t('Unable to update your group.'));
}
}
return $this->edit($values, $errors);
}
/**
* Form to associate a user to a group
*
@ -150,12 +70,11 @@ class Group extends BaseController
$values['group_id'] = $group_id;
}
$this->response->html($this->helper->layout->app('group/associate', array(
$this->response->html($this->template->render('group/associate', array(
'users' => $this->user->prepareList($this->groupMember->getNotMembers($group_id)),
'group' => $group,
'errors' => $errors,
'values' => $values,
'title' => t('Add group member to "%s"', $group['name']),
)));
}
@ -171,7 +90,7 @@ class Group extends BaseController
if (isset($values['group_id']) && isset($values['user_id'])) {
if ($this->groupMember->addUser($values['group_id'], $values['user_id'])) {
$this->flash->success(t('Group member added successfully.'));
return $this->response->redirect($this->helper->url->to('group', 'users', array('group_id' => $values['group_id'])));
return $this->response->redirect($this->helper->url->to('GroupListController', 'users', array('group_id' => $values['group_id'])), true);
} else {
$this->flash->failure(t('Unable to add group member.'));
}
@ -192,10 +111,9 @@ class Group extends BaseController
$group = $this->group->getById($group_id);
$user = $this->user->getById($user_id);
$this->response->html($this->helper->layout->app('group/dissociate', array(
$this->response->html($this->template->render('group/dissociate', array(
'group' => $group,
'user' => $user,
'title' => t('Remove user from group "%s"', $group['name']),
)));
}
@ -216,7 +134,7 @@ class Group extends BaseController
$this->flash->failure(t('Unable to remove this user from the group.'));
}
$this->response->redirect($this->helper->url->to('group', 'users', array('group_id' => $group_id)));
$this->response->redirect($this->helper->url->to('GroupListController', 'users', array('group_id' => $group_id)), true);
}
/**
@ -229,9 +147,8 @@ class Group extends BaseController
$group_id = $this->request->getIntegerParam('group_id');
$group = $this->group->getById($group_id);
$this->response->html($this->helper->layout->app('group/remove', array(
$this->response->html($this->template->render('group/remove', array(
'group' => $group,
'title' => t('Remove group'),
)));
}
@ -251,6 +168,6 @@ class Group extends BaseController
$this->flash->failure(t('Unable to remove this group.'));
}
$this->response->redirect($this->helper->url->to('group', 'index'));
$this->response->redirect($this->helper->url->to('GroupListController', 'index'), true);
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace Kanboard\Controller;
/**
* Class GroupModificationController
*
* @package Kanboard\Controller
* @author Frederic Guillot
*/
class GroupModificationController extends BaseController
{
/**
* Display a form to update a group
*
* @access public
* @param array $values
* @param array $errors
*/
public function show(array $values = array(), array $errors = array())
{
if (empty($values)) {
$values = $this->group->getById($this->request->getIntegerParam('group_id'));
}
$this->response->html($this->template->render('group_modification/show', array(
'errors' => $errors,
'values' => $values,
)));
}
/**
* Validate and save a group
*
* @access public
*/
public function save()
{
$values = $this->request->getValues();
list($valid, $errors) = $this->groupValidator->validateModification($values);
if ($valid) {
if ($this->group->update($values) !== false) {
$this->flash->success(t('Group updated successfully.'));
return $this->response->redirect($this->helper->url->to('GroupListController', 'index'), true);
} else {
$this->flash->failure(t('Unable to update your group.'));
}
}
return $this->show($values, $errors);
}
}

View File

@ -132,7 +132,9 @@ class AuthenticationProvider implements ServiceProviderInterface
$acl->add('Config', '*', Role::APP_ADMIN);
$acl->add('Currency', '*', Role::APP_ADMIN);
$acl->add('Gantt', array('projects', 'saveProjectDate'), Role::APP_MANAGER);
$acl->add('Group', '*', Role::APP_ADMIN);
$acl->add('GroupListController', '*', Role::APP_ADMIN);
$acl->add('GroupCreationController', '*', Role::APP_ADMIN);
$acl->add('GroupModificationController', '*', Role::APP_ADMIN);
$acl->add('Link', '*', Role::APP_ADMIN);
$acl->add('ProjectCreation', 'create', Role::APP_MANAGER);
$acl->add('Projectuser', '*', Role::APP_MANAGER);

View File

@ -161,13 +161,8 @@ class RouteProvider implements ServiceProviderInterface
$container['route']->addRoute('user/:user_id/avatar', 'AvatarFile', 'show');
// Groups
$container['route']->addRoute('groups', 'group', 'index');
$container['route']->addRoute('groups/create', 'group', 'create');
$container['route']->addRoute('group/:group_id/associate', 'group', 'associate');
$container['route']->addRoute('group/:group_id/dissociate/:user_id', 'group', 'dissociate');
$container['route']->addRoute('group/:group_id/edit', 'group', 'edit');
$container['route']->addRoute('group/:group_id/members', 'group', 'users');
$container['route']->addRoute('group/:group_id/remove', 'group', 'confirm');
$container['route']->addRoute('groups', 'GroupListController', 'index');
$container['route']->addRoute('group/:group_id/members', 'GroupListController', 'users');
// Config
$container['route']->addRoute('settings', 'config', 'index');

View File

@ -1,25 +1,20 @@
<section id="main">
<div class="page-header">
<ul>
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
<li><i class="fa fa-user fa-fw"></i><?= $this->url->link(t('View group members'), 'group', 'users', array('group_id' => $group['id'])) ?></li>
</ul>
</div>
<?php if (empty($users)): ?>
<p class="alert"><?= t('There is no user available.') ?></p>
<?php else: ?>
<form method="post" action="<?= $this->url->href('group', 'addUser', array('group_id' => $group['id'])) ?>" autocomplete="off">
<?= $this->form->csrf() ?>
<?= $this->form->hidden('group_id', $values) ?>
<div class="page-header">
<h2><?= t('Add group member to "%s"', $group['name']) ?></h2>
</div>
<?php if (empty($users)): ?>
<p class="alert"><?= t('There is no user available.') ?></p>
<?php else: ?>
<form class="popover-form" method="post" action="<?= $this->url->href('GroupListController', 'addUser', array('group_id' => $group['id'])) ?>" autocomplete="off">
<?= $this->form->csrf() ?>
<?= $this->form->hidden('group_id', $values) ?>
<?= $this->form->label(t('User'), 'user_id') ?>
<?= $this->form->select('user_id', $users, $values, $errors, array('required'), 'chosen-select') ?>
<?= $this->form->label(t('User'), 'user_id') ?>
<?= $this->form->select('user_id', $users, $values, $errors, array('required'), 'chosen-select') ?>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'group', 'index') ?>
</div>
</form>
<?php endif ?>
</section>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'GroupListController', 'index', array(), false, 'close-popover') ?>
</div>
</form>
<?php endif ?>

View File

@ -1,19 +0,0 @@
<section id="main">
<div class="page-header">
<ul>
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
</ul>
</div>
<form method="post" action="<?= $this->url->href('group', 'save') ?>" autocomplete="off">
<?= $this->form->csrf() ?>
<?= $this->form->label(t('Name'), 'name') ?>
<?= $this->form->text('name', $values, $errors, array('autofocus', 'required', 'maxlength="100"')) ?>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'group', 'index') ?>
</div>
</form>
</section>

View File

@ -1,17 +1,12 @@
<section id="main">
<div class="page-header">
<ul>
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
<li><i class="fa fa-user fa-fw"></i><?= $this->url->link(t('View group members'), 'group', 'users', array('group_id' => $group['id'])) ?></li>
</ul>
</div>
<div class="confirm">
<p class="alert alert-info"><?= t('Do you really want to remove the user "%s" from the group "%s"?', $user['name'] ?: $user['username'], $group['name']) ?></p>
<div class="page-header">
<h2><?= t('Remove user from group "%s"', $group['name']) ?></h2>
</div>
<div class="confirm">
<p class="alert alert-info"><?= t('Do you really want to remove the user "%s" from the group "%s"?', $user['name'] ?: $user['username'], $group['name']) ?></p>
<div class="form-actions">
<?= $this->url->link(t('Yes'), 'group', 'removeUser', array('group_id' => $group['id'], 'user_id' => $user['id']), true, 'btn btn-red') ?>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'group', 'users', array('group_id' => $group['id'])) ?>
</div>
<div class="form-actions">
<?= $this->url->link(t('Yes'), 'GroupListController', 'removeUser', array('group_id' => $group['id'], 'user_id' => $user['id']), true, 'btn btn-red') ?>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'GroupListController', 'users', array('group_id' => $group['id']), false, 'close-popover') ?>
</div>
</section>
</div>

View File

@ -1,22 +0,0 @@
<section id="main">
<div class="page-header">
<ul>
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
</ul>
</div>
<form method="post" action="<?= $this->url->href('group', 'update') ?>" autocomplete="off">
<?= $this->form->csrf() ?>
<?= $this->form->hidden('id', $values) ?>
<?= $this->form->hidden('external_id', $values) ?>
<?= $this->form->label(t('Name'), 'name') ?>
<?= $this->form->text('name', $values, $errors, array('autofocus', 'required', 'maxlength="100"')) ?>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'group', 'index') ?>
</div>
</form>
</section>

View File

@ -2,7 +2,7 @@
<div class="page-header">
<ul>
<li><i class="fa fa-user fa-fw"></i><?= $this->url->link(t('All users'), 'user', 'index') ?></li>
<li><i class="fa fa-user-plus fa-fw"></i><?= $this->url->link(t('New group'), 'group', 'create') ?></li>
<li><i class="fa fa-user-plus fa-fw"></i><?= $this->url->link(t('New group'), 'GroupCreationController', 'show', array(), false, 'popover') ?></li>
</ul>
</div>
<?php if ($paginator->isEmpty()): ?>
@ -24,16 +24,16 @@
<?= $this->text->e($group['external_id']) ?>
</td>
<td>
<?= $this->text->e($group['name']) ?>
<?= $this->url->link($this->text->e($group['name']), 'GroupListController', 'users', array('group_id' => $group['id'])) ?>
</td>
<td>
<div class="dropdown">
<a href="#" class="dropdown-menu dropdown-menu-link-icon"><i class="fa fa-cog fa-fw"></i><i class="fa fa-caret-down"></i></a>
<ul>
<li><?= $this->url->link(t('Add group member'), 'group', 'associate', array('group_id' => $group['id'])) ?></li>
<li><?= $this->url->link(t('Members'), 'group', 'users', array('group_id' => $group['id'])) ?></li>
<li><?= $this->url->link(t('Edit'), 'group', 'edit', array('group_id' => $group['id'])) ?></li>
<li><?= $this->url->link(t('Remove'), 'group', 'confirm', array('group_id' => $group['id'])) ?></li>
<li><?= $this->url->link(t('Add group member'), 'GroupListController', 'associate', array('group_id' => $group['id']), false, 'popover') ?></li>
<li><?= $this->url->link(t('Members'), 'GroupListController', 'users', array('group_id' => $group['id'])) ?></li>
<li><?= $this->url->link(t('Edit'), 'GroupModificationController', 'show', array('group_id' => $group['id']), false, 'popover') ?></li>
<li><?= $this->url->link(t('Remove'), 'GroupListController', 'confirm', array('group_id' => $group['id']), false, 'popover') ?></li>
</ul>
</div>
</td>

View File

@ -1,17 +1,12 @@
<section id="main">
<div class="page-header">
<ul>
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
<li><i class="fa fa-user fa-fw"></i><?= $this->url->link(t('View group members'), 'group', 'users', array('group_id' => $group['id'])) ?></li>
</ul>
</div>
<div class="confirm">
<p class="alert alert-info"><?= t('Do you really want to remove this group: "%s"?', $group['name']) ?></p>
<div class="page-header">
<h2><?= t('Remove group') ?></h2>
</div>
<div class="confirm">
<p class="alert alert-info"><?= t('Do you really want to remove this group: "%s"?', $group['name']) ?></p>
<div class="form-actions">
<?= $this->url->link(t('Yes'), 'group', 'remove', array('group_id' => $group['id']), true, 'btn btn-red') ?>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'group', 'index') ?>
</div>
<div class="form-actions">
<?= $this->url->link(t('Yes'), 'GroupListController', 'remove', array('group_id' => $group['id']), true, 'btn btn-red') ?>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'GroupListController', 'index', array(), false, 'close-popover') ?>
</div>
</section>
</div>

View File

@ -1,8 +1,8 @@
<section id="main">
<div class="page-header">
<ul>
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('Add group member'), 'group', 'associate', array('group_id' => $group['id'])) ?></li>
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'GroupListController', 'index') ?></li>
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('Add group member'), 'GroupListController', 'associate', array('group_id' => $group['id']), false, 'popover') ?></li>
</ul>
</div>
<?php if ($paginator->isEmpty()): ?>
@ -31,7 +31,8 @@
<a href="mailto:<?= $this->text->e($user['email']) ?>"><?= $this->text->e($user['email']) ?></a>
</td>
<td>
<?= $this->url->link(t('Remove this user'), 'group', 'dissociate', array('group_id' => $group['id'], 'user_id' => $user['id'])) ?>
<i class="fa fa-times fa-fw" aria-hidden="true"></i>
<?= $this->url->link(t('Remove this user'), 'GroupListController', 'dissociate', array('group_id' => $group['id'], 'user_id' => $user['id']), false, 'popover') ?>
</td>
</tr>
<?php endforeach ?>

View File

@ -0,0 +1,15 @@
<div class="page-header">
<h2><?= t('New group') ?></h2>
</div>
<form class="popover-form" method="post" action="<?= $this->url->href('GroupCreationController', 'save') ?>" autocomplete="off">
<?= $this->form->csrf() ?>
<?= $this->form->label(t('Name'), 'name') ?>
<?= $this->form->text('name', $values, $errors, array('autofocus', 'required', 'maxlength="100"')) ?>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'GroupListController', 'index', array(), false, 'close-popover') ?>
</div>
</form>

View File

@ -0,0 +1,18 @@
<div class="page-header">
<h2><?= t('Edit group') ?></h2>
</div>
<form class="popover-form" method="post" action="<?= $this->url->href('GroupModificationController', 'save') ?>" autocomplete="off">
<?= $this->form->csrf() ?>
<?= $this->form->hidden('id', $values) ?>
<?= $this->form->hidden('external_id', $values) ?>
<?= $this->form->label(t('Name'), 'name') ?>
<?= $this->form->text('name', $values, $errors, array('autofocus', 'required', 'maxlength="100"')) ?>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'GroupListController', 'index', array(), false, 'close-popover') ?>
</div>
</form>

View File

@ -80,7 +80,7 @@
</li>
<li>
<i class="fa fa-group fa-fw"></i>
<?= $this->url->link(t('Groups management'), 'group', 'index') ?>
<?= $this->url->link(t('Groups management'), 'GroupListController', 'index') ?>
</li>
<li>
<i class="fa fa-cog fa-fw"></i>

View File

@ -113,7 +113,7 @@
'title="'.t('Enter group name...').'"',
'data-dst-field="group_id"',
'data-dst-extra-field="external_id"',
'data-search-url="'.$this->url->href('GroupHelper', 'autocomplete').'"',
'data-search-url="'.$this->url->href('GroupAjaxController', 'autocomplete').'"',
),
'autocomplete') ?>

View File

@ -5,7 +5,7 @@
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New local user'), 'UserCreationController', 'show', array(), false, 'popover') ?></li>
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New remote user'), 'UserCreationController', 'show', array('remote' => 1), false, 'popover') ?></li>
<li><i class="fa fa-upload fa-fw"></i><?= $this->url->link(t('Import'), 'UserImportController', 'show', array(), false, 'popover') ?></li>
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'GroupListController', 'index') ?></li>
</ul>
<?php endif ?>
</div>

View File

@ -6,7 +6,7 @@
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New local user'), 'UserCreationController', 'show', array(), false, 'popover') ?></li>
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New remote user'), 'UserCreationController', 'show', array('remote' => 1), false, 'popover') ?></li>
<li><i class="fa fa-upload fa-fw"></i><?= $this->url->link(t('Import'), 'UserImportController', 'show', array(), false, 'popover') ?></li>
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'group', 'index') ?></li>
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('View all groups'), 'GroupListController', 'index') ?></li>
</ul>
<?php endif ?>
</div>