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..6f3cee20c23a9be85ca7835d0e23e33c0fe5cc9b 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,21 @@ </mat-form-field> <mat-divider></mat-divider> - <mat-table #table [dataSource]="content.options"> + <mat-table #table [dataSource]="displayAnswers"> <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" [checked]="answer.correct" + name="{{ answer.answerOption.label }}">{{ 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> @@ -29,17 +32,17 @@ <div fxLayout="row" fxLayoutGap="15px"> <div fxLayout="column" fxLayoutAlign="center"> - <mat-checkbox #answerIsCorrect color="primary">Is correct</mat-checkbox> + <mat-checkbox #answerIsCorrect [(ngModel)]="newAnswerOptionChecked" [checked]="newAnswerOptionChecked" color="primary" name="ischecked">Is correct</mat-checkbox> </div> <mat-form-field class="input-block"> - <input matInput #answerLabel placeholder="Answer" name="answer"> + <input matInput #answerLabel [(ngModel)]="newAnswerOptionLabel" placeholder="Answer" name="answer"> </mat-form-field> <mat-form-field class="input-block"> - <input matInput #answerPoints placeholder="Points" name="points"> + <input matInput #answerPoints [(ngModel)]="newAnswerOptionPoints" placeholder="Points" name="points"> </mat-form-field> <div fxLayout="column" fxLayoutAlign="center"> <button mat-button type="button" - (click)="addAnswer(answerIsCorrect.value, answerLabel.value, answerPoints.value)"> + (click)="addAnswer(); answerIsCorrect.checked = false; answerLabel.value = ''; answerPoints.value = ''"> Add Answer </button> </div> 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..8c72948d8dbaab118a052f48b55b2af7c496c2d2 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 DisplayAnswer { + answerOption: AnswerOption; + correct: boolean; + + constructor(answerOption: AnswerOption, correct: boolean) { + this.answerOption = answerOption; + this.correct = correct; + } +} @Component({ selector: 'app-creator-choice-content', @@ -9,32 +20,56 @@ import { ChoiceContent } from '../choice-content'; }) export class CreatorChoiceContentComponent implements OnInit { - content: ChoiceContent = new ChoiceContent('2', - '1', + content: ChoiceContent = new ChoiceContent('0', '1', - 'Choice Content 1', - 'This is the body of Choice Content 1', + '', + '', + '', 1, - [ - new AnswerOption('Option 1', '0'), - new AnswerOption('Option 2', '10'), - new AnswerOption('Option 3', '20'), - new AnswerOption('Option 4', '30') - ], - [1, 2, 3], + [], + [], true); displayedColumns = ['label', 'points']; - constructor() { + displayAnswers: DisplayAnswer[] = []; + + newAnswerOptionChecked = false; + newAnswerOptionLabel = ''; + newAnswerOptionPoints = ''; + + constructor(private contentService: ContentService) { } ngOnInit() { + this.fillCorrectAnswers(); + } + + fillCorrectAnswers() { + this.displayAnswers = []; + for (let i = 0; i < this.content.options.length; i++) { + this.displayAnswers.push(new DisplayAnswer(this.content.options[i], this.content.correctOptionIndexes.includes(i))); + } } 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() { + this.content.options.push(new AnswerOption(this.newAnswerOptionLabel, this.newAnswerOptionPoints)); + if (this.newAnswerOptionChecked) { + this.content.correctOptionIndexes.push(this.content.options.length - 1); + } + this.newAnswerOptionChecked = false; + this.newAnswerOptionLabel = ''; + this.newAnswerOptionPoints = ''; + this.fillCorrectAnswers(); + this.submitContent(); } } diff --git a/src/app/creator-text-content/creator-text-content.component.ts b/src/app/creator-text-content/creator-text-content.component.ts index 0e65839c428ef64df950b27e5e33c319115ae5e9..e3c37aac039dec98b119ab818a59a08c0e85fbba 100644 --- a/src/app/creator-text-content/creator-text-content.component.ts +++ b/src/app/creator-text-content/creator-text-content.component.ts @@ -1,5 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { TextContent } from '../text-content'; +import { ContentService } from '../content.service'; @Component({ selector: 'app-creator-text-content', @@ -10,19 +11,23 @@ export class CreatorTextContentComponent implements OnInit { content: TextContent = new TextContent('1', '1', - '1', - 'Text Content 1', - 'This is the body of Text Content 1', + '0', + '', + '', 1); - constructor() { + constructor(private contentService: ContentService) { } ngOnInit() { } submitContent() { - + if (this.content.contentId === '1') { + this.contentService.addContent(this.content).subscribe(); + } else { + // ToDo: Implement function in service + // this.contentService.updateContent(this.content).subscribe(); + } } - } diff --git a/src/app/participant-choice-content/participant-choice-content.component.html b/src/app/participant-choice-content/participant-choice-content.component.html index 295ef1677c000df77920fe4efbce34c1301661c7..b731b9397f64528f72a58473ea31e5af0fd77e0c 100644 --- a/src/app/participant-choice-content/participant-choice-content.component.html +++ b/src/app/participant-choice-content/participant-choice-content.component.html @@ -1,10 +1,10 @@ -<form> +<form (ngSubmit)="submitAnswer()"> <h1 class="mat-headline">{{ content.subject }}</h1> <p>{{ content.body }}</p> <mat-divider></mat-divider> <mat-list> - <mat-list-item *ngFor="let answer of content.options"> - <mat-checkbox color="primary">{{ answer.label }}</mat-checkbox> + <mat-list-item *ngFor="let answer of checkedAnswers"> + <mat-checkbox color="primary" [(ngModel)]="answer.checked" name="answer">{{ answer.answerOption.label }}</mat-checkbox> </mat-list-item> </mat-list> <button mat-raised-button color="primary">Send answer</button> diff --git a/src/app/participant-choice-content/participant-choice-content.component.ts b/src/app/participant-choice-content/participant-choice-content.component.ts index 365adb1b47b028a581eaadd4489098d2ffb5395c..1840583d16559ab0bd4dbd8e80d1dfe0e4e2673a 100644 --- a/src/app/participant-choice-content/participant-choice-content.component.ts +++ b/src/app/participant-choice-content/participant-choice-content.component.ts @@ -1,6 +1,17 @@ import { Component, OnInit } from '@angular/core'; import { ChoiceContent } from '../choice-content'; import { AnswerOption } from '../answer-option'; +import { ContentAnswerService } from '../content-answer.service'; + +class CheckedAnswer { + answerOption: AnswerOption; + checked: boolean; + + constructor(answerOption: AnswerOption, checked: boolean) { + this.answerOption = answerOption; + this.checked = checked; + } +} @Component({ selector: 'app-participant-choice-content', @@ -22,10 +33,29 @@ export class ParticipantChoiceContentComponent implements OnInit { ], [2, 3, 4], true); + checkedAnswers: CheckedAnswer[] = []; - constructor() { + constructor(private answerService: ContentAnswerService) { } ngOnInit() { + this.initAnswers(); + } + + initAnswers(): void { + for (const answerOption of this.content.options) { + this.checkedAnswers.push(new CheckedAnswer(answerOption, false)); + } + } + + submitAnswer(): void { + const selectedAnswers: number[] = []; + for (let i = 0; i < this.checkedAnswers.length; i++) { + if (this.checkedAnswers[i].checked) { + selectedAnswers.push(i); + } + } + // ToDo: Implement function in service + // this.answerService.addChoiceAnswer(selectedAnswers); } } diff --git a/src/app/participant-text-content/participant-text-content.component.html b/src/app/participant-text-content/participant-text-content.component.html index 3bc09c4017b6af5b081b43fd92a4a7b0cead1a72..6d3f5a502be39d56e8cbd89c1ed63c2beb776e9c 100644 --- a/src/app/participant-text-content/participant-text-content.component.html +++ b/src/app/participant-text-content/participant-text-content.component.html @@ -1,4 +1,4 @@ -<form (ngSubmit)="submit(answer.value)"> +<form (ngSubmit)="submitAnswer(answer.value)"> <h1 class="mat-headline">{{ content.subject }}</h1> <p>{{ content.body }}</p> <mat-divider></mat-divider> diff --git a/src/app/participant-text-content/participant-text-content.component.ts b/src/app/participant-text-content/participant-text-content.component.ts index efb0260069f5db2c077b3f761eef3156df76610f..7f1837eaa4dd27920d8af933ee52e5f860e1de87 100644 --- a/src/app/participant-text-content/participant-text-content.component.ts +++ b/src/app/participant-text-content/participant-text-content.component.ts @@ -1,5 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { TextContent } from '../text-content'; +import { ContentAnswerService } from '../content-answer.service'; +import { AnswerText } from '../answer-text'; @Component({ selector: 'app-participant-text-content', @@ -14,12 +16,22 @@ export class ParticipantTextContentComponent implements OnInit { 'This is the body of Text Content 1', 1); - constructor() { + constructor(private answerService: ContentAnswerService) { } ngOnInit() { } - submit(answer: string) { + submitAnswer(answer: string) { + this.answerService.addAnswerText({ + id: '0', + revision: this.content.revision, + contentId: this.content.contentId, + round: this.content.round, + subject: this.content.subject, + body: answer, + read: 'false', + creationTimestamp: new Date() + } as AnswerText).subscribe(); } }