Fixed sub-task handling
The previous implementation of sub-tasks did not work as expected: it was possible to mark sub-tasks as completed before the parent task's dependencies were satisfied. In addition, it was impossible to retrieve a task's path from the database without running a recursive query. Full paths to sub-tasks added to views, since it is now possible to obtain them.
This commit is contained in:
parent
91ae4f81fd
commit
2051303262
13 changed files with 1023 additions and 224 deletions
includes/t-tasks
|
@ -98,16 +98,16 @@ class Ctrl_TaskDetails
|
|||
$bTitle = "Active task";
|
||||
}
|
||||
|
||||
if ( $this->task->item !== null ) {
|
||||
$items = Loader::DAO( 'items' );
|
||||
$items->getLineage( $this->task->item = $items->get( $this->task->item ) );
|
||||
} else {
|
||||
$this->task->parent_task = Loader::DAO( 'tasks' )->get( $this->task->parent_task );
|
||||
$items = Loader::DAO( 'items' );
|
||||
$tasks = Loader::DAO( 'tasks' );
|
||||
|
||||
$items->getLineage( $this->task->item = $items->get( $this->task->item ) );
|
||||
if ( $this->task->parent_task !== null ) {
|
||||
$this->task->parent_task = $tasks->get( $this->task->parent_task );
|
||||
}
|
||||
|
||||
$box = Loader::View( 'box' , $bTitle , Loader::View( 'task_details' , $this->task ) );
|
||||
|
||||
$tasks = Loader::DAO( 'tasks' );
|
||||
if ( $this->task->completed_by === null ) {
|
||||
$box->addButton( BoxButton::create( 'Edit task' , 'tasks/edit?id=' . $this->task->id )
|
||||
->setClass( 'icon edit' ) );
|
||||
|
@ -138,7 +138,7 @@ class Ctrl_TaskDetails
|
|||
$timestamp = strtotime( $this->task->completed_at );
|
||||
}
|
||||
|
||||
if ( Loader::DAO( 'tasks' )->canDelete( $this->task ) ) {
|
||||
if ( $tasks->canDelete( $this->task ) ) {
|
||||
$box->addButton( BoxButton::create( 'Delete' , 'tasks/delete?id=' . $this->task->id )
|
||||
->setClass( 'icon delete' ) );
|
||||
}
|
||||
|
|
|
@ -287,9 +287,9 @@ class Ctrl_EditTaskForm
|
|||
->addField( Loader::Create( 'Field' , 'id' , 'hidden' )
|
||||
->setDefaultValue( $task->id ) )
|
||||
->addField( Loader::Create( 'Field' , 'nested' , 'hidden' )
|
||||
->setDefaultValue( $task->item === null ? 1 : 0 ) );
|
||||
->setDefaultValue( $task->parent_task === null ? 0 : 1 ) );
|
||||
|
||||
if ( $task->item !== null ) {
|
||||
if ( $task->parent_task === null ) {
|
||||
$form->addField( $this->createItemSelector( )
|
||||
->setDefaultValue( $task->item ) );
|
||||
}
|
||||
|
@ -457,7 +457,7 @@ class Ctrl_DependencyAddForm
|
|||
$form = Loader::Create( 'Form' , 'Add dependency' , 'add-dep' )
|
||||
->addField( Loader::Create( 'Field' , 'to' , 'hidden' )
|
||||
->setDefaultValue( $id ) );
|
||||
$this->addDependencySelector( $form , $task->possibleDependencies , $task->item !== null );
|
||||
$this->addDependencySelector( $form , $task->possibleDependencies , $task->parent_task === null );
|
||||
return $form->setURL( 'tasks/view?id=' . $id )
|
||||
->addController( Loader::Ctrl( 'dependency_add' ) )
|
||||
->controller( );
|
||||
|
|
|
@ -72,12 +72,15 @@ class View_TasksList
|
|||
if ( $task->completed_by !== null ) {
|
||||
$this->generateCompletedTask( $cell , $classes , $task );
|
||||
} else {
|
||||
if ( $task->missing_dependencies !== null ) {
|
||||
if ( $task->unsatisfied_direct_dependencies > 0 ) {
|
||||
$this->generateMissingDependencies( $cell , $classes , $task );
|
||||
}
|
||||
if ( $task->missing_subtasks !== null ) {
|
||||
if ( $task->incomplete_subtasks > 0 ) {
|
||||
$this->generateMissingSubtasks( $cell , $classes , $task );
|
||||
}
|
||||
if ( $task->unsatisfied_inherited_dependencies > 0 ) {
|
||||
$this->generateMissingInherited( $cell , $classes , $task );
|
||||
}
|
||||
if ( $task->assigned_to !== null ) {
|
||||
$this->generateAssignedTask( $cell , $classes , $task );
|
||||
}
|
||||
|
@ -98,9 +101,8 @@ class View_TasksList
|
|||
return;
|
||||
}
|
||||
|
||||
if ( $task->item !== null ) {
|
||||
$this->addItem( $cell , $task );
|
||||
} else {
|
||||
$this->addItem( $cell , $task );
|
||||
if ( $task->parent_task !== null ) {
|
||||
$this->addParentTask( $cell , $task );
|
||||
}
|
||||
}
|
||||
|
@ -128,13 +130,21 @@ class View_TasksList
|
|||
|
||||
protected function addParentTask( &$cell , $task )
|
||||
{
|
||||
$parent = $this->dao->get( $task->parent_task );
|
||||
$parents = $this->dao->getLineage( $task );
|
||||
$contents = array( );
|
||||
foreach ( $parents as $parent ) {
|
||||
list( $id , $title ) = $parent;
|
||||
if ( ! empty( $contents ) ) {
|
||||
array_push( $contents , ' » ' );
|
||||
}
|
||||
array_push( $contents , HTML::make( 'a' )
|
||||
->setAttribute( 'href' , $this->base . '/tasks/view?id=' . $id )
|
||||
->appendText( $title ) );
|
||||
}
|
||||
|
||||
array_push( $cell , HTML::make( 'dd' )
|
||||
->appendText( 'Sub-task of ' )
|
||||
->appendElement( HTML::make( 'a' )
|
||||
->setAttribute( 'href' , $this->base . '/tasks/view?id=' . $parent->id )
|
||||
->appendText( $parent->title ) ) );
|
||||
->append( $contents ) );
|
||||
}
|
||||
|
||||
protected function generateMissingDependencies( &$cell , &$classes , $task )
|
||||
|
@ -143,15 +153,15 @@ class View_TasksList
|
|||
return;
|
||||
}
|
||||
|
||||
if ( $task->missing_dependencies > 1 ) {
|
||||
if ( $task->unsatisfied_direct_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)" );
|
||||
$md = HTML::make( 'dd' )->appendText( "{$task->unsatisfied_direct_dependencies} missing dependenc$end" ) );
|
||||
if ( $task->unsatisfied_direct_dependencies != $task->unsatisfied_transitive_dependencies ) {
|
||||
$md->appendText( " ({$task->unsatisfied_transitive_dependencies} when counting transitive dependencies)" );
|
||||
}
|
||||
|
||||
array_push( $classes , 'missing-deps' );
|
||||
|
@ -163,13 +173,30 @@ class View_TasksList
|
|||
return;
|
||||
}
|
||||
|
||||
if ( $task->missing_subtasks > 1 ) {
|
||||
if ( $task->incomplete_subtasks > 1 ) {
|
||||
$end = 's';
|
||||
} else {
|
||||
$end = '';
|
||||
}
|
||||
array_push( $cell ,
|
||||
$md = HTML::make( 'dd' )->appendText( "{$task->missing_subtasks} incomplete sub-task$end" ) );
|
||||
array_push( $cell , HTML::make( 'dd' )->appendText(
|
||||
"{$task->incomplete_subtasks} incomplete sub-task$end (out of {$task->total_subtasks})" ) );
|
||||
|
||||
array_push( $classes , 'missing-deps' );
|
||||
}
|
||||
|
||||
protected function generateMissingInherited( &$cell , &$classes , $task )
|
||||
{
|
||||
if ( ! array_key_exists( 'deps' , $this->features ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $task->unsatisfied_inherited_dependencies > 1 ) {
|
||||
$end = 'ies';
|
||||
} else {
|
||||
$end = 'y';
|
||||
}
|
||||
array_push( $cell , HTML::make( 'dd' )->appendText(
|
||||
"{$task->unsatisfied_inherited_dependencies} unsatisfied dependenc$end in parent task(s)" ) );
|
||||
|
||||
array_push( $classes , 'missing-deps' );
|
||||
}
|
||||
|
@ -213,21 +240,28 @@ class View_TaskDetails
|
|||
public function render( )
|
||||
{
|
||||
$list = HTML::make( 'dl' )
|
||||
->setAttribute( 'class' , 'tasks' );
|
||||
->setAttribute( 'class' , 'tasks' )
|
||||
->appendElement( HTML::make( 'dt' )
|
||||
->appendText( 'On item:' ) )
|
||||
->appendElement( HTML::make( 'dd' )
|
||||
->append( $this->formatPlaceLineage( $this->task->item ) ) );
|
||||
|
||||
if ( $this->task->item !== null ) {
|
||||
$list->appendElement( HTML::make( 'dt' )
|
||||
->appendText( 'On item:' ) )
|
||||
->appendElement( HTML::make( 'dd' )
|
||||
->append( $this->formatPlaceLineage( $this->task->item ) ) );
|
||||
} else {
|
||||
if ( $this->task->parent_task !== null ) {
|
||||
$parents = Loader::DAO( 'tasks' )->getLineage( $this->task );
|
||||
$contents = array( );
|
||||
foreach ( $parents as $parent ) {
|
||||
list( $id , $title ) = $parent;
|
||||
if ( ! empty( $contents ) ) {
|
||||
array_push( $contents , ' » ' );
|
||||
}
|
||||
array_push( $contents , HTML::make( 'a' )
|
||||
->setAttribute( 'href' , $this->base . '/tasks/view?id=' . $id )
|
||||
->appendText( $title ) );
|
||||
}
|
||||
$list->appendElement( HTML::make( 'dt' )
|
||||
->appendText( 'Sub-task of:' ) )
|
||||
->appendElement( HTML::make( 'dd' )
|
||||
->appendElement( HTML::make( 'a' )
|
||||
->setAttribute( 'href' , $this->base .
|
||||
'/tasks/view?id=' . $this->task->parent_task->id )
|
||||
->appendText( $this->task->parent_task->title ) ) );
|
||||
->append( $contents ) );
|
||||
}
|
||||
|
||||
if ( $this->task->description != '' ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue