From 81d320c4b3140d12cc5ab4974af278bdaf2f3362 Mon Sep 17 00:00:00 2001 From: Hagen <hagen.dressler@mni.thm.de> Date: Wed, 14 Mar 2018 16:25:23 +0100 Subject: [PATCH] Edit component answer-statistic (add responded answer logic) --- .../answer-statistics.component.html | 3 +-- .../answer-statistics/answer-statistics.component.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/answer-statistics/answer-statistics.component.html b/src/app/answer-statistics/answer-statistics.component.html index 5da2ec7b4..14103d3de 100644 --- a/src/app/answer-statistics/answer-statistics.component.html +++ b/src/app/answer-statistics/answer-statistics.component.html @@ -12,7 +12,7 @@ {{ statistic.name }} <mat-progress-bar [value]="statistic.percent"> </mat-progress-bar> - <div align="right"> Votes: {{ statistic.votes }} </div> + <div align="right"> Responded answers: {{ statistic.answers }} </div> </div> </div> <div *ngIf="selected == 2"> @@ -24,4 +24,3 @@ </mat-tab-group> </mat-card> </div> - diff --git a/src/app/answer-statistics/answer-statistics.component.ts b/src/app/answer-statistics/answer-statistics.component.ts index ce5fa1f39..49a0ad855 100644 --- a/src/app/answer-statistics/answer-statistics.component.ts +++ b/src/app/answer-statistics/answer-statistics.component.ts @@ -42,7 +42,9 @@ export class AnswerStatisticsComponent implements OnInit { getAnswers(): void { for (const question of this.content) { - this.contentAnswerService.getAnswerTexts(question.id).subscribe( answer => [].push.apply(this.answers, answer)); + this.contentAnswerService.getAnswerTexts(question.id).subscribe( answer => { + [].push.apply(this.answers, answer); + }); } } @@ -50,10 +52,15 @@ export class AnswerStatisticsComponent implements OnInit { console.log(this.answers); this.statistics = []; for (const question of this.content) { + const count = this.countAnswers(question.id); this.statistics.push( { - name: question.subject, votes: '10', percent: '10', + name: question.subject, answers: count, percent: count * 100 / this.answers.length, }); } this.selected = value; } + + countAnswers(contentId: string): number { + return this.answers.filter(answer => answer.contentId === contentId).length; + } } -- GitLab