From 165a8dfb90306ddd250aeae3bd3cc3454ab4d2f6 Mon Sep 17 00:00:00 2001
From: Thomas Lenz <Thomas.Lenz@mni.thm.de>
Date: Wed, 4 Apr 2018 14:30:35 +0200
Subject: [PATCH] Add 'answer sent' chip to participant's choice-content and
 implement logic to check for only 1 selected answer in single-choice mode

---
 .../content-choice-participant.component.html      |  7 ++++++-
 .../content-choice-participant.component.ts        | 14 ++++++++++++--
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/app/components/fragments/content-choice-participant/content-choice-participant.component.html b/src/app/components/fragments/content-choice-participant/content-choice-participant.component.html
index b731b9397..39a8ceee9 100644
--- a/src/app/components/fragments/content-choice-participant/content-choice-participant.component.html
+++ b/src/app/components/fragments/content-choice-participant/content-choice-participant.component.html
@@ -4,8 +4,13 @@
   <mat-divider></mat-divider>
   <mat-list>
     <mat-list-item *ngFor="let answer of checkedAnswers">
-      <mat-checkbox color="primary" [(ngModel)]="answer.checked" name="answer">{{ answer.answerOption.label }}</mat-checkbox>
+      <mat-checkbox color="primary" [(ngModel)]="answer.checked" name="answer">{{ answer.answerOption.label }}
+      </mat-checkbox>
     </mat-list-item>
   </mat-list>
+  <mat-chip-list *ngIf="isAnswerSent">
+    <mat-chip color="primary" selected="true">Answer sent</mat-chip>
+  </mat-chip-list>
+  <mat-divider></mat-divider>
   <button mat-raised-button color="primary">Send answer</button>
 </form>
diff --git a/src/app/components/fragments/content-choice-participant/content-choice-participant.component.ts b/src/app/components/fragments/content-choice-participant/content-choice-participant.component.ts
index b7890316f..3ee2b27f4 100644
--- a/src/app/components/fragments/content-choice-participant/content-choice-participant.component.ts
+++ b/src/app/components/fragments/content-choice-participant/content-choice-participant.component.ts
@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
 import { ContentChoice } from '../../../models/content-choice';
 import { AnswerOption } from '../../../models/answer-option';
 import { ContentAnswerService } from '../../../services/http/content-answer.service';
+import { NotificationService } from '../../../services/util/notification.service';
 
 class CheckedAnswer {
   answerOption: AnswerOption;
@@ -32,10 +33,12 @@ export class ContentChoiceParticipantComponent implements OnInit {
       new AnswerOption('Option 4', '30')
     ],
     [2, 3, 4],
-    true);
+    false);
   checkedAnswers: CheckedAnswer[] = [];
+  isAnswerSent = false;
 
-  constructor(private answerService: ContentAnswerService) {
+  constructor(private answerService: ContentAnswerService,
+              private notificationService: NotificationService) {
   }
 
   ngOnInit() {
@@ -55,6 +58,13 @@ export class ContentChoiceParticipantComponent implements OnInit {
         selectedAnswers.push(i);
       }
     }
+    if (!this.content.multiple && selectedAnswers.length !== 1) {
+      this.notificationService.show('In single choice mode is only 1 selection allowed');
+      this.isAnswerSent = false;
+      return;
+    }
+    this.isAnswerSent = true;
+    this.notificationService.show('Answer successfully sent.');
     // ToDo: Implement function in service
     // this.answerService.addChoiceAnswer(selectedAnswers);
   }
-- 
GitLab