timemanager/frontend/src/app/dashboard/forgotten-task-start-dialog/forgotten-task-start-dialog.component.ts
Sebastian Böckelmann 5f60470e2a
All checks were successful
Java CI with Maven / test (push) Successful in 37s
Java CI with Maven / build-and-push-frontend (push) Successful in 7s
Java CI with Maven / build-and-push-backend (push) Successful in 7s
Reset select task in forgotten task scheduler
2023-11-18 18:45:38 +01:00

182 lines
5.1 KiB
TypeScript

import {Component, OnInit} from '@angular/core';
import {
ForgottenActivityRequest,
ScheduleService,
TaskgroupEntityInfo,
TaskOverviewInfo,
TaskService,
TaskShortInfo
} from "../../../api";
import {MatSnackBar} from "@angular/material/snack-bar";
import {DialogRef} from "@angular/cdk/dialog";
import {MatDialogRef} from "@angular/material/dialog";
import {filter, map, Observable, startWith, Subject} from "rxjs";
import {FormControl} from "@angular/forms";
import {CalendarEvent, CalendarEventAction, CalendarEventTimesChangedEvent} from "angular-calendar";
import * as moment from "moment/moment";
import {EventColor} from "calendar-utils";
import {TaskOverviewData} from "../taskgroup-overview/taskgroup-overview.component";
import {Router} from "@angular/router";
const colors: Record<string, EventColor> = {
red: {
primary: '#ad2121',
secondary: '#FAE3E3',
},
blue: {
primary: '#1e90ff',
secondary: '#D1E8FF',
},
yellow: {
primary: '#e3bc08',
secondary: '#FDF1BA',
},
};
@Component({
selector: 'app-forgotten-task-start-dialog',
templateUrl: './forgotten-task-start-dialog.component.html',
styleUrls: ['./forgotten-task-start-dialog.component.css']
})
export class ForgottenTaskStartDialogComponent implements OnInit{
myControl: FormControl = new FormControl('');
filteredOptions: Observable<string[]> | undefined;
viewDate: Date = new Date();
events: CalendarEvent[] = [];
refresh = new Subject<void>();
lastSchedule: boolean = false
plannedSchedule: boolean = false
minutesSpentControl: FormControl = new FormControl();
tasks: CalendarEvent[] = [];
taskgroupID: number | undefined
taskgroupSelected: boolean = false;
actions: CalendarEventAction[] = [
{
label: '<i class="fas fa-fw fa-trash-alt"></i>',
a11yLabel: 'Delete',
onClick: ({ event }: { event: CalendarEvent }): void => {
this.events = this.events.filter((iEvent) => iEvent !== event);
this.eventClicked('Deleted', event);
},
},
];
constructor(private router: Router,
private scheduleService: ScheduleService) {
}
ngOnInit() {
this.scheduleService.schedulesDateStartableGet(moment().format("yyyy-MM-DD"), false).subscribe({
next: resp => {
resp.forEach(schedule => {
this.events.push({
title: this.computeTaskPath(schedule.taskgroupPath, schedule.task),
color: colors['red'],
start: new Date(schedule.startTime),
end: new Date(schedule.finishedTime!),
draggable: false,
resizable: {
beforeStart: false,
afterEnd: false
},
meta: {
taskID: schedule.task.taskID,
scheduleID: schedule.scheduleID,
taskgroupID: schedule.taskgroupPath[schedule.taskgroupPath.length-1].taskgroupID
},
})
})
this.refresh.next()
}
})
}
externalDrop(event: CalendarEvent) {
if (this.events.indexOf(event) === -1) {
this.events = this.events.filter((iEvent) => iEvent !== event);
this.events.push(event);
}
}
eventDropped({
event,
newStart,
newEnd,
allDay,
}: CalendarEventTimesChangedEvent): void {
const externalIndex = this.tasks.indexOf(event);
if (typeof allDay !== 'undefined') {
event.allDay = allDay;
}
if (externalIndex > -1) {
this.tasks.splice(externalIndex, 1);
this.events.push(event);
this.taskgroupSelected = true;
}
event.start = newStart;
if (newEnd) {
event.end = newEnd;
}
this.events = [...this.events];
}
onSelectTaskgroup(taskgroup: TaskOverviewData) {
this.tasks = [];
taskgroup.tasks.forEach(task => {
this.tasks.push({
title: task.taskName,
color: colors['yellow'],
start: new Date(),
draggable: true,
cssClass: 'test',
resizable: {
beforeStart: true,
afterEnd: true
},
meta: {
taskID: task.taskID,
scheduleID: undefined,
taskgroupID: taskgroup.taskgroupID
},
actions: this.actions
})
})
this.taskgroupID = taskgroup.taskgroupID;
}
private computeTaskPath(taskgroupPath: Array<TaskgroupEntityInfo>, task: TaskShortInfo) {
let result = "";
taskgroupPath.forEach(taskgroupPathPart => {
result += taskgroupPathPart.taskgroupName + "/"
});
result += task!.taskName
return result;
}
eventClicked(click: string, event: CalendarEvent) {
if(click == 'Deleted') {
this.events = this.events.filter(se => se !== event);
this.taskgroupSelected = false;
}
}
register() {
this.scheduleService.schedulesTaskIDForgottenPost(this.events[0].meta.taskID, {
startTime: moment(this.events[0].start).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
endTime: moment(this.events[0].end).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
}).subscribe({
next: resp => {
this.router.navigateByUrl("/");
}
})
}
}