Fix bug when moving tasks position in the same column
This commit is contained in:
@@ -560,23 +560,30 @@ class Task extends Base
|
|||||||
->eq('project_id', $project_id)
|
->eq('project_id', $project_id)
|
||||||
->findAll();
|
->findAll();
|
||||||
|
|
||||||
// We sort everything by column and position
|
|
||||||
$board = $this->board->getColumnsList($project_id);
|
$board = $this->board->getColumnsList($project_id);
|
||||||
$columns = array();
|
$columns = array();
|
||||||
|
$task_id = (int) $task_id;
|
||||||
|
|
||||||
|
// Prepare the columns
|
||||||
foreach ($board as $board_column_id => $board_column_name) {
|
foreach ($board as $board_column_id => $board_column_name) {
|
||||||
$columns[$board_column_id] = array();
|
$columns[$board_column_id] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The column must exists
|
||||||
|
if (! isset($columns[$column_id])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort everything by column
|
||||||
foreach ($tasks as &$task) {
|
foreach ($tasks as &$task) {
|
||||||
if ($task['id'] != $task_id) {
|
if ($task['id'] != $task_id) {
|
||||||
$columns[$task['column_id']][$task['position'] - 1] = (int) $task['id'];
|
$columns[$task['column_id']][$task['position'] - 1] = (int) $task['id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The column must exists
|
// Sort all tasks by position
|
||||||
if (! isset($columns[$column_id])) {
|
foreach ($columns as &$column) {
|
||||||
return false;
|
ksort($column);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We put our task to the new position
|
// We put our task to the new position
|
||||||
@@ -601,7 +608,6 @@ class Task extends Base
|
|||||||
foreach ($columns as $column_id => $column) {
|
foreach ($columns as $column_id => $column) {
|
||||||
|
|
||||||
$position = 1;
|
$position = 1;
|
||||||
ksort($column);
|
|
||||||
|
|
||||||
foreach ($column as $task_id) {
|
foreach ($column as $task_id) {
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,78 @@ use Model\User;
|
|||||||
|
|
||||||
class TaskTest extends Base
|
class TaskTest extends Base
|
||||||
{
|
{
|
||||||
|
public function testMoveTaskTop()
|
||||||
|
{
|
||||||
|
$t = new Task($this->registry);
|
||||||
|
$p = new Project($this->registry);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||||
|
$this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
|
||||||
|
$this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
|
||||||
|
$this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
|
||||||
|
$this->assertEquals(4, $t->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
|
||||||
|
|
||||||
|
// Move the last task to hte top
|
||||||
|
$this->assertTrue($t->movePosition(1, 4, 1, 1));
|
||||||
|
|
||||||
|
// Check tasks position
|
||||||
|
$task = $t->getById(1);
|
||||||
|
$this->assertEquals(1, $task['id']);
|
||||||
|
$this->assertEquals(1, $task['column_id']);
|
||||||
|
$this->assertEquals(2, $task['position']);
|
||||||
|
|
||||||
|
$task = $t->getById(2);
|
||||||
|
$this->assertEquals(2, $task['id']);
|
||||||
|
$this->assertEquals(1, $task['column_id']);
|
||||||
|
$this->assertEquals(3, $task['position']);
|
||||||
|
|
||||||
|
$task = $t->getById(3);
|
||||||
|
$this->assertEquals(3, $task['id']);
|
||||||
|
$this->assertEquals(1, $task['column_id']);
|
||||||
|
$this->assertEquals(4, $task['position']);
|
||||||
|
|
||||||
|
$task = $t->getById(4);
|
||||||
|
$this->assertEquals(4, $task['id']);
|
||||||
|
$this->assertEquals(1, $task['column_id']);
|
||||||
|
$this->assertEquals(1, $task['position']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMoveTaskBottom()
|
||||||
|
{
|
||||||
|
$t = new Task($this->registry);
|
||||||
|
$p = new Project($this->registry);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
|
||||||
|
$this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
|
||||||
|
$this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
|
||||||
|
$this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
|
||||||
|
$this->assertEquals(4, $t->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
|
||||||
|
|
||||||
|
// Move the last task to hte top
|
||||||
|
$this->assertTrue($t->movePosition(1, 1, 1, 4));
|
||||||
|
|
||||||
|
// Check tasks position
|
||||||
|
$task = $t->getById(1);
|
||||||
|
$this->assertEquals(1, $task['id']);
|
||||||
|
$this->assertEquals(1, $task['column_id']);
|
||||||
|
$this->assertEquals(4, $task['position']);
|
||||||
|
|
||||||
|
$task = $t->getById(2);
|
||||||
|
$this->assertEquals(2, $task['id']);
|
||||||
|
$this->assertEquals(1, $task['column_id']);
|
||||||
|
$this->assertEquals(1, $task['position']);
|
||||||
|
|
||||||
|
$task = $t->getById(3);
|
||||||
|
$this->assertEquals(3, $task['id']);
|
||||||
|
$this->assertEquals(1, $task['column_id']);
|
||||||
|
$this->assertEquals(2, $task['position']);
|
||||||
|
|
||||||
|
$task = $t->getById(4);
|
||||||
|
$this->assertEquals(4, $task['id']);
|
||||||
|
$this->assertEquals(1, $task['column_id']);
|
||||||
|
$this->assertEquals(3, $task['position']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testMovePosition()
|
public function testMovePosition()
|
||||||
{
|
{
|
||||||
$t = new Task($this->registry);
|
$t = new Task($this->registry);
|
||||||
|
|||||||
Reference in New Issue
Block a user