Add Gantt chart for projects

This commit is contained in:
Frederic Guillot
2015-08-14 17:03:55 -04:00
parent c6a4fbb386
commit 17a3781bd8
47 changed files with 1169 additions and 102 deletions

View File

@@ -65,6 +65,7 @@ class Acl extends Base
'project' => array('edit', 'update', 'share', 'integration', 'users', 'alloweverybody', 'allow', 'setowner', 'revoke', 'duplicate', 'disable', 'enable'),
'swimlane' => '*',
'budget' => '*',
'gantt' => '*',
);
/**

View File

@@ -121,7 +121,7 @@ class Task extends Base
*/
public function getRecurrenceStatusList()
{
return array (
return array(
Task::RECURRING_STATUS_NONE => t('No'),
Task::RECURRING_STATUS_PENDING => t('Yes'),
);
@@ -135,7 +135,7 @@ class Task extends Base
*/
public function getRecurrenceTriggerList()
{
return array (
return array(
Task::RECURRING_TRIGGER_FIRST_COLUMN => t('When task is moved from first column'),
Task::RECURRING_TRIGGER_LAST_COLUMN => t('When task is moved to last column'),
Task::RECURRING_TRIGGER_CLOSE => t('When task is closed'),
@@ -150,7 +150,7 @@ class Task extends Base
*/
public function getRecurrenceBasedateList()
{
return array (
return array(
Task::RECURRING_BASEDATE_DUEDATE => t('Existing due date'),
Task::RECURRING_BASEDATE_TRIGGERDATE => t('Action date'),
);
@@ -164,10 +164,37 @@ class Task extends Base
*/
public function getRecurrenceTimeframeList()
{
return array (
return array(
Task::RECURRING_TIMEFRAME_DAYS => t('Day(s)'),
Task::RECURRING_TIMEFRAME_MONTHS => t('Month(s)'),
Task::RECURRING_TIMEFRAME_YEARS => t('Year(s)'),
);
}
/**
* Get task progress based on the column position
*
* @access public
* @param array $task
* @param array $columns
* @return integer
*/
public function getProgress(array $task, array $columns)
{
if ($task['is_active'] == self::STATUS_CLOSED) {
return 100;
}
$position = 0;
foreach ($columns as $column_id => $column_title) {
if ($column_id == $task['column_id']) {
break;
}
$position++;
}
return (int) ($position * 100) / count($columns);
}
}

View File

@@ -25,10 +25,17 @@ class TaskCreation extends Base
return 0;
}
$position = empty($values['position']) ? 0 : $values['position'];
$this->prepare($values);
$task_id = $this->persist(Task::TABLE, $values);
if ($task_id !== false) {
if ($position > 0 && $values['position'] > 1) {
$this->taskPosition->movePosition($values['project_id'], $task_id, $values['column_id'], $position, $values['swimlane_id'], false);
}
$this->fireEvents($task_id, $values);
}
@@ -46,7 +53,7 @@ class TaskCreation extends Base
$this->dateParser->convert($values, array('date_due'));
$this->dateParser->convert($values, array('date_started'), true);
$this->removeFields($values, array('another_task'));
$this->resetFields($values, array('creator_id', 'owner_id', 'swimlane_id', 'date_due', 'score', 'category_id', 'time_estimated'));
$this->resetFields($values, array('date_started', 'creator_id', 'owner_id', 'swimlane_id', 'date_due', 'score', 'category_id', 'time_estimated'));
if (empty($values['column_id'])) {
$values['column_id'] = $this->board->getFirstColumn($values['project_id']);

View File

@@ -86,6 +86,38 @@ class TaskFilter extends Base
return $this;
}
/**
* Prepare filter for Gantt chart
*
* @access public
* @return TaskFilter
*/
public function gantt()
{
$this->query = $this->db->table(Task::TABLE);
$this->query->join(Board::TABLE, 'id', 'column_id', Task::TABLE);
$this->query->join(User::TABLE, 'id', 'owner_id', Task::TABLE);
$this->query->columns(
Task::TABLE.'.id',
Task::TABLE.'.title',
Task::TABLE.'.project_id',
Task::TABLE.'.column_id',
Task::TABLE.'.color_id',
Task::TABLE.'.date_started',
Task::TABLE.'.date_due',
Task::TABLE.'.date_creation',
Task::TABLE.'.is_active',
Task::TABLE.'.position',
Board::TABLE.'.position AS column_position',
Board::TABLE.'.title AS column_title',
User::TABLE.'.name AS assignee_name',
User::TABLE.'.username AS assignee_username'
);
return $this;
}
/**
* Create a new query
*
@@ -674,6 +706,50 @@ class TaskFilter extends Base
});
}
/**
* Format tasks to be displayed in the Gantt chart
*
* @access public
* @return array
*/
public function toGanttBars()
{
$bars = array();
$columns = array();
foreach ($this->query->findAll() as $task) {
if (! isset($column_count[$task['project_id']])) {
$columns[$task['project_id']] = $this->board->getColumnsList($task['project_id']);
}
$start = $task['date_started'] ?: time();
$end = $task['date_due'] ?: $start;
$bars[] = array(
'id' => $task['id'],
'title' => $task['title'],
'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),
),
'column_title' => $task['column_title'],
'assignee' => $task['assignee_name'] ?: $task['assignee_username'],
'progress' => $this->task->getProgress($task, $columns[$task['project_id']]).'%',
'link' => $this->helper->url->href('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])),
'color' => $this->color->getColorProperties($task['color_id']),
'not_defined' => empty($task['date_due']) || empty($task['date_started']),
);
}
return $bars;
}
/**
* Format the results to the ajax autocompletion
*