Added configurable header and footer logos for PDF.

This commit is contained in:
Sean Engelhardt 2017-04-19 14:56:15 +02:00 committed by Emanuel Schütze
parent 06adfa0301
commit 2b94dc5942
4 changed files with 76 additions and 17 deletions

View File

@ -223,7 +223,9 @@ def get_config_variables():
name='logos_available', name='logos_available',
default_value=[ default_value=[
'logo_projector_main', 'logo_projector_main',
'logo_projector_header'], 'logo_projector_header',
'logo_pdf_header',
'logo_pdf_footer'],
weight=300, weight=300,
group='Logo', group='Logo',
hidden=True) hidden=True)
@ -247,3 +249,24 @@ def get_config_variables():
weight=302, weight=302,
group='Logo', group='Logo',
hidden=True) hidden=True)
#PDF logos
yield ConfigVariable(
name='logo_pdf_header',
default_value={
'display_name': 'Header PDF logo',
'path': ''},
input_type='logo',
weight=310,
group='Logo',
hidden=True)
yield ConfigVariable(
name='logo_pdf_footer',
default_value={
'display_name': 'Footer PDF logo',
'path': ''},
input_type='logo',
weight=311,
group='Logo',
hidden=True)

View File

@ -144,18 +144,19 @@ angular.module('OpenSlidesApp.core.pdf', [])
* @param {object} contentProvider - Object with on method `getContent`, which * @param {object} contentProvider - Object with on method `getContent`, which
* returns an array for content * returns an array for content
*/ */
var createInstance = function(contentProvider) { //images shall contain the the logos as URL: base64Str, just like the converter
var createInstance = function(contentProvider, images) {
// PDF header // PDF header
var getHeader = function() { var getHeader = function() {
var columns = []; var columns = [];
var logoUrl = Config.get('logo_pdf_header').value.path;
// add here your custom logo (which has to be added to a custom vfs_fonts.js) if (logoUrl) {
// see https://github.com/pdfmake/pdfmake/wiki/Custom-Fonts---client-side
/*
columns.push({ columns.push({
image: 'logo.png', image: images[logoUrl],
fit: [180,40] fit: [180,40]
});*/ });
}
var line1 = [ var line1 = [
Config.translate(Config.get('general_event_name').value), Config.translate(Config.get('general_event_name').value),
@ -768,7 +769,7 @@ angular.module('OpenSlidesApp.core.pdf', [])
height *= scaleByHeight; height *= scaleByHeight;
} }
alreadyConverted.push({ alreadyConverted.push({
image: BaseMap[element.getAttribute("src")], image: images[element.getAttribute("src")],
width: width, width: width,
height: height height: height
}); });
@ -837,7 +838,6 @@ angular.module('OpenSlidesApp.core.pdf', [])
ParseHtml(content, html); ParseHtml(content, html);
return content; return content;
}, },
BaseMap = images,
/** /**
* Creates containerelements for pdfMake * Creates containerelements for pdfMake
* e.g create("text":"MyText") result in { text: "MyText" } * e.g create("text":"MyText") result in { text: "MyText" }

View File

@ -321,6 +321,7 @@
ng-mouseleave="mediafile.logoHover=false" ng-mouseleave="mediafile.logoHover=false"
ng-show="mediafile.canBeUsedAsLogo()"> ng-show="mediafile.canBeUsedAsLogo()">
<span uib-dropdown> <span uib-dropdown>
<<<<<<< e1a95588e7f81cf06db3e753be82bc17a125d059
<span id="dropdownLogo{{ mediafile.id }}" class="pointer nobr" uib-dropdown-toggle> <span id="dropdownLogo{{ mediafile.id }}" class="pointer nobr" uib-dropdown-toggle>
<span uib-tooltip="{{ 'Manage logos' | translate }}" tooltip-class="nobr"> <span uib-tooltip="{{ 'Manage logos' | translate }}" tooltip-class="nobr">
<span ng-if="!mediafile.isUsedAsLogo()" ng-show="mediafile.hover"> <span ng-if="!mediafile.isUsedAsLogo()" ng-show="mediafile.hover">
@ -335,6 +336,22 @@
{{ logo.display_name | translate }}<span ng-if="!$last">,</br></span> {{ logo.display_name | translate }}<span ng-if="!$last">,</br></span>
</small> </small>
</span> </span>
=======
<span id="dropdownLogo{{ mediafile.id }}" class="pointer nobr"
uib-dropdown-toggle uib-tooltip="{{ 'Manage logos' | translate }}"
tooltip-class="nobr">
<span ng-if="!mediafile.isUsedAsLogo()" ng-show="mediafile.hover">
<i class="fa fa-picture-o"></i>
<i class="fa fa-plus"></i>
</span>
<span ng-if="mediafile.isUsedAsLogo()">
<i class="fa fa-picture-o spacer-right"></i>
<span ng-repeat="logo in mediafile.getLogos()">
<small>
{{ logo.display_name }}
</small>
<span ng-if="!$last"><br /><i class="fa fa-picture-o spacer-right"></i></span>
>>>>>>> add logos in PDF (WIP)
</span> </span>
</span> </span>
<span ng-if="hasProjectorHeaderLogo(mediafile) && mediafile.logoHover" <span ng-if="hasProjectorHeaderLogo(mediafile) && mediafile.logoHover"

View File

@ -495,9 +495,11 @@ angular.module('OpenSlidesApp.users.site', [
'osTableSort', 'osTableSort',
'gettext', 'gettext',
'PdfCreate', 'PdfCreate',
'PDFLayout',
'$q',
function($scope, $state, $http, ngDialog, UserForm, User, Group, PasswordGenerator, Projector, ProjectionDefault, function($scope, $state, $http, ngDialog, UserForm, User, Group, PasswordGenerator, Projector, ProjectionDefault,
UserListContentProvider, Config, UserAccessDataListContentProvider, PdfMakeDocumentProvider, gettextCatalog, UserListContentProvider, Config, UserAccessDataListContentProvider, PdfMakeDocumentProvider, gettextCatalog,
UserCsvExport, osTableFilter, osTableSort, gettext, PdfCreate) { UserCsvExport, osTableFilter, osTableSort, gettext, PdfCreate, PDFLayout, $q) {
User.bindAll({}, $scope, 'users'); User.bindAll({}, $scope, 'users');
Group.bindAll({where: {id: {'>': 1}}}, $scope, 'groups'); Group.bindAll({where: {id: {'>': 1}}}, $scope, 'groups');
$scope.$watch(function () { $scope.$watch(function () {
@ -685,10 +687,27 @@ angular.module('OpenSlidesApp.users.site', [
// Export as PDF // Export as PDF
$scope.pdfExportUserList = function () { $scope.pdfExportUserList = function () {
var imageMap = {};
var imagePromises = [];
var imageSources = [];
imageSources.push(Config.get('logo_pdf_header').value.path);
imageSources.push(Config.get('logo_pdf_footer').value.path);
imagePromises = _.map(imageSources, function (image_source) {
return PDFLayout.imageURLtoBase64(image_source).then(function (base64Str) {
imageMap[image_source] = base64Str;
});
});
return $q(function (resolve) {
$q.all(imagePromises).then(function(base64Str) {
var filename = gettextCatalog.getString("List of participants")+".pdf"; var filename = gettextCatalog.getString("List of participants")+".pdf";
var userListContentProvider = UserListContentProvider.createInstance($scope.usersFiltered, $scope.groups); var userListContentProvider = UserListContentProvider.createInstance($scope.usersFiltered, $scope.groups);
var documentProvider = PdfMakeDocumentProvider.createInstance(userListContentProvider); var documentProvider = PdfMakeDocumentProvider.createInstance(userListContentProvider, imageMap);
PdfCreate.download(documentProvider.getDocument(), filename); PdfCreate.download(documentProvider.getDocument(), filename);
});
});
}; };
$scope.pdfExportUserAccessDataList = function () { $scope.pdfExportUserAccessDataList = function () {
var filename = gettextCatalog.getString("List of access data")+".pdf"; var filename = gettextCatalog.getString("List of access data")+".pdf";