Now there is automatic navigation on the inserted url and on localStorage
144 lines
4.9 KiB
TypeScript
144 lines
4.9 KiB
TypeScript
import {Component, EventEmitter, Output, ViewChild} from '@angular/core';
|
|
import {AsyncPipe} from "@angular/common";
|
|
import {MatAccordion, MatExpansionModule, MatExpansionPanel} from "@angular/material/expansion";
|
|
import {MatChipListbox, MatChipsModule} from "@angular/material/chips";
|
|
import {catchError} from "rxjs";
|
|
import {FormControl, ReactiveFormsModule} from "@angular/forms";
|
|
import {LoadingIndicatorComponent} from "@component/common/loading-indicator/loading-indicator.component";
|
|
import {CampusBasicInfoResponse} from "@api/v1/campusBasicInfoResponse";
|
|
import {LectureHallResponse} from "@api/v1/lectureHallResponse";
|
|
import {CampusService} from "@api/v1/campus.service";
|
|
import {LectureHallService} from "@api/v1/lectureHall.service";
|
|
import {IScheduleTab} from "@component/schedule/tabs/ischedule-tab";
|
|
import {TabSelect, TabSelectData, TabSelectType, TabStorageService} from "@service/tab-storage.service";
|
|
|
|
@Component({
|
|
selector: 'app-lecture-hall',
|
|
standalone: true,
|
|
imports: [
|
|
MatChipsModule,
|
|
MatExpansionModule,
|
|
AsyncPipe,
|
|
ReactiveFormsModule,
|
|
MatAccordion,
|
|
LoadingIndicatorComponent
|
|
],
|
|
templateUrl: './lecture-hall.component.html',
|
|
styleUrl: './lecture-hall.component.css',
|
|
providers: [CampusService, LectureHallService]
|
|
})
|
|
|
|
export class LectureHallComponent implements IScheduleTab {
|
|
protected campusId: number | null = null;
|
|
protected formLectureHalls: FormControl = new FormControl();
|
|
|
|
protected campuses: CampusBasicInfoResponse[] | null = null;
|
|
protected lectureHallsFiltered: LectureHallResponse[] | null = null;
|
|
|
|
@Output() eventResult = new EventEmitter<number>();
|
|
|
|
@ViewChild('lecturePanel') lecturePanel!: MatExpansionPanel;
|
|
@ViewChild('lectureIndicator') lectureIndicator!: LoadingIndicatorComponent;
|
|
@ViewChild('campusIndicator') campusIndicator!: LoadingIndicatorComponent;
|
|
|
|
@ViewChild('campusChip') campusChip!: MatChipListbox;
|
|
@ViewChild('lectureChip') lectureChip!: MatChipListbox;
|
|
|
|
private lectureHalls: LectureHallResponse[] | null = null;
|
|
|
|
constructor(private campusApi: CampusService, private lectureHallApi: LectureHallService, private tabStorage: TabStorageService) {
|
|
}
|
|
|
|
existParams(data: TabSelectData): boolean {
|
|
return data.selected['campus'] !== undefined || data.selected['lecture'] !== undefined;
|
|
}
|
|
|
|
protected loadCampuses() {
|
|
this.campusApi.getCampus()
|
|
.pipe(catchError(error => {
|
|
this.campusIndicator.loading = false;
|
|
throw error;
|
|
}))
|
|
.subscribe(data => {
|
|
this.campuses = data;
|
|
|
|
let selected = TabStorageService.selected?.selected['campus'];
|
|
if (selected) {
|
|
let selectedCampus = data.find(x => x.id === selected.index);
|
|
|
|
if (selectedCampus === undefined || selectedCampus.codeName !== selected.name)
|
|
selectedCampus = data.find(x => x.codeName === selected.name);
|
|
|
|
if (selectedCampus !== undefined) {
|
|
TabStorageService.trySelectChip(selectedCampus.id, this.campusChip);
|
|
this.onCampusSelected(selectedCampus.id);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private filteringLectureHalls() {
|
|
this.lectureHallsFiltered = this.lectureHalls?.filter(x => x.campusId === this.campusId) ?? null;
|
|
}
|
|
|
|
protected onCampusSelected(index: number) {
|
|
this.formLectureHalls.reset();
|
|
|
|
this.tabStorage.select(new TabSelect(index, this.campuses!.find(x => x.id === index)?.codeName ?? ''), TabSelectType.lecture, 'campus');
|
|
|
|
if (index === undefined) {
|
|
this.campusId = null;
|
|
this.lectureHalls = [];
|
|
return;
|
|
}
|
|
|
|
this.campusId = index;
|
|
this.lecturePanel.open();
|
|
|
|
if (this.lectureHalls === null)
|
|
this.loadLectureHalls();
|
|
else
|
|
this.filteringLectureHalls();
|
|
}
|
|
|
|
protected loadLectureHalls() {
|
|
this.lectureHallApi.getLectureHalls()
|
|
.pipe(catchError(error => {
|
|
this.lectureIndicator.loading = false;
|
|
throw error;
|
|
}))
|
|
.subscribe(data => {
|
|
this.lectureHalls = data;
|
|
this.filteringLectureHalls();
|
|
|
|
let selected = TabStorageService.selected?.selected['lecture'];
|
|
if (selected) {
|
|
let selectedLecture = data.find(x => x.id === selected.index);
|
|
|
|
if (selectedLecture === undefined || selectedLecture.name !== selected.name)
|
|
selectedLecture = data.find(x => x.name === selected.name);
|
|
|
|
if (selectedLecture !== undefined) {
|
|
TabStorageService.trySelectChip(selectedLecture.id, this.lectureChip);
|
|
this.onLectureHallSelected(selectedLecture.id);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
protected onLectureHallSelected(index: number) {
|
|
if (index === undefined)
|
|
return;
|
|
|
|
this.tabStorage.select(new TabSelect(index, this.lectureHallsFiltered!.find(x => x.id === index)?.name ?? ''), TabSelectType.lecture, 'lecture');
|
|
|
|
this.lecturePanel.close();
|
|
this.eventResult.emit(index);
|
|
}
|
|
|
|
public load() {
|
|
if (this.campuses === null)
|
|
this.loadCampuses();
|
|
}
|
|
}
|