import { Component, OnInit, ChangeDetectionStrategy, ViewEncapsulation } from '@angular/core'; import { DateAdapter, CalendarEvent, CalendarView, CalendarMonthViewDay } from 'angular-calendar'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable, Subscription, Subject } from 'rxjs'; import { adapterFactory } from 'angular-calendar/date-adapters/date-fns'; import { ServerDataService } from '../server-data.service'; @Component({ selector: 'app-schedule', templateUrl: './schedule.component.html', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, styleUrls: ['./schedule.component.css'] }) export class ScheduleComponent implements OnInit { constructor(private dateadapter: DateAdapter, private http: HttpClient, private dataService: ServerDataService) {}; currentSystemName: string = "All"; sysNum: number = 0; currentSystem: any; locations = this.dataService.locations; currentLocation = this.locations[0]; systemsInLocation: any; currentVM: string = "All"; public systems: Array<any> = []; public vms: Array<any> = []; selectedDay: Date = new Date(); view: CalendarView = CalendarView.Week; viewDate: Date = this.selectedDay; refresh = new Subject<void>(); month: number = this.dateadapter.getMonth(this.viewDate); events: CalendarEvent[] = [ ]; CalendarView = CalendarView; res: any; gotoDay(date: Date) { this.viewDate = date; this.view = CalendarView.Day; } ngOnInit() { this.dataService.systemList .subscribe( (data:any) => { this.systems = data; this.getLocationSchedule(this.currentLocation, this.sysNum); this.filterScheduleBySystem(this.currentSystemName); }); } getLocationSchedule(location: string, num: number) { let schedule: any = []; this.currentLocation = location; this.currentSystemName = "All" this.sysNum = num; this.vms = []; this.systemsInLocation = []; for(let system of this.systems) { if(system.location === location) { schedule = schedule.concat(JSON.parse(system.schedule)); this.vms = this.vms.concat(JSON.parse(system.vms)); this.systemsInLocation.push(system); } } console.log(schedule); this.events = []; for(const time of schedule) { this.events.push({ start: new Date(time.start), end: new Date(time.end), title: "Priority " + time.priority + " : " + time.vm + " : " + time.desc, allDay: true }); } this.refresh.next(); } filterScheduleBySystem(system: string) { let sysschedule: any = []; for(let sys of this.systemsInLocation) { if(system === "All") { sysschedule = sysschedule.concat(JSON.parse(sys.schedule)); } else if(sys.id === system) { sysschedule = sysschedule.concat(JSON.parse(sys.schedule)); } } console.log(sysschedule); this.currentSystemName = system; this.events = []; for(const time of sysschedule) { this.events.push({ start: new Date(time.start), end: new Date(time.end), title: "Priority " + time.priority + " : " + time.vm + ": " + time.desc, allDay: true }); } this.refresh.next(); } }