refactor: bind components to api
This commit is contained in:
		| @@ -15,15 +15,21 @@ | ||||
|       <app-lecture-hall (eventResult)="lectureHallSelected($event)"/> | ||||
|     </div> | ||||
|   </mat-tab> | ||||
|   <!-- | ||||
|   <mat-tab label="Другое"> | ||||
|     <div class="margin-other-button"> | ||||
|       <app-other idButton="disciplines-button" textButton="Дисциплины" #discipline [dataLoaded]="disciplinesLoaded" (retryLoadData)="loadDisciplines()"/> | ||||
|       <app-other idButton="lecture-button" textButton="Кабинеты" #lecture [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()"/> | ||||
|       <app-other idButton="disciplines-button" textButton="Дисциплины" #discipline [dataLoaded]="disciplinesLoaded" | ||||
|                  (retryLoadData)="loadDisciplines()"/> | ||||
|       <app-other idButton="lecture-button" textButton="Кабинеты" #lecture | ||||
|                  [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> | ||||
|         <button mat-flat-button (click)="onClickNagmi()">Отфильтровать</button> | ||||
|         <button mat-flat-button>Отфильтровать</button> | ||||
|       </section> | ||||
|     </div> | ||||
|   </mat-tab> | ||||
|   --> | ||||
| </mat-tab-group> | ||||
|   | ||||
| @@ -43,9 +43,6 @@ export class TabsComponent { | ||||
|   constructor(private scheduleApi: ScheduleService) { | ||||
|   } | ||||
|  | ||||
|   protected campuses: Observable<CampusBasicInfoResponse[]> = of([]); | ||||
|   protected lectureHalls: Observable<LectureHallResponse[]> = of([]); | ||||
|   private lectureHallsData: Observable<LectureHallResponse[]> = of([]); | ||||
|   protected groupSelected(id: number) { | ||||
|     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('lecture') lectureHallEx!: OtherComponent; | ||||
|   @ViewChild('group') groupEx!: OtherComponent; | ||||
|   @ViewChild('professor') professorEx!: OtherComponent; | ||||
|    */ | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user