Changed PDF documentProvider to accept images and some cleanup.

This commit is contained in:
FinnStutzenstein 2017-04-26 16:09:27 +02:00 committed by Emanuel Schütze
parent 2b94dc5942
commit fb45d30a34
13 changed files with 878 additions and 781 deletions

View File

@ -75,6 +75,24 @@ angular.module('OpenSlidesApp.agenda.pdf', ['OpenSlidesApp.core.pdf'])
createInstance: createInstance
};
}]);
}])
.factory('AgendaPdfExport', [
'gettextCatalog',
'AgendaContentProvider',
'PdfMakeDocumentProvider',
'PdfCreate',
function (gettextCatalog, AgendaContentProvider, PdfMakeDocumentProvider, PdfCreate) {
return {
export: function (items) {
var filename = gettextCatalog.getString('Agenda') + '.pdf';
var agendaContentProvider = AgendaContentProvider.createInstance(items);
PdfMakeDocumentProvider.createInstance(agendaContentProvider).then(function (documentProvider) {
PdfCreate.download(documentProvider.getDocument(), filename);
});
},
};
}
]);
}());

View File

@ -89,17 +89,15 @@ angular.module('OpenSlidesApp.agenda.site', [
'AgendaTree',
'Projector',
'ProjectionDefault',
'AgendaContentProvider',
'PdfMakeDocumentProvider',
'gettextCatalog',
'gettext',
'osTableFilter',
'AgendaCsvExport',
'PdfCreate',
'AgendaPdfExport',
'ErrorMessage',
function($scope, $filter, $http, $state, DS, operator, ngDialog, Agenda, TopicForm,
AgendaTree, Projector, ProjectionDefault, AgendaContentProvider, PdfMakeDocumentProvider,
gettextCatalog, gettext, osTableFilter, AgendaCsvExport, PdfCreate, ErrorMessage) {
AgendaTree, Projector, ProjectionDefault, gettextCatalog, gettext, osTableFilter,
AgendaCsvExport, AgendaPdfExport, ErrorMessage) {
// Bind agenda tree to the scope
$scope.$watch(function () {
return Agenda.lastModified();
@ -276,10 +274,7 @@ angular.module('OpenSlidesApp.agenda.site', [
};
// export
$scope.pdfExport = function () {
var filename = gettextCatalog.getString('Agenda') + '.pdf';
var agendaContentProvider = AgendaContentProvider.createInstance($scope.itemsFiltered);
var documentProvider = PdfMakeDocumentProvider.createInstance(agendaContentProvider);
PdfCreate.download(documentProvider.getDocument(), filename);
AgendaPdfExport.export($scope.itemsFiltered);
};
$scope.csvExport = function () {
AgendaCsvExport.export($scope.itemsFiltered);

View File

@ -262,7 +262,8 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
return {
createInstance: createInstance
};
}])
}
])
.factory('BallotContentProvider', [
'$filter',
@ -271,12 +272,12 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
'Config',
'User',
function($filter, gettextCatalog, PDFLayout, Config, User) {
var createInstance = function(scope, poll, pollNumber) {
var createInstance = function(assignment, poll, pollNumber) {
// page title
var createTitle = function() {
return {
text: scope.assignment.title,
text: assignment.title,
style: 'title',
};
};
@ -480,7 +481,8 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
return {
createInstance: createInstance
};
}])
}
])
.factory('AssignmentCatalogContentProvider', [
'gettextCatalog',
@ -555,6 +557,65 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
return {
createInstance: createInstance
};
}]);
}
])
.factory('AssignmentPdfExport', [
'gettextCatalog',
'AssignmentContentProvider',
'AssignmentCatalogContentProvider',
'PdfMakeDocumentProvider',
'BallotContentProvider',
'PdfMakeBallotPaperProvider',
'PdfCreate',
function (gettextCatalog, AssignmentContentProvider, AssignmentCatalogContentProvider,
PdfMakeDocumentProvider, BallotContentProvider, PdfMakeBallotPaperProvider, PdfCreate) {
return {
export: function (assignments, singleAssignment) {
var filename = singleAssignment ?
gettextCatalog.getString('Election') + '_' + assignments.title :
gettextCatalog.getString('Elections');
filename += '.pdf';
if (singleAssignment) {
assignments = [assignments];
}
var assignmentContentProviderArray = [];
// Convert the assignments to content providers
angular.forEach(assignments, function(assignment) {
assignmentContentProviderArray.push(AssignmentContentProvider.createInstance(assignment));
});
var documentProviderPromise;
if (singleAssignment) {
documentProviderPromise =
PdfMakeDocumentProvider.createInstance(assignmentContentProviderArray[0]);
} else {
var assignmentCatalogContentProvider =
AssignmentCatalogContentProvider.createInstance(assignmentContentProviderArray);
documentProviderPromise =
PdfMakeDocumentProvider.createInstance(assignmentCatalogContentProvider);
}
documentProviderPromise.then(function (documentProvider) {
PdfCreate.download(documentProvider.getDocument(), filename);
});
},
createBallotPdf: function (assignment, pollId) {
var thePoll;
var pollNumber;
angular.forEach(assignment.polls, function(poll, pollIndex) {
if (poll.id == pollId) {
thePoll = poll;
pollNumber = pollIndex+1;
}
});
var filename = gettextCatalog.getString('Ballot') + '_' + pollNumber + '_' + assignment.title + '.pdf';
var ballotContentProvider = BallotContentProvider.createInstance(assignment, thePoll, pollNumber);
var documentProvider = PdfMakeBallotPaperProvider.createInstance(ballotContentProvider);
PdfCreate.download(documentProvider.getDocument(), filename);
},
};
}
]);
}());

