Merge pull request #5592 from tsiegleauq/assignment-projector-percentage

Fix assignment polldata discovery in percent pipe
This commit is contained in:
Emanuel Schütze 2020-10-06 22:33:34 +02:00 committed by GitHub
commit 706c1d9e36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)">
<span>
<span *ngIf="vote.showPercent">
{{ vote.amount | pollPercentBase: poll }}
{{ vote.amount | pollPercentBase: poll:'assignment' }}
</span>
{{ vote.amount | parsePollNumber }}
</span>

View File

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

View File

@ -14,7 +14,7 @@ import { PollData } from 'app/site/polls/services/poll.service';
*
* @example
* ```html
* <span> {{ voteYes | pollPercentBase: poll }} </span>
* <span> {{ voteYes | pollPercentBase: poll:'assignment' }} </span>
* ```
*/
@Pipe({
@ -26,10 +26,16 @@ export class PollPercentBasePipe implements PipeTransform {
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
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);
} else {
voteValueInPercent = this.motionPollService.getVoteValueInPercent(value, poll);

View File

@ -232,7 +232,7 @@ export class AssignmentPdfService {
.map((singleResult: VotingResult) => {
const votingKey = this.translate.instant(this.pollKeyVerbose.transform(singleResult.vote));
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} ${
singleResult.showPercent && resultInPercent ? resultInPercent : ''
}`;

View File

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