Task context menu generation and refactoring
This commit is contained in:
parent
6cb8069234
commit
588dabae44
@ -60,6 +60,7 @@
|
||||
<div class="board" *ngIf="activeBoard">
|
||||
<tb-column class="column"
|
||||
*ngFor="let column of activeBoard.columns"
|
||||
[column]="column"></tb-column>
|
||||
[column]="column"
|
||||
[boards]="boards"></tb-column>
|
||||
</div>
|
||||
|
||||
|
@ -29,7 +29,8 @@
|
||||
|
||||
<div class="tasks">
|
||||
<tb-task class="task-container" *ngFor="let task of columnData.ownTask"
|
||||
[task]="task" [add-task]="getShowModalFunction(task.id)"
|
||||
[task]="task" [boards]="boards"
|
||||
[add-task]="getShowModalFunction(task.id)"
|
||||
[remove-task]="getRemoveTaskFunction(task.id)"></tb-task>
|
||||
</div>
|
||||
|
||||
|
@ -46,6 +46,7 @@ export class ColumnDisplay implements OnInit {
|
||||
private taskToRemove: number;
|
||||
|
||||
@Input('column') columnData: Column;
|
||||
@Input('boards') boards: Array<Board>;
|
||||
|
||||
constructor(private elRef: ElementRef,
|
||||
private auth: AuthService,
|
||||
@ -138,14 +139,7 @@ export class ColumnDisplay implements OnInit {
|
||||
}
|
||||
});
|
||||
|
||||
let newBoard = new Board(+boardData.id, boardData.name,
|
||||
boardData.is_active === '1',
|
||||
boardData.ownColumn,
|
||||
boardData.ownCategory,
|
||||
boardData.ownAutoAction,
|
||||
boardData.ownIssuetracker,
|
||||
boardData.sharedUser);
|
||||
|
||||
let newBoard = this.convertBoardData(boardData);
|
||||
this.boardService.updateActiveBoard(newBoard);
|
||||
});
|
||||
}
|
||||
@ -159,20 +153,21 @@ export class ColumnDisplay implements OnInit {
|
||||
return;
|
||||
}
|
||||
|
||||
let boardData = response.data[1][0];
|
||||
|
||||
let newBoard = new Board(+boardData.id, boardData.name,
|
||||
boardData.is_active === '1',
|
||||
boardData.ownColumn,
|
||||
boardData.ownCategory,
|
||||
boardData.ownAutoAction,
|
||||
boardData.ownIssuetracker,
|
||||
boardData.sharedUser);
|
||||
|
||||
let newBoard = this.convertBoardData(response.data[1][0]);
|
||||
this.boardService.updateActiveBoard(newBoard);
|
||||
});
|
||||
}
|
||||
|
||||
private convertBoardData(boardData: any): Board {
|
||||
return new Board(+boardData.id, boardData.name,
|
||||
boardData.is_active === '1',
|
||||
boardData.ownColumn,
|
||||
boardData.ownCategory,
|
||||
boardData.ownAutoAction,
|
||||
boardData.ownIssuetracker,
|
||||
boardData.sharedUser);
|
||||
}
|
||||
|
||||
private getRemoveTaskFunction(taskId: number): Function {
|
||||
return () => {
|
||||
this.taskToRemove = taskId;
|
||||
|
@ -33,11 +33,18 @@ export class TaskDisplay implements OnInit {
|
||||
private selectMenuItem: ContextMenuItem;
|
||||
|
||||
private activeBoard: Board;
|
||||
private boardsList: Array<Board>;
|
||||
|
||||
@Input('task') taskData: Task;
|
||||
@Input('add-task') addTask: Function;
|
||||
@Input('remove-task') removeTask: Function;
|
||||
|
||||
@Input('boards')
|
||||
set boards(boards: Array<Board>) {
|
||||
this.boardsList = boards;
|
||||
this.generateContextMenuItems();
|
||||
}
|
||||
|
||||
constructor(private auth: AuthService,
|
||||
private sanitizer: DomSanitizer,
|
||||
private boardService: BoardService,
|
||||
@ -48,10 +55,12 @@ export class TaskDisplay implements OnInit {
|
||||
});
|
||||
|
||||
boardService.activeBoardChanged.subscribe((board: Board) => {
|
||||
this.activeBoard = board;
|
||||
|
||||
let menuText = 'Move to Column: <select>';
|
||||
|
||||
board.columns.forEach((column: Column) => {
|
||||
menuText += '<option>' + column.name + '</option>';
|
||||
menuText += '<option value="column.id">' + column.name + '</option>';
|
||||
});
|
||||
|
||||
menuText += '</select>';
|
||||
@ -63,18 +72,7 @@ export class TaskDisplay implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.contextMenuItems = [
|
||||
new ContextMenuItem('View Task'),
|
||||
new ContextMenuItem('Edit Task'),
|
||||
new ContextMenuItem('Remove Task', this.removeTask),
|
||||
new ContextMenuItem('', null, true),
|
||||
new ContextMenuItem('Copy To Board'),
|
||||
new ContextMenuItem('Move To Board'),
|
||||
new ContextMenuItem('', null, true),
|
||||
this.selectMenuItem,
|
||||
new ContextMenuItem('', null, true),
|
||||
new ContextMenuItem('Add Task', this.addTask)
|
||||
];
|
||||
this.generateContextMenuItems();
|
||||
}
|
||||
|
||||
getTaskDescription(): SafeHtml {
|
||||
@ -92,6 +90,41 @@ export class TaskDisplay implements OnInit {
|
||||
return yiq >= 140 ? '#333333' : '#efefef';
|
||||
}
|
||||
|
||||
private generateContextMenuItems() {
|
||||
this.contextMenuItems = [
|
||||
new ContextMenuItem('View Task'),
|
||||
new ContextMenuItem('Edit Task'),
|
||||
new ContextMenuItem('Remove Task', this.removeTask),
|
||||
new ContextMenuItem('', null, true),
|
||||
this.selectMenuItem,
|
||||
new ContextMenuItem('', null, true),
|
||||
new ContextMenuItem('Add Task', this.addTask)
|
||||
];
|
||||
|
||||
if (this.boardsList.length > 1) {
|
||||
this.contextMenuItems
|
||||
.splice(3, 0,
|
||||
new ContextMenuItem('', null, true),
|
||||
this.getMenuItem('Copy'),
|
||||
this.getMenuItem('Move'));
|
||||
}
|
||||
}
|
||||
|
||||
private getMenuItem(text: string): ContextMenuItem {
|
||||
let menuText = text + ' to Board: <select>';
|
||||
|
||||
this.boardsList.forEach((board: Board) => {
|
||||
if (board.name !== this.activeBoard.name) {
|
||||
menuText += '<option value="board.id">' + board.name + '</option>';
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
menuText += '</select>';
|
||||
|
||||
return new ContextMenuItem(menuText, null, false, false);
|
||||
}
|
||||
|
||||
private initMarked() {
|
||||
let renderer = new marked.Renderer();
|
||||
|
||||
|
Reference in New Issue
Block a user