Skip to content

Commit

Permalink
Added the possibility to convert a subtask to a task
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed May 18, 2016
1 parent d8472d1 commit 996997a
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version 1.0.29 (unreleased)

New features:

* Added the possibility to convert a subtask to a task
* Added menu entry to add tasks from all project views
* Add tasks in bulk from the board
* Add dropdown for projects
Expand Down
39 changes: 39 additions & 0 deletions app/Controller/SubtaskConverterController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Kanboard\Controller;

/**
* Class SubtaskConverterController
*
* @package Kanboard\Controller
* @author Frederic Guillot
*/
class SubtaskConverterController extends BaseController
{
public function show()
{
$task = $this->getTask();
$subtask = $this->getSubtask();

$this->response->html($this->template->render('subtask_converter/show', array(
'subtask' => $subtask,
'task' => $task,
)));
}

public function save()
{
$project = $this->getProject();
$subtask = $this->getSubtask();

$task_id = $this->subtask->convertToTask($project['id'], $subtask['id']);

if ($task_id !== false) {
$this->flash->success(t('Subtask converted to task successfully.'));
} else {
$this->flash->failure(t('Unable to convert the subtask.'));
}

$this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $project['id'], 'task_id' => $task_id)), true);
}
}
27 changes: 27 additions & 0 deletions app/Model/Subtask.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,31 @@ public function duplicate($src_task_id, $dst_task_id)
}
});
}

/**
* Convert a subtask to a task
*
* @access public
* @param integer $project_id
* @param integer $subtask_id
* @return integer
*/
public function convertToTask($project_id, $subtask_id)
{
$subtask = $this->getById($subtask_id);

$task_id = $this->taskCreation->create(array(
'project_id' => $project_id,
'title' => $subtask['title'],
'time_estimated' => $subtask['time_estimated'],
'time_spent' => $subtask['time_spent'],
'owner_id' => $subtask['user_id'],
));

if ($task_id !== false) {
$this->remove($subtask_id);
}

return $task_id;
}
}
6 changes: 6 additions & 0 deletions app/Template/subtask/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
<a href="#" class="dropdown-menu dropdown-menu-link-icon"><i class="fa fa-cog fa-fw"></i><i class="fa fa-caret-down"></i></a>
<ul>
<li>
<i class="fa fa-pencil-square-o" aria-hidden="true"></i>
<?= $this->url->link(t('Edit'), 'subtask', 'edit', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'subtask_id' => $subtask['id']), false, 'popover') ?>
</li>
<li>
<i class="fa fa-trash-o" aria-hidden="true"></i>
<?= $this->url->link(t('Remove'), 'subtask', 'confirm', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'subtask_id' => $subtask['id']), false, 'popover') ?>
</li>
<li>
<i class="fa fa-clone" aria-hidden="true"></i>
<?= $this->url->link(t('Convert to task'), 'SubtaskConverterController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'subtask_id' => $subtask['id']), false, 'popover') ?>
</li>
</ul>
</div>
13 changes: 8 additions & 5 deletions app/Template/subtask/remove.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
</div>

<div class="confirm">
<p class="alert alert-info">
<div class="alert alert-info">
<?= t('Do you really want to remove this sub-task?') ?>
</p>

<p><strong><?= $this->text->e($subtask['title']) ?></strong></p>
<ul>
<li>
<strong><?= $this->text->e($subtask['title']) ?></strong>
</li>
</ul>
</div>

<div class="form-actions">
<?= $this->url->link(t('Yes'), 'subtask', 'remove', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'subtask_id' => $subtask['id']), true, 'btn btn-red') ?>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?>
</div>
</div>
</div>
20 changes: 20 additions & 0 deletions app/Template/subtask_converter/show.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="page-header">
<h2><?= t('Convert sub-task to task') ?></h2>
</div>

<div class="confirm">
<div class="alert alert-info">
<?= t('Do you really want to convert this sub-task to a task?') ?>
<ul>
<li>
<strong><?= $this->text->e($subtask['title']) ?></strong>
</li>
</ul>
</div>

<div class="form-actions">
<?= $this->url->link(t('Yes'), 'SubtaskConverterController', 'save', array('task_id' => $task['id'], 'project_id' => $task['project_id'], 'subtask_id' => $subtask['id']), true, 'btn btn-red') ?>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?>
</div>
</div>
25 changes: 25 additions & 0 deletions tests/units/Model/SubtaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Kanboard\Model\Subtask;
use Kanboard\Model\Project;
use Kanboard\Core\User\UserSession;
use Kanboard\Model\TaskFinder;

class SubtaskTest extends Base
{
Expand Down Expand Up @@ -360,4 +361,28 @@ public function testChangePosition()
$this->assertFalse($subtaskModel->changePosition(1, 2, 0));
$this->assertFalse($subtaskModel->changePosition(1, 2, 4));
}

public function testConvertToTask()
{
$taskCreationModel = new TaskCreation($this->container);
$taskFinderModel = new TaskFinder($this->container);
$subtaskModel = new Subtask($this->container);
$projectModel = new Project($this->container);

$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));

$this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1, 'time_spent' => 2, 'time_estimated' => 3)));
$task_id = $subtaskModel->convertToTask(1, 1);

$this->assertNotFalse($task_id);
$this->assertEmpty($subtaskModel->getById(1));

$task = $taskFinderModel->getById($task_id);
$this->assertEquals('subtask #1', $task['title']);
$this->assertEquals(1, $task['project_id']);
$this->assertEquals(1, $task['owner_id']);
$this->assertEquals(2, $task['time_spent']);
$this->assertEquals(3, $task['time_estimated']);
}
}

0 comments on commit 996997a

Please sign in to comment.