Skip to content
Snippets Groups Projects
Commit 81d320c4 authored by Hagen Dreßler's avatar Hagen Dreßler
Browse files

Edit component answer-statistic (add responded answer logic)

parent a4d0a5eb
No related merge requests found
......@@ -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>
......@@ -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;
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment