refactor: bind components to api

This commit is contained in:
Polianin Nikita 2024-06-11 00:16:49 +03:00
parent 8a1921b6cb
commit 69e080033f
2 changed files with 13 additions and 68 deletions

View File

@ -15,15 +15,21 @@
<app-lecture-hall (eventResult)="lectureHallSelected($event)"/> <app-lecture-hall (eventResult)="lectureHallSelected($event)"/>
</div> </div>
</mat-tab> </mat-tab>
<!--
<mat-tab label="Другое"> <mat-tab label="Другое">
<div class="margin-other-button"> <div class="margin-other-button">
<app-other idButton="disciplines-button" textButton="Дисциплины" #discipline [dataLoaded]="disciplinesLoaded" (retryLoadData)="loadDisciplines()"/> <app-other idButton="disciplines-button" textButton="Дисциплины" #discipline [dataLoaded]="disciplinesLoaded"
<app-other idButton="lecture-button" textButton="Кабинеты" #lecture [dataLoaded]="campusesLoaded && lectureHallsLoaded" (retryLoadData)="loadLectureHalls()"/> (retryLoadData)="loadDisciplines()"/>
<app-other idButton="group-button" textButton="Группы" #group [dataLoaded]="facultiesLoaded && groupLoaded" (retryLoadData)="loadGroups()"/> <app-other idButton="lecture-button" textButton="Кабинеты" #lecture
<app-other idButton="professor-button" textButton="Профессоры" #professor [dataLoaded]="professorsLoaded" (retryLoadData)="professorsLoad()"/> [dataLoaded]="campusesLoaded && lectureHallsLoaded" (retryLoadData)="loadLectureHalls()"/>
<app-other idButton="group-button" textButton="Группы" #group [dataLoaded]="facultiesLoaded && groupLoaded"
(retryLoadData)="loadGroups()"/>
<app-other idButton="professor-button" textButton="Профессоры" #professor [dataLoaded]="professorsLoaded"
(retryLoadData)="professorsLoad()"/>
<section> <section>
<button mat-flat-button (click)="onClickNagmi()">Отфильтровать</button> <button mat-flat-button>Отфильтровать</button>
</section> </section>
</div> </div>
</mat-tab> </mat-tab>
-->
</mat-tab-group> </mat-tab-group>

View File

@ -43,9 +43,6 @@ export class TabsComponent {
constructor(private scheduleApi: ScheduleService) { constructor(private scheduleApi: ScheduleService) {
} }
protected campuses: Observable<CampusBasicInfoResponse[]> = of([]);
protected lectureHalls: Observable<LectureHallResponse[]> = of([]);
private lectureHallsData: Observable<LectureHallResponse[]> = of([]);
protected groupSelected(id: number) { protected groupSelected(id: number) {
this.eventResult.emit( this.eventResult.emit(
[ [
@ -153,68 +150,10 @@ export class TabsComponent {
} }
} }
protected async loadDisciplines() { /*
if (!this.disciplinesLoaded) {
this.disciplineApi.getDisciplines().pipe(
catchError((error) => {
this.disciplinesLoaded = null;
throw error;
})).subscribe(data => {
this.disciplineEx.Data = data.map(x =>
({
id: x.id,
name: x.name,
selected: false
}));
this.disciplinesLoaded = true;
});
}
}
protected async loadGroups() {
if (!this.facultiesLoaded)
await this.facultyLoad();
if (!this.groupLoaded) {
this.groupsData = this.groupApi.getGroups();
this.groupsData.pipe(
switchMap(groups => this.faculties.pipe(
map(campuses => {
return groups.map(x => {
const faculties = campuses.find(c => c.id === x.facultyId);
const name = faculties ? faculties.name : '';
return {
id: x.id,
name: `${x.name} (${name})`,
selected: false
};
});
})
))
).subscribe(data => {
this.groupEx.Data = data;
this.groupLoaded = true;
});
}
}
protected async extensionLoad() {
// Lecture Hall
await this.loadLectureHalls();
// Disciplines
await this.loadDisciplines();
// Groups
await this.loadGroups();
// Professors
if (this.professorsData.length === 0)
this.professorsLoad();
}
@ViewChild('discipline') disciplineEx!: OtherComponent; @ViewChild('discipline') disciplineEx!: OtherComponent;
@ViewChild('lecture') lectureHallEx!: OtherComponent; @ViewChild('lecture') lectureHallEx!: OtherComponent;
@ViewChild('group') groupEx!: OtherComponent; @ViewChild('group') groupEx!: OtherComponent;
@ViewChild('professor') professorEx!: OtherComponent; @ViewChild('professor') professorEx!: OtherComponent;
*/
} }