(hopefully) fix desync problems

This commit is contained in:
Olivier 'reivilibre' 2021-08-17 05:53:59 +01:00
parent b14228e28e
commit 9a7be5f2cb
2 changed files with 36 additions and 6 deletions

View File

@ -89,6 +89,25 @@ export class BoardDisplayComponent implements OnInit, OnDestroy {
boardService.showTask(params.taskId);
});
this.subs.push(sub);
this.subscribeEnableActiveBoard();
}
subscribeEnableActiveBoard() {
// We must do this otherwise the board can become out of sync when we update it and receive a new version of it.
// (Without this, we can't move more than one task on the board per page load!)
this.boardService.activeBoardChanged.subscribe(board => {
//console.log("enabling active board");
if (board) {
this.activeBoard = board;
this.pageName = board.name;
this.title.setTitle('TaskBoard - ' + this.activeBoard.name);
} else {
this.activeBoard = new Board();
this.pageName = 'No board...';
this.title.setTitle('TaskBoard');
}
});
}
ngOnInit() {
@ -201,11 +220,7 @@ export class BoardDisplayComponent implements OnInit, OnDestroy {
this.userFilter = null;
this.categoryFilter = null;
this.activeBoard = board;
this.pageName = board.name;
this.boardService.updateActiveBoard(board);
this.title.setTitle('TaskBoard - ' + this.activeBoard.name);
this.loading = false;
}

View File

@ -287,21 +287,36 @@ export class ColumnDisplayComponent implements OnInit, OnDestroy {
}
drop(event: CdkDragDrop<string[]>) {
const colId = event.container.id.substr(3) as unknown as number - 1;
const column = this.activeBoard.columns[colId];
const prevColId = event.previousContainer.id.substr(3) as unknown as number - 1;
const prevColumn = this.activeBoard.columns[prevColId];
if (event.previousContainer === event.container) {
this.moveItemInArray(event.container.data,
event.previousIndex, event.currentIndex);
// console.log("same", event.previousIndex, event.currentIndex, this.activeBoard);
} else {
this.transferArrayItem(event.previousContainer.data,
event.container.data, event.previousIndex, event.currentIndex);
// console.log("diff", event.previousIndex, event.currentIndex, this.activeBoard, event.container);
}
const colId = event.container.id.substr(3) as unknown as number - 1;
const column = this.activeBoard.columns[colId];
column.tasks.forEach((task, index) => {
task.position = index + 1;
});
if (prevColId != colId) {
prevColumn.tasks.forEach((task, index) => {
task.position = index + 1;
});
}
// console.log("updating", column.id, column.tasks.map(e => e.id));
this.boardService.updateColumn(column).subscribe((response: ApiResponse) => {
if (response.status !== 'success') {
response.alerts.forEach(note => this.notes.add(note));