Board drag/drop now uses Angular CDK - minor cleanup
This commit is contained in:
parent
4cc8512713
commit
fe5f529320
@ -73,7 +73,7 @@
|
|||||||
<p></p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="board" *ngIf="activeBoard">
|
<div class="board" cdkDropListGroup *ngIf="activeBoard">
|
||||||
<tb-column class="column" [id]="column.id"
|
<tb-column class="column" [id]="column.id"
|
||||||
*ngFor="let column of activeBoard.columns"
|
*ngFor="let column of activeBoard.columns"
|
||||||
[column]="column"
|
[column]="column"
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
ApiResponse,
|
ApiResponse,
|
||||||
Board,
|
Board,
|
||||||
Column,
|
Column,
|
||||||
User,
|
User
|
||||||
} from '../shared/models';
|
} from '../shared/models';
|
||||||
import {
|
import {
|
||||||
AuthService,
|
AuthService,
|
||||||
@ -180,9 +180,11 @@ export class BoardDisplayComponent implements OnInit, OnDestroy {
|
|||||||
updateBoards(): void {
|
updateBoards(): void {
|
||||||
this.boardService.getBoards().subscribe((response: ApiResponse) => {
|
this.boardService.getBoards().subscribe((response: ApiResponse) => {
|
||||||
this.boards = [];
|
this.boards = [];
|
||||||
|
|
||||||
if (response.data.length > 1) {
|
if (response.data.length > 1) {
|
||||||
this.updateBoardsList(response.data[1]);
|
this.updateBoardsList(response.data[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -252,18 +254,5 @@ export class BoardDisplayComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* istanbul ignore next */
|
|
||||||
private changeTaskColumn(taskId: number, toColumnId: number) {
|
|
||||||
const column = this.activeBoard.columns
|
|
||||||
.find(col => col.id === toColumnId);
|
|
||||||
const task = column.tasks.find(ta => ta.id === taskId);
|
|
||||||
|
|
||||||
if (task) {
|
|
||||||
task.column_id = toColumnId;
|
|
||||||
|
|
||||||
this.boardService.updateTask(task).subscribe();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,9 +72,11 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tasks" *ngIf="columnData" cdkDropList
|
<div class="tasks" *ngIf="columnData"
|
||||||
[cdkDropListData]="columnData.tasks">
|
cdkDropList
|
||||||
<tb-task class="task-container" [id]="task.id"
|
[cdkDropListData]="columnData.tasks"
|
||||||
|
(cdkDropListDropped)="drop($event, +columnData.id - 1)">
|
||||||
|
<tb-task class="task-container" [id]="task.id" cdkDrag
|
||||||
*ngFor="let task of columnData.tasks"
|
*ngFor="let task of columnData.tasks"
|
||||||
[task]="task" [boards]="boards"
|
[task]="task" [boards]="boards"
|
||||||
[add-task]="getShowModalFunction()"
|
[add-task]="getShowModalFunction()"
|
||||||
|
@ -8,6 +8,11 @@ import {
|
|||||||
Output
|
Output
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { DomSanitizer, } from '@angular/platform-browser';
|
import { DomSanitizer, } from '@angular/platform-browser';
|
||||||
|
import {
|
||||||
|
CdkDragDrop,
|
||||||
|
moveItemInArray,
|
||||||
|
transferArrayItem
|
||||||
|
} from '@angular/cdk/drag-drop';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ApiResponse,
|
ApiResponse,
|
||||||
@ -39,7 +44,6 @@ export class ColumnDisplayComponent implements OnInit, OnDestroy {
|
|||||||
private fileUpload: any;
|
private fileUpload: any;
|
||||||
private subs = [];
|
private subs = [];
|
||||||
|
|
||||||
public tasks: Task[];
|
|
||||||
public viewTaskActivities: ActivitySimple[];
|
public viewTaskActivities: ActivitySimple[];
|
||||||
|
|
||||||
public showActivity: boolean;
|
public showActivity: boolean;
|
||||||
@ -90,7 +94,6 @@ export class ColumnDisplayComponent implements OnInit, OnDestroy {
|
|||||||
public boardService: BoardService,
|
public boardService: BoardService,
|
||||||
private sanitizer: DomSanitizer) {
|
private sanitizer: DomSanitizer) {
|
||||||
this.templateElement = elRef.nativeElement;
|
this.templateElement = elRef.nativeElement;
|
||||||
this.tasks = [];
|
|
||||||
this.collapseTasks = false;
|
this.collapseTasks = false;
|
||||||
this.sortOption = 'pos';
|
this.sortOption = 'pos';
|
||||||
|
|
||||||
@ -240,6 +243,24 @@ export class ColumnDisplayComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop(event: CdkDragDrop<string[]>, colIndex: number) {
|
||||||
|
if (event.previousContainer === event.container) {
|
||||||
|
moveItemInArray(event.container.data,
|
||||||
|
event.previousIndex, event.currentIndex);
|
||||||
|
} else {
|
||||||
|
transferArrayItem(event.previousContainer.data,
|
||||||
|
event.container.data, event.previousIndex, event.currentIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.activeBoard.columns[colIndex].tasks.forEach((item, index) => {
|
||||||
|
item.position = index + 1;
|
||||||
|
item.column_id = this.activeBoard.columns[colIndex].id;
|
||||||
|
});
|
||||||
|
|
||||||
|
const task = this.activeBoard.columns[colIndex].tasks[event.currentIndex];
|
||||||
|
this.boardService.updateTask(task).subscribe(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
updateTask() {
|
updateTask() {
|
||||||
this.saving = true;
|
this.saving = true;
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
Output
|
Output
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { DomSanitizer } from '@angular/platform-browser';
|
import { DomSanitizer } from '@angular/platform-browser';
|
||||||
|
import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ApiResponse,
|
ApiResponse,
|
||||||
@ -83,23 +84,6 @@ export class TaskDisplayComponent implements OnInit {
|
|||||||
this.convertTaskDescription();
|
this.convertTaskDescription();
|
||||||
}
|
}
|
||||||
|
|
||||||
private convertTaskDescription() {
|
|
||||||
if (!this.taskData || !this.taskData.description) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = this.boardService.convertMarkdown(
|
|
||||||
this.taskData.description, this.markedCallback, true
|
|
||||||
);
|
|
||||||
|
|
||||||
data.html.replace(/(\{)([^}]+)(\})/g, '{{ "{" }}$2{{ "}" }}');
|
|
||||||
if (data.counts.total) {
|
|
||||||
this.percentComplete = data.counts.complete / data.counts.total;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.taskData.html = this.sanitizer.bypassSecurityTrustHtml(data.html);
|
|
||||||
}
|
|
||||||
|
|
||||||
getPercentStyle() {
|
getPercentStyle() {
|
||||||
return this.sanitizer.bypassSecurityTrustStyle(
|
return this.sanitizer.bypassSecurityTrustStyle(
|
||||||
'padding: 0; height: 5px; background-color: rgba(0, 0, 0, .4); ' +
|
'padding: 0; height: 5px; background-color: rgba(0, 0, 0, .4); ' +
|
||||||
@ -223,6 +207,23 @@ export class TaskDisplayComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private convertTaskDescription() {
|
||||||
|
if (!this.taskData || !this.taskData.description) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = this.boardService.convertMarkdown(
|
||||||
|
this.taskData.description, this.markedCallback, true
|
||||||
|
);
|
||||||
|
|
||||||
|
data.html.replace(/(\{)([^}]+)(\})/g, '{{ "{" }}$2{{ "}" }}');
|
||||||
|
if (data.counts.total) {
|
||||||
|
this.percentComplete = data.counts.complete / data.counts.total;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.taskData.html = this.sanitizer.bypassSecurityTrustHtml(data.html);
|
||||||
|
}
|
||||||
|
|
||||||
private checkDueDate() {
|
private checkDueDate() {
|
||||||
if (!this.taskData || this.taskData.due_date === '') {
|
if (!this.taskData || this.taskData.due_date === '') {
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user