From 3e75c9d94c94f3165139283076b7e051efa81aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Mon, 10 Dec 2018 14:35:53 +0100 Subject: [PATCH] Add new attribute 'contentId' to ContentStatistic for linking to content-statistic --- .../list-statistic/list-statistic.component.html | 8 ++++---- .../list-statistic/list-statistic.component.ts | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/app/components/shared/list-statistic/list-statistic.component.html b/src/app/components/shared/list-statistic/list-statistic.component.html index 91b94d2d7..b8e1367cf 100644 --- a/src/app/components/shared/list-statistic/list-statistic.component.html +++ b/src/app/components/shared/list-statistic/list-statistic.component.html @@ -14,7 +14,7 @@ 'positiveC' : cp.percent >= status.good, 'okayC' : cp.percent >= status.okay && cp.percent < status.good, 'negativeC' : cp.percent < status.okay, - 'emptyCC' : cp.percent < status.zero }">{{cp.content.subject}}</mat-cell> + 'emptyCC' : cp.percent < status.zero }" routerLink="/creator/room/{{ roomId }}/statistics/{{cp.contentId}}">{{cp.content.subject}}</mat-cell> </ng-container> <ng-container matColumnDef="percentage"> @@ -23,7 +23,7 @@ 'positiveC' : cp.percent >= status.good, 'okayC' : cp.percent >= status.okay && cp.percent < status.good, 'negativeC' : cp.percent < status.okay, - 'emptyC' : cp.percent < status.zero }">{{cp.percent.toFixed() + ' %'}}</mat-cell> + 'emptyC' : cp.percent < status.zero }" routerLink="/creator/room/{{ roomId }}/statistics/{{cp.contentId}}">{{cp.percent.toFixed() + ' %'}}</mat-cell> </ng-container> <ng-container matColumnDef="counts"> @@ -32,7 +32,7 @@ 'positiveC' : cp.percent >= status.good, 'okayC' : cp.percent >= status.okay && cp.percent < status.good, 'negativeC' : cp.percent < status.okay, - 'emptyC' : cp.percent < status.zero }">{{cp.counts}}</mat-cell> + 'emptyC' : cp.percent < status.zero }" routerLink="/creator/room/{{ roomId }}/statistics/{{cp.contentId}}">{{cp.counts}}</mat-cell> </ng-container> <ng-container matColumnDef="abstentions"> @@ -41,7 +41,7 @@ 'positiveC' : cp.percent >= status.good, 'okayC' : cp.percent >= status.okay && cp.percent < status.good, 'negativeC' : cp.percent < status.okay, - 'emptyC' : cp.percent < status.zero }">{{cp.abstentions}}</mat-cell> + 'emptyC' : cp.percent < status.zero }" routerLink="/creator/room/{{ roomId }}/statistics/{{cp.contentId}}">{{cp.abstentions}}</mat-cell> </ng-container> <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row> diff --git a/src/app/components/shared/list-statistic/list-statistic.component.ts b/src/app/components/shared/list-statistic/list-statistic.component.ts index d9889f421..f3dbe21d2 100644 --- a/src/app/components/shared/list-statistic/list-statistic.component.ts +++ b/src/app/components/shared/list-statistic/list-statistic.component.ts @@ -8,15 +8,18 @@ import { ContentChoice } from '../../../models/content-choice'; import { Combination } from '../../../models/round-statistics'; import { TranslateService } from '@ngx-translate/core'; import { LanguageService } from '../../../services/util/language.service'; +import { ActivatedRoute } from '@angular/router'; export class ContentStatistic { content: Content; + contentId: string; percent: number; counts: number; abstentions: number; - constructor(content: Content, percent: number, counts: number, abstentions: number) { + constructor(content: Content, contentId: string, percent: number, counts: number, abstentions: number) { this.content = content; + this.contentId = contentId; this.percent = percent; this.counts = counts; this.abstentions = abstentions; @@ -43,14 +46,19 @@ export class ListStatisticComponent implements OnInit { total = 0; totalP = 0; contentCounter = 0; + roomId: number; constructor(private contentService: ContentService, private translateService: TranslateService, - protected langService: LanguageService) { + protected langService: LanguageService, + protected route: ActivatedRoute) { langService.langEmitter.subscribe(lang => translateService.use(lang)); } ngOnInit() { + this.route.params.subscribe(params => { + this.roomId = params['roomId']; + }); this.translateService.use(localStorage.getItem('currentLang')); this.contentService.getContentChoiceByIds(this.contentGroup.contentIds).subscribe(contents => { this.getData(contents); @@ -63,7 +71,7 @@ export class ListStatisticComponent implements OnInit { let percent; this.dataSource = new Array<ContentStatistic>(length); for (let i = 0; i < length; i++) { - this.dataSource[i] = new ContentStatistic(null, 0, 0, 0 ); + this.dataSource[i] = new ContentStatistic(null, null, 0, 0, 0 ); this.dataSource[i].content = this.contents[i]; if (contents[i].format === ContentType.CHOICE) { this.contentService.getAnswer(contents[i].id).subscribe(answer => { @@ -76,6 +84,7 @@ export class ListStatisticComponent implements OnInit { } this.dataSource[i].abstentions = answer.roundStatistics[0].abstentionCount; this.dataSource[i].percent = percent; + this.dataSource[i].contentId = contents[i].id; if (percent >= 0) { this.totalP += percent; this.total = this.totalP / this.contentCounter; -- GitLab