Add parsing of decimal fields for projector data

Fixes an issue where the projector would not show special poll values,
such as "majority" or "not counted"
This commit is contained in:
Finn Stutzenstein 2020-10-05 11:35:20 +02:00 committed by Sean
parent de474e9eae
commit 435bb59472
7 changed files with 28 additions and 6 deletions

View File

@ -13,6 +13,7 @@ export enum MotionPollMethod {
export class MotionPoll extends BasePoll<MotionPoll, MotionOption, MotionPollMethod, PercentBase> { export class MotionPoll extends BasePoll<MotionPoll, MotionOption, MotionPollMethod, PercentBase> {
public static COLLECTIONSTRING = 'motions/motion-poll'; public static COLLECTIONSTRING = 'motions/motion-poll';
public static defaultGroupsConfig = 'motion_poll_default_groups'; public static defaultGroupsConfig = 'motion_poll_default_groups';
public static DECIMAL_FIELDS = ['votesvalid', 'votesinvalid', 'votescast'];
public id: number; public id: number;
public motion_id: number; public motion_id: number;
@ -29,4 +30,8 @@ export class MotionPoll extends BasePoll<MotionPoll, MotionOption, MotionPollMet
public constructor(input?: any) { public constructor(input?: any) {
super(MotionPoll.COLLECTIONSTRING, input); super(MotionPoll.COLLECTIONSTRING, input);
} }
protected getDecimalFields(): string[] {
return MotionPoll.DECIMAL_FIELDS;
}
} }

View File

@ -108,8 +108,4 @@ export abstract class BasePoll<
public get nextState(): PollState { public get nextState(): PollState {
return this.state + 1; return this.state + 1;
} }
protected getDecimalFields(): string[] {
return ['votesvalid', 'votesinvalid', 'votescast'];
}
} }

View File

@ -17,7 +17,7 @@ export class ParsePollNumberPipe implements PipeTransform {
public constructor(private translate: TranslateService) {} public constructor(private translate: TranslateService) {}
public transform(value: number): number | string { public transform(value: number): string {
switch (value) { switch (value) {
case VOTE_MAJORITY: case VOTE_MAJORITY:
return this.translate.instant('majority'); return this.translate.instant('majority');

View File

@ -67,6 +67,10 @@ export class ViewMotionPoll
public anySpecialVotes(): boolean { public anySpecialVotes(): boolean {
return this.result.yes < 0 || this.result.no < 0 || this.result.abstain < 0; return this.result.yes < 0 || this.result.no < 0 || this.result.abstain < 0;
} }
protected getDecimalFields(): string[] {
return MotionPoll.DECIMAL_FIELDS;
}
} }
export interface ViewMotionPoll extends MotionPoll { export interface ViewMotionPoll extends MotionPoll {

View File

@ -1,5 +1,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { AssignmentPoll } from 'app/shared/models/assignments/assignment-poll';
import { PollState } from 'app/shared/models/poll/base-poll'; import { PollState } from 'app/shared/models/poll/base-poll';
import { AssignmentPollService } from 'app/site/assignments/modules/assignment-poll/services/assignment-poll.service'; import { AssignmentPollService } from 'app/site/assignments/modules/assignment-poll/services/assignment-poll.service';
import { BasePollSlideComponentDirective } from 'app/slides/polls/base-poll-slide.component'; import { BasePollSlideComponentDirective } from 'app/slides/polls/base-poll-slide.component';
@ -17,4 +18,8 @@ export class AssignmentPollSlideComponent extends BasePollSlideComponentDirectiv
public PollState = PollState; public PollState = PollState;
public options = { maintainAspectRatio: false, responsive: true, legend: { position: 'right' } }; public options = { maintainAspectRatio: false, responsive: true, legend: { position: 'right' } };
protected getDecimalFields(): string[] {
return AssignmentPoll.DECIMAL_FIELDS;
}
} }

View File

@ -1,5 +1,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { MotionPoll } from 'app/shared/models/motions/motion-poll';
import { PollState } from 'app/shared/models/poll/base-poll'; import { PollState } from 'app/shared/models/poll/base-poll';
import { MotionPollService } from 'app/site/motions/services/motion-poll.service'; import { MotionPollService } from 'app/site/motions/services/motion-poll.service';
import { PollData, PollTableData } from 'app/site/polls/services/poll.service'; import { PollData, PollTableData } from 'app/site/polls/services/poll.service';
@ -32,6 +33,10 @@ export class MotionPollSlideComponent extends BasePollSlideComponentDirective<Mo
}); });
} }
protected getDecimalFields(): string[] {
return MotionPoll.DECIMAL_FIELDS;
}
public showChart(): boolean { public showChart(): boolean {
return this.pollService.showChart(this.pollData); return this.pollService.showChart(this.pollData);
} }

View File

@ -10,7 +10,7 @@ import { BasePollSlideData } from './base-poll-slide-data';
import { BaseSlideComponentDirective } from '../base-slide-component'; import { BaseSlideComponentDirective } from '../base-slide-component';
@Directive() @Directive()
export class BasePollSlideComponentDirective< export abstract class BasePollSlideComponentDirective<
T extends BasePollSlideData, T extends BasePollSlideData,
S extends PollService S extends PollService
> extends BaseSlideComponentDirective<T> { > extends BaseSlideComponentDirective<T> {
@ -19,6 +19,11 @@ export class BasePollSlideComponentDirective<
@Input() @Input()
public set data(value: SlideData<T>) { public set data(value: SlideData<T>) {
this._data = value; this._data = value;
this.getDecimalFields().forEach(field => {
if (value.data.poll[field] !== undefined) {
value.data.poll[field] = parseFloat(value.data.poll[field]);
}
});
if (value.data.poll.state === PollState.Published) { if (value.data.poll.state === PollState.Published) {
const chartData = this.pollService.generateChartData(value.data.poll); const chartData = this.pollService.generateChartData(value.data.poll);
this.chartDataSubject.next(chartData); this.chartDataSubject.next(chartData);
@ -37,4 +42,6 @@ export class BasePollSlideComponentDirective<
) { ) {
super(); super();
} }
protected abstract getDecimalFields(): string[];
} }