feat: add parameters as navigation
Now there is automatic navigation on the inserted url and on localStorage
This commit is contained in:
@ -9,7 +9,7 @@ import {FacultyResponse} from "@api/v1/facultyResponse";
|
||||
import {FacultyService} from "@api/v1/faculty.service";
|
||||
import {GroupService} from "@api/v1/group.service";
|
||||
import {IScheduleTab} from "@component/schedule/tabs/ischedule-tab";
|
||||
import {TabSelect, TabSelectType, TabStorageService} from "@service/tab-storage.service";
|
||||
import {TabSelect, TabSelectData, TabSelectType, TabStorageService} from "@service/tab-storage.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-group',
|
||||
@ -45,20 +45,17 @@ export class GroupComponent implements IScheduleTab {
|
||||
@ViewChild('courseChip') courseChip!: MatChipListbox;
|
||||
@ViewChild('groupChip') groupChip!: MatChipListbox;
|
||||
|
||||
private readonly selected: TabSelect[] | null = null;
|
||||
|
||||
@ViewChild('facultyIndicator') facultyIndicator!: LoadingIndicatorComponent;
|
||||
@ViewChild('courseIndicator') courseIndicator!: LoadingIndicatorComponent;
|
||||
@ViewChild('groupIndicator') groupIndicator!: LoadingIndicatorComponent;
|
||||
|
||||
@Output() eventResult = new EventEmitter<number>();
|
||||
|
||||
constructor(private facultyApi: FacultyService, private groupApi: GroupService) {
|
||||
let selectedData = TabStorageService.selected;
|
||||
if (selectedData !== null && selectedData.selected !== null) {
|
||||
if (selectedData.type === TabSelectType.group)
|
||||
this.selected = selectedData.selected;
|
||||
}
|
||||
constructor(private facultyApi: FacultyService, private groupApi: GroupService, private tabStorage: TabStorageService) {
|
||||
}
|
||||
|
||||
existParams(data: TabSelectData): boolean {
|
||||
return data.selected['group'] !== undefined || data.selected['course'] !== undefined || data.selected['faculty'] !== undefined;
|
||||
}
|
||||
|
||||
protected loadFaculties() {
|
||||
@ -70,11 +67,12 @@ export class GroupComponent implements IScheduleTab {
|
||||
.subscribe(data => {
|
||||
this.faculties = data;
|
||||
|
||||
if (this.selected !== null && this.selected.length >= 1) {
|
||||
let selectedFaculty = data.find(x => x.id === this.selected![0].index);
|
||||
let selected = TabStorageService.selected?.selected['faculty'];
|
||||
if (selected) {
|
||||
let selectedFaculty = data.find(x => x.id === selected.index);
|
||||
|
||||
if (selectedFaculty === undefined || selectedFaculty.name !== this.selected[0].name)
|
||||
selectedFaculty = data.find(x => x.name === this.selected![0].name);
|
||||
if (selectedFaculty === undefined || selectedFaculty.name !== selected.name)
|
||||
selectedFaculty = data.find(x => x.name === selected.name);
|
||||
|
||||
if (selectedFaculty !== undefined) {
|
||||
TabStorageService.trySelectChip(selectedFaculty.id, this.facultyChip);
|
||||
@ -104,8 +102,12 @@ export class GroupComponent implements IScheduleTab {
|
||||
.sort((a, b) => a - b))
|
||||
);
|
||||
|
||||
if (this.selected !== null && this.selected.length >= 2) {
|
||||
let selectedCourse = this.courseNumbers.find(x => x === this.selected![1].index);
|
||||
let selected = TabStorageService.selected?.selected['course'];
|
||||
if (selected) {
|
||||
let selectedCourse = this.courseNumbers.find(x => x === selected.index);
|
||||
|
||||
if (selectedCourse === undefined)
|
||||
selectedCourse = this.courseNumbers.find(x => x.toString() === selected.name);
|
||||
|
||||
if (selectedCourse !== undefined) {
|
||||
TabStorageService.trySelectChip(selectedCourse, this.courseChip);
|
||||
@ -113,11 +115,12 @@ export class GroupComponent implements IScheduleTab {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.selected !== null && this.selected.length >= 3) {
|
||||
let selectedGroup = data.find(x => x.id === this.selected![2].index);
|
||||
let selectedGroupStorage = TabStorageService.selected?.selected['group'];
|
||||
if (selectedGroupStorage) {
|
||||
let selectedGroup = data.find(x => x.id === selectedGroupStorage.index);
|
||||
|
||||
if (selectedGroup === undefined || selectedGroup.name !== this.selected[2].name)
|
||||
selectedGroup = data.find(x => x.name === this.selected![2].name);
|
||||
if (selectedGroup === undefined || selectedGroup.name !== selectedGroupStorage.name)
|
||||
selectedGroup = data.find(x => x.name === selectedGroupStorage.name);
|
||||
|
||||
if (selectedGroup !== undefined) {
|
||||
TabStorageService.trySelectChip(selectedGroup.id, this.groupChip);
|
||||
@ -144,7 +147,7 @@ export class GroupComponent implements IScheduleTab {
|
||||
return;
|
||||
}
|
||||
|
||||
TabStorageService.select(new TabSelect(index, this.faculties!.find(x => x.id === index)?.name ?? ''), TabSelectType.group, 0);
|
||||
this.tabStorage.select(new TabSelect(index, this.faculties!.find(x => x.id === index)?.name ?? ''), TabSelectType.group, 'faculty');
|
||||
|
||||
this.facultyId = index;
|
||||
this.courseNumberPanel.open();
|
||||
@ -161,7 +164,7 @@ export class GroupComponent implements IScheduleTab {
|
||||
return;
|
||||
}
|
||||
|
||||
TabStorageService.select(new TabSelect(course, course.toString()), TabSelectType.group, 1);
|
||||
this.tabStorage.select(new TabSelect(course, course.toString()), TabSelectType.group, 'course');
|
||||
|
||||
this.courseNumber = course;
|
||||
this.groupPanel.open();
|
||||
@ -172,7 +175,7 @@ export class GroupComponent implements IScheduleTab {
|
||||
if (index === undefined)
|
||||
return;
|
||||
|
||||
TabStorageService.select(new TabSelect(index, this.groups!.find(x => x.id == index)?.name ?? ''), TabSelectType.group, 2);
|
||||
this.tabStorage.select(new TabSelect(index, this.groups!.find(x => x.id == index)?.name ?? ''), TabSelectType.group, 'group');
|
||||
|
||||
this.groupPanel.close();
|
||||
this.eventResult.emit(index);
|
||||
|
Reference in New Issue
Block a user