diff --git a/src/app/answer-statistics/answer-statistics.component.html b/src/app/answer-statistics/answer-statistics.component.html index 5da2ec7b4f89fc10f43b6bc9efa001b81d935f13..14103d3de62c2887e21e75abf463b503504053ee 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 ce5fa1f3984fee1cbfe8f842849006f6eea9a94c..49a0ad8558408abc8f4e141a4f1269120d63ba87 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; + } }