Compare commits

..

No commits in common. "380b2efa0d0bad876e1ab3406fa724dbe1a7279c" and "a86e88e08775f5faba3d66fc60b2c667b69bce76" have entirely different histories.

11 changed files with 113 additions and 202 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "frontend", "name": "frontend",
"version": "1.0.0-b7", "version": "1.0.0-b6",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "frontend", "name": "frontend",
"version": "1.0.0-b7", "version": "1.0.0-b6",
"dependencies": { "dependencies": {
"@angular/animations": "^18.2.6", "@angular/animations": "^18.2.6",
"@angular/cdk": "~18.2.6", "@angular/cdk": "~18.2.6",

View File

@ -1,6 +1,6 @@
{ {
"name": "frontend", "name": "frontend",
"version": "1.0.0-b7", "version": "1.0.0-b6",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "ng serve", "start": "ng serve",

View File

@ -1,7 +1,7 @@
@if (loading) { @if (loading) {
<app-data-spinner/> <app-data-spinner/>
} @else { } @else {
<button mat-fab color="primary" (click)="retryLoad()"> <button mat-fab color="primary" (click)="retryFunction.emit()">
<mat-icon>refresh</mat-icon> <mat-icon>refresh</mat-icon>
</button> </button>
} }

View File

@ -18,9 +18,4 @@ import {MatButton, MatFabButton} from "@angular/material/button";
export class LoadingIndicatorComponent { export class LoadingIndicatorComponent {
@Input() loading: boolean = true; @Input() loading: boolean = true;
@Output() retryFunction: EventEmitter<void> = new EventEmitter<void>(); @Output() retryFunction: EventEmitter<void> = new EventEmitter<void>();
protected retryLoad() {
this.loading = true;
this.retryFunction.emit();
}
} }

View File

@ -1,4 +1,4 @@
import {Component, EventEmitter, ViewChild} from '@angular/core'; import {Component, EventEmitter, Output, ViewChild} from '@angular/core';
import {MatExpansionModule, MatExpansionPanel} from "@angular/material/expansion"; import {MatExpansionModule, MatExpansionPanel} from "@angular/material/expansion";
import {MatChipListbox, MatChipsModule} from '@angular/material/chips'; import {MatChipListbox, MatChipsModule} from '@angular/material/chips';
import {FormControl, FormsModule, ReactiveFormsModule} from "@angular/forms"; import {FormControl, FormsModule, ReactiveFormsModule} from "@angular/forms";
@ -9,11 +9,7 @@ import {FacultyResponse} from "@api/v1/facultyResponse";
import {FacultyService} from "@api/v1/faculty.service"; import {FacultyService} from "@api/v1/faculty.service";
import {GroupService} from "@api/v1/group.service"; import {GroupService} from "@api/v1/group.service";
import {IScheduleTab} from "@component/schedule/tabs/ischedule-tab"; import {IScheduleTab} from "@component/schedule/tabs/ischedule-tab";
import {TabSelect, TabStorageService} from "@service/tab-storage.service"; import {TabSelect, TabSelectData, TabSelectType, TabStorageService} from "@service/tab-storage.service";
enum Enclosure {
faculty, course, group
}
@Component({ @Component({
selector: 'app-group', selector: 'app-group',
@ -29,6 +25,7 @@ enum Enclosure {
styleUrl: './group.component.css', styleUrl: './group.component.css',
providers: [FacultyService, GroupService] providers: [FacultyService, GroupService]
}) })
export class GroupComponent implements IScheduleTab { export class GroupComponent implements IScheduleTab {
protected faculties: FacultyResponse[] | null = null; protected faculties: FacultyResponse[] | null = null;
protected courseNumbers: number[] | null = null; protected courseNumbers: number[] | null = null;
@ -54,50 +51,13 @@ export class GroupComponent implements IScheduleTab {
@ViewChild('courseIndicator') courseIndicator!: LoadingIndicatorComponent; @ViewChild('courseIndicator') courseIndicator!: LoadingIndicatorComponent;
@ViewChild('groupIndicator') groupIndicator!: LoadingIndicatorComponent; @ViewChild('groupIndicator') groupIndicator!: LoadingIndicatorComponent;
private resetCourse() { @Output() eventResult = new EventEmitter<number>();
this.courseNumber = null;
this.groups = []; constructor(private facultyApi: FacultyService, private groupApi: GroupService, private tabStorage: TabStorageService) {
this.formChipCourse.reset();
this.courseChip.value = undefined;
} }
private resetGroup() { existParams(data: TabSelectData): boolean {
this.filteredGroupsBehaviour = []; return data.selected['group'] !== undefined || data.selected['course'] !== undefined || data.selected['faculty'] !== undefined;
this.filteredGroupsMagistracy = [];
this.filteredGroupsSpecialist = [];
this.formChipGroup.reset();
this.groupChip.value = undefined;
}
public eventResult = new EventEmitter<number>();
public selectChangeEvent = new EventEmitter<TabSelect[]>();
constructor(private facultyApi: FacultyService, private groupApi: GroupService) {
}
private getSelectedTabs(): TabSelect[] {
const faculty = this.facultyChip.value;
const course = this.courseChip.value;
const group = this.groupChip.value;
const result: TabSelect[] = [];
if (faculty)
result.push(new TabSelect(faculty, this.faculties!.find(x => x.id === faculty)?.name ?? ''));
if (course)
result.push(new TabSelect(course, course.toString()));
if (group)
result.push(new TabSelect(group, this.groups!.find(x => x.id == group)?.name ?? ''));
return result;
}
public getEnclosureList(): string[] {
return Object.keys(Enclosure).filter((item) => {
return isNaN(Number(item));
});
} }
protected loadFaculties() { protected loadFaculties() {
@ -109,8 +69,7 @@ export class GroupComponent implements IScheduleTab {
.subscribe(data => { .subscribe(data => {
this.faculties = data; this.faculties = data;
let selected = TabStorageService.selected?.selected[this.getEnclosureList()[Enclosure.faculty]]; let selected = TabStorageService.selected?.selected['faculty'];
if (selected) { if (selected) {
let selectedFaculty = data.find(x => x.id === selected.index); let selectedFaculty = data.find(x => x.id === selected.index);
@ -119,7 +78,7 @@ export class GroupComponent implements IScheduleTab {
if (selectedFaculty !== undefined) { if (selectedFaculty !== undefined) {
TabStorageService.trySelectChip(selectedFaculty.id, this.facultyChip); TabStorageService.trySelectChip(selectedFaculty.id, this.facultyChip);
this.onFacultySelected(selectedFaculty.id, true); this.onFacultySelected(selectedFaculty.id);
} }
} }
}); });
@ -145,7 +104,7 @@ export class GroupComponent implements IScheduleTab {
.sort((a, b) => a - b)) .sort((a, b) => a - b))
); );
let selected = TabStorageService.selected?.selected[this.getEnclosureList()[Enclosure.course]]; let selected = TabStorageService.selected?.selected['course'];
if (selected) { if (selected) {
let selectedCourse = this.courseNumbers.find(x => x === selected.index); let selectedCourse = this.courseNumbers.find(x => x === selected.index);
@ -154,11 +113,11 @@ export class GroupComponent implements IScheduleTab {
if (selectedCourse !== undefined) { if (selectedCourse !== undefined) {
TabStorageService.trySelectChip(selectedCourse, this.courseChip); TabStorageService.trySelectChip(selectedCourse, this.courseChip);
this.onCourseSelected(selectedCourse, true); this.onCourseSelected(selectedCourse);
} }
} }
let selectedGroupStorage = TabStorageService.selected?.selected[this.getEnclosureList()[Enclosure.group]]; let selectedGroupStorage = TabStorageService.selected?.selected['group'];
if (selectedGroupStorage) { if (selectedGroupStorage) {
let selectedGroup = data.find(x => x.id === selectedGroupStorage.index); let selectedGroup = data.find(x => x.id === selectedGroupStorage.index);
@ -167,7 +126,7 @@ export class GroupComponent implements IScheduleTab {
if (selectedGroup !== undefined) { if (selectedGroup !== undefined) {
TabStorageService.trySelectChip(selectedGroup.id, this.groupChip); TabStorageService.trySelectChip(selectedGroup.id, this.groupChip);
this.onGroupSelected(selectedGroup.id, true); this.onGroupSelected(selectedGroup.id);
} }
} }
}); });
@ -188,19 +147,18 @@ export class GroupComponent implements IScheduleTab {
} }
} }
protected onFacultySelected(index: number, loadMode: boolean = false) { protected onFacultySelected(index: number) {
this.resetCourse(); this.courseNumber = null;
this.resetGroup(); this.groups = [];
this.formChipGroup.reset();
this.formChipCourse.reset();
if (index === undefined) { if (index === undefined) {
this.facultyId = null; this.facultyId = null;
return; return;
} }
if (loadMode) this.tabStorage.select(new TabSelect(index, this.faculties!.find(x => x.id === index)?.name ?? ''), TabSelectType.group, 'faculty');
this.facultyChip.value = index;
else
this.selectChangeEvent.emit(this.getSelectedTabs());
this.facultyId = index; this.facultyId = index;
this.courseNumberPanel.open(); this.courseNumberPanel.open();
@ -208,32 +166,29 @@ export class GroupComponent implements IScheduleTab {
this.loadCourseGroup(); this.loadCourseGroup();
} }
protected onCourseSelected(course: number, loadMode: boolean = false) { protected onCourseSelected(course: number) {
this.resetGroup(); this.filteredGroupsBehaviour = [];
this.filteredGroupsMagistracy = [];
this.filteredGroupsSpecialist = [];
this.formChipGroup.reset();
if (course === undefined) { if (course === undefined) {
this.courseNumber = null; this.courseNumber = null;
return; return;
} }
if (loadMode) this.tabStorage.select(new TabSelect(course, course.toString()), TabSelectType.group, 'course');
this.courseChip.value = course;
else
this.selectChangeEvent.emit(this.getSelectedTabs());
this.courseNumber = course; this.courseNumber = course;
this.groupPanel.open(); this.groupPanel.open();
this.loadCourseGroup(); this.loadCourseGroup();
} }
protected onGroupSelected(index: number, loadMode: boolean = false) { protected onGroupSelected(index: number) {
if (index === undefined) if (index === undefined)
return; return;
if (loadMode) this.tabStorage.select(new TabSelect(index, this.groups!.find(x => x.id == index)?.name ?? ''), TabSelectType.group, 'group');
this.groupChip.value = index;
this.selectChangeEvent.emit(this.getSelectedTabs());
this.groupPanel.close(); this.groupPanel.close();
this.eventResult.emit(index); this.eventResult.emit(index);

View File

@ -1,12 +1,8 @@
import {EventEmitter} from "@angular/core"; import {EventEmitter} from "@angular/core";
import {TabSelect} from "@service/tab-storage.service"; import {TabSelectData} from "@service/tab-storage.service";
export interface IScheduleTab { export interface IScheduleTab {
load(): void; load(): void;
getEnclosureList(): string[];
eventResult: EventEmitter<number>; eventResult: EventEmitter<number>;
selectChangeEvent: EventEmitter<TabSelect[]>; existParams(data: TabSelectData): boolean;
} }

View File

@ -1,4 +1,4 @@
import {Component, EventEmitter, ViewChild} from '@angular/core'; import {Component, EventEmitter, Output, ViewChild} from '@angular/core';
import {AsyncPipe} from "@angular/common"; import {AsyncPipe} from "@angular/common";
import {MatAccordion, MatExpansionModule, MatExpansionPanel} from "@angular/material/expansion"; import {MatAccordion, MatExpansionModule, MatExpansionPanel} from "@angular/material/expansion";
import {MatChipListbox, MatChipsModule} from "@angular/material/chips"; import {MatChipListbox, MatChipsModule} from "@angular/material/chips";
@ -10,11 +10,7 @@ import {LectureHallResponse} from "@api/v1/lectureHallResponse";
import {CampusService} from "@api/v1/campus.service"; import {CampusService} from "@api/v1/campus.service";
import {LectureHallService} from "@api/v1/lectureHall.service"; import {LectureHallService} from "@api/v1/lectureHall.service";
import {IScheduleTab} from "@component/schedule/tabs/ischedule-tab"; import {IScheduleTab} from "@component/schedule/tabs/ischedule-tab";
import {TabSelect, TabStorageService} from "@service/tab-storage.service"; import {TabSelect, TabSelectData, TabSelectType, TabStorageService} from "@service/tab-storage.service";
enum Enclosure {
campus, lecture
}
@Component({ @Component({
selector: 'app-lecture-hall', selector: 'app-lecture-hall',
@ -31,6 +27,7 @@ enum Enclosure {
styleUrl: './lecture-hall.component.css', styleUrl: './lecture-hall.component.css',
providers: [CampusService, LectureHallService] providers: [CampusService, LectureHallService]
}) })
export class LectureHallComponent implements IScheduleTab { export class LectureHallComponent implements IScheduleTab {
protected campusId: number | null = null; protected campusId: number | null = null;
protected formLectureHalls: FormControl = new FormControl(); protected formLectureHalls: FormControl = new FormControl();
@ -38,6 +35,8 @@ export class LectureHallComponent implements IScheduleTab {
protected campuses: CampusBasicInfoResponse[] | null = null; protected campuses: CampusBasicInfoResponse[] | null = null;
protected lectureHallsFiltered: LectureHallResponse[] | null = null; protected lectureHallsFiltered: LectureHallResponse[] | null = null;
@Output() eventResult = new EventEmitter<number>();
@ViewChild('lecturePanel') lecturePanel!: MatExpansionPanel; @ViewChild('lecturePanel') lecturePanel!: MatExpansionPanel;
@ViewChild('lectureIndicator') lectureIndicator!: LoadingIndicatorComponent; @ViewChild('lectureIndicator') lectureIndicator!: LoadingIndicatorComponent;
@ViewChild('campusIndicator') campusIndicator!: LoadingIndicatorComponent; @ViewChild('campusIndicator') campusIndicator!: LoadingIndicatorComponent;
@ -47,31 +46,11 @@ export class LectureHallComponent implements IScheduleTab {
private lectureHalls: LectureHallResponse[] | null = null; private lectureHalls: LectureHallResponse[] | null = null;
public eventResult = new EventEmitter<number>(); constructor(private campusApi: CampusService, private lectureHallApi: LectureHallService, private tabStorage: TabStorageService) {
public selectChangeEvent = new EventEmitter<TabSelect[]>();
constructor(private campusApi: CampusService, private lectureHallApi: LectureHallService) {
} }
private getSelectedTabs(): TabSelect[] { existParams(data: TabSelectData): boolean {
const campus = this.campusChip.value; return data.selected['campus'] !== undefined || data.selected['lecture'] !== undefined;
const lecture = this.lectureChip.value;
const result: TabSelect[] = [];
if (campus)
result.push(new TabSelect(campus, this.campuses!.find(x => x.id === campus)?.codeName ?? ''));
if (lecture)
result.push(new TabSelect(lecture, this.lectureHallsFiltered!.find(x => x.id === lecture)?.name ?? ''));
return result;
}
getEnclosureList(): string[] {
return Object.keys(Enclosure).filter((item) => {
return isNaN(Number(item));
});
} }
protected loadCampuses() { protected loadCampuses() {
@ -83,7 +62,7 @@ export class LectureHallComponent implements IScheduleTab {
.subscribe(data => { .subscribe(data => {
this.campuses = data; this.campuses = data;
let selected = TabStorageService.selected?.selected[this.getEnclosureList()[Enclosure.campus]]; let selected = TabStorageService.selected?.selected['campus'];
if (selected) { if (selected) {
let selectedCampus = data.find(x => x.id === selected.index); let selectedCampus = data.find(x => x.id === selected.index);
@ -92,7 +71,7 @@ export class LectureHallComponent implements IScheduleTab {
if (selectedCampus !== undefined) { if (selectedCampus !== undefined) {
TabStorageService.trySelectChip(selectedCampus.id, this.campusChip); TabStorageService.trySelectChip(selectedCampus.id, this.campusChip);
this.onCampusSelected(selectedCampus.id, true); this.onCampusSelected(selectedCampus.id);
} }
} }
}); });
@ -102,14 +81,10 @@ export class LectureHallComponent implements IScheduleTab {
this.lectureHallsFiltered = this.lectureHalls?.filter(x => x.campusId === this.campusId) ?? null; this.lectureHallsFiltered = this.lectureHalls?.filter(x => x.campusId === this.campusId) ?? null;
} }
protected onCampusSelected(index: number, loadMode: boolean = false) { protected onCampusSelected(index: number) {
this.formLectureHalls.reset(); this.formLectureHalls.reset();
this.lectureChip.value = undefined;
if (loadMode) this.tabStorage.select(new TabSelect(index, this.campuses!.find(x => x.id === index)?.codeName ?? ''), TabSelectType.lecture, 'campus');
this.campusChip.value = index;
else
this.selectChangeEvent.emit(this.getSelectedTabs());
if (index === undefined) { if (index === undefined) {
this.campusId = null; this.campusId = null;
@ -136,7 +111,7 @@ export class LectureHallComponent implements IScheduleTab {
this.lectureHalls = data; this.lectureHalls = data;
this.filteringLectureHalls(); this.filteringLectureHalls();
let selected = TabStorageService.selected?.selected[this.getEnclosureList()[Enclosure.lecture]]; let selected = TabStorageService.selected?.selected['lecture'];
if (selected) { if (selected) {
let selectedLecture = data.find(x => x.id === selected.index); let selectedLecture = data.find(x => x.id === selected.index);
@ -145,20 +120,17 @@ export class LectureHallComponent implements IScheduleTab {
if (selectedLecture !== undefined) { if (selectedLecture !== undefined) {
TabStorageService.trySelectChip(selectedLecture.id, this.lectureChip); TabStorageService.trySelectChip(selectedLecture.id, this.lectureChip);
this.onLectureHallSelected(selectedLecture.id, true); this.onLectureHallSelected(selectedLecture.id);
} }
} }
}); });
} }
protected onLectureHallSelected(index: number, loadMode: boolean = false) { protected onLectureHallSelected(index: number) {
if (index === undefined) if (index === undefined)
return; return;
if (loadMode) this.tabStorage.select(new TabSelect(index, this.lectureHallsFiltered!.find(x => x.id === index)?.name ?? ''), TabSelectType.lecture, 'lecture');
this.lectureChip.value = index;
else
this.selectChangeEvent.emit(this.getSelectedTabs());
this.lecturePanel.close(); this.lecturePanel.close();
this.eventResult.emit(index); this.eventResult.emit(index);

View File

@ -1,4 +1,4 @@
import {Component, EventEmitter, OnInit, ViewChild} from "@angular/core"; import {Component, EventEmitter, OnInit, Output, ViewChild} from "@angular/core";
import {MatFormField, MatInput} from "@angular/material/input"; import {MatFormField, MatInput} from "@angular/material/input";
import {FormControl, ReactiveFormsModule} from "@angular/forms"; import {FormControl, ReactiveFormsModule} from "@angular/forms";
import {MatAutocompleteModule} from "@angular/material/autocomplete"; import {MatAutocompleteModule} from "@angular/material/autocomplete";
@ -8,7 +8,7 @@ import {LoadingIndicatorComponent} from "@component/common/loading-indicator/loa
import {ProfessorResponse} from "@api/v1/professorResponse"; import {ProfessorResponse} from "@api/v1/professorResponse";
import {ProfessorService} from "@api/v1/professor.service"; import {ProfessorService} from "@api/v1/professor.service";
import {IScheduleTab} from "@component/schedule/tabs/ischedule-tab"; import {IScheduleTab} from "@component/schedule/tabs/ischedule-tab";
import {TabSelect, TabStorageService} from "@service/tab-storage.service"; import {TabSelect, TabSelectData, TabSelectType, TabStorageService} from "@service/tab-storage.service";
@Component({ @Component({
selector: 'app-professor', selector: 'app-professor',
@ -33,14 +33,13 @@ export class ProfessorComponent implements OnInit, IScheduleTab {
@ViewChild('professorIndicator') professorIndicator!: LoadingIndicatorComponent; @ViewChild('professorIndicator') professorIndicator!: LoadingIndicatorComponent;
public eventResult = new EventEmitter<number>(); @Output() eventResult = new EventEmitter<number>();
public selectChangeEvent = new EventEmitter<TabSelect[]>();
constructor(private api: ProfessorService) { constructor(private api: ProfessorService, private tabStorage: TabStorageService) {
} }
getEnclosureList(): string[] { existParams(data: TabSelectData): boolean {
return ['professor']; return data.selected['professor'] !== undefined;
} }
protected loadProfessors() { protected loadProfessors() {
@ -96,7 +95,7 @@ export class ProfessorComponent implements OnInit, IScheduleTab {
this.professorControl.setValue(selectedOption.name); this.professorControl.setValue(selectedOption.name);
this.eventResult.emit(selectedOption.id); this.eventResult.emit(selectedOption.id);
this.selectChangeEvent.emit([new TabSelect(selectedOption.id, selectedOption.name)]); this.tabStorage.select(new TabSelect(selectedOption.id, selectedOption.name), TabSelectType.professor, 'professor');
} }
} }

View File

@ -3,17 +3,17 @@
(selectedTabChange)="chooseTabs($event.index)"> (selectedTabChange)="chooseTabs($event.index)">
<mat-tab label="Группа"> <mat-tab label="Группа">
<div> <div>
<app-group #groupTab/> <app-group #groupTab (eventResult)="groupSelected($event)"/>
</div> </div>
</mat-tab> </mat-tab>
<mat-tab label="Преподаватель"> <mat-tab label="Преподаватель">
<div> <div>
<app-professor #professorTab/> <app-professor #professorTab (eventResult)="professorSelected($event)"/>
</div> </div>
</mat-tab> </mat-tab>
<mat-tab label="Кабинет"> <mat-tab label="Кабинет">
<div> <div>
<app-lecture-hall #lectureHallTab/> <app-lecture-hall #lectureHallTab (eventResult)="lectureHallSelected($event)"/>
</div> </div>
</mat-tab> </mat-tab>

View File

@ -17,7 +17,7 @@ import {GroupService} from "@api/v1/group.service";
import {ProfessorService} from "@api/v1/professor.service"; import {ProfessorService} from "@api/v1/professor.service";
import {AuthRoles} from "@model/AuthRoles"; import {AuthRoles} from "@model/AuthRoles";
import {HasRoleDirective} from "@/directives/has-role.directive"; import {HasRoleDirective} from "@/directives/has-role.directive";
import {TabSelectType, TabStorageService} from "@service/tab-storage.service"; import {TabStorageService} from "@service/tab-storage.service";
export enum TabsSelect { export enum TabsSelect {
Group, Group,
@ -49,91 +49,77 @@ export enum TabsSelect {
export class TabsComponent implements AfterViewInit { export class TabsComponent implements AfterViewInit {
@Output() eventResult = new EventEmitter<[TabsSelect, number, Observable<ScheduleResponse[]>]>(); @Output() eventResult = new EventEmitter<[TabsSelect, number, Observable<ScheduleResponse[]>]>();
private currentTab: number = -1;
constructor(private scheduleApi: ScheduleService, constructor(private scheduleApi: ScheduleService,
private disciplineApi: DisciplineService, private disciplineApi: DisciplineService,
private lectureApi: LectureHallService, private lectureApi: LectureHallService,
private groupApi: GroupService, private groupApi: GroupService,
private professorApi: ProfessorService, private professorApi: ProfessorService) {
private tabStorage: TabStorageService) {
} }
ngAfterViewInit(): void { ngAfterViewInit(): void {
this.groupTab.selectChangeEvent.subscribe(event => this.tabStorage.select(TabSelectType.group, event));
this.professorTab.selectChangeEvent.subscribe(event => this.tabStorage.select(TabSelectType.professor, event));
this.lectureHallTab.selectChangeEvent.subscribe(event => this.tabStorage.select(TabSelectType.lecture, event));
this.groupTab.eventResult.subscribe(event => this.eventResult.emit(
[
TabsSelect.Group,
event,
this.scheduleApi.getByGroup(event)
]
));
this.professorTab.eventResult.subscribe(event => this.eventResult.emit(
[
TabsSelect.Professor,
event,
this.scheduleApi.getByProfessor(event)
]
));
this.lectureHallTab.eventResult.subscribe(event => this.eventResult.emit(
[
TabsSelect.LectureHall,
event,
this.scheduleApi.getByLectureHall(event)
]
));
let selected = TabStorageService.selected; let selected = TabStorageService.selected;
let index = 0; let index = 0;
if (selected !== null) { if (selected !== null) {
const selectedKeys = Object.keys(selected?.selected);
if (selected.type === null) { if (selected.type === null) {
if (this.groupTab.getEnclosureList().every((value, index) => value === selectedKeys[index])) if (this.groupTab.existParams(selected))
index = 0; index = 0;
else if (this.professorTab.getEnclosureList().every((value, index) => value === selectedKeys[index])) else if (this.professorTab.existParams(selected))
index = 1; index = 1;
else if (this.lectureHallTab.getEnclosureList().every((value, index) => value === selectedKeys[index])) else if (this.lectureHallTab.existParams(selected))
index = 2; index = 2;
} else } else
index = selected.type; index = selected.type;
} }
if (index === 0) if (index === null || index === 0)
this.chooseTabs(0).then(); this.chooseTabs(0).then();
else else
this.tabs.selectedIndex = index; this.tabs.selectedIndex = index;
} }
protected groupSelected(id: number) {
this.eventResult.emit(
[
TabsSelect.Group,
id,
this.scheduleApi.getByGroup(id)
]
);
}
protected professorSelected(id: number) {
this.eventResult.emit(
[
TabsSelect.Professor,
id,
this.scheduleApi.getByProfessor(id)
]
);
}
protected lectureHallSelected(id: number) {
this.eventResult.emit(
[
TabsSelect.LectureHall,
id,
this.scheduleApi.getByLectureHall(id)
]
);
}
protected async chooseTabs(index: number) { protected async chooseTabs(index: number) {
let needGetEnclosure = false;
if (this.currentTab !== index) {
this.currentTab = index;
needGetEnclosure = true;
}
switch (index) { switch (index) {
case 0: case 0:
this.groupTab.load(); this.groupTab.load();
if (needGetEnclosure)
this.tabStorage.enclosure = this.groupTab.getEnclosureList();
break; break;
case 1: case 1:
this.professorTab.load(); this.professorTab.load();
if (needGetEnclosure)
this.tabStorage.enclosure = this.professorTab.getEnclosureList();
break; break;
case 2: case 2:
this.lectureHallTab.load(); this.lectureHallTab.load();
if (needGetEnclosure)
this.tabStorage.enclosure = this.lectureHallTab.getEnclosureList();
break; break;
case 3: case 3:
await this.loadDisciplines(); await this.loadDisciplines();

View File

@ -30,7 +30,6 @@ export interface TabSelectData {
}) })
export class TabStorageService { export class TabStorageService {
private static dataName = 'tabSelectedData'; private static dataName = 'tabSelectedData';
private _enclosure: string[] = [];
constructor(private router: Router, private location: Location) { constructor(private router: Router, private location: Location) {
} }
@ -53,18 +52,27 @@ export class TabStorageService {
}, 100); }, 100);
} }
public set enclosure(data: string[]) { private resetIfNeed(type: TabSelectType) {
this._enclosure = data; let selectedData = TabStorageService.selected;
if (selectedData === null || selectedData?.type === null)
return;
if (selectedData.type !== type) {
localStorage.removeItem(TabStorageService.dataName);
const currentUrl = this.router.url.split('?')[0];
this.location.replaceState(currentUrl);
}
} }
public select(type: TabSelectType, tabSelected: TabSelect[]) { public select(selected: TabSelect, type: TabSelectType, navigateName: string) {
let selectedData = {selected: {}} as TabSelectData; this.resetIfNeed(type);
let selectedData = TabStorageService.selected;
for (let index = 0; index < this._enclosure.length; index++) { if (selectedData === null || !selectedData.selected)
if (tabSelected[index]) selectedData = {selected: {}} as TabSelectData;
selectedData.selected[this._enclosure[index]] = tabSelected[index];
}
selectedData.selected[navigateName] = selected;
selectedData.type = type; selectedData.type = type;
localStorage.setItem(TabStorageService.dataName, JSON.stringify(selectedData)); localStorage.setItem(TabStorageService.dataName, JSON.stringify(selectedData));