From 18d245958d5b40e6faccd84968619ab60651c8d6 Mon Sep 17 00:00:00 2001 From: Matthew Ross Date: Sat, 2 Sep 2017 13:25:24 -0400 Subject: [PATCH] Fix task ordering when using drag/drop --- src/api/controllers/Tasks.php | 8 +++++- src/app/board/board.component.ts | 13 +++++++++ src/app/board/column/column.component.ts | 36 ++++++++++++------------ src/app/board/task/task.component.ts | 1 - src/index.html | 2 +- 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/api/controllers/Tasks.php b/src/api/controllers/Tasks.php index 3756406..98e6a57 100644 --- a/src/api/controllers/Tasks.php +++ b/src/api/controllers/Tasks.php @@ -181,10 +181,16 @@ class Tasks extends BaseController { return $column->board_id; } + private function sortTasks($a, $b) { + return strcmp($a->position, $b->position); + } + private function updateTaskOrder($task, $user, $isNew) { $column = R::load('column', $task->column_id); $user_opts = R::load('useroption', $user->user_option_id); + usort($column->xownTaskList, array($this, 'sortTasks')); + $counter = 1; foreach ($column->xownTaskList as $task) { $task->position = $counter; @@ -330,7 +336,7 @@ class Tasks extends BaseController { } } - function updateTaskColor($taskId, $beforePoints, $afterPoints) { + private function updateTaskColor($taskId, $beforePoints, $afterPoints) { $task = R::load('task', $taskId); $diff = (float)$beforePoints - (float)$afterPoints; diff --git a/src/app/board/board.component.ts b/src/app/board/board.component.ts index a5e5610..c7c1a9c 100644 --- a/src/app/board/board.component.ts +++ b/src/app/board/board.component.ts @@ -115,11 +115,24 @@ export class BoardDisplay implements OnInit { } }); + let lastTaskId: number, + lastToColumnId: number, + lastFromColumnId: number; + this.dragula.dropModel.subscribe((value: any) => { let taskId = +value[1].id, toColumnId = +value[2].parentNode.id, fromColumnId = +value[3].parentNode.id; + if (lastTaskId === taskId && lastToColumnId === toColumnId && + lastFromColumnId === fromColumnId) { + return; + } + + lastTaskId = taskId; + lastToColumnId = toColumnId; + lastFromColumnId = fromColumnId; + this.activeBoard.columns.forEach(column => { if (column.id === toColumnId || column.id === fromColumnId) { let position = 1, diff --git a/src/app/board/column/column.component.ts b/src/app/board/column/column.component.ts index 9733d8c..93f60f9 100644 --- a/src/app/board/column/column.component.ts +++ b/src/app/board/column/column.component.ts @@ -126,24 +126,24 @@ export class ColumnDisplay implements OnInit { } sortTasks() { - switch (this.sortOption) { - case 'pos': - this.columnData.tasks.sort((a, b) => { - return a.position - b.position; - }); - break; - case 'due': - this.columnData.tasks.sort((a, b) => { - return new Date(a.due_date).getTime() - - new Date(b.due_date).getTime(); - }); - break; - case 'pnt': - this.columnData.tasks.sort((a, b) => { - return b.points - a.points; - }); - break; - } + switch (this.sortOption) { + case 'pos': + this.columnData.tasks.sort((a, b) => { + return a.position - b.position; + }); + break; + case 'due': + this.columnData.tasks.sort((a, b) => { + return new Date(a.due_date).getTime() - + new Date(b.due_date).getTime(); + }); + break; + case 'pnt': + this.columnData.tasks.sort((a, b) => { + return b.points - a.points; + }); + break; + } } toggleCollapsed() { diff --git a/src/app/board/task/task.component.ts b/src/app/board/task/task.component.ts index eff0808..df0c738 100644 --- a/src/app/board/task/task.component.ts +++ b/src/app/board/task/task.component.ts @@ -171,7 +171,6 @@ export class TaskDisplay implements OnInit { '" target="tb_external" rel="noreferrer">' + result[0] + ''; - // text = text.replace(result[0], link); replacements.push({ str: result[0], link diff --git a/src/index.html b/src/index.html index 0ea3ea3..8fd3370 100644 --- a/src/index.html +++ b/src/index.html @@ -2,7 +2,7 @@ TaskBoard - Kanban App - +