timemanager/frontend/src/app/active-task-overview/active-task-overview.component.ts
Sebastian Böckelmann d7b2683ffc
All checks were successful
Java CI with Maven / build-and-push-frontend (push) Successful in 7s
Java CI with Maven / build-and-push-backend (push) Successful in 7s
Ui Support for Creating Subtasks
2024-03-16 10:57:50 +01:00

119 lines
3.9 KiB
TypeScript

import {Component, OnInit} from '@angular/core';
import {NavigationLink} from "../navigation-link-list/navigation-link-list.component";
import {ScheduleService, TaskService, TaskTaskgroupInfo} from "../../api";
import {MatSnackBar} from "@angular/material/snack-bar";
import {Router} from "@angular/router";
import {TaskEditorData} from "../tasks/task-editor/TaskEditorData";
import {TaskEditorComponent} from "../tasks/task-editor/task-editor.component";
import {MatDialog} from "@angular/material/dialog";
@Component({
selector: 'app-active-task-overview',
templateUrl: './active-task-overview.component.html',
styleUrls: ['./active-task-overview.component.css']
})
export class ActiveTaskOverviewComponent implements OnInit{
tasks: TaskTaskgroupInfo[] = []
defaultNavigationLinkPath: NavigationLink[] = [
{
linkText: "Dashboard",
routerLink: ['/']
},
{
linkText: "Active Tasks",
routerLink: ["/active"]
}
]
constructor(private taskService: TaskService,
private snackbar: MatSnackBar,
private scheduleService: ScheduleService,
private router: Router,
private dialog: MatDialog) {
}
ngOnInit(): void {
this.taskService.tasksAllScopeDetailedGet("ACTIVE", true).subscribe({
next: resp => {
this.tasks = resp as TaskTaskgroupInfo[]
},
error: err => {
if(err.status == 403) {
this.snackbar.open("No permissions", "", {duration: 2000});
} else if(err.status == 404) {
this.snackbar.open("Not found", "", {duration: 2000});
} else {
this.snackbar.open("Unexpected error", "", {duration: 2000});
}
}
})
}
calcProgress(task: TaskTaskgroupInfo): number {
console.log(task.workTime / task.eta * 100)
return task.workTime / task.eta * 100
}
startTaskNow(task: TaskTaskgroupInfo) {
this.scheduleService.schedulesTaskIDNowPost(task.taskID).subscribe({
next: resp => {
this.router.navigateByUrl("/");
},
error: err => {
if(err.status == 403) {
this.snackbar.open("No permissions", "", {duration: 2000});
} else if(err.status == 404) {
this.snackbar.open("Not found", "", {duration: 2000});
} else if(err.status == 409) {
this.snackbar.open("Task already running", "", {duration: 2000});
} else {
this.snackbar.open("Unexpected error", "", {duration: 2000});
}
}
})
}
deleteTask(deletedTask: TaskTaskgroupInfo) {
this.taskService.tasksTaskIDDelete(deletedTask.taskID).subscribe({
next: resp => {
this.tasks = this.tasks.filter(task => task.taskID !== deletedTask.taskID);
},
error: err => {
if(err.status == 403) {
this.snackbar.open("No permissions", "", {duration: 2000});
} else if(err.status == 404) {
this.snackbar.open("Not found", "", {duration: 2000});
} else {
this.snackbar.open("Unexpected error", "", {duration: 2000});
}
}
})
}
editTask(editedTask: TaskTaskgroupInfo) {
const taskEditorInfo: TaskEditorData = {
task: editedTask,
taskgroupID: editedTask.taskgroups[editedTask.taskgroups.length-1].taskgroupID,
parentTask: undefined
};
this.dialog.open(TaskEditorComponent, {data: taskEditorInfo, width: "600px"})
}
finishTask(task: TaskTaskgroupInfo) {
this.taskService.tasksTaskIDFinishPost(task.taskID).subscribe({
next: resp => {
this.tasks = this.tasks.filter(t => t.taskID !== task.taskID)
},
error: err => {
if(err.status == 403) {
this.snackbar.open("No permissions", "", {duration: 2000});
} else if(err.status == 404) {
this.snackbar.open("Not found", "", {duration: 2000});
} else {
this.snackbar.open("Unexpected error", "", {duration: 2000});
}
}
})
}
}