159 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			159 lines
		
	
	
		
			4.9 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
 | |
| } from "../../../api";
 | |
| import {ActivatedRoute} 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;
 | |
|   @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[] = [
 | |
|     {
 | |
|       title: 'An all day event',
 | |
|       color: colors['yellow'],
 | |
|       start: new Date(),
 | |
|       allDay: true,
 | |
|     },
 | |
|     {
 | |
|       title: 'A non all day event',
 | |
|       color: colors['blue'],
 | |
|       start: new Date(),
 | |
|     },
 | |
|   ]
 | |
| 
 | |
|   @ViewChild('basicScheduler') basicScheduler: BasicSchedulerComponent | undefined
 | |
| 
 | |
|   constructor(private activatedRoute: ActivatedRoute,
 | |
|               private taskgroupService: TaskgroupService,
 | |
|               private taskService: TaskService,
 | |
|               private scheduleService: ScheduleService) {
 | |
|   }
 | |
| 
 | |
|   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.fetchBasicSchedules();
 | |
|           }
 | |
|         })
 | |
|       }
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   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();
 | |
|   }
 | |
| 
 | |
|   fetchBasicSchedules() {
 | |
|     this.scheduleService.schedulesTaskIDScheduleTypeGet(this.task!.taskID, "BASIC").subscribe({
 | |
|       next: resp => {
 | |
|         resp.forEach(basicSchedule => {
 | |
|           this.events.push({
 | |
|             start: new Date(basicSchedule.scheduleDate),
 | |
|             title: this.task!.taskName,
 | |
|             color: colors['red'],
 | |
|             allDay: true
 | |
|           })
 | |
|         })
 | |
|         this.refresh.next();
 | |
|       }
 | |
|     })
 | |
| 
 | |
|   }
 | |
| }
 |