Merge pull request #2702 from tsiegleauq/assignmentImprove2559
improves the assignments (fixes #2559)
This commit is contained in:
commit
510d60ef0f
@ -13,6 +13,7 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
|
||||
|
||||
// page title
|
||||
var title = PDFLayout.createTitle(assignment.title);
|
||||
var isElectedSemaphore = false;
|
||||
|
||||
// number of posts
|
||||
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
|
||||
var electedCandidateLine = function(candidateName, pollOption, pollTableBody) {
|
||||
if (pollOption.is_elected) {
|
||||
isElectedSemaphore = true;
|
||||
return {
|
||||
text: candidateName + "*",
|
||||
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
|
||||
var createPollResultTable = function() {
|
||||
var resultBody = [];
|
||||
@ -137,60 +157,29 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
|
||||
angular.forEach(poll.options, function(pollOption, optionIndex) {
|
||||
var candidateName = pollOption.candidate.get_full_name();
|
||||
var votes = pollOption.getVotes(); // 0 = yes, 1 = no, 2 = abstain
|
||||
var candidateLine;
|
||||
var tableLine = [];
|
||||
|
||||
tableLine.push(electedCandidateLine(candidateName, pollOption, pollTableBody));
|
||||
if (poll.pollmethod == 'votes') {
|
||||
pollTableBody.push([
|
||||
electedCandidateLine(candidateName, pollOption, pollTableBody),
|
||||
tableLine.push(
|
||||
{
|
||||
text: votes[0].value + " " + votes[0].percentStr,
|
||||
text: parseVoteValue(votes[0], false),
|
||||
style: PDFLayout.flipTableRowStyle(pollTableBody.length)
|
||||
}
|
||||
]);
|
||||
} else if (poll.pollmethod == 'yn') {
|
||||
pollTableBody.push([
|
||||
electedCandidateLine(candidateName, pollOption, pollTableBody),
|
||||
);
|
||||
} else {
|
||||
var resultBlock = [];
|
||||
angular.forEach(votes, function(vote) {
|
||||
resultBlock.push(parseVoteValue(vote, true));
|
||||
});
|
||||
tableLine.push(
|
||||
{
|
||||
text: [
|
||||
{
|
||||
text: votes[0].label + ": " +
|
||||
votes[0].value + " " +
|
||||
votes[0].percentStr + "\n"
|
||||
},
|
||||
{
|
||||
text: votes[1].label + ": " +
|
||||
votes[1].value + " " +
|
||||
votes[1].percentStr
|
||||
}
|
||||
],
|
||||
text: resultBlock,
|
||||
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
|
||||
@ -248,7 +237,7 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
|
||||
});
|
||||
|
||||
// add the legend to the result body
|
||||
if (assignment.polls.length > 0) {
|
||||
if (assignment.polls.length > 0 && isElectedSemaphore) {
|
||||
resultBody.push({
|
||||
text: "* = " + gettextCatalog.getString("is elected"),
|
||||
margin: [0, 5, 0, 0],
|
||||
|
@ -570,7 +570,7 @@ angular.module('OpenSlidesApp.assignments.site', [
|
||||
|
||||
//creates the document as pdf
|
||||
$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 documentProvider = PdfMakeDocumentProvider.createInstance(assignmentContentProvider);
|
||||
pdfMake.createPdf(documentProvider.getDocument()).download(filename);
|
||||
@ -586,7 +586,7 @@ angular.module('OpenSlidesApp.assignments.site', [
|
||||
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 documentProvider = PdfMakeBallotPaperProvider.createInstance(ballotContentProvider);
|
||||
pdfMake.createPdf(documentProvider.getDocument()).download(filename);
|
||||
|
Loading…
Reference in New Issue
Block a user