Add task transitions csv export

This commit is contained in:
Frederic Guillot 2015-03-28 12:39:46 -04:00
parent 87d2c6d99e
commit 26fea9b96b
25 changed files with 281 additions and 37 deletions

View File

@ -20,6 +20,7 @@ use Symfony\Component\Console\Command\Command;
* @property \Model\Task $task
* @property \Model\TaskExport $taskExport
* @property \Model\TaskFinder $taskFinder
* @property \Model\Transition $transition
*/
abstract class Base extends Command
{

View File

@ -0,0 +1,34 @@
<?php
namespace Console;
use Core\Tool;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class TransitionExport extends Base
{
protected function configure()
{
$this
->setName('export:transitions')
->setDescription('Task transitions CSV export')
->addArgument('project_id', InputArgument::REQUIRED, 'Project id')
->addArgument('start_date', InputArgument::REQUIRED, 'Start date (YYYY-MM-DD)')
->addArgument('end_date', InputArgument::REQUIRED, 'End date (YYYY-MM-DD)');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$data = $this->transition->export(
$input->getArgument('project_id'),
$input->getArgument('start_date'),
$input->getArgument('end_date')
);
if (is_array($data)) {
Tool::csv($data);
}
}
}

View File

@ -72,4 +72,14 @@ class Export extends Base
{
$this->common('projectDailySummary', 'getAggregatedMetrics', t('Summary'), 'summary', t('Daily project summary export'));
}
/**
* Transition export
*
* @access public
*/
public function transitions()
{
$this->common('transition', 'export', t('Transitions'), 'transitions', t('Task transitions export'));
}
}

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -814,4 +814,7 @@ return array(
'Transitions' => 'Transitions',
'Executer' => 'Exécutant',
'Time spent in the column' => 'Temps passé dans la colonne',
'Task transitions' => 'Transitions des tâches',
'Task transitions export' => 'Export des transitions des tâches',
'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => 'Ce rapport contient tous les mouvements de colonne pour chaque tâche avec la date, l\'utilisateur et le temps passé pour chaque transition.',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -812,4 +812,7 @@ return array(
// 'Transitions' => '',
// 'Executer' => '',
// 'Time spent in the column' => '',
// 'Task transitions' => '',
// 'Task transitions export' => '',
// 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '',
);

View File

@ -64,4 +64,107 @@ class Transition extends Base
->join(Board::TABLE.' as dst', 'id', 'dst_column_id', self::TABLE, 'dst')
->findAll();
}
/**
* Get all transitions by project
*
* @access public
* @param integer $project_id
* @param mixed $from Start date (timestamp or user formatted date)
* @param mixed $to End date (timestamp or user formatted date)
* @return array
*/
public function getAllByProjectAndDate($project_id, $from, $to)
{
if (! is_numeric($from)) {
$from = $this->dateParser->removeTimeFromTimestamp($this->dateParser->getTimestamp($from));
}
if (! is_numeric($to)) {
$to = $this->dateParser->removeTimeFromTimestamp(strtotime('+1 day', $this->dateParser->getTimestamp($to)));
}
return $this->db->table(self::TABLE)
->columns(
Task::TABLE.'.id',
Task::TABLE.'.title',
'src.title as src_column',
'dst.title as dst_column',
User::TABLE.'.name',
User::TABLE.'.username',
self::TABLE.'.user_id',
self::TABLE.'.date',
self::TABLE.'.time_spent'
)
->gte('date', $from)
->lte('date', $to)
->eq(self::TABLE.'.project_id', $project_id)
->desc('date')
->join(Task::TABLE, 'id', 'task_id')
->join(User::TABLE, 'id', 'user_id')
->join(Board::TABLE.' as src', 'id', 'src_column_id', self::TABLE, 'src')
->join(Board::TABLE.' as dst', 'id', 'dst_column_id', self::TABLE, 'dst')
->findAll();
}
/**
* Get project export
*
* @access public
* @param integer $project_id Project id
* @param mixed $from Start date (timestamp or user formatted date)
* @param mixed $to End date (timestamp or user formatted date)
* @return array
*/
public function export($project_id, $from, $to)
{
$results = array($this->getColumns());
$transitions = $this->getAllByProjectAndDate($project_id, $from, $to);
foreach ($transitions as $transition) {
$results[] = $this->format($transition);
}
return $results;
}
/**
* Get column titles
*
* @access public
* @return string[]
*/
public function getColumns()
{
return array(
e('Id'),
e('Task Title'),
e('Source column'),
e('Destination column'),
e('Executer'),
e('Date'),
e('Time spent'),
);
}
/**
* Format the output of a transition array
*
* @access public
* @param array $transition
* @return array
*/
public function format(array $transition)
{
$values = array();
$values[] = $transition['id'];
$values[] = $transition['title'];
$values[] = $transition['src_column'];
$values[] = $transition['dst_column'];
$values[] = $transition['name'] ?: $transition['username'];
$values[] = date('Y-m-d H:i', $transition['date']);
$values[] = round($transition['time_spent'] / 3600, 2);
return $values;
}
}

