Add global Gantt chart for all projects

This commit is contained in:
Frederic Guillot
2015-08-22 16:20:53 -04:00
parent 18fd39e6d6
commit fd60964c23
39 changed files with 506 additions and 78 deletions

View File

@@ -65,7 +65,7 @@ class Acl extends Base
'project' => array('edit', 'update', 'share', 'integration', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'),
'swimlane' => '*',
'budget' => '*',
'gantt' => '*',
'gantt' => array('project', 'savetaskdate', 'task', 'savetask'),
);
/**
@@ -77,6 +77,7 @@ class Acl extends Base
private $project_admin_acl = array(
'project' => array('remove'),
'projectuser' => '*',
'gantt' => array('projects', 'saveprojectdate'),
);
/**

View File

@@ -77,7 +77,7 @@ class DateParser extends Base
}
/**
* Parse a date ad return a unix timestamp, try different date formats
* Parse a date and return a unix timestamp, try different date formats
*
* @access public
* @param string $value Date to parse
@@ -96,6 +96,18 @@ class DateParser extends Base
return 0;
}
/**
* Get ISO8601 date from user input
*
* @access public
* @param string $value Date to parse
* @return string
*/
public function getIsoDate($value)
{
return date('Y-m-d', ctype_digit($value) ? $value : $this->getTimestamp($value));
}
/**
* Get all combinations of date/time formats
*

View File

@@ -114,6 +114,54 @@ class Project extends Base
return $this->db->table(self::TABLE)->eq('id', $project_id)->eq('is_private', 1)->exists();
}
/**
* Get all projects to generate the Gantt chart
*
* @access public
* @param array $project_ids
* @return array
*/
public function getGanttBars(array $project_ids)
{
if (empty($project_ids)) {
return array();
}
$colors = $this->color->getDefaultColors();
$projects = $this->db->table(self::TABLE)->asc('start_date')->in('id', $project_ids)->eq('is_active', self::ACTIVE)->eq('is_private', 0)->findAll();
$bars = array();
foreach ($projects as $project) {
$start = empty($project['start_date']) ? time() : strtotime($project['start_date']);
$end = empty($project['end_date']) ? $start : strtotime($project['end_date']);
$color = next($colors) ?: reset($colors);
$bars[] = array(
'type' => 'project',
'id' => $project['id'],
'title' => $project['name'],
'start' => array(
(int) date('Y', $start),
(int) date('n', $start),
(int) date('j', $start),
),
'end' => array(
(int) date('Y', $end),
(int) date('n', $end),
(int) date('j', $end),
),
'link' => $this->helper->url->href('project', 'show', array('project_id' => $project['id'])),
'board_link' => $this->helper->url->href('board', 'show', array('project_id' => $project['id'])),
'gantt_link' => $this->helper->url->href('gantt', 'project', array('project_id' => $project['id'])),
'color' => $color,
'not_defined' => empty($project['start_date']) || empty($project['end_date']),
'users' => $this->projectPermission->getProjectUsers($project['id']),
);
}
return $bars;
}
/**
* Get all projects
*
@@ -271,8 +319,7 @@ class Project extends Base
{
foreach ($projects as &$project) {
$this->getColumnStats($project);
$project['managers'] = $this->projectPermission->getManagers($project['id']);
$project['members'] = $this->projectPermission->getOnlyMembers($project['id']);
$project = array_merge($project, $this->projectPermission->getProjectUsers($project['id']));
}
return $projects;

View File

@@ -49,6 +49,36 @@ class ProjectPermission extends Base
return $allowed_users;
}
/**
* Get a list of members and managers with a single SQL query
*
* @access public
* @param integer $project_id Project id
* @return array
*/
public function getProjectUsers($project_id)
{
$result = array(
'managers' => array(),
'members' => array(),
);
$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', self::TABLE.'.is_owner')
->findAll();
foreach ($users as $user) {
$key = $user['is_owner'] == 1 ? 'managers' : 'members';
$result[$key][$user['id']] = $user['name'] ?: $user['username'];
}
return $result;
}
/**
* Get a list of allowed people for a project
*
@@ -65,27 +95,6 @@ class ProjectPermission extends Base
return $this->getAssociatedUsers($project_id);
}
/**
* Get a list of standard user members for a project
*
* @access public
* @param integer $project_id Project id
* @return array
*/
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();
return $this->user->prepareList($users);
}
/**
* Get a list of owners for a project
*

View File

@@ -726,6 +726,7 @@ class TaskFilter extends Base
$end = $task['date_due'] ?: $start;
$bars[] = array(
'type' => 'task',
'id' => $task['id'],
'title' => $task['title'],
'start' => array(