diff --git a/src/app/creator-choice-content/creator-choice-content.component.html b/src/app/creator-choice-content/creator-choice-content.component.html index 53ae04cfc6d52c08d269093c704e271f094b678c..b7554136c8617e2f717411103e45f6790daef4fd 100644 --- a/src/app/creator-choice-content/creator-choice-content.component.html +++ b/src/app/creator-choice-content/creator-choice-content.component.html @@ -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> diff --git a/src/app/creator-choice-content/creator-choice-content.component.ts b/src/app/creator-choice-content/creator-choice-content.component.ts index c8c96da294715e66826f915a60609c5cf573c25f..50ddc36b14d51b308707e5628c47d7e9bdba141e 100644 --- a/src/app/creator-choice-content/creator-choice-content.component.ts +++ b/src/app/creator-choice-content/creator-choice-content.component.ts @@ -1,6 +1,17 @@ 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(); } }