Cleanup and improvement of tasks lists

Removed duplicate code in task lists views (now using a single class
with constructor parameters). Added specific display for assigned tasks
that have missing dependencies.
This commit is contained in:
Emmanuel BENOîT 2012-02-06 17:57:56 +01:00
parent dae65c0b4b
commit 634ed8f5ee
5 changed files with 67 additions and 64 deletions

View file

@ -277,7 +277,8 @@ class Ctrl_ItemTasks
{ {
$tasks = Loader::DAO( 'tasks' )->getTasksAt( $this->item ); $tasks = Loader::DAO( 'tasks' )->getTasksAt( $this->item );
return Loader::View( 'box' , 'Tasks' , Loader::View( 'tasks' , $tasks ) ) return Loader::View( 'box' , 'Tasks' , Loader::View( 'tasks_list' , $tasks , array(
'deps' , 'assigned' , 'completed' ) ) )
->addButton( BoxButton::create( 'Add task' , 'tasks/add?to=' . $this->item->id ) ->addButton( BoxButton::create( 'Add task' , 'tasks/add?to=' . $this->item->id )
->setClass( 'list-add' ) ); ->setClass( 'list-add' ) );
} }

View file

@ -33,10 +33,9 @@ $package[ 'ctrls' ][] = 'task_notes';
$package[ 'ctrls' ][] = 'toggle_task'; $package[ 'ctrls' ][] = 'toggle_task';
$package[ 'ctrls' ][] = 'view_task'; $package[ 'ctrls' ][] = 'view_task';
$package[ 'views' ][] = 'all_tasks'; $package[ 'views' ][] = 'tasks_list';
$package[ 'views' ][] = 'tasks'; $package[ 'views' ][] = 'task_dependencies';
$package[ 'views' ][] = 'task_details'; $package[ 'views' ][] = 'task_details';
$package[ 'views' ][] = 'task_note'; $package[ 'views' ][] = 'task_note';
$package[ 'views' ][] = 'task_dependencies';
$package[ 'pages' ][] = 'tasks_tasks'; $package[ 'pages' ][] = 'tasks_tasks';

View file

