Fixed motion pdf layout

for voting result and summary change recommendations
This commit is contained in:
Emanuel Schütze 2016-12-01 22:55:18 +01:00
parent cdc37b4dd5
commit 52b9c651bb

View File

@ -89,79 +89,129 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
}
// voting result
var column1 = [];
var column2 = [];
var column3 = [];
motion.polls.map(function(poll, index) {
var votenumber = '';
if (motion.polls.length > 1) {
votenumber = index + 1 + '. ' + gettextCatalog.getString('Vote');
}
// yes
var yes = poll.getVote(poll.yes, 'yes');
column1.push(gettextCatalog.getString('Yes') + ':');
column2.push(yes.value);
column3.push(yes.percentStr);
// no
var no = poll.getVote(poll.no, 'no');
column1.push(gettextCatalog.getString('No') + ':');
column2.push(no.value);
column3.push(no.percentStr);
// abstain
var abstain = poll.getVote(poll.abstain, 'abstain');
column1.push(gettextCatalog.getString('Abstain') + ':');
column2.push(abstain.value);
column3.push(abstain.percentStr);
// votes valid
if (poll.votesvalid) {
var valid = poll.getVote(poll.votesvalid, 'votesvalid');
column1.push(gettextCatalog.getString('Valid votes') + ':');
column2.push(valid.value);
column3.push(valid.percentStr);
}
// votes invalid
if (poll.votesvalid) {
var invalid = poll.getVote(poll.votesinvalid, 'votesinvalid');
column1.push(gettextCatalog.getString('Invalid votes') + ':');
column2.push(invalid.value);
column3.push(invalid.percentStr);
}
// votes cast
if (poll.votescast) {
var cast = poll.getVote(poll.votescast, 'votescast');
column1.push(gettextCatalog.getString('Votes cast') + ':');
column2.push(cast.value);
column3.push(cast.percentStr);
}
});
metaTableBody.push([
{
text: gettextCatalog.getString('Voting result') + ':',
style: ['bold', 'grey']
},
{
columns: [
{
text: column1.join('\n'),
width: 'auto'
},
{
text: column2.join('\n'),
width: 'auto',
alignment: 'right'
},
{
text: column3.join('\n'),
width: 'auto',
alignment: 'right'
},
],
columnGap: 7,
style: 'grey'
}
]);
if (motion.polls.length > 0 && motion.polls[0].has_votes) {
var column1 = [];
var column2 = [];
var column3 = [];
motion.polls.map(function(poll, index) {
if (poll.has_votes) {
// votenumber
if (motion.polls.length > 1) {
column1.push(index + 1 + '. ' + gettextCatalog.getString('Vote'));
column2.push('');
column3.push('');
}
// yes
var yes = poll.getVote(poll.yes, 'yes');
column1.push(gettextCatalog.getString('Yes') + ':');
column2.push(yes.value);
column3.push(yes.percentStr);
// no
var no = poll.getVote(poll.no, 'no');
column1.push(gettextCatalog.getString('No') + ':');
column2.push(no.value);
column3.push(no.percentStr);
// abstain
var abstain = poll.getVote(poll.abstain, 'abstain');
column1.push(gettextCatalog.getString('Abstain') + ':');
column2.push(abstain.value);
column3.push(abstain.percentStr);
// votes valid
if (poll.votesvalid) {
var valid = poll.getVote(poll.votesvalid, 'votesvalid');
column1.push(gettextCatalog.getString('Valid votes') + ':');
column2.push(valid.value);
column3.push(valid.percentStr);
}
// votes invalid
if (poll.votesvalid) {
var invalid = poll.getVote(poll.votesinvalid, 'votesinvalid');
column1.push(gettextCatalog.getString('Invalid votes') + ':');
column2.push(invalid.value);
column3.push(invalid.percentStr);
}
// votes cast
if (poll.votescast) {
var cast = poll.getVote(poll.votescast, 'votescast');
column1.push(gettextCatalog.getString('Votes cast') + ':');
column2.push(cast.value);
column3.push(cast.percentStr);
}
}
});
metaTableBody.push([
{
text: gettextCatalog.getString('Voting result') + ':',
style: ['bold', 'grey']
},
{
columns: [
{
text: column1.join('\n'),
width: 'auto'
},
{
text: column2.join('\n'),
width: 'auto',
alignment: 'right'
},
{
text: column3.join('\n'),
width: 'auto',
alignment: 'right'
},
],
columnGap: 7,
style: 'grey'
}
]);
}
// summary of change recommendations (for motion diff version only)
if ($scope.viewChangeRecommendations.mode == "diff") {
var columnLineNumbers = [];
var columnChangeType = [];
angular.forEach($scope.change_recommendations, function(change) {
// line numbers column
var line;
if (change.line_from >= change.line_to - 1) {
line = change.line_from;
} else {
line = change.line_from + ' - ' + (change.line_to - 1);
}
columnLineNumbers.push(
gettextCatalog.getString('Line') + ' ' + line + ': '
);
// change type column
if (change.getType(motion.getVersion($scope.version).text) === 0) {
columnChangeType.push(gettextCatalog.getString("Replacement"));
} else if (change.getType(motion.getVersion($scope.version).text) === 1) {
columnChangeType.push(gettextCatalog.getString("Insertion"));
} else if (change.getType(motion.getVersion($scope.version).text) === 2) {
columnChangeType.push(gettextCatalog.getString("Deletion"));
}
});
metaTableBody.push([
{
text: gettextCatalog.getString('Summary of change recommendations'),
style: ['bold', 'grey']
},
{
columns: [
{
text: columnLineNumbers.join('\n'),
width: 'auto'
},
{
text: columnChangeType.join('\n'),
width: 'auto'
}
],
columnGap: 7,
style: 'grey'
}
]);
}
// build table
var metaTableJsonString = {
@ -188,45 +238,6 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
return metaTableJsonString;
};
// summary of change recommendations (for motion diff version only)
var motionDiffSummary = function() {
if ($scope.viewChangeRecommendations.mode == "diff") {
var motionDiffLogBox = [];
motionDiffLogBox.push({
text: gettextCatalog.getString('Summary of change recommendations'),
style: 'bold'
});
angular.forEach($scope.change_recommendations, function(change) {
var changeType = "";
var lineNumbers = "";
if (change.getType(motion.getVersion($scope.version).text) === 0) {
changeType = gettextCatalog.getString("Replacement");
} else if (change.getType(motion.getVersion($scope.version).text) === 1) {
changeType = gettextCatalog.getString("Insertion");
} else if (change.getType(motion.getVersion($scope.version).text) === 2) {
changeType = gettextCatalog.getString("Deletion");
}
if (change.line_from >= change.line_to - 1) {
lineNumbers = change.line_from;
} else {
lineNumbers = change.line_from + " - " + (change.line_to - 1);
}
motionDiffLogBox.push({
text: gettextCatalog.getString('Line') + " " + lineNumbers + ": " + changeType + "\n"
});
});
motionDiffLogBox.push({
text: "\n\n"
});
return motionDiffLogBox;
} else {
return "";
}
};
// motion title
var motionTitle = function() {
return [{
@ -285,7 +296,6 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
title,
subtitle,
metaTable(),
motionDiffSummary(),
motionTitle(),
motionText(),
];