improves the assignments (fixes #2559)

This commit is contained in:
Sean Engelhardt 2016-11-26 14:10:21 +01:00
parent 829acce22d
commit 2bb440b2aa
2 changed files with 37 additions and 48 deletions

View File

@ -13,6 +13,7 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
// page title // page title
var title = PDFLayout.createTitle(assignment.title); var title = PDFLayout.createTitle(assignment.title);
var isElectedSemaphore = false;
// number of posts // number of posts
var createPreamble = function() { var createPreamble = function() {
@ -93,6 +94,7 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
// handles the case if a candidate is elected or not // handles the case if a candidate is elected or not
var electedCandidateLine = function(candidateName, pollOption, pollTableBody) { var electedCandidateLine = function(candidateName, pollOption, pollTableBody) {
if (pollOption.is_elected) { if (pollOption.is_elected) {
isElectedSemaphore = true;
return { return {
text: candidateName + "*", text: candidateName + "*",
bold: true, bold: true,
@ -106,6 +108,24 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
} }
}; };
//creates the voting string for the result table and differentiates between special values
var parseVoteValue = function(voteObject, printLabel) {
var voteVal = "";
if (printLabel) {
voteVal += voteObject.label + ": ";
}
voteVal += voteObject.value;
if (voteObject.percentStr) {
voteVal += " " + voteObject.percentStr;
}
voteVal += "\n";
return voteVal;
};
// creates the election result table // creates the election result table
var createPollResultTable = function() { var createPollResultTable = function() {
var resultBody = []; var resultBody = [];
@ -137,60 +157,29 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
angular.forEach(poll.options, function(pollOption, optionIndex) { angular.forEach(poll.options, function(pollOption, optionIndex) {
var candidateName = pollOption.candidate.get_full_name(); var candidateName = pollOption.candidate.get_full_name();
var votes = pollOption.getVotes(); // 0 = yes, 1 = no, 2 = abstain var votes = pollOption.getVotes(); // 0 = yes, 1 = no, 2 = abstain
var candidateLine; var tableLine = [];
tableLine.push(electedCandidateLine(candidateName, pollOption, pollTableBody));
if (poll.pollmethod == 'votes') { if (poll.pollmethod == 'votes') {
pollTableBody.push([ tableLine.push(
electedCandidateLine(candidateName, pollOption, pollTableBody),
{ {
text: votes[0].value + " " + votes[0].percentStr, text: parseVoteValue(votes[0], false),
style: PDFLayout.flipTableRowStyle(pollTableBody.length) style: PDFLayout.flipTableRowStyle(pollTableBody.length)
} }
]); );
} else if (poll.pollmethod == 'yn') { } else {
pollTableBody.push([ var resultBlock = [];
electedCandidateLine(candidateName, pollOption, pollTableBody), angular.forEach(votes, function(vote) {
resultBlock.push(parseVoteValue(vote, true));
});
tableLine.push(
{ {
text: [ text: resultBlock,
{
text: votes[0].label + ": " +
votes[0].value + " " +
votes[0].percentStr + "\n"
},
{
text: votes[1].label + ": " +
votes[1].value + " " +
votes[1].percentStr
}
],
style: PDFLayout.flipTableRowStyle(pollTableBody.length) style: PDFLayout.flipTableRowStyle(pollTableBody.length)
} }
]); );
} else if (poll.pollmethod == 'yna') {
pollTableBody.push([
electedCandidateLine(candidateName, pollOption, pollTableBody),
{
text: [
{
text: votes[0].label + ": " +
votes[0].value + " " +
votes[0].percentStr + "\n"
},
{
text: votes[1].label + ": " +
votes[1].value + " " +
votes[1].percentStr + "\n"
},
{
text: votes[2].label + ": " +
votes[2].value + " " +
votes[2].percentStr
}
],
style: PDFLayout.flipTableRowStyle(pollTableBody.length)
}
]);
} }
pollTableBody.push(tableLine);
}); });
//it is technically possible to make a single push-statement //it is technically possible to make a single push-statement
@ -248,7 +237,7 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
}); });
// add the legend to the result body // add the legend to the result body
if (assignment.polls.length > 0) { if (assignment.polls.length > 0 && isElectedSemaphore) {
resultBody.push({ resultBody.push({
text: "* = " + gettextCatalog.getString("is elected"), text: "* = " + gettextCatalog.getString("is elected"),
margin: [0, 5, 0, 0], margin: [0, 5, 0, 0],

View File

@ -548,7 +548,7 @@ angular.module('OpenSlidesApp.assignments.site', [
//creates the document as pdf //creates the document as pdf
$scope.makePDF_singleAssignment = function() { $scope.makePDF_singleAssignment = function() {
var filename = gettextCatalog.getString("Election") + " " + $scope.assignment.title + ".pdf"; var filename = gettextCatalog.getString("Election") + "_" + $scope.assignment.title + ".pdf";
var assignmentContentProvider = AssignmentContentProvider.createInstance(assignment); var assignmentContentProvider = AssignmentContentProvider.createInstance(assignment);
var documentProvider = PdfMakeDocumentProvider.createInstance(assignmentContentProvider); var documentProvider = PdfMakeDocumentProvider.createInstance(assignmentContentProvider);
pdfMake.createPdf(documentProvider.getDocument()).download(filename); pdfMake.createPdf(documentProvider.getDocument()).download(filename);
@ -564,7 +564,7 @@ angular.module('OpenSlidesApp.assignments.site', [
pollNumber = pollIndex+1; pollNumber = pollIndex+1;
} }
}); });
var filename = gettextCatalog.getString("Ballot") + " " + pollNumber + " " + $scope.assignment.title + ".pdf"; var filename = gettextCatalog.getString("Ballot") + "_" + pollNumber + "_" + $scope.assignment.title + ".pdf";
var ballotContentProvider = BallotContentProvider.createInstance($scope, thePoll, pollNumber); var ballotContentProvider = BallotContentProvider.createInstance($scope, thePoll, pollNumber);
var documentProvider = PdfMakeBallotPaperProvider.createInstance(ballotContentProvider); var documentProvider = PdfMakeBallotPaperProvider.createInstance(ballotContentProvider);
pdfMake.createPdf(documentProvider.getDocument()).download(filename); pdfMake.createPdf(documentProvider.getDocument()).download(filename);