Add projects to the dashboard and rename some methods

This commit is contained in:
Frédéric Guillot
2014-11-09 12:47:49 -05:00
parent e0117cb8ed
commit 3df63e051f
30 changed files with 262 additions and 75 deletions

View File

@@ -27,7 +27,7 @@ class Action extends Base
'available_events' => $this->action->getAvailableEvents(),
'available_params' => $this->action->getAllActionParameters(),
'columns_list' => $this->board->getColumnsList($project['id']),
'users_list' => $this->projectPermission->getUsersList($project['id']),
'users_list' => $this->projectPermission->getMemberList($project['id']),
'projects_list' => $this->project->getList(false),
'colors_list' => $this->color->getList(),
'categories_list' => $this->category->getList($project['id']),
@@ -85,7 +85,7 @@ class Action extends Base
'values' => $values,
'action_params' => $action_params,
'columns_list' => $this->board->getColumnsList($project['id']),
'users_list' => $this->projectPermission->getUsersList($project['id']),
'users_list' => $this->projectPermission->getMemberList($project['id']),
'projects_list' => $projects_list,
'colors_list' => $this->color->getList(),
'categories_list' => $this->category->getList($project['id']),

View File

@@ -20,12 +20,14 @@ class App extends Base
public function index()
{
$user_id = $this->acl->getUserId();
$projects = $this->projectPermission->getAllowedProjects($user_id);
$projects = $this->projectPermission->getMemberProjects($user_id);
$project_ids = array_keys($projects);
$this->response->html($this->template->layout('app_index', array(
'board_selector' => $projects,
'events' => $this->projectActivity->getProjects(array_keys($projects), 10),
'board_selector' => $this->projectPermission->getAllowedProjects($user_id),
'events' => $this->projectActivity->getProjects($project_ids, 10),
'tasks' => $this->taskFinder->getAllTasksByUser($user_id),
'projects' => $this->project->getSummary($project_ids),
'title' => t('Dashboard'),
)));
}

View File

