lecturer-template-view.component.ts 2.78 KiB
import {Component, OnDestroy, OnInit} from '@angular/core';
import {MinutePaperWrapperDao} from 'src/app/dao/minute-paper-wrapper.dao';
import {LecturerDataService} from 'src/app/services/lecturer-data.service';
import {LecturerInfoService} from 'src/app/services/lecturer-info.service';
import {Router} from '@angular/router';
import {GridOptions} from 'ag-grid-community';
import {EditTemplateButtonComponent} from 'src/app/GridComponents/EditTemplateButton/edit-template-button.component';
import {DeleteTemplateButtonComponent} from 'src/app/GridComponents/DeleteTemplateButton/delete-template-button.component';
import {LecturerViewService} from 'src/app/services/lecturer-view.service';
@Component({
selector: 'app-lecturer-template-view',
templateUrl: './lecturer-template-view.component.html',
styleUrls: ['./lecturer-template-view.component.css']
})
export class LecturerTemplateViewComponent implements OnInit, OnDestroy {
public templates: any;
public gridOptions: GridOptions;
public columnDefs = [
{headerName: 'Paper Name', valueGetter: param => param.data.paper.name, sortable: true, lockPosition: true},
{headerName: 'Topic', valueGetter: param => param.data.paper.topic, sortable: true, lockPosition: true, filter: true},
{headerName: 'Anonymous', valueGetter: param => param.data.paper.anonymous, sortable: true, lockPosition: true},
{headerName: 'Creation Date', valueGetter: param => param.data.paper.creationDate, sortable: true, lockPosition: true},
{headerName: 'Edit Template', cellRendererFramework: EditTemplateButtonComponent, lockPosition: true},
{headerName: 'Delete Template', cellRendererFramework: DeleteTemplateButtonComponent, lockPosition: true},
];
private lecturerId: String;
constructor(private lecturerDataService: LecturerDataService,
private lecturerInfoService: LecturerInfoService,
private lectureViewService: LecturerViewService,
private router: Router) {
}
ngOnInit(): void {
this.gridOptions = {
context: {componentParent: this}
};
this.lecturerId = sessionStorage.getItem('username');
this.templates = this.lecturerInfoService.getTemplates(this.lecturerId);
this.lectureViewService.changeToTemplateView(true);
}
ngOnDestroy(): void {
this.templates = [];
}
public editTemplate(template: MinutePaperWrapperDao) {
this.lecturerDataService.currentTemplate = template;
this.router.navigate(['/edit-template-view']);
this.ngOnDestroy();
}
public removeTemplate(wrapper: MinutePaperWrapperDao, transaction: any) {
const check = confirm('Are you sure you want to delete this template?');
if (check) {
this.gridOptions.api.updateRowData(transaction);
this.lecturerInfoService.deleteTemplate(wrapper.paper.paperId).subscribe();
}
}
}