Merge pull request #2508 from tsiegleauq/userListPdfMake

Create the user list over pdfmake
This commit is contained in:
Norman Jäckel 2016-10-14 11:50:31 +02:00 committed by GitHub
commit 447339ec33
4 changed files with 146 additions and 5 deletions

View File

@ -129,6 +129,15 @@ angular.module('OpenSlidesApp.core.pdf', [])
listChild: { listChild: {
fontSize: 11, fontSize: 11,
margin: [0,5] margin: [0,5]
},
tableHeader: {
bold: true
},
tableEven: {
fillColor: 'white'
},
tableOdd: {
fillColor: '#e7e7e7'
} }
} }
}; };

View File

@ -0,0 +1,116 @@
(function () {
'use strict';
angular.module('OpenSlidesApp.users.pdf', ['OpenSlidesApp.core.pdf'])
.factory('UserListContentProvider', [
'gettextCatalog',
'PdfPredefinedFunctions',
function(gettextCatalog, PdfPredefinedFunctions) {
var createInstance = function(userList, groups) {
//use the Predefined Functions to create the title
var title = PdfPredefinedFunctions.createTitle(gettextCatalog.getString("List of participants"));
//function to generate the user list
var createUserList = function() {
var userJsonList = [];
angular.forEach(userList, function (user, counter) {
//check if the row is even or odd
var rowStyle = [];
if (counter % 2 === 0) {
rowStyle = 'tableEven';
} else {
rowStyle = 'tableOdd';
}
//parse for the group names
var userGroups = [];
angular.forEach(user.groups_id, function (id) {
if (id) {
angular.forEach(groups, function(group) {
if (id == group.id) {
userGroups.push(gettextCatalog.getString(group.name));
}
});
}
});
var userJsonObj = [
{
text: "" + (counter+1),
style: rowStyle
},
{
text: user.short_name,
style: rowStyle
},
{
text: user.structure_level,
style: rowStyle
},
{
text: userGroups.join(" "),
style: rowStyle
}
];
userJsonList.push(userJsonObj);
});
var userTableBody = [
[
{
text: '#',
style: 'tableHeader'
},
{
text: gettextCatalog.getString("Name"),
style: 'tableHeader'
},
{
text: gettextCatalog.getString("Structure level"),
style: 'tableHeader'
},
{
text: gettextCatalog.getString("Groups"),
style: 'tableHeader'
}
]
];
userTableBody = userTableBody.concat((userJsonList));
var userTableJsonString = {
table: {
widths: ['auto', '*', 'auto', 'auto'],
headerRows: 1,
body: userTableBody
},
layout: 'headerLineOnly'
};
return userTableJsonString;
};
var getContent = function() {
return [
title,
createUserList()
];
};
return {
getContent: getContent
};
};
return {
createInstance: createInstance
};
}]);
}());

View File

@ -2,7 +2,11 @@
'use strict'; 'use strict';
angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users']) angular.module('OpenSlidesApp.users.site', [
'OpenSlidesApp.users',
'OpenSlidesApp.core.pdf',
'OpenSlidesApp.users.pdf'
])
.config([ .config([
'mainMenuProvider', 'mainMenuProvider',
@ -423,7 +427,11 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
'PasswordGenerator', 'PasswordGenerator',
'Projector', 'Projector',
'ProjectionDefault', 'ProjectionDefault',
function($scope, $state, $http, ngDialog, UserForm, User, Group, PasswordGenerator, Projector, ProjectionDefault) { 'UserListContentProvider',
'PdfMakeDocumentProvider',
'gettextCatalog',
function($scope, $state, $http, ngDialog, UserForm, User, Group, PasswordGenerator, Projector, ProjectionDefault,
UserListContentProvider, PdfMakeDocumentProvider, gettextCatalog) {
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 () {
@ -548,6 +556,13 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
$scope.isSelectMode = false; $scope.isSelectMode = false;
$scope.uncheckAll(); $scope.uncheckAll();
}; };
$scope.makePDF_userList = function () {
var filename = gettextCatalog.getString("List of participants")+".pdf";
var userListContentProvider = UserListContentProvider.createInstance($scope.users, $scope.groups);
var documentProvider = PdfMakeDocumentProvider.createInstance(userListContentProvider);
pdfMake.createPdf(documentProvider.getDocument()).download(filename);
};
} }
]) ])
@ -959,7 +974,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
existingUsers.forEach(function(user_) { existingUsers.forEach(function(user_) {
if (user_.first_name == user.first_name && if (user_.first_name == user.first_name &&
user_.last_name == user.last_name && user_.last_name == user.last_name &&
user_.structure_level == user.structure_level) { user_.structure_level == user.structure_level) {
deletePromises.push(User.destroy(user_.id)); deletePromises.push(User.destroy(user_.id));
} }
}); });
@ -968,7 +983,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
function(success) { function(success) {
user.imported = true; user.imported = true;
} }
); );
}); });
} else if (!user.duplicate || } else if (!user.duplicate ||
(user.duplicateAction == $scope.duplicateActions[2])) { (user.duplicateAction == $scope.duplicateActions[2])) {

View File

@ -21,7 +21,8 @@
<span class="caret"></span> <span class="caret"></span>
</button> </button>
<ul class="dropdown-menu" uib-dropdown-menu aria-labelledby="user-pdf-dropdown"> <ul class="dropdown-menu" uib-dropdown-menu aria-labelledby="user-pdf-dropdown">
<li><a ui-sref="user_listpdf" target="_blank"> <li>
<a ng-click="makePDF_userList()" class="btn">
<i class="fa fa-list fa-fw"></i> <i class="fa fa-list fa-fw"></i>
<translate>List of participants</translate> <translate>List of participants</translate>
</a> </a>