103 lines
3.5 KiB
TypeScript
103 lines
3.5 KiB
TypeScript
import {Component, Input, OnChanges, ViewChild} from '@angular/core';
|
|
import {TaskEntityInfo, TaskService} from "../../../api";
|
|
import {MatPaginator} from "@angular/material/paginator";
|
|
import {MatSort} from "@angular/material/sort";
|
|
import {MatTableDataSource} from "@angular/material/table";
|
|
import {TaskEditorComponent} from "../task-editor/task-editor.component";
|
|
import {TaskEditorData} from "../task-editor/TaskEditorData";
|
|
import {MatDialog} from "@angular/material/dialog";
|
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
|
import {ClearTaskDialogComponent, ClearTaskDialogData} from "../clear-task-dialog/clear-task-dialog.component";
|
|
|
|
@Component({
|
|
selector: 'app-task-dashboard',
|
|
templateUrl: './task-dashboard.component.html',
|
|
styleUrls: ['./task-dashboard.component.css']
|
|
})
|
|
export class TaskDashboardComponent implements OnChanges{
|
|
ngOnChanges(): void {
|
|
if(this.taskgroupID != undefined) {
|
|
this.taskService.tasksTaskgroupIDStatusGet(this.taskgroupID!, "all").subscribe({
|
|
next: resp => {
|
|
this.datasource = new MatTableDataSource<TaskEntityInfo>(resp);
|
|
this.datasource.paginator = this.paginator!;
|
|
this.datasource.sort = this.sort!;
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
@Input("taskgroupID") taskgroupID: number | undefined
|
|
@ViewChild(MatPaginator) paginator: MatPaginator | undefined
|
|
@ViewChild(MatSort) sort: MatSort | undefined
|
|
|
|
displayedColumns: string[] = ['status', 'name', 'eta', 'start', 'deadline', 'finished', 'edit', 'delete'];
|
|
datasource: MatTableDataSource<TaskEntityInfo> = new MatTableDataSource<TaskEntityInfo>();
|
|
|
|
constructor(private taskService: TaskService,
|
|
private dialog: MatDialog,
|
|
private snackbar: MatSnackBar) {
|
|
}
|
|
|
|
|
|
applyFilter(event: Event) {
|
|
const filterValue = (event.target as HTMLInputElement).value;
|
|
this.datasource.filter = filterValue.trim().toLowerCase();
|
|
|
|
if (this.datasource.paginator) {
|
|
this.datasource.paginator.firstPage();
|
|
}
|
|
}
|
|
|
|
getStatusOfTask(task: TaskEntityInfo) {
|
|
return "green";
|
|
}
|
|
|
|
deleteTask(deletedTask: TaskEntityInfo) {
|
|
this.taskService.tasksTaskIDDelete(deletedTask.taskID).subscribe({
|
|
next: resp => {
|
|
if(resp.status == "success") {
|
|
this.datasource.data = this.datasource.data.filter(task => task.taskID !== deletedTask.taskID);
|
|
} else {
|
|
this.snackbar.open("Unexpected behavior", "", {duration: 2000});
|
|
}
|
|
},
|
|
error: err => {
|
|
if(err.status == 403) {
|
|
this.snackbar.open("No permission", "", {duration: 2000});
|
|
} else if(err.status == 404) {
|
|
this.snackbar.open("Task not found", "", {duration: 2000});
|
|
} else {
|
|
this.snackbar.open("Unexpected error", "", {duration: 2000});
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
editTask(task: TaskEntityInfo) {
|
|
const taskEditorInfo: TaskEditorData = {
|
|
task: task,
|
|
taskgroupID: this.taskgroupID!
|
|
};
|
|
const dialogRef = this.dialog.open(TaskEditorComponent, {data: taskEditorInfo, minWidth: "400px"})
|
|
}
|
|
|
|
clearTasks() {
|
|
const clearTaskData: ClearTaskDialogData = {
|
|
tasks: this.datasource.data,
|
|
taskgroupID: this.taskgroupID!
|
|
}
|
|
const dialogRef = this.dialog.open(ClearTaskDialogComponent, {data: clearTaskData, width: "600px"});
|
|
dialogRef.afterClosed().subscribe(res => {
|
|
if(res != undefined) {
|
|
this.datasource.data = this.datasource.data.filter(task => !res.includes(task));
|
|
}
|
|
})
|
|
}
|
|
addTask(task: TaskEntityInfo) {
|
|
const data = this.datasource.data;
|
|
data.push(task)
|
|
this.datasource.data = data;
|
|
}
|
|
}
|