import {Component, OnInit} from '@angular/core'; import {AdvancedScheduleInfo, BasicScheduleInfo, ScheduleInfo, ScheduleService} from "../../api"; import {NavigationLink} from "../navigation-link-list/navigation-link-list.component"; import {MatSnackBar} from "@angular/material/snack-bar"; import {MatDialog} from "@angular/material/dialog"; import { MissedScheduleForgetConfirmationDialogComponent } from "./missed-schedule-forget-confirmation-dialog/missed-schedule-forget-confirmation-dialog.component"; @Component({ selector: 'app-missed-schedules', templateUrl: './missed-schedules.component.html', styleUrls: ['./missed-schedules.component.css'] }) export class MissedSchedulesComponent implements OnInit{ missedSchedules: ScheduleInfo[] = [] defaultNavigationLinkPath: NavigationLink[] = [ { linkText: "Dashboard", routerLink: ['/'] }, { linkText: "Missed Schedules", routerLink: ["/reschedule"] } ] constructor(private scheduleService: ScheduleService, private snackbar: MatSnackBar, private dialog: MatDialog) { } ngOnInit() { this.scheduleService.schedulesMissedGet().subscribe({ next: resp => { this.missedSchedules = resp; } }) } forgetSchedule(scheduleInfo: ScheduleInfo) { this.scheduleService.schedulesScheduleIDDelete(scheduleInfo.scheduleID).subscribe({ next: resp => { this.missedSchedules = this.missedSchedules.filter(schedule => schedule.scheduleID !== scheduleInfo.scheduleID) }, error: err => { if(err.status == 403) { this.snackbar.open("No permission", "", {duration: 2000}) } else if(err.status == 404) { this.snackbar.open("Schedule not found", "", {duration: 2000}); } else { this.snackbar.open("Unexpected error", "", {duration: 2000}); } } }) } forgetAllSchedules() { const dialogRef = this.dialog.open(MissedScheduleForgetConfirmationDialogComponent, {data: this.missedSchedules, width: "400px"}); dialogRef.afterClosed().subscribe(res => { if(res != undefined) { this.missedSchedules = []; } }) } toBasicSchedule(schedule: ScheduleInfo) { return schedule as BasicScheduleInfo } toAdvancedSchedule(schedule: ScheduleInfo) { return schedule as AdvancedScheduleInfo } }