feat: add saving of user's selection
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
import {Component, EventEmitter, Output} from '@angular/core';
|
||||
import {OtherComponent} from "@component/schedule/tabs/other/other.component";
|
||||
import {MatTab, MatTabChangeEvent, MatTabGroup} from "@angular/material/tabs";
|
||||
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 {ReactiveFormsModule} from "@angular/forms";
|
||||
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";
|
||||
@ -10,6 +10,14 @@ import {ProfessorComponent} from "@component/schedule/tabs/professor/professor.c
|
||||
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,
|
||||
@ -30,17 +38,34 @@ export enum TabsSelect {
|
||||
DataSpinnerComponent,
|
||||
GroupComponent,
|
||||
ProfessorComponent,
|
||||
LectureHallComponent
|
||||
LectureHallComponent,
|
||||
FormsModule,
|
||||
HasRoleDirective
|
||||
],
|
||||
templateUrl: './tabs.component.html',
|
||||
styleUrl: './tabs.component.css',
|
||||
providers: [ScheduleService]
|
||||
providers: [ScheduleService, DisciplineService, LectureHallService, GroupService, ProfessorService]
|
||||
})
|
||||
|
||||
export class TabsComponent {
|
||||
export class TabsComponent implements AfterViewInit {
|
||||
@Output() eventResult = new EventEmitter<[TabsSelect, number, Observable<ScheduleResponse[]>]>();
|
||||
|
||||
constructor(private scheduleApi: ScheduleService) {
|
||||
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) {
|
||||
@ -145,15 +170,74 @@ export class TabsComponent {
|
||||
);
|
||||
}
|
||||
|
||||
protected async chooseTabs(event: MatTabChangeEvent) {
|
||||
switch (event.index) {
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user