timemanager/frontend/src/app/dashboard/taskgroup-overview/taskgroup-overview.component.ts
Sebastian Böckelmann ec5c74ca7d
All checks were successful
Java CI with Maven / test (push) Successful in 34s
Java CI with Maven / build-and-push-frontend (push) Successful in 8s
Java CI with Maven / build-and-push-backend (push) Successful in 8s
Remove unfinished schedules from Taskoverview and taskgroup-overview
2023-11-18 08:36:37 +01:00

116 lines
3.7 KiB
TypeScript

import {Component, EventEmitter, Output} from '@angular/core';
import {MatIconModule} from "@angular/material/icon";
import {MatButtonModule} from "@angular/material/button";
import {MatTreeFlatDataSource, MatTreeFlattener, MatTreeModule} from "@angular/material/tree";
import {FlatTreeControl} from "@angular/cdk/tree";
import {RecursiveTaskgroupInfo, TaskgroupService, TaskOverviewInfo, TaskShortInfo} from "../../../api";
import {TaskCreationEmitterInfo, TaskOverviewComponent} from "../task-overview/task-overview.component";
/** Flat node with expandable and level information */
interface ExampleFlatNode {
expandable: boolean;
level: number;
name: string
activeTasks: number;
hasOverdueTask: boolean;
tasks: TaskOverviewInfo[];
taskgroupID: number
}
export interface TaskOverviewData {
tasks: TaskOverviewInfo[],
taskgroupID: number
}
@Component({
selector: 'app-taskgroup-overview',
templateUrl: './taskgroup-overview.component.html',
styleUrls: ['./taskgroup-overview.component.css']
})
export class TaskgroupOverviewComponent {
@Output('taskgroupSelected') taskgroupSelected: EventEmitter<TaskOverviewData> = new EventEmitter<TaskOverviewData>();
private _transformer = (node: RecursiveTaskgroupInfo, level: number) => {
return {
expandable: !!node.childTaskgroups && node.childTaskgroups.length > 0,
name: node.taskgroupName,
level: level,
activeTasks: node.amountActiveTasks,
hasOverdueTask: node.hasOverdueTask,
tasks: node.activeTasks,
taskgroupID: node.taskgroupID
};
};
treeControl = new FlatTreeControl<ExampleFlatNode>(
node => node.level,
node => node.expandable,
);
treeFlattener = new MatTreeFlattener(
this._transformer,
node => node.level,
node => node.expandable,
node => node.childTaskgroups,
);
dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
constructor(private taskgroupService: TaskgroupService) {
}
ngOnInit() {
this.taskgroupService.taskgroupsTreeGet().subscribe({
next: resp => {
this.dataSource.data = resp;
}
})
}
hasChild = (_: number, node: ExampleFlatNode) => node.expandable;
onSelectTaskgroup(tasks: TaskOverviewInfo[], taskgroupID: number) {
this.taskgroupSelected.emit({
tasks: tasks,
taskgroupID: taskgroupID
})
}
finishTask(taskID: number) {
let taskgroupQueue : RecursiveTaskgroupInfo[] = this.dataSource.data.slice();
while(taskgroupQueue.length > 0) {
const currentTaskgroup = taskgroupQueue.pop()!;
const searchedTask = currentTaskgroup.activeTasks.find(searchedTask => searchedTask.taskID === taskID);
if(searchedTask == undefined) {
currentTaskgroup.childTaskgroups.forEach(childTask => {
taskgroupQueue.push(childTask);
})
} else {
currentTaskgroup.activeTasks = currentTaskgroup.activeTasks.filter(taskFilter => taskFilter.taskID !== searchedTask.taskID);
}
}
}
private findTaskgroup(taskgroupID: number) {
let taskgroupQueue : RecursiveTaskgroupInfo[] = this.dataSource.data.slice();
while(taskgroupQueue.length > 0) {
const currentTaskgroup = taskgroupQueue.pop()!;
if(currentTaskgroup.taskgroupID === taskgroupID) {
return currentTaskgroup;
} else {
currentTaskgroup.childTaskgroups.forEach(childgroup => taskgroupQueue.push(childgroup));
}
}
return undefined
}
onCreateTask(taskCreationInfo: TaskCreationEmitterInfo) {
const taskgroup: RecursiveTaskgroupInfo | undefined = this.findTaskgroup(taskCreationInfo.taskgroupID);
if(taskgroup != undefined) {
taskgroup.activeTasks.push(taskCreationInfo.task);
}
}
}