-
ywb16155 authored
commit #25 - updating CRUD repositories to have necessary annotation for delete functions, updating components to destroy themselves when navigating away
ywb16155 authoredcommit #25 - updating CRUD repositories to have necessary annotation for delete functions, updating components to destroy themselves when navigating away
lecturer-dashboard.component.ts 2.31 KiB
import {Component, OnDestroy, OnInit} from '@angular/core';
import {takeWhile} from 'rxjs/operators';
import {OmpClassDao} from 'src/app/dao/omp-class.dao';
import {LecturerInfoService} from 'src/app/services/lecturer-info.service';
import {ActivatedRoute, Router} from '@angular/router';
import {LecturerDataService} from 'src/app/services/lecturer-data.service';
import {LecturerViewService} from 'src/app/services/lecturer-view.service';
@Component({
selector: 'app-lecturer-dashboard',
templateUrl: './lecturer-dashboard.component.html',
styleUrls: ['./lecturer-dashboard.component.css']
})
export class LecturerDashboardComponent implements OnInit, OnDestroy {
private isAlive = true;
private lecturerId: String;
public classList: OmpClassDao[];
constructor(private lecturerInfoService: LecturerInfoService,
private lecturerDataService: LecturerDataService,
private lecturerViewService: LecturerViewService,
private router: Router,
private route: ActivatedRoute) {
}
ngOnInit(): void {
this.route.params.subscribe(params => { this.lecturerId = params.id; }).add(takeWhile(() => this.isAlive));
this.lecturerDataService.lecturerId = this.lecturerId;
this.classList = [];
this.getClasses();
}
ngOnDestroy(): void {
this.classList = [];
this.isAlive = false;
}
private getClasses() {
this.lecturerInfoService.getLecturerClasses(this.lecturerId).subscribe((data: OmpClassDao[]) => {
data.forEach(c => this.classList.push(c));
});
}
public goToPaperView(classCode: String) {
this.lecturerDataService.classCode = classCode;
this.lecturerViewService.changeToDashboard(false);
this.router.navigate(['/paper-view']);
this.ngOnDestroy();
}
public goToTemplateView() {
this.lecturerViewService.changeToDashboard(false);
this.router.navigate(['/template-view']);
this.ngOnDestroy();
}
public createPaperView() {
this.lecturerDataService.isTemplate = false;
this.lecturerViewService.changeToDashboard(false);
this.router.navigate(['/creation-view']);
this.ngOnDestroy();
}
public createTemplateView() {
this.lecturerDataService.isTemplate = true;
this.lecturerViewService.changeToDashboard(false);
this.router.navigate(['/creation-view']);
this.ngOnDestroy();
}
}