Merge pull request #5603 from tsiegleauq/poll-values-on-projector
Use numbers exclusively in PollNumberPipe
This commit is contained in:
commit
28be46cf5a
@ -13,6 +13,7 @@ export enum MotionPollMethod {
|
||||
export class MotionPoll extends BasePoll<MotionPoll, MotionOption, MotionPollMethod, PercentBase> {
|
||||
public static COLLECTIONSTRING = 'motions/motion-poll';
|
||||
public static defaultGroupsConfig = 'motion_poll_default_groups';
|
||||
public static DECIMAL_FIELDS = ['votesvalid', 'votesinvalid', 'votescast'];
|
||||
|
||||
public id: number;
|
||||
public motion_id: number;
|
||||
@ -29,4 +30,8 @@ export class MotionPoll extends BasePoll<MotionPoll, MotionOption, MotionPollMet
|
||||
public constructor(input?: any) {
|
||||
super(MotionPoll.COLLECTIONSTRING, input);
|
||||
}
|
||||
|
||||
protected getDecimalFields(): string[] {
|
||||
return MotionPoll.DECIMAL_FIELDS;
|
||||
}
|
||||
}
|
||||
|
@ -108,8 +108,4 @@ export abstract class BasePoll<
|
||||
public get nextState(): PollState {
|
||||
return this.state + 1;
|
||||
}
|
||||
|
||||
protected getDecimalFields(): string[] {
|
||||
return ['votesvalid', 'votesinvalid', 'votescast'];
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ export class ParsePollNumberPipe implements PipeTransform {
|
||||
|
||||
public constructor(private translate: TranslateService) {}
|
||||
|
||||
public transform(value: number): number | string {
|
||||
public transform(value: number): string {
|
||||
switch (value) {
|
||||
case VOTE_MAJORITY:
|
||||
return this.translate.instant('majority');
|
||||
|
@ -67,6 +67,10 @@ export class ViewMotionPoll
|
||||
public anySpecialVotes(): boolean {
|
||||
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 {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
import { AssignmentPoll } from 'app/shared/models/assignments/assignment-poll';
|
||||
import { PollState } from 'app/shared/models/poll/base-poll';
|
||||
import { AssignmentPollService } from 'app/site/assignments/modules/assignment-poll/services/assignment-poll.service';
|
||||
import { BasePollSlideComponentDirective } from 'app/slides/polls/base-poll-slide.component';
|
||||
@ -17,4 +18,8 @@ export class AssignmentPollSlideComponent extends BasePollSlideComponentDirectiv
|
||||
public PollState = PollState;
|
||||
|
||||
public options = { maintainAspectRatio: false, responsive: true, legend: { position: 'right' } };
|
||||
|
||||
protected getDecimalFields(): string[] {
|
||||
return AssignmentPoll.DECIMAL_FIELDS;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
import { MotionPoll } from 'app/shared/models/motions/motion-poll';
|
||||
import { PollState } from 'app/shared/models/poll/base-poll';
|
||||
import { MotionPollService } from 'app/site/motions/services/motion-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 {
|
||||
return this.pollService.showChart(this.pollData);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import { BasePollSlideData } from './base-poll-slide-data';
|
||||
import { BaseSlideComponentDirective } from '../base-slide-component';
|
||||
|
||||
@Directive()
|
||||
export class BasePollSlideComponentDirective<
|
||||
export abstract class BasePollSlideComponentDirective<
|
||||
T extends BasePollSlideData,
|
||||
S extends PollService
|
||||
> extends BaseSlideComponentDirective<T> {
|
||||
@ -19,6 +19,11 @@ export class BasePollSlideComponentDirective<
|
||||
@Input()
|
||||
public set data(value: SlideData<T>) {
|
||||
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) {
|
||||
const chartData = this.pollService.generateChartData(value.data.poll);
|
||||
this.chartDataSubject.next(chartData);
|
||||
@ -37,4 +42,6 @@ export class BasePollSlideComponentDirective<
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
protected abstract getDecimalFields(): string[];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user