Merge pull request #2498 from tsiegleauq/agendaPDFmake
Generate agendas using pdfmake
This commit is contained in:
commit
6f70fb630c
80
openslides/agenda/static/js/agenda/pdf.js
Normal file
80
openslides/agenda/static/js/agenda/pdf.js
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
(function () {
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('OpenSlidesApp.agenda.pdf', ['OpenSlidesApp.core.pdf'])
|
||||||
|
|
||||||
|
.factory('AgendaContentProvider', [
|
||||||
|
'gettextCatalog',
|
||||||
|
'PdfPredefinedFunctions',
|
||||||
|
function(gettextCatalog, PdfPredefinedFunctions) {
|
||||||
|
|
||||||
|
var createInstance = function(items) {
|
||||||
|
|
||||||
|
//use the Predefined Functions to create the title
|
||||||
|
var title = PdfPredefinedFunctions.createTitle(gettextCatalog.getString("Agenda"));
|
||||||
|
|
||||||
|
//function to generate the item list out of the given "items" object
|
||||||
|
var createItemList = function() {
|
||||||
|
var agenda_items = [];
|
||||||
|
angular.forEach(items, function (item) {
|
||||||
|
if (item.is_hidden === false) {
|
||||||
|
|
||||||
|
var itemIndent = item.parentCount * 20;
|
||||||
|
|
||||||
|
var itemStyle;
|
||||||
|
if (item.parentCount === 0) {
|
||||||
|
itemStyle = 'listParent';
|
||||||
|
} else {
|
||||||
|
itemStyle = 'listChild';
|
||||||
|
}
|
||||||
|
|
||||||
|
var itemNumberWidth;
|
||||||
|
if (item.item_number === "") {
|
||||||
|
itemNumberWidth = 0;
|
||||||
|
} else {
|
||||||
|
itemNumberWidth = 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
var agendaJsonString = {
|
||||||
|
style: itemStyle,
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
width: itemIndent,
|
||||||
|
text: ''
|
||||||
|
},
|
||||||
|
{
|
||||||
|
width: itemNumberWidth,
|
||||||
|
text: item.item_number
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: item.title
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
agenda_items.push(agendaJsonString);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return agenda_items;
|
||||||
|
};
|
||||||
|
|
||||||
|
var getContent = function() {
|
||||||
|
return [
|
||||||
|
title,
|
||||||
|
createItemList()
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
getContent: getContent
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
createInstance: createInstance
|
||||||
|
};
|
||||||
|
|
||||||
|
}]);
|
||||||
|
|
||||||
|
}());
|
@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda'])
|
angular.module('OpenSlidesApp.agenda.site', [
|
||||||
|
'OpenSlidesApp.agenda',
|
||||||
|
'OpenSlidesApp.core.pdf',
|
||||||
|
'OpenSlidesApp.agenda.pdf'
|
||||||
|
])
|
||||||
|
|
||||||
.config([
|
.config([
|
||||||
'mainMenuProvider',
|
'mainMenuProvider',
|
||||||
@ -100,7 +104,11 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda'])
|
|||||||
'AgendaTree',
|
'AgendaTree',
|
||||||
'Projector',
|
'Projector',
|
||||||
'ProjectionDefault',
|
'ProjectionDefault',
|
||||||
function($scope, $filter, $http, $state, DS, operator, ngDialog, Agenda, TopicForm, AgendaTree, Projector, ProjectionDefault) {
|
'AgendaContentProvider',
|
||||||
|
'PdfMakeDocumentProvider',
|
||||||
|
'gettextCatalog',
|
||||||
|
function($scope, $filter, $http, $state, DS, operator, ngDialog, Agenda, TopicForm, AgendaTree, Projector,
|
||||||
|
ProjectionDefault, AgendaContentProvider, PdfMakeDocumentProvider, gettextCatalog) {
|
||||||
// Bind agenda tree to the scope
|
// Bind agenda tree to the scope
|
||||||
$scope.$watch(function () {
|
$scope.$watch(function () {
|
||||||
return Agenda.lastModified();
|
return Agenda.lastModified();
|
||||||
@ -306,6 +314,13 @@ angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda'])
|
|||||||
$scope.autoNumbering = function() {
|
$scope.autoNumbering = function() {
|
||||||
$http.post('/rest/agenda/item/numbering/', {});
|
$http.post('/rest/agenda/item/numbering/', {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.makePDF = function() {
|
||||||
|
var filename = gettextCatalog.getString("Agenda")+".pdf";
|
||||||
|
var agendaContentProvider = AgendaContentProvider.createInstance($scope.items);
|
||||||
|
var documentProvider = PdfMakeDocumentProvider.createInstance(agendaContentProvider);
|
||||||
|
pdfMake.createPdf(documentProvider.getDocument()).download(filename);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<div class="btn-group button" uib-dropdown
|
<div class="btn-group button" uib-dropdown
|
||||||
uib-tooltip="{{ 'Projector' | translate }} {{ isAgendaProjected(mainListTree) }}"
|
uib-tooltip="{{ 'Projector' | translate }} {{ isAgendaProjected(mainListTree) }}"
|
||||||
tooltip-enable="isAgendaProjected(mainListTree) > 0"
|
tooltip-enable="isAgendaProjected(mainListTree) > 0"
|
||||||
os-perms="core.can_manage_projector">
|
os-perms="core.can_manage_projector">
|
||||||
<button type="button" class="btn btn-default btn-sm"
|
<button type="button" class="btn btn-default btn-sm"
|
||||||
title="{{ 'Project agenda' | translate }}"
|
title="{{ 'Project agenda' | translate }}"
|
||||||
ng-click="projectAgenda(defaultProjectorId_all_items, mainListTree)"
|
ng-click="projectAgenda(defaultProjectorId_all_items, mainListTree)"
|
||||||
@ -83,7 +83,7 @@
|
|||||||
<translate>Numbering</translate>
|
<translate>Numbering</translate>
|
||||||
</a>
|
</a>
|
||||||
<!-- pdf -->
|
<!-- pdf -->
|
||||||
<a ui-sref="agenda_pdf" target="_blank" class="btn btn-default btn-sm">
|
<a ng-click="makePDF()" class="btn btn-default btn-sm">
|
||||||
<i class="fa fa-file-pdf-o fa-lg"></i>
|
<i class="fa fa-file-pdf-o fa-lg"></i>
|
||||||
<translate>PDF</translate>
|
<translate>PDF</translate>
|
||||||
</a>
|
</a>
|
||||||
|
@ -4,6 +4,21 @@
|
|||||||
|
|
||||||
angular.module('OpenSlidesApp.core.pdf', [])
|
angular.module('OpenSlidesApp.core.pdf', [])
|
||||||
|
|
||||||
|
.factory('PdfPredefinedFunctions', [
|
||||||
|
function() {
|
||||||
|
var PdfPredefinedFunctions = {};
|
||||||
|
|
||||||
|
PdfPredefinedFunctions.createTitle = function(titleString) {
|
||||||
|
return {
|
||||||
|
text: titleString,
|
||||||
|
style: "title"
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return PdfPredefinedFunctions;
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
.factory('HTMLValidizer', function() {
|
.factory('HTMLValidizer', function() {
|
||||||
var HTMLValidizer = {};
|
var HTMLValidizer = {};
|
||||||
|
|
||||||
@ -106,6 +121,14 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
tableofcontent: {
|
tableofcontent: {
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
margin: [0,3]
|
margin: [0,3]
|
||||||
|
},
|
||||||
|
listParent: {
|
||||||
|
fontSize: 14,
|
||||||
|
margin: [0,5]
|
||||||
|
},
|
||||||
|
listChild: {
|
||||||
|
fontSize: 11,
|
||||||
|
margin: [0,5]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
angular.module('OpenSlidesApp.motions.pdf', [])
|
angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
||||||
|
|
||||||
.factory('MotionContentProvider', ['gettextCatalog', function(gettextCatalog) {
|
.factory('MotionContentProvider', [
|
||||||
|
'gettextCatalog',
|
||||||
|
'PdfPredefinedFunctions',
|
||||||
|
function(gettextCatalog, PdfPredefinedFunctions) {
|
||||||
/**
|
/**
|
||||||
* Provides the content as JS objects for Motions in pdfMake context
|
* Provides the content as JS objects for Motions in pdfMake context
|
||||||
* @constructor
|
* @constructor
|
||||||
@ -12,6 +15,9 @@ angular.module('OpenSlidesApp.motions.pdf', [])
|
|||||||
|
|
||||||
var createInstance = function(converter, motion, $scope, User) {
|
var createInstance = function(converter, motion, $scope, User) {
|
||||||
|
|
||||||
|
var header = PdfPredefinedFunctions.createTitle(gettextCatalog.getString("Motion") + " " +
|
||||||
|
motion.identifier + ": " + motion.getTitle($scope.version));
|
||||||
|
|
||||||
// generates the text of the motion. Also septerates between line-numbers
|
// generates the text of the motion. Also septerates between line-numbers
|
||||||
var textContent = function() {
|
var textContent = function() {
|
||||||
if ($scope.lineNumberMode == "inline" || $scope.lineNumberMode == "outside") {
|
if ($scope.lineNumberMode == "inline" || $scope.lineNumberMode == "outside") {
|
||||||
@ -32,14 +38,6 @@ angular.module('OpenSlidesApp.motions.pdf', [])
|
|||||||
return converter.convertHTML(motion.getReason($scope.version), $scope);
|
return converter.convertHTML(motion.getReason($scope.version), $scope);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate header text of motion
|
|
||||||
var motionHeader = function() {
|
|
||||||
var header = converter.createElement("text", gettextCatalog.getString("Motion") + " " + motion.identifier + ": " + motion.getTitle($scope.version));
|
|
||||||
header.bold = true;
|
|
||||||
header.fontSize = 26;
|
|
||||||
return header;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Generate text of signment
|
// Generate text of signment
|
||||||
var signment = function() {
|
var signment = function() {
|
||||||
var label = converter.createElement("text", gettextCatalog.getString('Submitter') + ':\nStatus:');
|
var label = converter.createElement("text", gettextCatalog.getString('Submitter') + ':\nStatus:');
|
||||||
@ -119,7 +117,7 @@ angular.module('OpenSlidesApp.motions.pdf', [])
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generates title section for motion
|
//Generates title section for motion
|
||||||
var titleSection = function() {
|
var titleSection = function() {
|
||||||
var title = converter.createElement("text", motion.getTitle($scope.version));
|
var title = converter.createElement("text", motion.getTitle($scope.version));
|
||||||
title.bold = true;
|
title.bold = true;
|
||||||
@ -154,7 +152,7 @@ angular.module('OpenSlidesApp.motions.pdf', [])
|
|||||||
var getContent = function() {
|
var getContent = function() {
|
||||||
if (reasonContent().length === 0 ) {
|
if (reasonContent().length === 0 ) {
|
||||||
return [
|
return [
|
||||||
motionHeader(),
|
header,
|
||||||
signment(),
|
signment(),
|
||||||
polls(),
|
polls(),
|
||||||
titleSection(),
|
titleSection(),
|
||||||
@ -162,7 +160,7 @@ angular.module('OpenSlidesApp.motions.pdf', [])
|
|||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
return [
|
return [
|
||||||
motionHeader(),
|
header,
|
||||||
signment(),
|
signment(),
|
||||||
polls(),
|
polls(),
|
||||||
titleSection(),
|
titleSection(),
|
||||||
@ -315,7 +313,10 @@ angular.module('OpenSlidesApp.motions.pdf', [])
|
|||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
.factory('MotionCatalogContentProvider', ['gettextCatalog', function(gettextCatalog) {
|
.factory('MotionCatalogContentProvider', [
|
||||||
|
'gettextCatalog',
|
||||||
|
'PdfPredefinedFunctions',
|
||||||
|
function(gettextCatalog, PdfPredefinedFunctions) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -326,14 +327,7 @@ angular.module('OpenSlidesApp.motions.pdf', [])
|
|||||||
*/
|
*/
|
||||||
var createInstance = function(allMotions, $scope, User, Category) {
|
var createInstance = function(allMotions, $scope, User, Category) {
|
||||||
|
|
||||||
//function to create the Table of contents
|
var title = PdfPredefinedFunctions.createTitle("Motions");
|
||||||
var createTitle = function() {
|
|
||||||
|
|
||||||
return {
|
|
||||||
text: gettextCatalog.getString("Motions"),
|
|
||||||
style: "title"
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
var createTOContent = function(motionTitles) {
|
var createTOContent = function(motionTitles) {
|
||||||
|
|
||||||
@ -420,7 +414,7 @@ angular.module('OpenSlidesApp.motions.pdf', [])
|
|||||||
});
|
});
|
||||||
|
|
||||||
return [
|
return [
|
||||||
createTitle(),
|
title,
|
||||||
createTOCatergories(),
|
createTOCatergories(),
|
||||||
createTOContent(motionTitles),
|
createTOContent(motionTitles),
|
||||||
motionContent
|
motionContent
|
||||||
|
Loading…
Reference in New Issue
Block a user