Skip to content
Snippets Groups Projects
Verified Commit 763eb79b authored by Lukas Maximilian Kimpel's avatar Lukas Maximilian Kimpel
Browse files

Implement submit function to add or edit choice content

Implement function to add Answers to ChoiceContent
parent 74d85fc8
1 merge request!92Resolve "content types (logic)"
......@@ -7,18 +7,19 @@
</mat-form-field>
<mat-divider></mat-divider>
<mat-table #table [dataSource]="content.options">
<mat-table #table [dataSource]="correctAnswers">
<ng-container matColumnDef="label">
<mat-header-cell *matHeaderCellDef>Answer</mat-header-cell>
<mat-cell *matCellDef="let answer">
<mat-checkbox color="primary">{{ answer.label }}</mat-checkbox>
<!-- ToDo: Check ngModel -->
<mat-checkbox color="primary" [(ngModel)]="answer.correct" name="answer">{{ answer.answerOption.label }} is {{ answer.correct }}</mat-checkbox>
</mat-cell>
</ng-container>
<ng-container matColumnDef="points">
<mat-header-cell *matHeaderCellDef>Points</mat-header-cell>
<mat-cell *matCellDef="let answer">{{ answer.points }}</mat-cell>
<mat-cell *matCellDef="let answer">{{ answer.answerOption.points }}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
......
import { Component, OnInit } from '@angular/core';
import { AnswerOption } from '../answer-option';
import { ChoiceContent } from '../choice-content';
import { ContentService } from '../content.service';
export class CorrectAnswer {
answerOption: AnswerOption;
correct: boolean;
constructor(answerOption: AnswerOption, correct: boolean) {
this.answerOption = answerOption;
this.correct = correct;
}
}
@Component({
selector: 'app-creator-choice-content',
......@@ -9,7 +20,7 @@ import { ChoiceContent } from '../choice-content';
})
export class CreatorChoiceContentComponent implements OnInit {
content: ChoiceContent = new ChoiceContent('2',
content: ChoiceContent = new ChoiceContent('0',
'1',
'1',
'Choice Content 1',
......@@ -21,20 +32,37 @@ export class CreatorChoiceContentComponent implements OnInit {
new AnswerOption('Option 3', '20'),
new AnswerOption('Option 4', '30')
],
[1, 2, 3],
[0, 1, 3],
true);
displayedColumns = ['label', 'points'];
constructor() {
correctAnswers: CorrectAnswer[] = [];
constructor(private contentService: ContentService) {
}
ngOnInit() {
for (let i = 0; i < this.content.options.length; i++) {
this.correctAnswers.push(new CorrectAnswer(this.content.options[i], this.content.correctOptionIndexes.includes(i)));
}
console.log(this.correctAnswers);
}
submitContent() {
if (this.content.contentId === '0') {
this.contentService.addContent(this.content).subscribe();
} else {
// ToDo: Implement function in service
// this.contentService.updateContent(this.content).subscribe();
}
}
addAnswer(isCorrect: boolean, label: string, points: number) {
addAnswer(isCorrect: boolean, label: string, points: string) {
this.content.options.push(new AnswerOption(label, points));
if (isCorrect) {
this.content.correctOptionIndexes.push(this.content.options.length);
}
this.submitContent();
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment