Skip to content
Snippets Groups Projects
lecturer-dashboard.component.ts 2.92 KiB
Newer Older
ywb16155's avatar
ywb16155 committed
import {Component, OnDestroy, OnInit, ViewChild} 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';
ywb16155's avatar
ywb16155 committed
import {AgGridNg2} from 'ag-grid-angular/main';
import {GridOptions} from 'ag-grid-community';

@Component({
  selector: 'app-lecturer-dashboard',
  templateUrl: './lecturer-dashboard.component.html',
  styleUrls: ['./lecturer-dashboard.component.css']
})
export class LecturerDashboardComponent implements OnInit, OnDestroy {

ywb16155's avatar
ywb16155 committed
  @ViewChild('agGrid') agGrid: AgGridNg2;

  public gridOptions: GridOptions;
ywb16155's avatar
ywb16155 committed
  public columnDefs = [
    {headerName: 'Class Code', field: 'classCode', sortable: true, lockPosition: true},
    {headerName: 'Class Name', field: 'classname', sortable: true, lockPosition: true},
    {headerName: 'Year', field: 'year', sortable: true, lockPosition: true},
  private isAlive = true;
  private lecturerId: String;
  public classList: OmpClassDao[];
ywb16155's avatar
ywb16155 committed
  public rowData: any;

  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.gridOptions = {};
ywb16155's avatar
ywb16155 committed
    this.rowData = this.lecturerInfoService.getLecturerClasses(this.lecturerId);
    this.classList = [];
ywb16155's avatar
ywb16155 committed
    this.agGrid.ngOnDestroy();
  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']);
  }

  public goToTemplateView() {
    this.lecturerViewService.changeToDashboard(false);
    this.router.navigate(['/template-view']);
    this.lecturerDataService.isTemplate = false;
    this.lecturerViewService.changeToDashboard(false);
    this.router.navigate(['/creation-view']);
    this.lecturerDataService.isTemplate = true;
    this.lecturerViewService.changeToDashboard(false);
    this.router.navigate(['/creation-view']);