Add project users overview

This commit is contained in:
Frederic Guillot 2015-08-16 22:17:45 -04:00
parent 06638ff5e9
commit 2fd177363b
21 changed files with 468 additions and 55 deletions

View File

@ -42,7 +42,7 @@ class Gantt extends Base
*/
public function saveDate()
{
$project = $this->getProject();
$this->getProject();
$values = $this->request->getJson();
$result = $this->taskModification->update(array(

View File

@ -30,7 +30,7 @@ class Project extends Base
->setUrl('project', 'index')
->setMax(20)
->setOrder('name')
->setQuery($this->project->getQueryColumnStats($project_ids))
->setQuery($this->project->getQueryProjectDetails($project_ids))
->calculate();
$this->response->html($this->template->layout('project/index', array(

View File

@ -0,0 +1,136 @@
<?php
namespace Controller;
use Model\User as UserModel;
use Model\Task as TaskModel;
/**
* Project User overview
*
* @package controller
* @author Frederic Guillot
*/
class Projectuser extends Base
{
/**
* Common layout for users overview views
*
* @access private
* @param string $template Template name
* @param array $params Template parameters
* @return string
*/
private function layout($template, array $params)
{
$params['board_selector'] = $this->projectPermission->getAllowedProjects($this->userSession->getId());
$params['content_for_sublayout'] = $this->template->render($template, $params);
$params['filter'] = array('user_id' => $params['user_id']);
return $this->template->layout('project_user/layout', $params);
}
private function common()
{
$user_id = $this->request->getIntegerParam('user_id', UserModel::EVERYBODY_ID);
if ($this->userSession->isAdmin()) {
$project_ids = $this->project->getAllIds();
}
else {
$project_ids = $this->projectPermission->getMemberProjectIds($this->userSession->getId());
}
return array($user_id, $project_ids, $this->user->getList(true));
}
private function role($is_owner, $action, $title, $title_user)
{
list($user_id, $project_ids, $users) = $this->common();
$query = $this->projectPermission->getQueryByRole($project_ids, $is_owner)->callback(array($this->project, 'applyColumnStats'));
if ($user_id !== UserModel::EVERYBODY_ID) {
$query->eq(UserModel::TABLE.'.id', $user_id);
$title = t($title_user, $users[$user_id]);
}
$paginator = $this->paginator
->setUrl('projectuser', $action, array('user_id' => $user_id))
->setMax(30)
->setOrder('projects.name')
->setQuery($query)
->calculate();
$this->response->html($this->layout('project_user/roles', array(
'paginator' => $paginator,
'title' => $title,
'action' => $action,
'user_id' => $user_id,
'users' => $users,
)));
}
private function tasks($is_active, $action, $title, $title_user)
{
list($user_id, $project_ids, $users) = $this->common();
$query = $this->taskFinder->getProjectUserOverviewQuery($project_ids, $is_active);
if ($user_id !== UserModel::EVERYBODY_ID) {
$query->eq(TaskModel::TABLE.'.owner_id', $user_id);
$title = t($title_user, $users[$user_id]);
}
$paginator = $this->paginator
->setUrl('projectuser', $action, array('user_id' => $user_id))
->setMax(50)
->setOrder(TaskModel::TABLE.'.id')
->setQuery($query)
->calculate();
$this->response->html($this->layout('project_user/tasks', array(
'paginator' => $paginator,
'title' => $title,
'action' => $action,
'user_id' => $user_id,
'users' => $users,
)));
}
/**
* Display the list of project managers
*
*/
public function managers()
{
$this->role(1, 'managers', t('People who are project managers'), 'Projects where "%s" is manager');
}
/**
* Display the list of project members
*
*/
public function members()
{
$this->role(0, 'members', t('People who are project members'), 'Projects where "%s" is member');
}
/**
* Display the list of open taks
*
*/
public function opens()
{
$this->tasks(TaskModel::STATUS_OPEN, 'opens', t('Open tasks'), 'Open tasks assigned to "%s"');
}
/**
* Display the list of closed tasks
*
*/
public function closed()
{
$this->tasks(TaskModel::STATUS_CLOSED, 'closed', t('Closed tasks'), 'Closed tasks assigned to "%s"');
}
}

View File

@ -76,6 +76,7 @@ class Acl extends Base
*/
private $project_admin_acl = array(
'project' => array('remove'),
'projectuser' => '*',
);
/**

View File

@ -260,6 +260,24 @@ class Project extends Base
return $projects;
}
/**
* Fetch more information for each project
*
* @access public
* @param array $projects
* @return array
*/
public function applyProjectDetails(array $projects)
{
foreach ($projects as &$project) {
$this->getColumnStats($project);
$project['managers'] = $this->projectPermission->getManagers($project['id']);
$project['members'] = $this->projectPermission->getOnlyMembers($project['id']);
}
return $projects;
}
/**
* Get project summary for a list of project
*
@ -279,6 +297,25 @@ class Project extends Base
->callback(array($this, 'applyColumnStats'));
}
/**
* Get project details (users + columns) for a list of project
*
* @access public
* @param array $project_ids List of project id
* @return \PicoDb\Table
*/
public function getQueryProjectDetails(array $project_ids)
{
if (empty($project_ids)) {
return $this->db->table(Project::TABLE)->limit(0);
}
return $this->db
->table(Project::TABLE)
->in('id', $project_ids)
->callback(array($this, 'applyProjectDetails'));
}
/**
* Create a project
*

View File

@ -66,18 +66,19 @@ class ProjectPermission extends Base
}
/**
* Get a list of people associated to the project
* Get a list of standard user members for a project
*
* @access public
* @param integer $project_id Project id
* @return array
*/
public function getAssociatedUsers($project_id)
public function getOnlyMembers($project_id)
{
$users = $this->db
->table(self::TABLE)
->join(User::TABLE, 'id', 'user_id')
->eq('project_id', $project_id)
->eq('is_owner', 0)
->asc('username')
->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name')
->findAll();
@ -106,6 +107,57 @@ class ProjectPermission extends Base
return $this->user->prepareList($users);
}
/**
* Get query for project users overview
*
* @access public
* @param array $project_ids
* @param integer $is_owner
* @return \PicoDb\Table
*/
public function getQueryByRole(array $project_ids, $is_owner = 0)
{
if (empty($project_ids)) {
$project_ids = array(-1);
}
return $this
->db
->table(self::TABLE)
->join(User::TABLE, 'id', 'user_id')
->join(Project::TABLE, 'id', 'project_id')
->eq(self::TABLE.'.is_owner', $is_owner)
->eq(Project::TABLE.'.is_private', 0)
->in(Project::TABLE.'.id', $project_ids)
->columns(
User::TABLE.'.id',
User::TABLE.'.username',
User::TABLE.'.name',
Project::TABLE.'.name AS project_name',
Project::TABLE.'.id'
);
}
/**
* Get a list of people associated to the project
*
* @access public
* @param integer $project_id Project id
* @return array
*/
public function getAssociatedUsers($project_id)
{
$users = $this->db
->table(self::TABLE)
->join(User::TABLE, 'id', 'user_id')
->eq('project_id', $project_id)
->asc('username')
->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name')
->findAll();
return $this->user->prepareList($users);
}
/**
* Get allowed and not allowed users for a project
*
@ -127,7 +179,6 @@ class ProjectPermission extends Base
$users['managers'] = $this->getManagers($project_id);
foreach ($all_users as $user_id => $username) {
if (! isset($users['allowed'][$user_id])) {
$users['not_allowed'][$user_id] = $username;
}
@ -269,26 +320,6 @@ class ProjectPermission extends Base
->exists();
}
/**
* Filter a list of projects for a given user
*
* @access public
* @param array $projects Project list: ['project_id' => 'project_name']
* @param integer $user_id User id
* @param string $filter Method name to apply
* @return array
*/
public function filterProjects(array $projects, $user_id, $filter = 'isUserAllowed')
{
foreach ($projects as $project_id => $project_name) {
if (! $this->$filter($project_id, $user_id)) {
unset($projects[$project_id]);
}
}
return $projects;
}
/**
* Return a list of allowed active projects for a given user
*

View File

@ -12,6 +12,43 @@ use PDO;
*/
class TaskFinder extends Base
{
/**
* Get query for project user overview
*
* @access public
* @param array $project_ids
* @param integer $is_active
* @return \PicoDb\Table
*/
public function getProjectUserOverviewQuery(array $project_ids, $is_active)
{
if (empty($project_ids)) {
$project_ids = array(-1);
}
return $this->db
->table(Task::TABLE)
->columns(
Task::TABLE.'.id',
Task::TABLE.'.title',
Task::TABLE.'.date_due',
Task::TABLE.'.date_started',
Task::TABLE.'.project_id',
Task::TABLE.'.color_id',
Task::TABLE.'.time_spent',
Task::TABLE.'.time_estimated',
Project::TABLE.'.name AS project_name',
Board::TABLE.'.title AS column_name',
User::TABLE.'.username AS assignee_username',
User::TABLE.'.name AS assignee_name'
)
->eq(Task::TABLE.'.is_active', $is_active)
->in(Project::TABLE.'.id', $project_ids)
->join(Project::TABLE, 'id', 'project_id')
->join(Board::TABLE, 'id', 'column_id', Task::TABLE)
->join(User::TABLE, 'id', 'owner_id', Task::TABLE);
}
/**
* Get query for assigned user tasks
*

View File

@ -208,12 +208,19 @@ class User extends Base
* List all users (key-value pairs with id/username)
*
* @access public
* @param boolean $prepend Prepend "All users"
* @return array
*/
public function getList()
public function getList($prepend = false)
{
$users = $this->db->table(self::TABLE)->columns('id', 'username', 'name')->findAll();
return $this->prepareList($users);
$listing = $this->prepareList($users);
if ($prepend) {
return array(User::EVERYBODY_ID => t('Everybody')) + $listing;
}
return $listing;
}
/**

View File

@ -12,7 +12,7 @@
<?php endif ?>
<?php if (! isset($not_editable)): ?>
<?= $this->asset->js('assets/js/app.js', true) ?>
<?= $this->asset->js('assets/js/app.js') ?>
<?php endif ?>
<?= $this->asset->colorCss() ?>
@ -48,7 +48,13 @@
<ul>
<?php if (isset($board_selector) && ! empty($board_selector)): ?>
<li>
<select id="board-selector" tabindex="-1" data-notfound="<?= t('No results match:') ?>" data-placeholder="<?= t('Display another project') ?>" data-board-url="<?= $this->url->href('board', 'show', array('project_id' => 'PROJECT_ID')) ?>">
<select id="board-selector"
class="chosen-select select-auto-redirect"
tabindex="-1"
data-notfound="<?= t('No results match:') ?>"
data-placeholder="<?= t('Display another project') ?>"
data-redirect-regex="PROJECT_ID"
data-redirect-url="<?= $this->url->href('board', 'show', array('project_id' => 'PROJECT_ID')) ?>">
<option value=""></option>
<?php foreach($board_selector as $board_id => $board_name): ?>
<option value="<?= $board_id ?>"><?= $this->e($board_name) ?></option>

View File

@ -5,18 +5,24 @@
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New project'), 'project', 'create') ?></li>
<?php endif ?>
<li><i class="fa fa-lock fa-fw"></i><?= $this->url->link(t('New private project'), 'project', 'create', array('private' => 1)) ?></li>
<?php if ($this->user->isProjectAdmin() || $this->user->isAdmin()): ?>
<li><i class="fa fa-users fa-fw"></i><?= $this->url->link(t('Users overview'), 'projectuser', 'managers') ?></li>
<?php endif ?>
</ul>
</div>
<section>
<?php if ($paginator->isEmpty()): ?>
<p class="alert"><?= t('No project') ?></p>
<?php else: ?>
<table class="table-fixed">
<table class="table-stripped">
<tr>
<th class="column-8"><?= $paginator->order(t('Id'), 'id') ?></th>
<th class="column-8"><?= $paginator->order(t('Status'), 'is_active') ?></th>
<th class="column-8"><?= $paginator->order(t('Identifier'), 'identifier') ?></th>
<th class="column-5"><?= $paginator->order(t('Id'), 'id') ?></th>
<th class="column-5"><?= $paginator->order(t('Status'), 'is_active') ?></th>
<th class="column-20"><?= $paginator->order(t('Project'), 'name') ?></th>
<?php if ($this->user->isAdmin() || $this->user->isProjectAdmin()): ?>
<th class="column-15"><?= t('Managers') ?></th>
<th class="column-15"><?= t('Members') ?></th>
<?php endif ?>
<th><?= t('Columns') ?></th>
</tr>
<?php foreach ($paginator->getCollection() as $project): ?>
@ -32,16 +38,14 @@
<?php endif ?>
</td>
<td>
<?= $this->e($project['identifier']) ?>
</td>
<td>
<?= $this->url->link('<i class="fa fa-th"></i>', 'board', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Board')) ?>&nbsp;
<?= $this->url->link('<i class="fa fa-th"></i>', 'board', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Board')) ?>
<?= $this->url->link('<i class="fa fa-sliders fa-fw"></i>', 'gantt', 'project', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Gantt chart')) ?>
<?php if ($project['is_public']): ?>
<i class="fa fa-share-alt fa-fw"></i>
<i class="fa fa-share-alt fa-fw" title="<?= t('Shared project') ?>"></i>
<?php endif ?>
<?php if ($project['is_private']): ?>
<i class="fa fa-lock fa-fw"></i>
<i class="fa fa-lock fa-fw" title="<?= t('Private project') ?>"></i>
<?php endif ?>
<?= $this->url->link($this->e($project['name']), 'project', 'show', array('project_id' => $project['id'])) ?>
@ -51,6 +55,26 @@
</span>
<?php endif ?>
</td>
<?php if ($this->user->isAdmin() || $this->user->isProjectAdmin()): ?>
<td>
<ul>
<?php foreach ($project['managers'] as $user_id => $user_name): ?>
<li><?= $this->url->link($this->e($user_name), 'projectuser', 'opens', array('user_id' => $user_id)) ?></li>
<?php endforeach ?>
</ul>
</td>
<td>
<?php if ($project['is_everybody_allowed'] == 1): ?>
<?= t('Everybody') ?>
<?php else: ?>
<ul>
<?php foreach ($project['members'] as $user_id => $user_name): ?>
<li><?= $this->url->link($this->e($user_name), 'projectuser', 'opens', array('user_id' => $user_id)) ?></li>
<?php endforeach ?>
</ul>
<?php endif ?>
</td>
<?php endif ?>
<td class="dashboard-project-stats">
<?php foreach ($project['columns'] as $column): ?>
<strong title="<?= t('Task count') ?>"><?= $column['nb_tasks'] ?></strong>

View File

@ -0,0 +1,28 @@
<section id="main">
<div class="page-header">
<ul>
<?php if ($this->user->isProjectAdmin() || $this->user->isAdmin()): ?>
<li><i class="fa fa-plus fa-fw"></i><?= $this->url->link(t('New project'), 'project', 'create') ?></li>
<?php endif ?>
<li>
<i class="fa fa-lock fa-fw"></i>
<?= $this->url->link(t('New private project'), 'project', 'create', array('private' => 1)) ?>
</li>
<li>
<i class="fa fa-folder fa-fw"></i>
<?= $this->url->link(t('All projects'), 'project', 'index') ?>
</li>
</ul>
</div>
<section class="sidebar-container">
<?= $this->render('project_user/sidebar', array('users' => $users, 'action' => $action, 'filter' => $filter)) ?>
<div class="sidebar-content">
<div class="page-header">
<h2><?= $this->e($title) ?></h2>
</div>
<?= $content_for_sublayout ?>
</div>
</section>
</section>

View File

@ -0,0 +1,33 @@
<?php if ($paginator->isEmpty()): ?>
<p class="alert"><?= t('No project') ?></p>
<?php else: ?>
<table class="table-fixed">
<tr>
<th class="column-20"><?= $paginator->order(t('User'), 'users.username') ?></th>
<th class="column-25"><?= $paginator->order(t('Project'), 'projects.name') ?></th>
<th><?= t('Columns') ?></th>
</tr>
<?php foreach ($paginator->getCollection() as $project): ?>
<tr>
<td>
<?= $this->e($this->user->getFullname($project)) ?>
</td>
<td>
<?= $this->url->link('<i class="fa fa-th"></i>', 'board', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Board')) ?>
<?= $this->url->link('<i class="fa fa-sliders fa-fw"></i>', 'gantt', 'project', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Gantt chart')) ?>
<?= $this->url->link('<i class="fa fa-cog fa-fw"></i>', 'project', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Project settings')) ?>
<?= $this->e($project['project_name']) ?>
</td>
<td class="dashboard-project-stats">
<?php foreach ($project['columns'] as $column): ?>
<strong title="<?= t('Task count') ?>"><?= $column['nb_tasks'] ?></strong>
<span><?= $this->e($column['title']) ?></span>
<?php endforeach ?>
</td>
</tr>
<?php endforeach ?>
</table>
<?= $paginator ?>
<?php endif ?>

View File

@ -0,0 +1,28 @@
<div class="sidebar">
<h2><?= t('Actions') ?></h2>
<?= $this->form->select(
'user_id',
$users,
$filter,
array(),
array('data-redirect-url="'.$this->url->href('projectuser', $action, array('user_id' => 'USER_ID')).'"', 'data-redirect-regex="USER_ID"'),
'chosen-select select-auto-redirect'
) ?>
<br/><br/>
<ul>
<li>
<?= $this->url->link(t('Project managers'), 'projectuser', 'managers', $filter) ?>
</li>
<li>
<?= $this->url->link(t('Project members'), 'projectuser', 'members', $filter) ?>
</li>
<li>
<?= $this->url->link(t('Open tasks'), 'projectuser', 'opens', $filter) ?>
</li>
<li>
<?= $this->url->link(t('Closed tasks'), 'projectuser', 'closed', $filter) ?>
</li>
</ul>
</div>

View File

@ -0,0 +1,46 @@
<?php if ($paginator->isEmpty()): ?>
<p class="alert"><?= t('No tasks found.') ?></p>
<?php elseif (! $paginator->isEmpty()): ?>
<table class="table-small">
<tr>
<th class="column-5"><?= $paginator->order(t('Id'), 'tasks.id') ?></th>
<th class="column-10"><?= $paginator->order(t('Project'), 'projects.name') ?></th>
<th class="column-15"><?= $paginator->order(t('Column'), 'tasks.column_id') ?></th>
<th><?= $paginator->order(t('Title'), 'tasks.title') ?></th>
<th class="column-15"><?= $paginator->order(t('Assignee'), 'users.username') ?></th>
<th class="column-15"><?= $paginator->order(t('Start date'), 'tasks.date_started') ?></th>
<th class="column-15"><?= $paginator->order(t('Due date'), 'tasks.date_due') ?></th>
</tr>
<?php foreach ($paginator->getCollection() as $task): ?>
<tr>
<td class="task-table color-<?= $task['color_id'] ?>">
<?= $this->url->link('#'.$this->e($task['id']), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, '', t('View this task')) ?>
</td>
<td>
<?= $this->url->link($this->e($task['project_name']), 'board', 'show', array('project_id' => $task['project_id'])) ?>
</td>
<td>
<?= $this->e($task['column_name']) ?>
</td>
<td>
<?= $this->url->link($this->e($task['title']), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, '', t('View this task')) ?>
</td>
<td>
<?php if ($task['assignee_username']): ?>
<?= $this->e($task['assignee_name'] ?: $task['assignee_username']) ?>
<?php else: ?>
<?= t('Unassigned') ?>
<?php endif ?>
</td>
<td>
<?= dt('%B %e, %Y', $task['date_started']) ?>
</td>
<td>
<?= dt('%B %e, %Y', $task['date_due']) ?>
</td>
</tr>
<?php endforeach ?>
</table>
<?= $paginator ?>
<?php endif ?>

View File

@ -23,8 +23,8 @@
<?= $this->form->select('language', $languages, $values, $errors) ?><br/>
<?php if ($this->user->isAdmin()): ?>
<?= $this->form->checkbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1) ?><br/>
<?= $this->form->checkbox('is_project_admin', t('Project Administrator'), 1, isset($values['is_project_admin']) && $values['is_project_admin'] == 1) ?><br/>
<?= $this->form->checkbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1) ?>
<?= $this->form->checkbox('is_project_admin', t('Project Administrator'), 1, isset($values['is_project_admin']) && $values['is_project_admin'] == 1) ?>
<?php endif ?>
<div class="form-actions">

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -43,7 +43,6 @@ hr {
border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}
#board-selector,
.chosen-select {
min-height: 27px; /* Reserve some space to avoid re-layout due to chosen */
}

View File

@ -82,6 +82,10 @@ th a:hover {
width: 20%;
}
.column-25 {
width: 25%;
}
.column-30 {
width: 30%;
}

File diff suppressed because one or more lines are too long

View File

@ -7,7 +7,7 @@ function App() {
this.tooltip = new Tooltip(this);
this.popover = new Popover(this);
this.keyboardShortcuts();
this.boardSelector();
this.chosen();
this.poll();
// Alert box fadeout
@ -144,20 +144,16 @@ App.prototype.taskAutoComplete = function() {
}
};
App.prototype.boardSelector = function() {
App.prototype.chosen = function() {
$(".chosen-select").chosen({
width: "200px",
width: "180px",
no_results_text: $(".chosen-select").data("notfound"),
disable_search_threshold: 10
});
$("#board-selector").chosen({
width: 180,
no_results_text: $("#board-selector").data("notfound")
});
$("#board-selector").change(function() {
window.location = $(this).attr("data-board-url").replace(/PROJECT_ID/g, $(this).val());
$(".select-auto-redirect").change(function() {
var regex = new RegExp($(this).data('redirect-regex'), 'g');
window.location = $(this).data('redirect-url').replace(regex, $(this).val());
});
};