Fix assignment polldata discovery in percent pipe

Fixes an issue where projector data was not delivering enough
information to guess if a poll data belongs to an assignment or a
motion.
This error resultet that the percent base pipe used the percent bases
for motions to calculate for assignments
This commit is contained in:
Sean 2020-10-01 12:16:07 +02:00
parent c0fb65316c
commit 98a8de3c2d
5 changed files with 13 additions and 7 deletions

View File

@ -30,7 +30,7 @@
<div class="single-result" [ngClass]="getVoteClass(vote)" *ngIf="vote && voteFitsMethod(vote)"> <div class="single-result" [ngClass]="getVoteClass(vote)" *ngIf="vote && voteFitsMethod(vote)">
<span> <span>
<span *ngIf="vote.showPercent"> <span *ngIf="vote.showPercent">
{{ vote.amount | pollPercentBase: poll }} {{ vote.amount | pollPercentBase: poll:'assignment' }}
</span> </span>
{{ vote.amount | parsePollNumber }} {{ vote.amount | parsePollNumber }}
</span> </span>

View File

@ -20,7 +20,7 @@
<!-- Percent numbers --> <!-- Percent numbers -->
<td class="result-cell-definition"> <td class="result-cell-definition">
<span *ngIf="row.value[0].showPercent"> <span *ngIf="row.value[0].showPercent">
{{ row.value[0].amount | pollPercentBase: poll }} {{ row.value[0].amount | pollPercentBase: poll:'motion' }}
</span> </span>
</td> </td>

View File

@ -14,7 +14,7 @@ import { PollData } from 'app/site/polls/services/poll.service';
* *
* @example * @example
* ```html * ```html
* <span> {{ voteYes | pollPercentBase: poll }} </span> * <span> {{ voteYes | pollPercentBase: poll:'assignment' }} </span>
* ``` * ```
*/ */
@Pipe({ @Pipe({
@ -26,10 +26,16 @@ export class PollPercentBasePipe implements PipeTransform {
private motionPollService: MotionPollService private motionPollService: MotionPollService
) {} ) {}
public transform(value: number, poll: PollData): string | null { public transform(value: number, poll: PollData, type: 'motion' | 'assignment'): string | null {
// logic handles over the pollService to avoid circular dependencies // logic handles over the pollService to avoid circular dependencies
let voteValueInPercent: string; let voteValueInPercent: string;
if ((<any>poll).assignment) {
/**
* PollData has not enough explicit information to simply guess the type correctly.
* This should not be a problem when PollData is a real model or a real type. Since
* we cannot expect the projector to work with real types for now, we need to provice the type
*/
if (type === 'assignment') {
voteValueInPercent = this.assignmentPollService.getVoteValueInPercent(value, poll); voteValueInPercent = this.assignmentPollService.getVoteValueInPercent(value, poll);
} else { } else {
voteValueInPercent = this.motionPollService.getVoteValueInPercent(value, poll); voteValueInPercent = this.motionPollService.getVoteValueInPercent(value, poll);

View File

@ -232,7 +232,7 @@ export class AssignmentPdfService {
.map((singleResult: VotingResult) => { .map((singleResult: VotingResult) => {
const votingKey = this.translate.instant(this.pollKeyVerbose.transform(singleResult.vote)); const votingKey = this.translate.instant(this.pollKeyVerbose.transform(singleResult.vote));
const resultValue = this.parsePollNumber.transform(singleResult.amount); const resultValue = this.parsePollNumber.transform(singleResult.amount);
const resultInPercent = this.pollPercentBase.transform(singleResult.amount, poll); const resultInPercent = this.pollPercentBase.transform(singleResult.amount, poll, 'assignment');
return `${votingKey}${!!votingKey ? ': ' : ''}${resultValue} ${ return `${votingKey}${!!votingKey ? ': ' : ''}${resultValue} ${
singleResult.showPercent && resultInPercent ? resultInPercent : '' singleResult.showPercent && resultInPercent ? resultInPercent : ''
}`; }`;

View File

@ -94,7 +94,7 @@
<os-icon-container [icon]="row.value[0].icon" size="large"> <os-icon-container [icon]="row.value[0].icon" size="large">
{{ row.value[0].amount | parsePollNumber }} {{ row.value[0].amount | parsePollNumber }}
<span *ngIf="row.value[0].showPercent"> <span *ngIf="row.value[0].showPercent">
{{ row.value[0].amount | pollPercentBase: poll }} {{ row.value[0].amount | pollPercentBase: poll:'motion' }}
</span> </span>
</os-icon-container> </os-icon-container>
</div> </div>