timemanager/frontend/src/app/dashboard/active-schedule/active-schedule.component.ts
Sebastian Böckelmann cd98423f6b
All checks were successful
Java CI with Maven / build-and-push-frontend (push) Successful in 9s
Java CI with Maven / build-and-push-backend (push) Successful in 8s
Added Link from active schedule to task detail-overview
2024-04-18 20:09:06 +02:00

152 lines
4.4 KiB
TypeScript

import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {
ScheduleInfo,
ScheduleService,
TaskgroupEntityInfo,
TaskOverviewInfo,
TaskScheduleStopResponse
} from "../../../api";
import {StopActiveScheduleInfo} from "./StopActiveScheduleInfo";
import {TaskOverviewComponent} from "../task-overview/task-overview.component";
import {MatDialog} from "@angular/material/dialog";
import {ForgottenTaskStartDialogComponent} from "../forgotten-task-start-dialog/forgotten-task-start-dialog.component";
import {StopScheduleManuallyComponent} from "./stop-schedule-manually/stop-schedule-manually.component";
export interface StopActiveScheduleEmitterInfo {
stopactiveScheduleResponse: StopActiveScheduleInfo,
finish: boolean,
taskID: number
}
@Component({
selector: 'app-active-schedule',
templateUrl: './active-schedule.component.html',
styleUrls: ['./active-schedule.component.css']
})
export class ActiveScheduleComponent implements OnInit{
activeSchedule: ScheduleInfo | undefined
taskgroupID: number | undefined
startTime: number = 0;
currentTime: number = 0;
displayTime: string = "00:00:00"
@Output('onStopTask') scheduleStopEmitter = new EventEmitter<StopActiveScheduleEmitterInfo>;
@Output('registerForgotten') registerForgottenEmitter = new EventEmitter<TaskScheduleStopResponse>
constructor(private scheduleService: ScheduleService,
private dialog: MatDialog) {
}
updateTime() {
const now = Date.now();
const elapsed = this.activeSchedule != undefined ? now - this.startTime + this.currentTime : this.currentTime;
this.displayTime = this.formatTime(elapsed);
requestAnimationFrame(() => this.updateTime());
}
formatTime(milliseconds: number): string {
const seconds = Math.floor((milliseconds / 1000) % 60);
const minutes = Math.floor((milliseconds / 1000 / 60) % 60);
const hours = Math.floor(milliseconds / 1000 / 60 / 60);
return `${this.padNumber(hours)}:${this.padNumber(minutes)}:${this.padNumber(seconds)}`;
}
padNumber(num: number): string {
return num < 10 ? `0${num}` : `${num}`;
}
ngOnInit(): void {
this.scheduleService.schedulesActiveGet().subscribe({
next: resp => {
if(resp.scheduleID >= 0) {
this.activateSchedule(resp);
this.taskgroupID = resp.taskgroupPath[resp.taskgroupPath.length-1].taskgroupID
console.log(this.taskgroupID)
}
},
})
}
stopTask(finish: boolean) {
this.scheduleService.schedulesScheduleIDStopFinishPost(this.activeSchedule!.scheduleID, finish).subscribe({
next: resp => {
this.scheduleStopEmitter.emit({
stopactiveScheduleResponse: {
schedule: this.activeSchedule!,
workedMinutes: resp.workTime
},
finish: finish,
taskID: this.activeSchedule!.task.taskID
})
console.log(resp.workTime)
this.activeSchedule = undefined
}
})
}
activateSchedule(schedule: ScheduleInfo) {
this.activeSchedule = schedule;
this.startTime = new Date(this.activeSchedule.startTime).getTime();
this.updateTime();
}
finishTaskByOverview(task: TaskOverviewInfo) {
this.activeSchedule = undefined
}
abortSchedule() {
this.scheduleService.schedulesScheduleIDDelete(this.activeSchedule!.scheduleID).subscribe({
next: resp => {
this.activeSchedule = undefined;
}
})
}
finishSchedule() {
this.scheduleService.schedulesScheduleIDStopFinishPost(this.activeSchedule!.scheduleID, true).subscribe({
next: resp => {
this.activeSchedule = undefined;
}
})
}
finishManual() {
const dialogRef = this.dialog.open(StopScheduleManuallyComponent, {
data: this.activeSchedule,
minWidth: "400px"})
dialogRef.afterClosed().subscribe(res => {
if(res != undefined) {
this.scheduleStopEmitter.emit({
finish: false,
taskID: this.activeSchedule!.scheduleID,
stopactiveScheduleResponse: {
schedule: this.activeSchedule!,
workedMinutes: res
}
})
this.activeSchedule = undefined;
}
})
}
openForgettedActivityDialog() {
const dialogRef = this.dialog.open(ForgottenTaskStartDialogComponent, {width: "400px"})
dialogRef.afterClosed().subscribe(res => {
if(res != undefined) {
this.registerForgottenEmitter.emit(res);
}
})
}
}