@@ -42,12 +42,11 @@ class Board extends Base
{
$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,
'users_list' => $this->projectPermission->getMemberList($project['id']),
'current_project_id' => $project['id'],
'current_project_name' => $project['name'],
);
@@ -95,12 +94,11 @@ class Board extends Base
{
$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'],
);
@@ -213,7 +211,7 @@ class Board extends Base
$this->user->storeLastSeenProjectId($project['id']);
$this->response->html($this->template->layout('board_index', array(
'users' => $this->projectPermission->getUsersList($project['id'], true, true),
'users' => $this->projectPermission->getMemberList($project['id'], true, true),
'filters' => array('user_id' => UserModel::EVERYBODY_ID),
'projects' => $projects,
'current_project_id' => $project['id'],

View File

@@ -146,7 +146,7 @@ class Project extends Base
public function update()
{
$project = $this->getProjectManagement();
$values = $this->request->getValues() + array('is_active' => 0);
$values = $this->request->getValues();
list($valid, $errors) = $this->project->validateModification($values);
if ($valid) {
@@ -527,9 +527,11 @@ class Project extends Base
if ($valid) {
if ($this->project->create($values, $this->acl->getUserId())) {
$project_id = $this->project->create($values, $this->acl->getUserId());
if ($project_id) {
$this->session->flash(t('Your project have been created successfully.'));
$this->response->redirect('?controller=project');
$this->response->redirect('?controller=project&action=show&project_id='.$project_id);
}
else {
$this->session->flashError(t('Unable to create your project.'));

View File

@@ -42,7 +42,7 @@ class Subtask extends Base
'another_subtask' => $this->request->getIntegerParam('another_subtask', 0)
),
'errors' => array(),
'users_list' => $this->projectPermission->getUsersList($task['project_id']),
'users_list' => $this->projectPermission->getMemberList($task['project_id']),
'task' => $task,
)));
}
@@ -78,7 +78,7 @@ class Subtask extends Base
$this->response->html($this->taskLayout('subtask_create', array(
'values' => $values,
'errors' => $errors,
'users_list' => $this->projectPermission->getUsersList($task['project_id']),
'users_list' => $this->projectPermission->getMemberList($task['project_id']),
'task' => $task,
)));
}
@@ -96,7 +96,7 @@ class Subtask extends Base
$this->response->html($this->taskLayout('subtask_edit', array(
'values' => $subtask,
'errors' => array(),
'users_list' => $this->projectPermission->getUsersList($task['project_id']),
'users_list' => $this->projectPermission->getMemberList($task['project_id']),
'status_list' => $this->subTask->getStatusList(),
'subtask' => $subtask,
'task' => $task,
@@ -131,7 +131,7 @@ class Subtask extends Base
$this->response->html($this->taskLayout('subtask_edit', array(
'values' => $values,
'errors' => $errors,
'users_list' => $this->projectPermission->getUsersList($task['project_id']),
'users_list' => $this->projectPermission->getMemberList($task['project_id']),
'status_list' => $this->subTask->getStatusList(),
'subtask' => $subtask,
'task' => $task,

View File

@@ -101,7 +101,7 @@ class Task extends Base
),
'projects_list' => $this->project->getListByStatus(ProjectModel::ACTIVE),
'columns_list' => $this->board->getColumnsList($project['id']),
'users_list' => $this->projectPermission->getUsersList($project['id']),
'users_list' => $this->projectPermission->getMemberList($project['id']),
'colors_list' => $this->color->getList(),
'categories_list' => $this->category->getList($project['id']),
'date_format' => $this->config->get('application_date_format'),
@@ -149,7 +149,7 @@ class Task extends Base
'values' => $values,
'projects_list' => $this->project->getListByStatus(ProjectModel::ACTIVE),
'columns_list' => $this->board->getColumnsList($project['id']),
'users_list' => $this->projectPermission->getUsersList($project['id']),
'users_list' => $this->projectPermission->getMemberList($project['id']),
'colors_list' => $this->color->getList(),
'categories_list' => $this->category->getList($project['id']),
'date_format' => $this->config->get('application_date_format'),
@@ -174,7 +174,7 @@ class Task extends Base
'values' => $task,
'errors' => array(),
'task' => $task,
'users_list' => $this->projectPermission->getUsersList($task['project_id']),
'users_list' => $this->projectPermission->getMemberList($task['project_id']),
'colors_list' => $this->color->getList(),
'categories_list' => $this->category->getList($task['project_id']),
'date_format' => $this->config->get('application_date_format'),
@@ -224,7 +224,7 @@ class Task extends Base
'errors' => $errors,
'task' => $task,
'columns_list' => $this->board->getColumnsList($values['project_id']),
'users_list' => $this->projectPermission->getUsersList($values['project_id']),
'users_list' => $this->projectPermission->getMemberList($values['project_id']),
'colors_list' => $this->color->getList(),
'categories_list' => $this->category->getList($values['project_id']),
'date_format' => $this->config->get('application_date_format'),
@@ -451,7 +451,7 @@ class Task extends Base
$task = $this->getTask();
$values = $task;
$errors = array();
$projects_list = $this->projectPermission->getAllowedProjects($this->acl->getUserId());
$projects_list = $this->projectPermission->getMemberProjects($this->acl->getUserId());
unset($projects_list[$task['project_id']]);

View File

@@ -561,4 +561,8 @@ return array(
// 'Github issue comment created' => '',
// 'Configure' => '',
// 'Project management' => '',
// 'My projects' => '',
// 'Columns' => '',
// 'Task' => '',
// 'Your are not member of any project.' => '',
);

View File

@@ -561,4 +561,8 @@ return array(
'Github issue comment created' => 'Github Fehler Kommentar hinzugefügt',
// 'Configure' => '',
// 'Project management' => '',
// 'My projects' => '',
// 'Columns' => '',
// 'Task' => '',
// 'Your are not member of any project.' => '',
);

View File

@@ -561,4 +561,8 @@ return array(
// 'Github issue comment created' => '',
// 'Configure' => '',
// 'Project management' => '',
// 'My projects' => '',
// 'Columns' => '',
// 'Task' => '',
// 'Your are not member of any project.' => '',
);

View File

@@ -561,4 +561,8 @@ return array(
// 'Github issue comment created' => '',
// 'Configure' => '',
// 'Project management' => '',
// 'My projects' => '',
// 'Columns' => '',
// 'Task' => '',
// 'Your are not member of any project.' => '',
);

View File

@@ -561,4 +561,8 @@ return array(
'Github issue comment created' => 'Commentaire créé sur un ticket Github',
'Configure' => 'Configurer',
'Project management' => 'Gestion des projets',
'My projects' => 'Mes projets',
'Columns' => 'Colonnes',
'Task' => 'Tâche',
'Your are not member of any project.' => 'Vous n\'êtes membre d\'aucun projet.',
);

View File

@@ -561,4 +561,8 @@ return array(
// 'Github issue comment created' => '',
// 'Configure' => '',
// 'Project management' => '',
// 'My projects' => '',
// 'Columns' => '',
// 'Task' => '',
// 'Your are not member of any project.' => '',
);

View File

@@ -561,4 +561,8 @@ return array(
// 'Github issue comment created' => '',
// 'Configure' => '',
// 'Project management' => '',
// 'My projects' => '',
// 'Columns' => '',
// 'Task' => '',
// 'Your are not member of any project.' => '',
);

View File

@@ -561,4 +561,8 @@ return array(
// 'Github issue comment created' => '',
// 'Configure' => '',
// 'Project management' => '',
// 'My projects' => '',
// 'Columns' => '',
// 'Task' => '',
// 'Your are not member of any project.' => '',
);

View File

@@ -561,4 +561,8 @@ return array(
// 'Github issue comment created' => '',
// 'Configure' => '',
// 'Project management' => '',
// 'My projects' => '',
// 'Columns' => '',
// 'Task' => '',
// 'Your are not member of any project.' => '',
);

View File

@@ -561,4 +561,8 @@ return array(
// 'Github issue comment created' => '',
// 'Configure' => '',
// 'Project management' => '',
// 'My projects' => '',
// 'Columns' => '',
// 'Task' => '',
// 'Your are not member of any project.' => '',
);

View File

@@ -561,4 +561,8 @@ return array(
// 'Github issue comment created' => '',
// 'Configure' => '',
// 'Project management' => '',
// 'My projects' => '',
// 'Columns' => '',
// 'Task' => '',
// 'Your are not member of any project.' => '',
);

View File

@@ -561,4 +561,8 @@ return array(
// 'Github issue comment created' => '',
// 'Configure' => '',
// 'Project management' => '',
// 'My projects' => '',
// 'Columns' => '',
// 'Task' => '',
// 'Your are not member of any project.' => '',
);

View File

@@ -561,4 +561,8 @@ return array(
// 'Github issue comment created' => '',
// 'Configure' => '',
// 'Project management' => '',
// 'My projects' => '',
// 'Columns' => '',
// 'Task' => '',
// 'Your are not member of any project.' => '',
);

View File

@@ -95,6 +95,40 @@ class Project extends Base
return (bool) $this->db->table(self::TABLE)->eq('id', $project_id)->eq('is_private', 1)->count();
}
/**
* Get project summary for a list of project (number of tasks for each column)
*
* @access public
* @param array $project_ids List of project id
* @param integer $status Project status
* @param string $order Sort on this column
* @param string $direction Sorting direction
* @return array Project properties
*/
public function getSummary(array $project_ids, $status = self::ACTIVE, $order = 'last_modified', $direction = 'desc')
{
if (empty($project_ids)) {
return array();
}
$projects = $this->db->table(self::TABLE)
->in('id', $project_ids)
->eq('is_active', $status)
->orderby($order, $direction)
->findAll();
foreach ($projects as &$project) {
$project['columns'] = $this->board->getColumns($project['id']);
foreach ($project['columns'] as &$column) {
$column['nb_tasks'] = $this->taskFinder->countByColumnId($project['id'], $column['id']);
}
}
return $projects;
}
/**
* Get all projects, optionaly fetch stats for each project and can check users permissions
*
@@ -192,7 +226,7 @@ class Project extends Base
public function getStats($project_id)
{
$stats = array();
$columns = $this->board->getcolumns($project_id);
$columns = $this->board->getColumns($project_id);
$stats['nb_active_tasks'] = 0;
foreach ($columns as &$column) {

View File

@@ -29,9 +29,9 @@ class ProjectPermission extends Base
* @param bool $prepend_everybody Prepend the 'Everbody' value
* @return array
*/
public function getUsersList($project_id, $prepend_unassigned = true, $prepend_everybody = false)
public function getMemberList($project_id, $prepend_unassigned = true, $prepend_everybody = false)
{
$allowed_users = $this->getAllowedUsers($project_id);
$allowed_users = $this->getMembers($project_id);
if ($prepend_unassigned) {
$allowed_users = array(t('Unassigned')) + $allowed_users;
@@ -51,7 +51,7 @@ class ProjectPermission extends Base
* @param integer $project_id Project id
* @return array
*/
public function getAllowedUsers($project_id)
public function getMembers($project_id)
{
if ($this->isEverybodyAllowed($project_id)) {
return $this->user->getList();
@@ -96,7 +96,7 @@ class ProjectPermission extends Base
$all_users = $this->user->getList();
$users['allowed'] = $this->getAllowedUsers($project_id);
$users['allowed'] = $this->getMembers($project_id);
foreach ($all_users as $user_id => $username) {
@@ -141,19 +141,15 @@ class ProjectPermission extends Base
}
/**
* Check if a specific user is allowed to access to a given project
* Check if a specific user is member of a project
*
* @access public
* @param integer $project_id Project id
* @param integer $user_id User id
* @return bool
*/
public function isUserAllowed($project_id, $user_id)
public function isMember($project_id, $user_id)
{
if ($this->user->isAdmin($user_id)) {
return true;
}
if ($this->isEverybodyAllowed($project_id)) {
return true;
}
@@ -165,6 +161,19 @@ class ProjectPermission extends Base
->count();
}
/**
* Check if a specific user is allowed to access to a given project
*
* @access public
* @param integer $project_id Project id
* @param integer $user_id User id
* @return bool
*/
public function isUserAllowed($project_id, $user_id)
{
return $this->user->isAdmin($user_id) || $this->isMember($project_id, $user_id);
}
/**
* Return true if everybody is allowed for the project
*
@@ -204,12 +213,13 @@ class ProjectPermission extends Base
* @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)
public function filterProjects(array $projects, $user_id, $filter = 'isUserAllowed')
{
foreach ($projects as $project_id => $project_name) {
if (! $this->isUserAllowed($project_id, $user_id)) {
if (! $this->$filter($project_id, $user_id)) {
unset($projects[$project_id]);
}
}
@@ -218,7 +228,7 @@ class ProjectPermission extends Base
}
/**
* Return a list of projects for a given user
* Return a list of allowed projects for a given user
*
* @access public
* @param integer $user_id User id
@@ -226,7 +236,19 @@ class ProjectPermission extends Base
*/
public function getAllowedProjects($user_id)
{
return $this->filterProjects($this->project->getListByStatus(Project::ACTIVE), $user_id);
return $this->filterProjects($this->project->getListByStatus(Project::ACTIVE), $user_id, 'isUserAllowed');
}
/**
* Return a list of projects where the user is member
*
* @access public
* @param integer $user_id User id
* @return array
*/
public function getMemberProjects($user_id)
{
return $this->filterProjects($this->project->getListByStatus(Project::ACTIVE), $user_id, 'isMember');
}
/**
@@ -239,7 +261,7 @@ class ProjectPermission extends Base
*/
public function duplicate($project_from, $project_to)
{
$users = $this->getAllowedUsers($project_from);
$users = $this->getMembers($project_from);
foreach ($users as $user_id => $name) {
if (! $this->allowUser($project_to, $user_id)) {

View File

@@ -1,8 +1,4 @@
<section id="main">
<div class="page-header">
<h2><?= t('Forbidden') ?></h2>
</div>
<p class="alert alert-error">
<?= t('Access Forbidden') ?>
</p>

View File

@@ -14,17 +14,48 @@
</div>
<section id="dashboard">
<div class="dashboard-left-column">
<h2><?= t('My projects') ?></h2>
<?php if (empty($projects)): ?>
<p class="alert"><?= t('Your are not member of any project.') ?></p>
<?php else: ?>
<table>
<tr>
<th width="5%">&nbsp;</th>
<th width="15%"><?= t('Project') ?></th>
<th width="75%"><?= t('Columns') ?></th>
</tr>
<?php foreach ($projects as $project): ?>
<tr>
<td>
<?= Helper\a('#'.$project['id'], 'board', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link') ?>
</td>
<td>
<?php if (Helper\is_project_admin($project)): ?>
<?= Helper\a('<i class="fa fa-cog"></i>', 'project', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Settings')) ?>&nbsp;
<?php endif ?>
<?= Helper\a(Helper\escape($project['name']), 'board', 'show', array('project_id' => $project['id'])) ?>
</td>
<td class="dashboard-project-stats">
<?php foreach ($project['columns'] as $column): ?>
<strong title="<?= t('Task count') ?>"><?= $column['nb_tasks'] ?></strong>
<span><?= Helper\escape($column['title']) ?></span>
<?php endforeach ?>
</td>
</tr>
<?php endforeach ?>
</table>
<?php endif ?>
<h2><?= t('My tasks') ?></h2>
<?php if (empty($tasks)): ?>
<p class="alert"><?= t('There is nothing assigned to you.') ?></p>
<?php else: ?>
<table>
<tr>
<th>&nbsp;</th>
<th width="5%">&nbsp;</th>
<th width="15%"><?= t('Project') ?></th>
<th width="40%"><?= t('Title') ?></th>
<th><?= t('Due date') ?></th>
<th><?= t('Date created') ?></th>
<th width="60%"><?= t('Task') ?></th>
<th width="20%"><?= t('Due date') ?></th>
</tr>
<?php foreach ($tasks as $task): ?>
<tr>
@@ -40,9 +71,6 @@
<td>
<?= dt('%B %e, %Y', $task['date_due']) ?>
</td>
<td>
<?= dt('%B %e, %Y', $task['date_creation']) ?>
</td>
</tr>
<?php endforeach ?>
</table>

View File

@@ -77,6 +77,16 @@ function is_admin()
return $_SESSION['user']['is_admin'] == 1;
}
/**
* Return true if the user can configure the project (project are previously filtered)
*
* @return boolean
*/
function is_project_admin(array $project)
{
return is_admin() || $project['is_private'] == 1;
}
/**
* Return the username
*