refactor: rewrite for new models

This commit is contained in:
Polianin Nikita 2024-06-05 21:47:46 +03:00
parent 799d2d8166
commit 83fc7df137
6 changed files with 53 additions and 49 deletions

View File

@ -4,8 +4,8 @@ import {MatIcon} from "@angular/material/icon";
import {DatePipe} from "@angular/common";
import {addDays} from "@progress/kendo-date-math";
import {MatDivider} from "@angular/material/divider";
import {Schedule} from "@page/schedule/schedule.component";
import {DataSpinnerComponent} from "@component/common/data-spinner/data-spinner.component";
import {ScheduleResponse} from "@api/v1/scheduleResponse";
interface TableData {
pairNumber: number;
@ -34,14 +34,14 @@ export class TableComponent implements OnChanges {
protected tableDataSource: MatTableDataSource<TableData> = new MatTableDataSource<TableData>([]);
protected daysOfWeek: string[] = ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'];
protected displayedColumns: string[] = ['pairNumber'];
protected dataSource: Schedule[] = [];
protected dataSource: ScheduleResponse[] = [];
protected isOneGroup: boolean = false;
@Input() currentWeek!: number;
@Input() startWeek!: Date;
@Input() isLoad: boolean = false;
@Input() set data(schedule: Schedule[]) {
@Input() set data(schedule: ScheduleResponse[]) {
this.dataSource = schedule;
this.convertData();
this.isOneGroup = schedule.every((item, _, array) => item.group === array[0].group);
@ -69,9 +69,13 @@ export class TableComponent implements OnChanges {
for (let k: number = 1; k < 7; k++) {
convertedData.data[k.toString()] = this.dataSource.filter(x =>
x.pairNumber === i
&& x.dayOfWeek === k
&& x.isEven === (this.currentWeek % 2 === 0));
x.pairNumber === i &&
x.dayOfWeek === k &&
x.isEven === (this.currentWeek % 2 === 0) &&
(
(x.isExcludedWeeks && (!x.weeks || !x.weeks.includes(this.currentWeek))) ||
(!x.isExcludedWeeks && (!x.weeks || x.weeks.includes(this.currentWeek)))
));
}
tableData.push(convertedData);
@ -81,8 +85,8 @@ export class TableComponent implements OnChanges {
this.isLoad = false;
}
protected checkAvailableData(data: any[]): boolean {
return data && data.length !== 0 && data.every(x => x !== null);
protected checkAvailableData(data: any[] | any): boolean {
return data && data.length !== 0 && (!Array.isArray(data) || data.every(x => x !== null));
}
protected readonly addDays = addDays;

View File

@ -4,9 +4,9 @@ import {MatChipListboxChange, MatChipsModule} from '@angular/material/chips';
import {FormControl, ReactiveFormsModule} from "@angular/forms";
import {AsyncPipe} from "@angular/common";
import {map, Observable, of} from "rxjs";
import {FacultyResponse} from "@model/facultyResponse";
import {GroupResponse} from "@model/groupResponse";
import {LoadingIndicatorComponent} from "@component/common/loading-indicator/loading-indicator.component";
import {GroupResponse} from "@api/v1/groupResponse";
import {FacultyResponse} from "@api/v1/facultyResponse";
@Component({
selector: 'app-group',

View File

@ -3,10 +3,10 @@ import {AsyncPipe} from "@angular/common";
import {MatAccordion, MatExpansionModule, MatExpansionPanel} from "@angular/material/expansion";
import {MatChipListboxChange, MatChipsModule} from "@angular/material/chips";
import {Observable, of} from "rxjs";
import {CampusBasicInfoResponse} from "@model/campusBasicInfoResponse";
import {FormControl, ReactiveFormsModule} from "@angular/forms";
import {LectureHallResponse} from "@model/lectureHallResponse";
import {LoadingIndicatorComponent} from "@component/common/loading-indicator/loading-indicator.component";
import {CampusBasicInfoResponse} from "@api/v1/campusBasicInfoResponse";
import {LectureHallResponse} from "@api/v1/lectureHallResponse";
@Component({
selector: 'app-lecture-hall',

View File

@ -43,6 +43,7 @@ export interface SelectData {
templateUrl: './other.component.html',
styleUrl: './other.component.css'
})
export class OtherComponent {
private _searchQuery: string = '';
protected filteredData: BehaviorSubject<SelectData[]> = new BehaviorSubject<SelectData[]>([]);

View File

@ -4,8 +4,8 @@ import {FormControl, ReactiveFormsModule} from "@angular/forms";
import {MatAutocompleteModule, MatAutocompleteSelectedEvent} from "@angular/material/autocomplete";
import {AsyncPipe} from "@angular/common";
import {map, Observable, startWith} from "rxjs";
import {ProfessorResponse} from "@model/professorResponse";
import {LoadingIndicatorComponent} from "@component/common/loading-indicator/loading-indicator.component";
import {ProfessorResponse} from "@api/v1/professorResponse";
@Component({
selector: 'app-professor',

View File

@ -1,26 +1,26 @@
import {Component, EventEmitter, Output, ViewChild} from '@angular/core';
import {HttpClientModule} from "@angular/common/http";
import {ApiService} from '@service/api.service';
import {OtherComponent} from "@component/schedule/tabs/other/other.component";
import {MatTab, MatTabChangeEvent, MatTabGroup} from "@angular/material/tabs";
import {
ProfessorComponent
} from "@component/schedule/tabs/professor/professor.component";
import {GroupComponent} from "@component/schedule/tabs/group/group.component";
import {
LectureHallComponent
} from "@component/schedule/tabs/lecture-hall/lecture-hall.component";
import {ProfessorResponse} from "@model/professorResponse";
import {catchError, map, Observable, of, switchMap, tap} from "rxjs";
import {GroupResponse} from "@model/groupResponse";
import {FacultyResponse} from "@model/facultyResponse";
import {CampusBasicInfoResponse} from "@model/campusBasicInfoResponse";
import {LectureHallResponse} from "@model/lectureHallResponse";
import {ReactiveFormsModule} from "@angular/forms";
import {AsyncPipe, NgIf} from "@angular/common";
import {DisciplineResponse} from "@model/disciplineResponse";
import {MatButton} from "@angular/material/button";
import {DataSpinnerComponent} from "@component/common/data-spinner/data-spinner.component";
import {ProfessorResponse} from "@api/v1/professorResponse";
import {FacultyResponse} from "@api/v1/facultyResponse";
import {GroupResponse} from "@api/v1/groupResponse";
import {CampusBasicInfoResponse} from "@api/v1/campusBasicInfoResponse";
import {LectureHallResponse} from "@api/v1/lectureHallResponse";
import {DisciplineService} from "@api/v1/discipline.service";
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 {FacultyService} from "@api/v1/faculty.service";
import {GroupService} from "@api/v1/group.service";
import {ProfessorService} from "@api/v1/professor.service";
import {CampusService} from "@api/v1/campus.service";
import {LectureHallService} from "@api/v1/lectureHall.service";
@Component({
selector: 'app-tabs',
@ -30,17 +30,18 @@ import {DataSpinnerComponent} from "@component/common/data-spinner/data-spinner.
OtherComponent,
MatTabGroup,
MatTab,
ProfessorComponent,
GroupComponent,
LectureHallComponent,
ReactiveFormsModule,
AsyncPipe,
NgIf,
MatButton,
DataSpinnerComponent
DataSpinnerComponent,
GroupComponent,
ProfessorComponent,
LectureHallComponent
],
templateUrl: './tabs.component.html',
styleUrl: './tabs.component.css'
styleUrl: './tabs.component.css',
providers: [FacultyService, GroupService, ProfessorService, CampusService, LectureHallService, DisciplineService ]
})
export class TabsComponent {
@ -66,12 +67,17 @@ export class TabsComponent {
@Output() lectureHallSelected: EventEmitter<number> = new EventEmitter<number>();
@Output() professorSelected: EventEmitter<number> = new EventEmitter<number>();
constructor(private api: ApiService) {
constructor(
private facultyApi: FacultyService,
private groupApi: GroupService,
private professorApi: ProfessorService,
private campusApi: CampusService,
private lectureHallApi: LectureHallService,
private disciplineApi: DisciplineService) {
this.facultyLoad().then();
}
protected async chooseTabs(event: MatTabChangeEvent) {
console.log(event);
switch (event.index) {
case 0:
await this.facultyLoad();
@ -92,7 +98,7 @@ export class TabsComponent {
if (this.facultiesLoaded === null) this.facultiesLoaded = false;
if (this.facultiesLoaded) return;
this.faculties = this.api.get<FacultyResponse[]>("Faculty/Get").pipe(
this.faculties = this.facultyApi.getFaculties().pipe(
tap(() => {
this.facultiesLoaded = true;
}),
@ -109,7 +115,7 @@ export class TabsComponent {
if (this.groupLoaded)
this.groups = this.groupsData.pipe(map(data => data.filter(x => x.facultyId === id)));
else
this.groups = this.api.get<GroupResponse[]>("Group/GetByFaculty/" + id).pipe(
this.groups = this.groupApi.getByFaculty(id).pipe(
tap(() => {
this.groupLoaded = false;
}),
@ -125,7 +131,7 @@ export class TabsComponent {
if (this.professorsLoaded) return;
this.api.get<ProfessorResponse[]>("Professor/Get").pipe(
this.professorApi.getProfessors().pipe(
catchError((error) => {
this.professorsLoaded = null;
throw error;
@ -147,7 +153,7 @@ export class TabsComponent {
if (this.campusesLoaded) return;
this.campuses = this.api.get<CampusBasicInfoResponse[]>("Campus/Get").pipe(
this.campuses = this.campusApi.getCampus().pipe(
tap(() => {
this.campusesLoaded = true;
}),
@ -164,7 +170,7 @@ export class TabsComponent {
if (this.lectureHallsLoaded)
this.lectureHalls = this.lectureHallsData.pipe(map(data => data.filter(x => x.campusId === id)));
else
this.lectureHalls = this.api.get<LectureHallResponse[]>("LectureHall/GetByCampus/" + id).pipe(
this.lectureHalls = this.lectureHallApi.getByCampus(id).pipe(
tap(() => {
this.lectureHallsLoaded = false;
}),
@ -180,7 +186,7 @@ export class TabsComponent {
await this.campusLoad();
if (!this.lectureHallsLoaded) {
this.lectureHallsData = this.api.get<LectureHallResponse[]>("LectureHall/Get");
this.lectureHallsData = this.lectureHallApi.getLectureHalls();
this.lectureHallsData.pipe(
switchMap(lectureHalls => this.campuses.pipe(
map(campuses => {
@ -205,7 +211,7 @@ export class TabsComponent {
protected async loadDisciplines() {
if (!this.disciplinesLoaded) {
this.api.get<DisciplineResponse[]>("Discipline/Get").pipe(
this.disciplineApi.getDisciplines().pipe(
catchError((error) => {
this.disciplinesLoaded = null;
throw error;
@ -226,7 +232,7 @@ export class TabsComponent {
await this.facultyLoad();
if (!this.groupLoaded) {
this.groupsData = this.api.get<GroupResponse[]>("Group/Get");
this.groupsData = this.groupApi.getGroups();
this.groupsData.pipe(
switchMap(groups => this.faculties.pipe(
map(campuses => {
@ -267,11 +273,4 @@ export class TabsComponent {
@ViewChild('lecture') lectureHallEx!: OtherComponent;
@ViewChild('group') groupEx!: OtherComponent;
@ViewChild('professor') professorEx!: OtherComponent;
onClickNagmi() {
console.log('huy = ' + this.disciplineEx.selectedIds);
console.log('huy2 = ' + this.lectureHallEx.selectedIds);
console.log('huy3 = ' + this.groupEx.selectedIds);
console.log('huy3 = ' + this.professorEx.selectedIds);
}
}