@ -31,7 +31,7 @@ class Ctrl_AllTasks
} }
$tree = Loader::DAO( 'items' )->getTree( ); $tree = Loader::DAO( 'items' )->getTree( );
$box = Loader::View( 'box' , $title , Loader::View( 'all_tasks' , $tasks , $mode ) ) $box = Loader::View( 'box' , $title , Loader::View( 'tasks_list' , $tasks ) )
->addButton( BoxButton::create( $bTitle , 'tasks?mode=' . $bMode ) ->addButton( BoxButton::create( $bTitle , 'tasks?mode=' . $bMode )
->setClass( 'icon refresh' ) ); ->setClass( 'icon refresh' ) );
if ( !empty( $tree ) ) { if ( !empty( $tree ) ) {

View file

@ -1,14 +1,16 @@
<?php <?php
abstract class View_TasksBase class View_TasksList
extends BaseURLAwareView extends BaseURLAwareView
{ {
protected $tasks; protected $tasks;
protected $dao; protected $dao;
protected function __construct( ) public function __construct( $tasks , $features = array( 'item' , 'assigned' , 'deps' , 'completed' ) )
{ {
$this->tasks = $tasks;
$this->features = array_combine( $features , array_fill( 0 , count( $features ) , 1 ) );
$this->dao = Loader::DAO( 'tasks' ); $this->dao = Loader::DAO( 'tasks' );
} }
@ -58,70 +60,42 @@ abstract class View_TasksBase
->appendElement( HTML::make( 'a' ) ->appendElement( HTML::make( 'a' )
->setAttribute( 'href' , $this->base . '/tasks/view?id=' . $task->id ) ->setAttribute( 'href' , $this->base . '/tasks/view?id=' . $task->id )
->appendText( $task->title ) ) ); ->appendText( $task->title ) ) );
$cell = array_merge( $cell , $this->generateSpecificLines( $task ) ); $this->addItem( $cell , $task );
$classes = array( );
$addedAt = strtotime( $task->added_at ); $addedAt = strtotime( $task->added_at );
$addedAtDate = date( 'd/m/o' , $addedAt ); $addedAtDate = date( 'd/m/o' , $addedAt );
$addedAtTime = date( 'H:i:s' , $addedAt ); $addedAtTime = date( 'H:i:s' , $addedAt );
array_push( $cell , array_push( $cell ,
HTML::make( 'dd' )->appendText( "Added $addedAtDate at $addedAtTime by {$task->added_by}" ) ); HTML::make( 'dd' )->appendText( "Added $addedAtDate at $addedAtTime by {$task->added_by}" ) );
if ( $task->missing_dependencies !== null ) {
if ( $task->missing_dependencies > 1 ) {
$end = 'ies';
} else {
$end = 'y';
}
array_push( $cell ,
$md = HTML::make( 'dd' )->appendText( "{$task->missing_dependencies} missing dependenc$end" ) );
if ( $task->total_missing_dependencies != $task->missing_dependencies ) {
$md->appendText( " ({$task->total_missing_dependencies} when counting transitive dependencies)" );
}
foreach ( $cell as $entry ) { if ( $task->completed_by !== null ) {
$entry->setAttribute( 'class' , 'missing-deps' ); $this->generateCompletedTask( $cell , $classes , $task );
} else {
if ( $task->missing_dependencies !== null ) {
$this->generateMissingDependencies( $cell , $classes , $task );
} }
} elseif ( $task->assigned_to !== null ) { if ( $task->assigned_to !== null ) {
array_push( $cell , HTML::make( 'dd' )->appendText( 'Assigned to ' . $task->assigned_to ) ); $this->generateAssignedTask( $cell , $classes , $task );
foreach ( $cell as $entry ) {
$entry->setAttribute( 'class' , 'assigned' );
} }
} elseif ( $task->completed_by !== null ) { }
$completedAt = strtotime( $task->completed_at );
$completedAtDate = date( 'd/m/o' , $completedAt );
$completedAtTime = date( 'H:i:s' , $completedAt );
array_push( $cell , HTML::make( 'dd' )->appendText(
"Completed $completedAtDate at $completedAtTime by {$task->completed_by}" ) );
if ( ! empty( $classes ) ) {
foreach ( $cell as $entry ) { foreach ( $cell as $entry ) {
$entry->setAttribute( 'class' , 'completed' ); $entry->setAttribute( 'class' , join( ' ' , $classes ) );
} }
} }
return $cell; return $cell;
} }
protected abstract function generateSpecificLines( $task ); protected function addItem( &$cell , $task )
}
class View_AllTasks
extends View_TasksBase
{
public function __construct( $tasks )
{ {
parent::__construct( ); if ( ! array_key_exists( 'item' , $this->features ) ) {
$this->tasks = $tasks; return;
} }
protected function generateSpecificLines( $task ) $item = Loader::DAO( 'items' )->get( $task->item );
{
return array( HTML::make( 'dd' )->append( $this->formatPlaceLineage( $task->item ) ) );
}
private function formatPlaceLineage( $item )
{
$item = Loader::DAO( 'items' )->get( $item );
$lineage = $item->lineage; $lineage = $item->lineage;
array_push( $lineage , $item->id ); array_push( $lineage , $item->id );
@ -136,26 +110,52 @@ class View_AllTasks
} }
array_unshift( $contents, 'On ' ); array_unshift( $contents, 'On ' );
return $contents; array_push( $cell , HTML::make( 'dd' )->append( $contents ) );
} }
}
protected function generateMissingDependencies( &$cell , &$classes , $task )
class View_Tasks
extends View_TasksBase
{
public function __construct( $tasks )
{ {
parent::__construct( ); if ( ! array_key_exists( 'deps' , $this->features ) ) {
$this->tasks = $tasks; return;
}
if ( $task->missing_dependencies > 1 ) {
$end = 'ies';
} else {
$end = 'y';
}
array_push( $cell ,
$md = HTML::make( 'dd' )->appendText( "{$task->missing_dependencies} missing dependenc$end" ) );
if ( $task->total_missing_dependencies != $task->missing_dependencies ) {
$md->appendText( " ({$task->total_missing_dependencies} when counting transitive dependencies)" );
}
array_push( $classes , 'missing-deps' );
} }
protected function generateAssignedTask( &$cell , &$classes , $task )
protected function generateSpecificLines( $task )
{ {
return array( ); if ( ! array_key_exists( 'assigned' , $this->features ) ) {
return;
}
array_push( $cell , HTML::make( 'dd' )->appendText( 'Assigned to ' . $task->assigned_to ) );
array_push( $classes , 'assigned' );
} }
protected function generateCompletedTask( &$cell , &$classes , $task )
{
if ( ! array_key_exists( 'completed' , $this->features ) ) {
return;
}
$completedAt = strtotime( $task->completed_at );
$completedAtDate = date( 'd/m/o' , $completedAt );
$completedAtTime = date( 'H:i:s' , $completedAt );
array_push( $cell , HTML::make( 'dd' )->appendText(
"Completed $completedAtDate at $completedAtTime by {$task->completed_by}" ) );
array_push( $classes , 'completed' );
}
} }

View file

@ -399,6 +399,9 @@ dl.tasks .missing-deps, dl.tasks .missing-deps * {
dl.tasks .assigned, dl.tasks .assigned * { dl.tasks .assigned, dl.tasks .assigned * {
color: #1f7f1f color: #1f7f1f
} }
dl.tasks .missing-deps.assigned, dl.tasks .missing-deps.assigned * {
color: #7f7f1f
}
dl.tasks dt.sub-title.completed { dl.tasks dt.sub-title.completed {
color: #bfbfbf; color: #bfbfbf;