View File

@ -265,18 +265,14 @@ angular.module('OpenSlidesApp.assignments.site', [
'Projector',
'ProjectionDefault',
'gettextCatalog',
'AssignmentContentProvider',
'AssignmentCatalogContentProvider',
'PdfMakeDocumentProvider',
'User',
'osTableFilter',
'osTableSort',
'gettext',
'PdfCreate',
'AssignmentPhases',
'AssignmentPdfExport',
function($scope, ngDialog, AssignmentForm, Assignment, Tag, Agenda, Projector, ProjectionDefault,
gettextCatalog, AssignmentContentProvider, AssignmentCatalogContentProvider, PdfMakeDocumentProvider,
User, osTableFilter, osTableSort, gettext, PdfCreate, AssignmentPhases) {
gettextCatalog, User, osTableFilter, osTableSort, gettext, AssignmentPhases, AssignmentPdfExport) {
Assignment.bindAll({}, $scope, 'assignments');
Tag.bindAll({}, $scope, 'tags');
$scope.$watch(function () {
@ -383,20 +379,8 @@ angular.module('OpenSlidesApp.assignments.site', [
Assignment.destroy(assignment.id);
};
// create the PDF List
$scope.makePDF_assignmentList = function () {
var filename = gettextCatalog.getString("Elections") + ".pdf";
var assignmentContentProviderArray = [];
//convert the filtered assignments to content providers
angular.forEach($scope.assignmentsFiltered, function(assignment) {
assignmentContentProviderArray.push(AssignmentContentProvider.createInstance(assignment));
});
var assignmentCatalogContentProvider =
AssignmentCatalogContentProvider.createInstance(assignmentContentProviderArray);
var documentProvider =
PdfMakeDocumentProvider.createInstance(assignmentCatalogContentProvider);
PdfCreate.download(documentProvider.getDocument(), filename);
$scope.pdfExport = function () {
AssignmentPdfExport.export($scope.assignmentsFiltered);
};
}
])
@ -416,18 +400,13 @@ angular.module('OpenSlidesApp.assignments.site', [
'assignmentId',
'Projector',
'ProjectionDefault',
'AssignmentContentProvider',
'BallotContentProvider',
'PdfMakeDocumentProvider',
'PdfMakeBallotPaperProvider',
'gettextCatalog',
'PdfCreate',
'AssignmentPhases',
'AssignmentPdfExport',
'ErrorMessage',
function($scope, $http, $filter, $timeout, filterFilter, gettext, ngDialog, AssignmentForm, operator, Assignment,
User, assignmentId, Projector, ProjectionDefault, AssignmentContentProvider, BallotContentProvider,
PdfMakeDocumentProvider, PdfMakeBallotPaperProvider, gettextCatalog, PdfCreate, AssignmentPhases,
ErrorMessage) {
function($scope, $http, $filter, $timeout, filterFilter, gettext, ngDialog, AssignmentForm, operator,
Assignment, User, assignmentId, Projector, ProjectionDefault, gettextCatalog, AssignmentPhases,
AssignmentPdfExport, ErrorMessage) {
User.bindAll({}, $scope, 'users');
var assignment = Assignment.get(assignmentId);
Assignment.loadRelations(assignment, 'agenda_item');
@ -600,28 +579,13 @@ angular.module('OpenSlidesApp.assignments.site', [
};
//creates the document as pdf
$scope.makePDF_singleAssignment = function() {
var filename = gettextCatalog.getString("Election") + "_" + $scope.assignment.title + ".pdf";
var assignmentContentProvider = AssignmentContentProvider.createInstance($scope.assignment);
var documentProvider = PdfMakeDocumentProvider.createInstance(assignmentContentProvider);
PdfCreate.download(documentProvider.getDocument(), filename);
// Creates the document as pdf
$scope.pdfExport = function() {
AssignmentPdfExport.export($scope.assignment, true);
};
//creates the ballotpaper as pdf
$scope.makePDF_assignmentpoll = function(pollID) {
var thePoll;
var pollNumber;
angular.forEach($scope.assignment.polls, function(poll, pollIndex) {
if (poll.id == pollID) {
thePoll = poll;
pollNumber = pollIndex+1;
}
});
var filename = gettextCatalog.getString("Ballot") + "_" + pollNumber + "_" + $scope.assignment.title + ".pdf";
var ballotContentProvider = BallotContentProvider.createInstance($scope, thePoll, pollNumber);
var documentProvider = PdfMakeBallotPaperProvider.createInstance(ballotContentProvider);
PdfCreate.download(documentProvider.getDocument(), filename);
// Creates the ballotpaper as pdf
$scope.ballotpaperExport = function(pollId) {
AssignmentPdfExport.createBallotPdf($scope.assignment, pollId);
};
// Just mark some vote value strings for translation.

View File

@ -21,7 +21,7 @@
<i class="fa fa-pencil"></i>
</a>
<!-- pdf -->
<a ng-click="makePDF_singleAssignment()" target="_blank" class="btn btn-default btn-sm">
<a ng-click="pdfExport()" target="_blank" class="btn btn-default btn-sm">
<i class="fa fa-file-pdf-o fa-lg"></i>
<translate>PDF</translate>
</a>
@ -152,7 +152,7 @@
<!-- angular requires to open the link in new tab with "target='_blank'".
Otherwise the pdf url can't be open in same window; angular redirects to "/". -->
<!-- PDF -->
<a ng-click="makePDF_assignmentpoll(poll.id)" target="_blank" class="btn btn-default btn-sm">
<a ng-click="ballotpaperExport(poll.id)" target="_blank" class="btn btn-default btn-sm">
<i class="fa fa-file-pdf-o"></i>
<translate>Print ballot paper</translate>
</a>

View File

@ -39,7 +39,7 @@
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownExport">
<!-- PDF export -->
<li>
<a href="" ng-click="makePDF_assignmentList()">
<a href="" ng-click="pdfExport()">
<i class="fa fa-file-pdf-o"></i>
<translate>PDF</translate>
</a>

View File

@ -250,7 +250,7 @@ def get_config_variables():
group='Logo',
hidden=True)
#PDF logos
# PDF logos
yield ConfigVariable(
name='logo_pdf_header',
default_value={

View File

@ -96,9 +96,14 @@ self.addEventListener('message', function(e) {
// see https://github.com/bpampuch/pdfmake/issues/38
if (data.footerTpl) {
data.footer = function (currentPage, pageCount) {
var footerText = data.footerTpl.text
var footerText = '';
for(var i = 0; i < data.footerTpl.columns.length; i++) {
if (data.footerTpl.columns[i].text) {
footerText = data.footerTpl.columns[i].text
.replace('{{currentPage}}', currentPage)
.replace('{{pageCount}}', pageCount);
}
}
return {
text: footerText,
alignment: data.footerTpl.alignment,

View File

@ -135,9 +135,11 @@ angular.module('OpenSlidesApp.core.pdf', [])
.factory('PdfMakeDocumentProvider', [
'$q',
'Config',
'PDFLayout',
function(Config, PDFLayout) {
'PdfImageConverter',
function($q, Config, PDFLayout, PdfImageConverter) {
/**
* Provides the global document
* @constructor
@ -145,16 +147,20 @@ angular.module('OpenSlidesApp.core.pdf', [])
* returns an array for content
*/
//images shall contain the the logos as URL: base64Str, just like the converter
var createInstance = function(contentProvider, images) {
var createInstance = function(contentProvider) {
// Logo urls
var logoHeaderUrl = Config.get('logo_pdf_header').value.path,
logoFooterUrl = Config.get('logo_pdf_footer').value.path;
var imageMap = {};
// PDF header
var getHeader = function() {
var columns = [];
var logoUrl = Config.get('logo_pdf_header').value.path;
if (logoUrl) {
if (logoHeaderUrl) {
columns.push({
image: images[logoUrl],
fit: [180,40]
image: imageMap[logoHeaderUrl],
fit: [180, 40],
});
}
@ -169,15 +175,15 @@ angular.module('OpenSlidesApp.core.pdf', [])
var text = [line1, line2].join('\n');
columns.push({
text: text,
fontSize:10,
width: '100%'
fontSize: 10,
width: '100%',
});
return {
color: '#555',
fontSize: 9,
margin: [75, 30, 75, 10], // [left, top, right, bottom]
columns: columns,
columnGap: 10
columnGap: 10,
};
};
@ -186,12 +192,26 @@ angular.module('OpenSlidesApp.core.pdf', [])
// Used placeholder for currentPage and pageCount which
// are replaced by dynamic footer function in pdf-worker.js.
var getFooter = function() {
var columns = [];
// TODO: This does't work. The image does not get rendered.
if (logoFooterUrl) {
columns.push({
image: imageMap[logoFooterUrl],
fit: [180,40],
});
}
columns.push({
text: '{{currentPage}} / {{pageCount}}',
width: '100%',
});
return {
alignment: 'right',
margin: [0, 15, 75, 0],
fontSize: 9,
color: '#555',
text: '{{currentPage}} / {{pageCount}}'
columns: columns,
columnGap: 10,
};
};
// Generates the document(definition) for pdfMake
@ -296,9 +316,18 @@ angular.module('OpenSlidesApp.core.pdf', [])
};
};
return {
return $q(function (resolve) {
var imageSources = [
logoHeaderUrl,
logoFooterUrl
];
PdfImageConverter.toBase64(imageSources).then(function (_imageMap) {
imageMap = _imageMap;
resolve({
getDocument: getDocument
};
});
});
});
};
return {
createInstance: createInstance
@ -862,7 +891,34 @@ angular.module('OpenSlidesApp.core.pdf', [])
return {
createInstance: createInstance
};
}])
}
])
.factory('PdfImageConverter', [
'$q',
'PDFLayout',
function ($q, PDFLayout) {
return {
toBase64: function (imageSources) {
var imageMap = {};
var imagePromises = _.map(imageSources, function (imageSource) {
if (imageSource) {
return PDFLayout.imageURLtoBase64(imageSource).then(function (base64Str) {
imageMap[imageSource] = base64Str;
});
}
});
return $q(function (resolve) {
//resolve promises to get base64
$q.all(imagePromises).then(function() {
resolve(imageMap);
});
});
}
};
}
])
.factory('PdfCreate', [
'$timeout',

View File

@ -321,7 +321,6 @@
ng-mouseleave="mediafile.logoHover=false"
ng-show="mediafile.canBeUsedAsLogo()">
<span uib-dropdown>
<<<<<<< e1a95588e7f81cf06db3e753be82bc17a125d059
<span id="dropdownLogo{{ mediafile.id }}" class="pointer nobr" uib-dropdown-toggle>
<span uib-tooltip="{{ 'Manage logos' | translate }}" tooltip-class="nobr">
<span ng-if="!mediafile.isUsedAsLogo()" ng-show="mediafile.hover">
@ -336,29 +335,13 @@
{{ logo.display_name | translate }}<span ng-if="!$last">,</br></span>
</small>
</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 ng-if="hasProjectorHeaderLogo(mediafile) && mediafile.logoHover"
uib-tooltip="{{ 'The projector header should have a default size of 1024x70px. Adapt the image width if you change the projector resolution.' | translate }}">
<i class="fa fa-info-circle"></i>
</span>
<i class="fa fa-cog fa-lg spacer-left" ng-show="mediafile.logoHover"></i>
<i class="fa fa-cog fa-lg spacer-left" ng-show="mediafile.logoHover && mediafile.isUsedAsLogo()"></i>
</span>
<ul class="dropdown-menu" aria-labelledby="dropdownLogos{{ mediafile.id }}">
<li ng-repeat="logo in logos">

View File

@ -5,21 +5,38 @@
angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
.factory('MotionContentProvider', [
'$q',
'operator',
'gettextCatalog',
'PDFLayout',
'PdfMakeConverter',
'PdfImageConverter',
'HTMLValidizer',
'Category',
'Config',
'Motion',
function(operator, gettextCatalog, PDFLayout, Category, Config, Motion) {
function($q, operator, gettextCatalog, PDFLayout, PdfMakeConverter, PdfImageConverter, HTMLValidizer, Category, Config, Motion) {
/**
* Provides the content as JS objects for Motions in pdfMake context
* @constructor
*/
var createInstance = function(converter, motion, motionVersion, changeRecommendationMode,
var createInstance = function(motion, motionVersion, changeRecommendationMode,
changeRecommendations, lineNumberMode, includeReason, includeComments) {
var converter;
// Query all image sources from motion text and reason
// TODO: Do we need images for comments here too??
var getImageSources = function () {
var text = motion.getTextByMode(changeRecommendationMode, null);
var content = HTMLValidizer.validize(text) + HTMLValidizer.validize(motion.getReason());
var map = Function.prototype.call.bind([].map);
return map($(content).find('img'), function(element) {
return element.getAttribute('src');
});
};
// title
var identifier = motion.identifier ? ' ' + motion.identifier : '';
var title = PDFLayout.createTitle(
@ -254,7 +271,6 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
};
};
// motion text (with line-numbers)
var motionText = function() {
var motionTextContent = motion.getTextByMode(changeRecommendationMode, motionVersion);
@ -303,19 +319,6 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
}
};
// getters
var getTitle = function() {
return motion.getTitle(motionVersion);
};
var getIdentifier = function() {
return motion.identifier ? motion.identifier : '';
};
var getCategory = function() {
return motion.category;
};
// Generates content as a pdfmake consumable
var getContent = function() {
var content = [
@ -336,18 +339,38 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
}
return content;
};
return {
// getters
var getTitle = function() {
return motion.getTitle(motionVersion);
};
var getIdentifier = function() {
return motion.identifier ? motion.identifier : '';
};
var getCategory = function() {
return motion.category;
};
return $q(function (resolve) {
PdfImageConverter.toBase64(getImageSources()).then(function (imageMap) {
converter = PdfMakeConverter.createInstance(imageMap);
resolve({
getContent: getContent,
getTitle: getTitle,
getIdentifier: getIdentifier,
getCategory: getCategory
};
});
});
});
};
return {
createInstance: createInstance
};
}])
}
])
.factory('PollContentProvider', [
'PDFLayout',
@ -459,7 +482,8 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
return {
createInstance: createInstance
};
}])
}
])
.factory('MotionCatalogContentProvider', [
'gettextCatalog',
@ -467,7 +491,6 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
'Category',
'Config',
function(gettextCatalog, PDFLayout, Category, Config) {
/**
* Constructor
* @function
@ -601,7 +624,8 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
return {
createInstance: createInstance
};
}])
}
])
.factory('MotionPdfExport', [
'$http',
@ -633,7 +657,6 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
includeReason: true,
includeComments: false,
});
var image_sources = [];
if (singleMotion) {
_.defaults(params, {
@ -653,49 +676,34 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
'where': {'motion_version_id': {'==': motion.active_version}}
});
}
var text = motion.getTextByMode(params.changeRecommendationMode, null);
var content = HTMLValidizer.validize(text) + HTMLValidizer.validize(motion.getReason());
var map = Function.prototype.call.bind([].map);
var tmp_image_sources = map($(content).find('img'), function(element) {
return element.getAttribute('src');
});
image_sources = image_sources.concat(tmp_image_sources);
});
var imageMap = {};
var imagePromises = _.map(image_sources, function (image_source) {
return PDFLayout.imageURLtoBase64(image_source).then(function (base64Str) {
imageMap[image_source] = base64Str;
var motionContentProviderArray = [];
var motionContentProviderPromises = _.map(motions, function (motion) {
var version = (singleMotion ? params.version : motion.active_version);
return MotionContentProvider.createInstance(
motion, version, params.changeRecommendationMode,
motion.changeRecommendations, params.lineNumberMode,
params.includeReason, params.includeComments
).then(function (contentProvider) {
motionContentProviderArray.push(contentProvider);
});
});
return $q(function (resolve) {
//resolve promises to get base64
$q.all(imagePromises).then(function(base64Str) {
var converter = PdfMakeConverter.createInstance(imageMap);
var motionContentProviderArray = [];
//convert all motions to motionContentProviders
angular.forEach(motions, function (motion) {
var version = (singleMotion ? params.version : motion.active_version);
motionContentProviderArray.push(MotionContentProvider.createInstance(
converter, motion, version, params.changeRecommendationMode,
motion.changeRecommendations, params.lineNumberMode,
params.includeReason, params.includeComments
));
});
var documentProvider;
$q.all(motionContentProviderPromises).then(function() {
var documentProviderPromise;
if (singleMotion) {
documentProvider = PdfMakeDocumentProvider.createInstance(motionContentProviderArray[0]);
documentProviderPromise = PdfMakeDocumentProvider.createInstance(motionContentProviderArray[0]);
} else {
var motionCatalogContentProvider = MotionCatalogContentProvider.createInstance(motionContentProviderArray);
documentProvider = PdfMakeDocumentProvider.createInstance(motionCatalogContentProvider);
documentProviderPromise = PdfMakeDocumentProvider.createInstance(motionCatalogContentProvider);
}
documentProviderPromise.then(function (documentProvider) {
resolve(documentProvider);
});
});
});
},
export: function (motions, params, singleMotion) {
_.defaults(params, {

View File

@ -102,15 +102,16 @@ angular.module('OpenSlidesApp.users.pdf', ['OpenSlidesApp.core.pdf'])
return {
createInstance: createInstance
};
}])
}
])
.factory('UserAccessDataListContentProvider', [
'gettextCatalog',
'PDFLayout',
function(gettextCatalog, PDFLayout) {
'Config',
function(gettextCatalog, PDFLayout, Config) {
var createInstance = function(userList, groups, Config) {
var createInstance = function(userList) {
var creadeUserHeadLine = function(user) {
var titleLine = [];
@ -256,14 +257,17 @@ angular.module('OpenSlidesApp.users.pdf', ['OpenSlidesApp.core.pdf'])
var getContent = function() {
var content = [];
angular.forEach(userList, function (user) {
angular.forEach(userList, function (user, index) {
content.push(creadeUserHeadLine(user));
content.push(createAccessDataContent(user));
content.push(createWelcomeText());
// No pagebreak after the last user
if (index !== userList.length - 1) {
content.push({
text: '',
pageBreak: 'after'
});
}
});
return [
@ -280,5 +284,38 @@ angular.module('OpenSlidesApp.users.pdf', ['OpenSlidesApp.core.pdf'])
createInstance: createInstance
};
}
])
.factory('UserPdfExport', [
'gettextCatalog',
'UserListContentProvider',
'UserAccessDataListContentProvider',
'PdfMakeDocumentProvider',
'PdfCreate',
function (gettextCatalog, UserListContentProvider, UserAccessDataListContentProvider, PdfMakeDocumentProvider, PdfCreate) {
return {
exportUserList: function (users) {
var filename = gettextCatalog.getString('List of participants') + '.pdf';
var userListContentProvider = UserListContentProvider.createInstance(users);
PdfMakeDocumentProvider.createInstance(userListContentProvider).then(
function (documentProvider) {
PdfCreate.download(documentProvider.getDocument(), filename);
}
);
},
exportUserAccessDataList: function (users) {
var filename = gettextCatalog.getString('List of access data') + '.pdf';
var userAccessDataListContentProvider = UserAccessDataListContentProvider.createInstance(
users);
PdfMakeDocumentProvider.createInstance(userAccessDataListContentProvider).then(
function (documentProvider) {
var noFooter = true;
PdfCreate.download(documentProvider.getDocument(noFooter), filename);
}
);
}
};
}
]);
}());

View File

@ -478,6 +478,7 @@ angular.module('OpenSlidesApp.users.site', [
'$scope',
'$state',
'$http',
'$q',
'ngDialog',
'UserForm',
'User',
@ -485,21 +486,15 @@ angular.module('OpenSlidesApp.users.site', [
'PasswordGenerator',
'Projector',
'ProjectionDefault',
'UserListContentProvider',
'Config',
'UserAccessDataListContentProvider',
'PdfMakeDocumentProvider',
'gettextCatalog',
'UserCsvExport',
'osTableFilter',
'osTableSort',
'gettext',
'PdfCreate',
'PDFLayout',
'$q',
function($scope, $state, $http, ngDialog, UserForm, User, Group, PasswordGenerator, Projector, ProjectionDefault,
UserListContentProvider, Config, UserAccessDataListContentProvider, PdfMakeDocumentProvider, gettextCatalog,
UserCsvExport, osTableFilter, osTableSort, gettext, PdfCreate, PDFLayout, $q) {
'UserPdfExport',
function($scope, $state, $http, $q, ngDialog, UserForm, User, Group, PasswordGenerator, Projector, ProjectionDefault,
Config, gettextCatalog, UserCsvExport, osTableFilter, osTableSort, gettext, UserPdfExport) {
User.bindAll({}, $scope, 'users');
Group.bindAll({where: {id: {'>': 1}}}, $scope, 'groups');
$scope.$watch(function () {
@ -687,35 +682,10 @@ angular.module('OpenSlidesApp.users.site', [
// Export as PDF
$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 userListContentProvider = UserListContentProvider.createInstance($scope.usersFiltered, $scope.groups);
var documentProvider = PdfMakeDocumentProvider.createInstance(userListContentProvider, imageMap);
PdfCreate.download(documentProvider.getDocument(), filename);
});
});
UserPdfExport.exportUserList($scope.usersFiltered);
};
$scope.pdfExportUserAccessDataList = function () {
var filename = gettextCatalog.getString("List of access data")+".pdf";
var userAccessDataListContentProvider = UserAccessDataListContentProvider.createInstance(
$scope.usersFiltered, $scope.groups, Config);
var documentProvider = PdfMakeDocumentProvider.createInstance(userAccessDataListContentProvider);
var noFooter = true;
PdfCreate.download(documentProvider.getDocument(noFooter), filename);
UserPdfExport.exportUserAccessDataList($scope.usersFiltered);
};
// Export as a csv file
$scope.csvExport = function () {