244 lines
7.6 KiB
TypeScript
244 lines
7.6 KiB
TypeScript
import {AfterViewInit, Component, EventEmitter, Output, ViewChild} from '@angular/core';
|
|
import {OtherComponent, SelectData} from "@component/schedule/tabs/other/other.component";
|
|
import {MatTab, MatTabGroup} from "@angular/material/tabs";
|
|
import {map, Observable} from "rxjs";
|
|
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
|
|
import {MatButton} from "@angular/material/button";
|
|
import {DataSpinnerComponent} from "@component/common/data-spinner/data-spinner.component";
|
|
import {GroupComponent} from "@component/schedule/tabs/group/group.component";
|
|
import {ProfessorComponent} from "@component/schedule/tabs/professor/professor.component";
|
|
import {LectureHallComponent} from "@component/schedule/tabs/lecture-hall/lecture-hall.component";
|
|
import {ScheduleService} from "@api/v1/schedule.service";
|
|
import {ScheduleResponse} from "@api/v1/scheduleResponse";
|
|
import {IScheduleTab} from "@component/schedule/tabs/ischedule-tab";
|
|
import {DisciplineService} from "@api/v1/discipline.service";
|
|
import {LectureHallService} from "@api/v1/lectureHall.service";
|
|
import {GroupService} from "@api/v1/group.service";
|
|
import {ProfessorService} from "@api/v1/professor.service";
|
|
import {AuthRoles} from "@model/AuthRoles";
|
|
import {HasRoleDirective} from "@/directives/has-role.directive";
|
|
import {TabStorageComponent} from "@component/common/tab-storage/tab-storage.component";
|
|
|
|
export enum TabsSelect {
|
|
Group,
|
|
Professor,
|
|
LectureHall,
|
|
Other
|
|
}
|
|
|
|
@Component({
|
|
selector: 'app-tabs',
|
|
standalone: true,
|
|
imports: [
|
|
OtherComponent,
|
|
MatTabGroup,
|
|
MatTab,
|
|
ReactiveFormsModule,
|
|
MatButton,
|
|
DataSpinnerComponent,
|
|
GroupComponent,
|
|
ProfessorComponent,
|
|
LectureHallComponent,
|
|
FormsModule,
|
|
HasRoleDirective
|
|
],
|
|
templateUrl: './tabs.component.html',
|
|
styleUrl: './tabs.component.css',
|
|
providers: [ScheduleService, DisciplineService, LectureHallService, GroupService, ProfessorService]
|
|
})
|
|
|
|
export class TabsComponent implements AfterViewInit {
|
|
@Output() eventResult = new EventEmitter<[TabsSelect, number, Observable<ScheduleResponse[]>]>();
|
|
|
|
constructor(private scheduleApi: ScheduleService,
|
|
private disciplineApi: DisciplineService,
|
|
private lectureApi: LectureHallService,
|
|
private groupApi: GroupService,
|
|
private professorApi: ProfessorService) {
|
|
}
|
|
|
|
ngAfterViewInit(): void {
|
|
let selected = TabStorageComponent.selected;
|
|
|
|
let index = 0;
|
|
if (selected !== null)
|
|
index = selected.type;
|
|
|
|
this.chooseTabs(index).then();
|
|
this.tabs.selectedIndex = index;
|
|
}
|
|
|
|
protected groupSelected(id: number) {
|
|
this.eventResult.emit(
|
|
[
|
|
TabsSelect.Group,
|
|
id,
|
|
this.scheduleApi.getByGroup(id)
|
|
.pipe(
|
|
map(g =>
|
|
g.map(data =>
|
|
({
|
|
dayOfWeek: data.dayOfWeek,
|
|
pairNumber: data.pairNumber,
|
|
isEven: data.isEven,
|
|
discipline: data.discipline,
|
|
disciplineId: data.disciplineId,
|
|
isExcludedWeeks: data.isExcludedWeeks,
|
|
weeks: data.weeks,
|
|
typeOfOccupations: data.typeOfOccupations,
|
|
group: data.group,
|
|
groupId: data.groupId,
|
|
lectureHalls: data.lectureHalls,
|
|
lectureHallsId: data.lectureHallsId,
|
|
professors: data.professors,
|
|
professorsId: data.professorsId,
|
|
campus: data.campus,
|
|
campusId: data.campusId,
|
|
linkToMeet: data.linkToMeet
|
|
}))
|
|
)
|
|
)
|
|
]
|
|
);
|
|
}
|
|
|
|
protected professorSelected(id: number) {
|
|
this.eventResult.emit(
|
|
[
|
|
TabsSelect.Professor,
|
|
id,
|
|
this.scheduleApi.getByProfessor(id)
|
|
.pipe(
|
|
map(p =>
|
|
p.map(data =>
|
|
({
|
|
dayOfWeek: data.dayOfWeek,
|
|
pairNumber: data.pairNumber,
|
|
isEven: data.isEven,
|
|
discipline: data.discipline,
|
|
disciplineId: data.disciplineId,
|
|
isExcludedWeeks: data.isExcludedWeeks,
|
|
weeks: data.weeks,
|
|
typeOfOccupations: data.typeOfOccupations,
|
|
group: data.group,
|
|
groupId: data.groupId,
|
|
lectureHalls: data.lectureHalls,
|
|
lectureHallsId: data.lectureHallsId,
|
|
professors: data.professors,
|
|
professorsId: data.professorsId,
|
|
campus: data.campus,
|
|
campusId: data.campusId,
|
|
linkToMeet: data.linkToMeet
|
|
}))
|
|
)
|
|
)
|
|
]
|
|
);
|
|
}
|
|
|
|
protected lectureHallSelected(id: number) {
|
|
this.eventResult.emit(
|
|
[
|
|
TabsSelect.LectureHall,
|
|
id,
|
|
this.scheduleApi.getByLectureHall(id)
|
|
.pipe(
|
|
map(lh =>
|
|
lh.map(data =>
|
|
({
|
|
dayOfWeek: data.dayOfWeek,
|
|
pairNumber: data.pairNumber,
|
|
isEven: data.isEven,
|
|
discipline: data.discipline,
|
|
disciplineId: data.disciplineId,
|
|
isExcludedWeeks: data.isExcludedWeeks,
|
|
weeks: data.weeks,
|
|
typeOfOccupations: data.typeOfOccupations,
|
|
group: data.group,
|
|
groupId: data.groupId,
|
|
lectureHalls: data.lectureHalls,
|
|
lectureHallsId: data.lectureHallsId,
|
|
professors: data.professors,
|
|
professorsId: data.professorsId,
|
|
campus: data.campus,
|
|
campusId: data.campusId,
|
|
linkToMeet: data.linkToMeet
|
|
}))
|
|
)
|
|
)
|
|
]
|
|
);
|
|
}
|
|
|
|
protected async chooseTabs(index: number) {
|
|
switch (index) {
|
|
case 0:
|
|
this.groupTab.load();
|
|
break;
|
|
case 1:
|
|
this.professorTab.load();
|
|
break;
|
|
case 2:
|
|
this.lectureHallTab.load();
|
|
break;
|
|
case 3:
|
|
await this.loadDisciplines();
|
|
await this.loadLectureHalls();
|
|
await this.loadGroups();
|
|
await this.loadProfessors();
|
|
break;
|
|
default:
|
|
await this.chooseTabs(0);
|
|
break;
|
|
}
|
|
}
|
|
|
|
protected async loadDisciplines() {
|
|
this.disciplineApi.getDisciplines().subscribe(data => {
|
|
this.disciplineEx.Data = data.map(x => ({
|
|
id: x.id,
|
|
name: x.name
|
|
}) as SelectData);
|
|
});
|
|
}
|
|
|
|
protected async loadLectureHalls() {
|
|
this.lectureApi.getLectureHalls().subscribe(data => {
|
|
this.lectureHallEx.Data = data.map(x => ({
|
|
id: x.id,
|
|
name: x.name
|
|
}) as SelectData);
|
|
});
|
|
}
|
|
|
|
protected async loadGroups() {
|
|
this.groupApi.getGroups().subscribe(data => {
|
|
this.groupEx.Data = data.map(x => ({
|
|
id: x.id,
|
|
name: x.name
|
|
}) as SelectData);
|
|
});
|
|
}
|
|
|
|
protected async loadProfessors() {
|
|
this.professorApi.getProfessors().subscribe(data => {
|
|
this.professorEx.Data = data.map(x => ({
|
|
id: x.id,
|
|
name: x.name
|
|
}) as SelectData);
|
|
});
|
|
}
|
|
|
|
@ViewChild('groupTab') groupTab!: IScheduleTab;
|
|
@ViewChild('professorTab') professorTab!: IScheduleTab;
|
|
@ViewChild('lectureHallTab') lectureHallTab!: IScheduleTab;
|
|
|
|
@ViewChild('discipline') disciplineEx!: OtherComponent;
|
|
@ViewChild('lecture') lectureHallEx!: OtherComponent;
|
|
@ViewChild('group') groupEx!: OtherComponent;
|
|
@ViewChild('professor') professorEx!: OtherComponent;
|
|
|
|
@ViewChild('tabGroup') tabs!: MatTabGroup;
|
|
protected readonly AuthRoles = AuthRoles;
|
|
}
|