Merge pull request #5407 from tsiegleauq/assignment-pdf-reduce
Fix assignment pdf results
This commit is contained in:
commit
2cdb3f4ef3
@ -3,10 +3,11 @@ import { Injectable } from '@angular/core';
|
|||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
import { HtmlToPdfService } from 'app/core/pdf-services/html-to-pdf.service';
|
import { HtmlToPdfService } from 'app/core/pdf-services/html-to-pdf.service';
|
||||||
|
import { AssignmentPollMethod } from 'app/shared/models/assignments/assignment-poll';
|
||||||
import { ParsePollNumberPipe } from 'app/shared/pipes/parse-poll-number.pipe';
|
import { ParsePollNumberPipe } from 'app/shared/pipes/parse-poll-number.pipe';
|
||||||
import { PollKeyVerbosePipe } from 'app/shared/pipes/poll-key-verbose.pipe';
|
import { PollKeyVerbosePipe } from 'app/shared/pipes/poll-key-verbose.pipe';
|
||||||
import { PollPercentBasePipe } from 'app/shared/pipes/poll-percent-base.pipe';
|
import { PollPercentBasePipe } from 'app/shared/pipes/poll-percent-base.pipe';
|
||||||
import { PollTableData } from 'app/site/polls/services/poll.service';
|
import { PollTableData, VotingResult } from 'app/site/polls/services/poll.service';
|
||||||
import { AssignmentPollService } from './assignment-poll.service';
|
import { AssignmentPollService } from './assignment-poll.service';
|
||||||
import { ViewAssignment } from '../models/view-assignment';
|
import { ViewAssignment } from '../models/view-assignment';
|
||||||
import { ViewAssignmentPoll } from '../models/view-assignment-poll';
|
import { ViewAssignmentPoll } from '../models/view-assignment-poll';
|
||||||
@ -185,7 +186,6 @@ export class AssignmentPdfService {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const tableData = this.assignmentPollService.generateTableData(poll);
|
const tableData = this.assignmentPollService.generateTableData(poll);
|
||||||
|
|
||||||
for (const pollResult of tableData) {
|
for (const pollResult of tableData) {
|
||||||
const voteOption = this.translate.instant(this.pollKeyVerbose.transform(pollResult.votingOption));
|
const voteOption = this.translate.instant(this.pollKeyVerbose.transform(pollResult.votingOption));
|
||||||
const resultLine = this.getPollResult(pollResult, poll);
|
const resultLine = this.getPollResult(pollResult, poll);
|
||||||
@ -219,14 +219,24 @@ export class AssignmentPdfService {
|
|||||||
* Converts pollData to a printable string representation
|
* Converts pollData to a printable string representation
|
||||||
*/
|
*/
|
||||||
private getPollResult(votingResult: PollTableData, poll: ViewAssignmentPoll): string {
|
private getPollResult(votingResult: PollTableData, poll: ViewAssignmentPoll): string {
|
||||||
const resultList = votingResult.value.map(singleResult => {
|
const resultList = votingResult.value
|
||||||
const votingKey = this.translate.instant(this.pollKeyVerbose.transform(singleResult.vote));
|
.filter((singleResult: VotingResult) => {
|
||||||
const resultValue = this.parsePollNumber.transform(singleResult.amount);
|
if (poll.pollmethod === AssignmentPollMethod.Votes) {
|
||||||
const resultInPercent = this.pollPercentBase.transform(singleResult.amount, poll);
|
return singleResult.vote !== 'no' && singleResult.vote !== 'abstain';
|
||||||
return `${votingKey}${!!votingKey ? ': ' : ''}${resultValue} ${
|
} else if (poll.pollmethod === AssignmentPollMethod.YN) {
|
||||||
singleResult.showPercent && resultInPercent ? resultInPercent : ''
|
return singleResult.vote !== 'abstain';
|
||||||
}`;
|
} else {
|
||||||
});
|
return true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.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);
|
||||||
|
return `${votingKey}${!!votingKey ? ': ' : ''}${resultValue} ${
|
||||||
|
singleResult.showPercent && resultInPercent ? resultInPercent : ''
|
||||||
|
}`;
|
||||||
|
});
|
||||||
return resultList.join('\n');
|
return resultList.join('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user