timemanager/frontend/src/app/schedules/scheduler/scheduler.component.ts

173 lines
5.5 KiB
TypeScript

import {Component, OnInit, ViewChild} from '@angular/core';
import {NavigationLink, NavigationLinkListComponent} from "../../navigation-link-list/navigation-link-list.component";
import {
BasicScheduleEntityInfo, ScheduleService,
TaskEntityInfo,
TaskgroupEntityInfo,
TaskgroupService,
TaskService, TaskShortInfo
} from "../../../api";
import {ActivatedRoute, Router} from "@angular/router";
import {CalendarDateFormatter, CalendarEvent, CalendarView} from "angular-calendar";
import { Subject } from 'rxjs';
import {CalendarDatePipe} from "angular-calendar/modules/common/calendar-date/calendar-date.pipe";
import {BasicSchedulerComponent} from "../basic-scheduler/basic-scheduler.component";
import * as events from "events";
import { EventColor } from 'calendar-utils';
const colors: Record<string, EventColor> = {
red: {
primary: '#ad2121',
secondary: '#FAE3E3',
},
blue: {
primary: '#1e90ff',
secondary: '#D1E8FF',
},
yellow: {
primary: '#e3bc08',
secondary: '#FDF1BA',
},
};
@Component({
selector: 'app-scheduler',
templateUrl: './scheduler.component.html',
styleUrls: ['./scheduler.component.css']
})
export class SchedulerComponent implements OnInit{
defaultNavigationLinkPath: NavigationLink[] = [
{
linkText: "Dashboard",
routerLink: ['/']
},
{
linkText: "Taskgroups",
routerLink: ["/taskgroups"]
}
]
taskgroups: TaskgroupEntityInfo[] = []
taskgroup: TaskgroupEntityInfo | undefined
taskgroupPath: TaskgroupEntityInfo[] = []
taskgroupID: number = -1;
scheduleID: number = -1;
@ViewChild('navLinkList') navLinkListComponent: NavigationLinkListComponent | undefined
task: TaskEntityInfo | undefined
scheduleStrategy: number = 1
/**************************************************/
//Calendar-Stuff
/**************************************************/
view: CalendarView = CalendarView.Week;
viewDate = new Date();
daysInWeek = 7;
refresh: Subject<void> = new Subject<void>()
events: CalendarEvent[] = []
@ViewChild('basicScheduler') basicScheduler: BasicSchedulerComponent | undefined
constructor(private activatedRoute: ActivatedRoute,
private taskgroupService: TaskgroupService,
private taskService: TaskService,
private scheduleService: ScheduleService,
private router: Router) {
}
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.initializeNavigationLinkList()
}
})
}
if(params.has('taskID')) {
this.taskService.tasksTaskIDGet(Number(params.get('taskID'))).subscribe({
next: resp => {
this.task = resp;
this.initializeNavigationLinkList()
this.fetschSchedules();
}
})
}
if(params.has('scheduleID')) {
this.scheduleID = Number(params.get('scheduleID'));
}
});
}
initializeNavigationLinkList() {
if(this.taskgroup != undefined && this.task != undefined) {
this.navLinkListComponent!.addNavigationLink(this.taskgroup!.taskgroupName, ['/taskgroups', this.taskgroup!.taskgroupID.toString()])
this.taskgroupPath.forEach(taskgroupEntity => {
this.navLinkListComponent!.addNavigationLink(taskgroupEntity.taskgroupName, ['/taskgroups', taskgroupEntity.taskgroupID.toString()]);
})
this.navLinkListComponent!.addNavigationLink(this.task!.taskName, ['/taskgroups', this.taskgroup!.taskgroupID.toString(), 'tasks', this.task.taskID.toString()]);
this.navLinkListComponent!.addNavigationLink('Schedule', [this.taskgroup!.taskgroupID.toString(), 'tasks', this.task.taskID.toString(), 'schedule'])
}
}
protected readonly CalendarView = CalendarView;
timeClick(clickedDate: Date) {
if(this.basicScheduler != undefined) {
this.basicScheduler.setDate(clickedDate)
}
}
onBasicSchedule(scheduleInfo: BasicScheduleEntityInfo) {
this.events.push({
start: new Date(scheduleInfo.scheduleDate),
title: this.task!.taskName,
color: colors['red'],
allDay: true
})
this.refresh.next();
}
fetschSchedules() {
this.scheduleService.schedulesGet().subscribe({
next: resp => {
resp.forEach(schedule => {
let color: EventColor = colors['red']
if(schedule.scheduleID === this.scheduleID) {
color = colors['yellow']
}
if(schedule.scheduleType === 'BASIC') {
this.events.push({
start: new Date(schedule.schedule.scheduleDate),
title: this.computeTaskPath(schedule.taskgroupPath, schedule.task),
color: color,
allDay: true,
})
}
})
this.refresh.next();
}
})
}
eventClicked({ event }: { event: CalendarEvent }): void {
this.router.navigateByUrl("/taskgroups/" + this.taskgroupID.toString() + "/tasks/" + this.task!.taskID )
}
computeTaskPath(taskgroupPath: TaskgroupEntityInfo[], task: TaskShortInfo | TaskEntityInfo) {
let result = "";
taskgroupPath.forEach(taskgroupPathPart => {
result += taskgroupPathPart.taskgroupName + "/"
});
result += task!.taskName
return result;
}
}