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}); } } }) } }