(hopefully) fix desync problems
This commit is contained in:
parent
b14228e28e
commit
9a7be5f2cb
@ -89,6 +89,25 @@ export class BoardDisplayComponent implements OnInit, OnDestroy {
|
|||||||
boardService.showTask(params.taskId);
|
boardService.showTask(params.taskId);
|
||||||
});
|
});
|
||||||
this.subs.push(sub);
|
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() {
|
ngOnInit() {
|
||||||
@ -201,11 +220,7 @@ export class BoardDisplayComponent implements OnInit, OnDestroy {
|
|||||||
this.userFilter = null;
|
this.userFilter = null;
|
||||||
this.categoryFilter = null;
|
this.categoryFilter = null;
|
||||||
|
|
||||||
this.activeBoard = board;
|
|
||||||
this.pageName = board.name;
|
|
||||||
|
|
||||||
this.boardService.updateActiveBoard(board);
|
this.boardService.updateActiveBoard(board);
|
||||||
this.title.setTitle('TaskBoard - ' + this.activeBoard.name);
|
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
|
@ -287,21 +287,36 @@ export class ColumnDisplayComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
drop(event: CdkDragDrop<string[]>) {
|
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) {
|
if (event.previousContainer === event.container) {
|
||||||
this.moveItemInArray(event.container.data,
|
this.moveItemInArray(event.container.data,
|
||||||
event.previousIndex, event.currentIndex);
|
event.previousIndex, event.currentIndex);
|
||||||
|
// console.log("same", event.previousIndex, event.currentIndex, this.activeBoard);
|
||||||
} else {
|
} else {
|
||||||
this.transferArrayItem(event.previousContainer.data,
|
this.transferArrayItem(event.previousContainer.data,
|
||||||
event.container.data, event.previousIndex, event.currentIndex);
|
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) => {
|
column.tasks.forEach((task, index) => {
|
||||||
task.position = index + 1;
|
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) => {
|
this.boardService.updateColumn(column).subscribe((response: ApiResponse) => {
|
||||||
if (response.status !== 'success') {
|
if (response.status !== 'success') {
|
||||||
response.alerts.forEach(note => this.notes.add(note));
|
response.alerts.forEach(note => this.notes.add(note));
|
||||||
|
Reference in New Issue
Block a user