feat: add parameters as navigation

Now there is automatic navigation on the inserted url and on localStorage
This commit is contained in:
2024-08-28 03:52:47 +03:00
parent 60218a73f2
commit 79393a39c3
7 changed files with 131 additions and 80 deletions

@ -8,7 +8,7 @@ import {LoadingIndicatorComponent} from "@component/common/loading-indicator/loa
import {ProfessorResponse} from "@api/v1/professorResponse";
import {ProfessorService} from "@api/v1/professor.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-professor',
@ -30,18 +30,16 @@ export class ProfessorComponent implements OnInit, IScheduleTab {
protected filteredProfessors!: Observable<ProfessorResponse[]>;
protected professors: ProfessorResponse[] | null = null;
private readonly selected: TabSelect[] | null = null;
@ViewChild('professorIndicator') professorIndicator!: LoadingIndicatorComponent;
@Output() eventResult = new EventEmitter<number>();
constructor(private api: ProfessorService) {
let selectedData = TabStorageService.selected;
if (selectedData !== null && selectedData.selected !== null) {
if (selectedData.type === TabSelectType.professor)
this.selected = selectedData.selected;
}
constructor(private api: ProfessorService, private tabStorage: TabStorageService) {
}
existParams(data: TabSelectData): boolean {
return data.selected['professor'] !== undefined;
}
protected loadProfessors() {
@ -54,11 +52,12 @@ export class ProfessorComponent implements OnInit, IScheduleTab {
.subscribe(data => {
this.professors = data;
if (this.selected !== null && this.selected.length >= 1) {
let selectedProfessor = data.find(x => x.id === this.selected![0].index);
let selected = TabStorageService.selected?.selected['professor'];
if (selected) {
let selectedProfessor = data.find(x => x.id === selected.index);
if (selectedProfessor === undefined || selectedProfessor.name !== this.selected[0].name)
selectedProfessor = data.find(x => x.name === this.selected![0].name);
if (selectedProfessor === undefined || selectedProfessor.name !== selected.name)
selectedProfessor = data.find(x => x.name === selected.name);
if (selectedProfessor !== undefined)
this.onOptionSelected(selectedProfessor.id);
@ -96,7 +95,7 @@ export class ProfessorComponent implements OnInit, IScheduleTab {
this.professorControl.setValue(selectedOption.name);
this.eventResult.emit(selectedOption.id);
TabStorageService.select(new TabSelect(selectedOption.id, selectedOption.name), TabSelectType.professor, 0);
this.tabStorage.select(new TabSelect(selectedOption.id, selectedOption.name), TabSelectType.professor, 'professor');
}
}