Add drag and drop to change swimlane positions

This commit is contained in:
Frederic Guillot
2016-02-20 18:11:08 -05:00
parent da7259819b
commit 5fe68d4d49
41 changed files with 588 additions and 645 deletions

View File

@@ -86,7 +86,23 @@ class SwimlaneTest extends Base
$this->assertEquals(0, $default['show_default_swimlane']);
}
public function testDisable()
public function testDisableEnableDefaultSwimlane()
{
$projectModel = new Project($this->container);
$swimlaneModel = new Swimlane($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
$this->assertTrue($swimlaneModel->disableDefault(1));
$default = $swimlaneModel->getDefault(1);
$this->assertEquals(0, $default['show_default_swimlane']);
$this->assertTrue($swimlaneModel->enableDefault(1));
$default = $swimlaneModel->getDefault(1);
$this->assertEquals(1, $default['show_default_swimlane']);
}
public function testDisableEnable()
{
$p = new Project($this->container);
$s = new Swimlane($this->container);
@@ -210,172 +226,6 @@ class SwimlaneTest extends Base
$this->assertEquals(1, $swimlane['position']);
}
public function testMoveUp()
{
$p = new Project($this->container);
$s = new Swimlane($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
$this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'Swimlane #3')));
$swimlane = $s->getById(1);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(1, $swimlane['position']);
$swimlane = $s->getById(2);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(2, $swimlane['position']);
$swimlane = $s->getById(3);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(3, $swimlane['position']);
// Move the swimlane 3 up
$this->assertTrue($s->moveUp(1, 3));
$swimlane = $s->getById(1);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(1, $swimlane['position']);
$swimlane = $s->getById(2);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(3, $swimlane['position']);
$swimlane = $s->getById(3);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(2, $swimlane['position']);
// First swimlane can be moved up
$this->assertFalse($s->moveUp(1, 1));
// Move with a disabled swimlane
$this->assertTrue($s->disable(1, 1));
$swimlane = $s->getById(1);
$this->assertNotEmpty($swimlane);
$this->assertEquals(0, $swimlane['is_active']);
$this->assertEquals(0, $swimlane['position']);
$swimlane = $s->getById(2);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(2, $swimlane['position']);
$swimlane = $s->getById(3);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(1, $swimlane['position']);
// Move the 2nd swimlane up
$this->assertTrue($s->moveUp(1, 2));
$swimlane = $s->getById(1);
$this->assertNotEmpty($swimlane);
$this->assertEquals(0, $swimlane['is_active']);
$this->assertEquals(0, $swimlane['position']);
$swimlane = $s->getById(2);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(1, $swimlane['position']);
$swimlane = $s->getById(3);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(2, $swimlane['position']);
}
public function testMoveDown()
{
$p = new Project($this->container);
$s = new Swimlane($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
$this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'Swimlane #3')));
$swimlane = $s->getById(1);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(1, $swimlane['position']);
$swimlane = $s->getById(2);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(2, $swimlane['position']);
$swimlane = $s->getById(3);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(3, $swimlane['position']);
// Move the swimlane 1 down
$this->assertTrue($s->moveDown(1, 1));
$swimlane = $s->getById(1);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(2, $swimlane['position']);
$swimlane = $s->getById(2);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(1, $swimlane['position']);
$swimlane = $s->getById(3);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(3, $swimlane['position']);
// Last swimlane can be moved down
$this->assertFalse($s->moveDown(1, 3));
// Move with a disabled swimlane
$this->assertTrue($s->disable(1, 3));
$swimlane = $s->getById(1);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(2, $swimlane['position']);
$swimlane = $s->getById(2);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(1, $swimlane['position']);
$swimlane = $s->getById(3);
$this->assertNotEmpty($swimlane);
$this->assertEquals(0, $swimlane['is_active']);
$this->assertEquals(0, $swimlane['position']);
// Move the 2st swimlane down
$this->assertTrue($s->moveDown(1, 2));
$swimlane = $s->getById(1);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(1, $swimlane['position']);
$swimlane = $s->getById(2);
$this->assertNotEmpty($swimlane);
$this->assertEquals(1, $swimlane['is_active']);
$this->assertEquals(2, $swimlane['position']);
$swimlane = $s->getById(3);
$this->assertNotEmpty($swimlane);
$this->assertEquals(0, $swimlane['is_active']);
$this->assertEquals(0, $swimlane['position']);
}
public function testDuplicateSwimlane()
{
$p = new Project($this->container);
@@ -406,4 +256,93 @@ class SwimlaneTest extends Base
$new_default = $s->getDefault(2);
$this->assertEquals('New Default', $new_default['default_swimlane']);
}
public function testChangePosition()
{
$projectModel = new Project($this->container);
$swimlaneModel = new Swimlane($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
$this->assertEquals(3, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #3')));
$this->assertEquals(4, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #4')));
$swimlanes = $swimlaneModel->getAllByStatus(1);
$this->assertEquals(1, $swimlanes[0]['position']);
$this->assertEquals(1, $swimlanes[0]['id']);
$this->assertEquals(2, $swimlanes[1]['position']);
$this->assertEquals(2, $swimlanes[1]['id']);
$this->assertEquals(3, $swimlanes[2]['position']);
$this->assertEquals(3, $swimlanes[2]['id']);
$this->assertTrue($swimlaneModel->changePosition(1, 3, 2));
$swimlanes = $swimlaneModel->getAllByStatus(1);
$this->assertEquals(1, $swimlanes[0]['position']);
$this->assertEquals(1, $swimlanes[0]['id']);
$this->assertEquals(2, $swimlanes[1]['position']);
$this->assertEquals(3, $swimlanes[1]['id']);
$this->assertEquals(3, $swimlanes[2]['position']);
$this->assertEquals(2, $swimlanes[2]['id']);
$this->assertTrue($swimlaneModel->changePosition(1, 2, 1));
$swimlanes = $swimlaneModel->getAllByStatus(1);
$this->assertEquals(1, $swimlanes[0]['position']);
$this->assertEquals(2, $swimlanes[0]['id']);
$this->assertEquals(2, $swimlanes[1]['position']);
$this->assertEquals(1, $swimlanes[1]['id']);
$this->assertEquals(3, $swimlanes[2]['position']);
$this->assertEquals(3, $swimlanes[2]['id']);
$this->assertTrue($swimlaneModel->changePosition(1, 2, 2));
$swimlanes = $swimlaneModel->getAllByStatus(1);
$this->assertEquals(1, $swimlanes[0]['position']);
$this->assertEquals(1, $swimlanes[0]['id']);
$this->assertEquals(2, $swimlanes[1]['position']);
$this->assertEquals(2, $swimlanes[1]['id']);
$this->assertEquals(3, $swimlanes[2]['position']);
$this->assertEquals(3, $swimlanes[2]['id']);
$this->assertTrue($swimlaneModel->changePosition(1, 4, 1));
$swimlanes = $swimlaneModel->getAllByStatus(1);
$this->assertEquals(1, $swimlanes[0]['position']);
$this->assertEquals(4, $swimlanes[0]['id']);
$this->assertEquals(2, $swimlanes[1]['position']);
$this->assertEquals(1, $swimlanes[1]['id']);
$this->assertEquals(3, $swimlanes[2]['position']);
$this->assertEquals(2, $swimlanes[2]['id']);
$this->assertFalse($swimlaneModel->changePosition(1, 2, 0));
$this->assertFalse($swimlaneModel->changePosition(1, 2, 5));
}
public function testChangePositionWithInactiveSwimlane()
{
$projectModel = new Project($this->container);
$swimlaneModel = new Swimlane($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
$this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #2', 'is_active' => 0)));
$this->assertEquals(3, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #3', 'is_active' => 0)));
$this->assertEquals(4, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #4')));
$swimlanes = $swimlaneModel->getAllByStatus(1);
$this->assertEquals(1, $swimlanes[0]['position']);
$this->assertEquals(1, $swimlanes[0]['id']);
$this->assertEquals(2, $swimlanes[1]['position']);
$this->assertEquals(4, $swimlanes[1]['id']);
$this->assertTrue($swimlaneModel->changePosition(1, 4, 1));
$swimlanes = $swimlaneModel->getAllByStatus(1);
$this->assertEquals(1, $swimlanes[0]['position']);
$this->assertEquals(4, $swimlanes[0]['id']);
$this->assertEquals(2, $swimlanes[1]['position']);
$this->assertEquals(1, $swimlanes[1]['id']);
}
}