Throw errors if pdf generation fails, if an image could not be loaded (fixes #3730)
This commit is contained in:
parent
f8df7ddda6
commit
ecb76fd888
@ -82,13 +82,16 @@ angular.module('OpenSlidesApp.agenda.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
'AgendaContentProvider',
|
'AgendaContentProvider',
|
||||||
'PdfMakeDocumentProvider',
|
'PdfMakeDocumentProvider',
|
||||||
'PdfCreate',
|
'PdfCreate',
|
||||||
function (gettextCatalog, AgendaContentProvider, PdfMakeDocumentProvider, PdfCreate) {
|
'Messaging',
|
||||||
|
function (gettextCatalog, AgendaContentProvider, PdfMakeDocumentProvider, PdfCreate, Messaging) {
|
||||||
return {
|
return {
|
||||||
export: function (items) {
|
export: function (items) {
|
||||||
var filename = gettextCatalog.getString('Agenda') + '.pdf';
|
var filename = gettextCatalog.getString('Agenda') + '.pdf';
|
||||||
var agendaContentProvider = AgendaContentProvider.createInstance(items);
|
var agendaContentProvider = AgendaContentProvider.createInstance(items);
|
||||||
PdfMakeDocumentProvider.createInstance(agendaContentProvider).then(function (documentProvider) {
|
PdfMakeDocumentProvider.createInstance(agendaContentProvider).then(function (documentProvider) {
|
||||||
PdfCreate.download(documentProvider, filename);
|
PdfCreate.download(documentProvider, filename);
|
||||||
|
}, function (error) {
|
||||||
|
Messaging.addMessage(error.msg, 'error');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -514,7 +514,7 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
return imageMap;
|
return imageMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
return $q(function (resolve) {
|
return $q(function (resolve, reject) {
|
||||||
var imageSources = [
|
var imageSources = [
|
||||||
logoBallotPaperUrl,
|
logoBallotPaperUrl,
|
||||||
];
|
];
|
||||||
@ -524,7 +524,7 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
getContent: getContent,
|
getContent: getContent,
|
||||||
getImageMap: getImageMap,
|
getImageMap: getImageMap,
|
||||||
});
|
});
|
||||||
});
|
}, reject);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -618,8 +618,10 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
'BallotContentProvider',
|
'BallotContentProvider',
|
||||||
'PdfMakeBallotPaperProvider',
|
'PdfMakeBallotPaperProvider',
|
||||||
'PdfCreate',
|
'PdfCreate',
|
||||||
|
'Messaging',
|
||||||
function (gettextCatalog, AssignmentContentProvider, AssignmentCatalogContentProvider,
|
function (gettextCatalog, AssignmentContentProvider, AssignmentCatalogContentProvider,
|
||||||
PdfMakeDocumentProvider, BallotContentProvider, PdfMakeBallotPaperProvider, PdfCreate) {
|
PdfMakeDocumentProvider, BallotContentProvider, PdfMakeBallotPaperProvider, PdfCreate,
|
||||||
|
Messaging) {
|
||||||
return {
|
return {
|
||||||
export: function (assignments, singleAssignment) {
|
export: function (assignments, singleAssignment) {
|
||||||
var filename = singleAssignment ?
|
var filename = singleAssignment ?
|
||||||
@ -629,11 +631,10 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
if (singleAssignment) {
|
if (singleAssignment) {
|
||||||
assignments = [assignments];
|
assignments = [assignments];
|
||||||
}
|
}
|
||||||
var assignmentContentProviderArray = [];
|
|
||||||
|
|
||||||
// Convert the assignments to content providers
|
// Convert the assignments to content providers
|
||||||
angular.forEach(assignments, function(assignment) {
|
var assignmentContentProviderArray = _.map(assignments, function (assignment) {
|
||||||
assignmentContentProviderArray.push(AssignmentContentProvider.createInstance(assignment));
|
return AssignmentContentProvider.createInstance(assignment);
|
||||||
});
|
});
|
||||||
|
|
||||||
var documentProviderPromise;
|
var documentProviderPromise;
|
||||||
@ -648,6 +649,8 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
}
|
}
|
||||||
documentProviderPromise.then(function (documentProvider) {
|
documentProviderPromise.then(function (documentProvider) {
|
||||||
PdfCreate.download(documentProvider, filename);
|
PdfCreate.download(documentProvider, filename);
|
||||||
|
}, function (error) {
|
||||||
|
Messaging.addMessage(error.msg, 'error');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
createBallotPdf: function (assignment, pollId) {
|
createBallotPdf: function (assignment, pollId) {
|
||||||
@ -663,6 +666,8 @@ angular.module('OpenSlidesApp.assignments.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
BallotContentProvider.createInstance(assignment, thePoll, pollNumber).then(function (ballotContentProvider) {
|
BallotContentProvider.createInstance(assignment, thePoll, pollNumber).then(function (ballotContentProvider) {
|
||||||
var documentProvider = PdfMakeBallotPaperProvider.createInstance(ballotContentProvider);
|
var documentProvider = PdfMakeBallotPaperProvider.createInstance(ballotContentProvider);
|
||||||
PdfCreate.download(documentProvider, filename);
|
PdfCreate.download(documentProvider, filename);
|
||||||
|
}, function (error) {
|
||||||
|
Messaging.addMessage(error.msg, 'error');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -8,7 +8,8 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
* General layout functions for building PDFs with pdfmake.
|
* General layout functions for building PDFs with pdfmake.
|
||||||
*/
|
*/
|
||||||
.factory('PDFLayout', [
|
.factory('PDFLayout', [
|
||||||
function() {
|
'gettextCatalog',
|
||||||
|
function(gettextCatalog) {
|
||||||
var PDFLayout = {};
|
var PDFLayout = {};
|
||||||
var BallotCircleDimensions = {
|
var BallotCircleDimensions = {
|
||||||
yDistance: 6,
|
yDistance: 6,
|
||||||
@ -89,10 +90,17 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
|
|
||||||
// returns a promise for converting an image in data URL format with size information
|
// returns a promise for converting an image in data URL format with size information
|
||||||
PDFLayout.imageURLtoBase64 = function(url) {
|
PDFLayout.imageURLtoBase64 = function(url) {
|
||||||
var promise = new Promise(function(resolve) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.crossOrigin = "Anonymous";
|
img.crossOrigin = "Anonymous";
|
||||||
img.onload = function() {
|
img.onerror = function () {
|
||||||
|
reject({
|
||||||
|
msg: '<i class="fa fa-exclamation-triangle fa-lg spacer-right"></i>' +
|
||||||
|
gettextCatalog.getString('Error while generating PDF file') +
|
||||||
|
': <code>' + gettextCatalog.getString('Cannot load image') + ' ' + url + '</code>',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
img.onload = function () {
|
||||||
var canvas = document.createElement("canvas");
|
var canvas = document.createElement("canvas");
|
||||||
canvas.width = img.width;
|
canvas.width = img.width;
|
||||||
canvas.height = img.height;
|
canvas.height = img.height;
|
||||||
@ -348,7 +356,7 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
return imageMap;
|
return imageMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
return $q(function (resolve) {
|
return $q(function (resolve, reject) {
|
||||||
var imageSources = [
|
var imageSources = [
|
||||||
logoHeaderUrl,
|
logoHeaderUrl,
|
||||||
logoFooterUrl
|
logoFooterUrl
|
||||||
@ -363,11 +371,11 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
getDocument: getDocument,
|
getDocument: getDocument,
|
||||||
getImageMap: getImageMap,
|
getImageMap: getImageMap,
|
||||||
});
|
});
|
||||||
});
|
}, reject);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
createInstance: createInstance
|
createInstance: createInstance,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
@ -1114,11 +1122,11 @@ angular.module('OpenSlidesApp.core.pdf', [])
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $q(function (resolve) {
|
return $q(function (resolve, reject) {
|
||||||
//resolve promises to get base64
|
//resolve promises to get base64
|
||||||
$q.all(imagePromises).then(function() {
|
$q.all(imagePromises).then(function() {
|
||||||
resolve(imageMap);
|
resolve(imageMap);
|
||||||
});
|
}, reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -450,7 +450,7 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
return imageMap;
|
return imageMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
return $q(function (resolve) {
|
return $q(function (resolve, reject) {
|
||||||
ImageConverter.toBase64(getImageSources()).then(function (_imageMap) {
|
ImageConverter.toBase64(getImageSources()).then(function (_imageMap) {
|
||||||
imageMap = _imageMap;
|
imageMap = _imageMap;
|
||||||
converter = PdfMakeConverter.createInstance(_imageMap);
|
converter = PdfMakeConverter.createInstance(_imageMap);
|
||||||
@ -461,7 +461,7 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
getCategory: getCategory,
|
getCategory: getCategory,
|
||||||
getImageMap: getImageMap,
|
getImageMap: getImageMap,
|
||||||
});
|
});
|
||||||
});
|
}, reject);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -623,7 +623,7 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
return imageMap;
|
return imageMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
return $q(function (resolve) {
|
return $q(function (resolve, reject) {
|
||||||
ImageConverter.toBase64(getImageSources()).then(function (_imageMap) {
|
ImageConverter.toBase64(getImageSources()).then(function (_imageMap) {
|
||||||
imageMap = _imageMap;
|
imageMap = _imageMap;
|
||||||
converter = PdfMakeConverter.createInstance(_imageMap);
|
converter = PdfMakeConverter.createInstance(_imageMap);
|
||||||
@ -631,7 +631,7 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
getContent: getContent,
|
getContent: getContent,
|
||||||
getImageMap: getImageMap,
|
getImageMap: getImageMap,
|
||||||
});
|
});
|
||||||
});
|
}, reject);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -786,7 +786,7 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
return imageMap;
|
return imageMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
return $q(function (resolve) {
|
return $q(function (resolve, reject) {
|
||||||
var imageSources = [
|
var imageSources = [
|
||||||
logoBallotPaperUrl,
|
logoBallotPaperUrl,
|
||||||
];
|
];
|
||||||
@ -796,7 +796,7 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
getContent: getContent,
|
getContent: getContent,
|
||||||
getImageMap: getImageMap,
|
getImageMap: getImageMap,
|
||||||
});
|
});
|
||||||
});
|
}, reject);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
@ -1014,14 +1014,17 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
var motionContentProviderArray = [];
|
var motionContentProviderArray = [];
|
||||||
var motionContentProviderPromises = _.map(motions, function (motion) {
|
var motionContentProviderPromises = _.map(motions, function (motion) {
|
||||||
var version = (singleMotion ? params.version : motion.active_version);
|
var version = (singleMotion ? params.version : motion.active_version);
|
||||||
return MotionContentProvider.createInstance(
|
return $q(function (resolve, reject) {
|
||||||
motion, version, params
|
MotionContentProvider.createInstance(
|
||||||
).then(function (contentProvider) {
|
motion, version, params
|
||||||
motionContentProviderArray.push(contentProvider);
|
).then(function (contentProvider) {
|
||||||
|
motionContentProviderArray.push(contentProvider);
|
||||||
|
resolve();
|
||||||
|
}, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return $q(function (resolve) {
|
return $q(function (resolve, reject) {
|
||||||
$q.all(motionContentProviderPromises).then(function() {
|
$q.all(motionContentProviderPromises).then(function() {
|
||||||
var documentProviderPromise;
|
var documentProviderPromise;
|
||||||
if (singleMotion) {
|
if (singleMotion) {
|
||||||
@ -1032,8 +1035,8 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
}
|
}
|
||||||
documentProviderPromise.then(function (documentProvider) {
|
documentProviderPromise.then(function (documentProvider) {
|
||||||
resolve(documentProvider);
|
resolve(documentProvider);
|
||||||
});
|
}, reject);
|
||||||
});
|
}, reject);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
export: function (motions, params, singleMotion) {
|
export: function (motions, params, singleMotion) {
|
||||||
@ -1044,6 +1047,8 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
this.getDocumentProvider(motions, params, singleMotion).then(
|
this.getDocumentProvider(motions, params, singleMotion).then(
|
||||||
function (documentProvider) {
|
function (documentProvider) {
|
||||||
PdfCreate.download(documentProvider, params.filename);
|
PdfCreate.download(documentProvider, params.filename);
|
||||||
|
}, function (error) {
|
||||||
|
Messaging.addMessage(error.msg, 'error');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -1073,12 +1078,12 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
usedFilenames.push(filename);
|
usedFilenames.push(filename);
|
||||||
filename += '.pdf';
|
filename += '.pdf';
|
||||||
|
|
||||||
return $q(function (resolve) {
|
return $q(function (resolve, reject) {
|
||||||
// get documentProvider for every motion.
|
// get documentProvider for every motion.
|
||||||
self.getDocumentProvider(motion, params, true).then(function (documentProvider) {
|
self.getDocumentProvider(motion, params, true).then(function (documentProvider) {
|
||||||
docMap[filename] = documentProvider;
|
docMap[filename] = documentProvider;
|
||||||
resolve();
|
resolve();
|
||||||
});
|
}, reject);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$q.all(docPromises).then(function () {
|
$q.all(docPromises).then(function () {
|
||||||
@ -1097,6 +1102,8 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
'spacer-right"></i>' + gettextCatalog.getString('Error while generating ZIP file') +
|
'spacer-right"></i>' + gettextCatalog.getString('Error while generating ZIP file') +
|
||||||
': <code>' + error + '</code>', 'error');
|
': <code>' + error + '</code>', 'error');
|
||||||
});
|
});
|
||||||
|
}, function (error) {
|
||||||
|
Messaging.createOrEditMessage(messageId, error.msg, 'error');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
createPollPdf: function (motion, version) {
|
createPollPdf: function (motion, version) {
|
||||||
@ -1106,6 +1113,8 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
PollContentProvider.createInstance(title, id).then(function (pollContentProvider) {
|
PollContentProvider.createInstance(title, id).then(function (pollContentProvider) {
|
||||||
var documentProvider = PdfMakeBallotPaperProvider.createInstance(pollContentProvider);
|
var documentProvider = PdfMakeBallotPaperProvider.createInstance(pollContentProvider);
|
||||||
PdfCreate.download(documentProvider, filename);
|
PdfCreate.download(documentProvider, filename);
|
||||||
|
}, function (error) {
|
||||||
|
Messaging.addMessage(error.msg, 'error');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
exportPersonalNote: function (motion, filename) {
|
exportPersonalNote: function (motion, filename) {
|
||||||
@ -1117,7 +1126,11 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
MotionPartialContentProvider.createInstance(motion, content).then(function (contentProvider) {
|
MotionPartialContentProvider.createInstance(motion, content).then(function (contentProvider) {
|
||||||
PdfMakeDocumentProvider.createInstance(contentProvider).then(function (documentProvider) {
|
PdfMakeDocumentProvider.createInstance(contentProvider).then(function (documentProvider) {
|
||||||
PdfCreate.download(documentProvider, filename);
|
PdfCreate.download(documentProvider, filename);
|
||||||
|
}, function (error) {
|
||||||
|
Messaging.addMessage(error.msg, 'error');
|
||||||
});
|
});
|
||||||
|
}, function (error) {
|
||||||
|
Messaging.addMessage(error.msg, 'error');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
exportComment: function (motion, commentId, filename) {
|
exportComment: function (motion, commentId, filename) {
|
||||||
@ -1134,7 +1147,11 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
MotionPartialContentProvider.createInstance(motion, content).then(function (contentProvider) {
|
MotionPartialContentProvider.createInstance(motion, content).then(function (contentProvider) {
|
||||||
PdfMakeDocumentProvider.createInstance(contentProvider).then(function (documentProvider) {
|
PdfMakeDocumentProvider.createInstance(contentProvider).then(function (documentProvider) {
|
||||||
PdfCreate.download(documentProvider, filename);
|
PdfCreate.download(documentProvider, filename);
|
||||||
|
}, function (error) {
|
||||||
|
Messaging.addMessage(error.msg, 'error');
|
||||||
});
|
});
|
||||||
|
}, function (error) {
|
||||||
|
Messaging.addMessage(error.msg, 'error');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -294,7 +294,9 @@ angular.module('OpenSlidesApp.users.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
'UserAccessDataListContentProvider',
|
'UserAccessDataListContentProvider',
|
||||||
'PdfMakeDocumentProvider',
|
'PdfMakeDocumentProvider',
|
||||||
'PdfCreate',
|
'PdfCreate',
|
||||||
function (gettextCatalog, UserListContentProvider, UserAccessDataListContentProvider, PdfMakeDocumentProvider, PdfCreate) {
|
'Messaging',
|
||||||
|
function (gettextCatalog, UserListContentProvider, UserAccessDataListContentProvider,
|
||||||
|
PdfMakeDocumentProvider, PdfCreate, Messaging) {
|
||||||
return {
|
return {
|
||||||
exportUserList: function (users) {
|
exportUserList: function (users) {
|
||||||
var filename = gettextCatalog.getString('List of participants') + '.pdf';
|
var filename = gettextCatalog.getString('List of participants') + '.pdf';
|
||||||
@ -302,6 +304,8 @@ angular.module('OpenSlidesApp.users.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
PdfMakeDocumentProvider.createInstance(userListContentProvider).then(
|
PdfMakeDocumentProvider.createInstance(userListContentProvider).then(
|
||||||
function (documentProvider) {
|
function (documentProvider) {
|
||||||
PdfCreate.download(documentProvider, filename);
|
PdfCreate.download(documentProvider, filename);
|
||||||
|
}, function (error) {
|
||||||
|
Messaging.addMessage(error.msg, 'error');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -313,6 +317,8 @@ angular.module('OpenSlidesApp.users.pdf', ['OpenSlidesApp.core.pdf'])
|
|||||||
PdfMakeDocumentProvider.createInstance(userAccessDataListContentProvider, true).then(
|
PdfMakeDocumentProvider.createInstance(userAccessDataListContentProvider, true).then(
|
||||||
function (documentProvider) {
|
function (documentProvider) {
|
||||||
PdfCreate.download(documentProvider, filename, true);
|
PdfCreate.download(documentProvider, filename, true);
|
||||||
|
}, function (error) {
|
||||||
|
Messaging.addMessage(error.msg, 'error');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user