Skip to content
Snippets Groups Projects
Commit 786a782b authored by Lukas Mauß's avatar Lukas Mauß
Browse files

Outsource redundant code

parent d6121fcd
No related merge requests found
......@@ -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 }" routerLink="{{nextLink}}{{cp.contentId}}">{{cp.content.subject}}</mat-cell>
'emptyCC' : cp.percent < status.zero }" (click)="goToStats(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 }" routerLink="{{nextLink}}{{cp.contentId}}">{{cp.percent.toFixed() + ' %'}}</mat-cell>
'emptyC' : cp.percent < status.zero }" (click)="goToStats(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 }" routerLink="{{nextLink}}{{cp.contentId}}">{{cp.counts}}</mat-cell>
'emptyC' : cp.percent < status.zero }" (click)="goToStats(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 }" routerLink="{{nextLink}}{{cp.contentId}}">{{cp.abstentions}}</mat-cell>
'emptyC' : cp.percent < status.zero }" (click)="goToStats(cp.contentId)">{{cp.abstentions}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
......
......@@ -8,7 +8,7 @@ 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';
import { ActivatedRoute, Router } from '@angular/router';
import { AuthenticationService } from '../../../services/http/authentication.service';
import { UserRole } from '../../../models/user-roles.enum';
......@@ -49,10 +49,11 @@ export class ListStatisticComponent implements OnInit {
totalP = 0;
contentCounter = 0;
roomId: number;
nextLink: string;
baseUrl: string;
constructor(private contentService: ContentService,
private translateService: TranslateService,
private router: Router,
protected langService: LanguageService,
protected route: ActivatedRoute,
protected authService: AuthenticationService) {
......@@ -62,16 +63,24 @@ export class ListStatisticComponent implements OnInit {
ngOnInit() {
this.route.params.subscribe(params => {
this.roomId = params['roomId'];
if (this.authService.getRole() === UserRole.CREATOR) {
this.nextLink = `/creator/room/${ this.roomId }/statistics/`;
} else {
this.nextLink = `/participant/room/${ this.roomId }/statistics/`;
}
});
this.translateService.use(localStorage.getItem('currentLang'));
this.contentService.getContentChoiceByIds(this.contentGroup.contentIds).subscribe(contents => {
this.getData(contents);
});
this.getBaseUrl();
}
getBaseUrl() {
if (this.authService.getRole() === UserRole.CREATOR) {
this.baseUrl = `/creator/room/${ this.roomId }/statistics/`;
} else {
this.baseUrl = `/participant/room/${ this.roomId }/statistics/`;
}
}
goToStats(id: string) {
this.router.navigate([`${this.baseUrl}${id}`]);
}
getData(contents: ContentChoice[]) {
......
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