View File

@ -0,0 +1,26 @@
<div class="page-header">
<h2>
<?= t('Task transitions export') ?>
</h2>
</div>
<p class="alert alert-info"><?= t('This report contains all column moves for each task with the date, the user and the time spent for each transition.') ?></p>
<form method="get" action="?" autocomplete="off">
<?= $this->formHidden('controller', $values) ?>
<?= $this->formHidden('action', $values) ?>
<?= $this->formHidden('project_id', $values) ?>
<?= $this->formLabel(t('Start Date'), 'from') ?>
<?= $this->formText('from', $values, $errors, array('required', 'placeholder="'.$this->inList($date_format, $date_formats).'"'), 'form-date') ?><br/>
<?= $this->formLabel(t('End Date'), 'to') ?>
<?= $this->formText('to', $values, $errors, array('required', 'placeholder="'.$this->inList($date_format, $date_formats).'"'), 'form-date') ?>
<div class="form-help"><?= t('Others formats accepted: %s and %s', date('Y-m-d'), date('Y_m_d')) ?></div>
<div class="form-actions">
<input type="submit" value="<?= t('Execute') ?>" class="btn btn-blue"/>
</div>
</form>

View File

@ -62,6 +62,9 @@
<li>
<?= $this->a(t('Subtasks'), 'export', 'subtasks', array('project_id' => $project['id'])) ?>
</li>
<li>
<?= $this->a(t('Task transitions'), 'export', 'transitions', array('project_id' => $project['id'])) ?>
</li>
<li>
<?= $this->a(t('Daily project summary'), 'export', 'summary', array('project_id' => $project['id'])) ?>
</li>

View File

@ -17,16 +17,16 @@ $ ./kanboard
Kanboard version master
Usage:
[options] command [arguments]
command [options] [arguments]
Options:
--help (-h) Display this help message.
--quiet (-q) Do not output any message.
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.
--version (-V) Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
--no-interaction (-n) Do not ask any interactive question.
--help (-h) Display this help message
--quiet (-q) Do not output any message
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version (-V) Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
--no-interaction (-n) Do not ask any interactive question
Available commands:
help Displays help for a command
@ -35,6 +35,7 @@ export
export:daily-project-summary Daily project summary CSV export (number of tasks per column and per day)
export:subtasks Subtasks CSV export
export:tasks Tasks CSV export
export:transitions Task transitions CSV export
notification
notification:overdue-tasks Send notifications for overdue tasks
projects
@ -44,20 +45,6 @@ projects
Available commands
------------------
### Subtasks CSV export
Usage:
```bash
./kanboard export:subtasks <project_id> <start_date> <end_date>
```
Example:
```bash
./kanboard export:subtasks 1 2014-10-01 2014-11-30 > /tmp/my_custom_export.csv
```
### Tasks CSV export
Usage:
@ -72,7 +59,49 @@ Example:
./kanboard export:tasks 1 2014-10-01 2014-11-30 > /tmp/my_custom_export.csv
```
CSV data are sent to stdout.
CSV data are sent to `stdout`.
### Subtasks CSV export
Usage:
```bash
./kanboard export:subtasks <project_id> <start_date> <end_date>
```
Example:
```bash
./kanboard export:subtasks 1 2014-10-01 2014-11-30 > /tmp/my_custom_export.csv
```
### Task transitions CSV export
Usage:
```bash
./kanboard export:transitions <project_id> <start_date> <end_date>
```
Example:
```bash
./kanboard export:transitions 1 2014-10-01 2014-11-30 > /tmp/my_custom_export.csv
```
### Export daily summaries data in CSV
The exported data will be printed on the standard output:
```bash
./kanboard export:daily-project-summary <project_id> <start_date> <end_date>
```
Example:
```bash
./kanboard export:daily-project-summary 1 2014-10-01 2014-11-30 > /tmp/my_custom_export.csv
```
### Send notifications for overdue tasks
@ -111,17 +140,3 @@ Run calculation for Project #0
Run calculation for Project #1
Run calculation for Project #10
```
### Export daily summaries data in CSV
The exported data will be printed on the standard output:
```bash
./kanboard export:daily-project-summary <project_id> <start_date> <end_date>
```
Example:
```bash
./kanboard export:daily-project-summary 1 2014-10-01 2014-11-30 > /tmp/my_custom_export.csv
```

View File

@ -14,4 +14,5 @@ $application->add(new Console\SubtaskExport($container));
$application->add(new Console\TaskExport($container));
$application->add(new Console\ProjectDailySummaryCalculation($container));
$application->add(new Console\ProjectDailySummaryExport($container));
$application->add(new Console\TransitionExport($container));
$application->run();