Newer
Older
import {Component, OnDestroy, OnInit} from '@angular/core';
ywb16155
committed
import {LecturerInfoService} from 'src/app/services/lecturer-info.service';
import {LecturerDataService} from 'src/app/services/lecturer-data.service';
import {LecturerViewService} from 'src/app/services/lecturer-view.service';
import {Router} from '@angular/router';
import {QuestionDao} from 'src/app/dao/question.dao';
import {OmpClassDao} from 'src/app/dao/omp-class.dao';
import {MinutePaperDao} from '../../dao/minute-paper.dao';
import {MinutePaperWrapperDao} from '../../dao/minute-paper-wrapper.dao';
@Component({
selector: 'app-lecturer-create-omp-view',
templateUrl: './lecturer-create-omp-view.component.html',
styleUrls: ['./lecturer-create-omp-view.component.css']
})
export class LecturerCreateOmpViewComponent implements OnInit, OnDestroy {
public isTemplate: Boolean;
public questions: QuestionDao[];
public classes: OmpClassDao[];
public name: String;
public topic: String;
public isAnonymous: Boolean;
public currentClass: OmpClassDao;
constructor(private lecturerInfoService: LecturerInfoService,
private lecturerDataService: LecturerDataService,
private lecturerViewService: LecturerViewService,
private router: Router) {
}
ngOnInit(): void {
this.questions = [];
this.classes = [];
this.initialiseForms();
}
ngOnDestroy(): void {
this.questions = [];
this.classes = [];
}
private getClasses(): void {
this.lecturerInfoService.getLecturerClasses(this.lecturerDataService.lecturerId)
.subscribe((data: OmpClassDao[]) => data.forEach(e => {
this.classes.push(e);
this.currentClass = this.classes[0];
}));
}
private initialiseForms(): void {
this.name = 'Enter a name for this one-minute paper!';
this.topic = 'Enter a topic for this one-minute paper';
this.isTemplate = this.lecturerDataService.isTemplate;
this.getClasses();
// TODO - if (template) then define template array list
this.isAnonymous = false;
this.addQuestion();
private createWrapperObject() {
const paper = new MinutePaperDao('0', this.lecturerDataService.lecturerId, this.currentClass.classCode,
this.name, this.topic, this.isTemplate, this.isAnonymous, '0000-00-00');
return new MinutePaperWrapperDao(paper, this.questions);
}
public createPaper(): void {
this.lecturerInfoService.createPaper(this.createWrapperObject()).subscribe();
}
public createTemplate(): void {
this.lecturerInfoService.createTemplate(this.createWrapperObject()).subscribe();
}
public flipIsAnonymous(): void {
this.isAnonymous = !this.isAnonymous;
}
public addQuestion(): void {
this.questions.push(new QuestionDao('0', '0', 'Enter your question text!'));
public removeQuestion(index: number): void {
this.questions.splice(index, 1);