timemanager/frontend/src/app/tasks/task-detail-overview/task-detail-overview.component.ts
Sebastian Böckelmann 7cd1d68739
All checks were successful
Java CI with Maven / build-and-push-frontend (push) Successful in 8s
Java CI with Maven / build-and-push-backend (push) Successful in 8s
Implement Delete Button in Task Detail Overview
2024-04-17 20:55:50 +02:00

199 lines
6.2 KiB
TypeScript

import {Component, OnInit, ViewChild} from '@angular/core';
import {NavigationLink, NavigationLinkListComponent} from "../../navigation-link-list/navigation-link-list.component";
import {ActivatedRoute, Router} from "@angular/router";
import {
AdvancedScheduleInfo,
ScheduleInfo,
ScheduleService,
TaskEntityInfo,
TaskgroupEntityInfo,
TaskgroupService,
TaskService
} from "../../../api";
import {TaskDashboardComponent} from "../task-dashboard/task-dashboard.component";
import {MatDialog} from "@angular/material/dialog";
import {TaskEditorComponent} from "../task-editor/task-editor.component";
import {TaskEditorData} from "../task-editor/TaskEditorData";
import * as moment from "moment";
import {ScheduleDashboardComponent} from "../../schedules/schedule-dashboard/schedule-dashboard.component";
import {TaskStatusService} from "../task-status.service";
import {TaskSeriesCreatorComponent} from "../task-series-creator/task-series-creator.component";
@Component({
selector: 'app-task-detail-overview',
templateUrl: './task-detail-overview.component.html',
styleUrls: ['./task-detail-overview.component.css']
})
export class TaskDetailOverviewComponent implements OnInit {
defaultNavigationLinkPath: NavigationLink[] = [
{
linkText: "Dashboard",
routerLink: ['/']
},
{
linkText: "Taskgroups",
routerLink: ["/taskgroups"]
}
]
taskgroups: TaskgroupEntityInfo[] = []
taskgroup: TaskgroupEntityInfo | undefined
taskgroupPath: TaskgroupEntityInfo[] = []
taskgroupID: number = -1;
@ViewChild('navLinkList') navLinkListComponent: NavigationLinkListComponent | undefined
task: TaskEntityInfo | undefined
schedules: ScheduleInfo[] = []
schedulesLoaded: boolean = false;
taskStatus: string = "🟢"
currentProgress: string = "0";
futureProgress: string = "0";
subTasks: TaskEntityInfo[] = [];
constructor(private activatedRoute: ActivatedRoute,
private taskgroupService: TaskgroupService,
private taskService: TaskService,
private dialog: MatDialog,
private scheduleService: ScheduleService,
private router: Router,
private taskStatusService: TaskStatusService) {
}
ngOnInit(): void {
this.activatedRoute.paramMap.subscribe(params => {
if (params.has('taskgroupID')) {
this.taskgroupID = Number(params.get('taskgroupID'));
this.taskgroupService.taskgroupsTaskgroupIDGet(this.taskgroupID).subscribe({
next: resp => {
this.taskgroups = resp.children
this.taskgroupPath = resp.ancestors
this.taskgroup = resp.taskgroupInfo;
this.navLinkListComponent!.resetComponent([
{
linkText: "Dashboard",
routerLink: ['/']
},
{
linkText: "Taskgroups",
routerLink: ["/taskgroups"]
}
]);
this.taskgroupPath.forEach(taskgroupEntity => {
this.navLinkListComponent!.addNavigationLink(taskgroupEntity.taskgroupName, ['/taskgroups', taskgroupEntity.taskgroupID.toString()]);
})
}
})
}
if(params.has('taskID')) {
this.taskService.tasksTaskIDGet(Number(params.get('taskID'))).subscribe({
next: resp => {
this.task = resp;
this.taskStatus = this.getStatusOfTask(resp)
this.calcProgress();
}
});
this.scheduleService.schedulesTaskIDGet(Number(params.get('taskID'))).subscribe({
next: resp => {
this.schedules = resp;
this.schedulesLoaded = true;
this.calcProgress();
}
})
this.taskService.tasksTaskIDSubtasksGet(Number(params.get('taskID'))).subscribe({
next: resp => {
this.subTasks = resp;
}
})
}
});
}
getStatusOfTask(task: TaskEntityInfo ) {
const taskStatus = this.taskStatusService.computeTaskStatus(task);
return this.taskStatusService.convertTaskStatusToColor(taskStatus);
}
calcProgress() {
if(this.task != undefined && this.task!.eta > 0) {
const currentProgress = this.task!.workTime / this.task!.eta * 100;
let futureProgress = 0;
this.schedules.forEach(schedule => {
if(schedule.scheduleType == "ADVANCED" && schedule.startTime == null) {
let advancedSchedule: AdvancedScheduleInfo = schedule as AdvancedScheduleInfo;
if(moment(advancedSchedule.scheduleStartTime).isBefore(moment())) {
const duration = moment.duration(moment(advancedSchedule.scheduleStopTime).diff(moment(advancedSchedule.scheduleStartTime)));
const plannedMinutes = duration.asMinutes();
futureProgress += plannedMinutes;
}
}
})
this.futureProgress = (futureProgress) / this.task!.eta *100 + "%";
this.currentProgress = currentProgress + "%";
}
}
openTaskEditor() {
if(this.task != undefined) {
const taskEditorInfo: TaskEditorData = {
task: this.task!,
taskgroupID: this.taskgroupID!,
parentTask: undefined
};
this.dialog.open(TaskEditorComponent, {data: taskEditorInfo, width: "600px"})
}
}
startTaskNow() {
if(this.task != undefined) {
this.scheduleService.schedulesTaskIDNowPost(this.task.taskID).subscribe({
next: resp => {
this.router.navigateByUrl('/');
}
});
}
}
finishTask() {
this.taskService.tasksTaskIDFinishPost(this.task!.taskID).subscribe({
next: resp => {
this.task!.finished = !this.task!.finished;
}
})
}
openRepeatingTaskEditor() {
const dialogRef = this.dialog.open(TaskSeriesCreatorComponent, {
data: this.task!,
minWidth: "400px"
})
}
addSubtask() {
const editorData: TaskEditorData = {
task: undefined,
taskgroupID: this.taskgroupID,
parentTask: this.task
}
const dialogRef = this.dialog.open(TaskEditorComponent, {
data: editorData,
minWidth: "400px"
})
}
deleteTask() {
this.taskService.tasksTaskIDDelete(this.task!.taskID).subscribe({
next: resp => {
this.router.navigateByUrl("/")
}
})
}
}