1
0
Fork 0
mirror of https://github.com/nextcloud/calendar.git synced 2024-10-07 16:40:09 +02:00

add better error handling for importing calendars (#745)

Signed-off-by: Georg Ehrke <developer@georgehrke.com>
This commit is contained in:
Georg Ehrke 2018-03-05 15:48:11 +01:00 committed by GitHub
parent 8e66356401
commit 29d75bdc83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 13 deletions

View file

@ -159,15 +159,9 @@ app.controller('ImportController', ['$scope', '$filter', 'CalendarService', 'VEv
$scope.closeIfNecessary = function() {
var unfinishedFiles = $scope.files.filter(function(fileWrapper) {
return !fileWrapper.wasCanceled() && !fileWrapper.isDone() && !fileWrapper.isEmpty();
});
var filesEncounteredErrors = $scope.files.filter(function(fileWrapper) {
return fileWrapper.isDone() && fileWrapper.hasErrors();
});
const emptyFiles = $scope.files.filter((fileWrapper) => {
return fileWrapper.isEmpty();
});
const unfinishedFiles = $scope.files.filter((file) => (!file.wasCanceled() && !file.isDone() && !file.isEmpty() && !file.hasParsingErrors()));
const filesEncounteredErrors = $scope.files.filter((file) => ((file.isDone() && file.hasErrors()) || file.hasParsingErrors()));
const emptyFiles = $scope.files.filter((file) => file.isEmpty());
if (unfinishedFiles.length === 0 && filesEncounteredErrors.length === 0 && emptyFiles.length === 0) {
$uibModalInstance.close();

View file

@ -113,15 +113,28 @@ app.factory('ImportFileWrapper', function(Hook, ICalSplitterUtility) {
return context.errors > 0;
};
iface.isEmpty = function() {
return context.progressToReach === 0;
};
iface.isEmpty = () => iface.state === ImportFileWrapper.stateEmpty;
iface.hasParsingErrors = () => iface.state === ImportFileWrapper.stateParsingError;
iface.read = function(afterReadCallback) {
var reader = new FileReader();
reader.onload = function(event) {
context.splittedICal = ICalSplitterUtility.split(event.target.result);
try {
context.splittedICal = ICalSplitterUtility.split(event.target.result);
} catch(e) {
context.splittedICal = {
vevents: [],
vjournals: [],
vtodos: []
};
context.progressToReach = 0;
iface.state = ImportFileWrapper.stateParsingError;
iface.emit(ImportFileWrapper.hookDone);
return;
}
context.progressToReach = context.splittedICal.vevents.length +
context.splittedICal.vjournals.length +
context.splittedICal.vtodos.length;
@ -150,6 +163,7 @@ app.factory('ImportFileWrapper', function(Hook, ICalSplitterUtility) {
return obj instanceof ImportFileWrapper || (typeof obj === 'object' && obj !== null && obj._isAImportFileWrapperObject !== null);
};
ImportFileWrapper.stateParsingError = -3;
ImportFileWrapper.stateEmpty = -2;
ImportFileWrapper.stateCanceled = -1;
ImportFileWrapper.stateAnalyzing = 0;

View file

@ -67,6 +67,10 @@
ng-show="file.isEmpty()">
<?php p($l->t('File is empty')); ?>
</span>
<span
ng-show="file.hasParsingErrors()">
<?php p($l->t('File could not be parsed')); ?>
</span>
<span
ng-show="file.isScheduled()">
<?php p($l->t('Import scheduled')); ?>

0
tests/data/emptyfile.ics Normal file
View file

10
tests/data/garbage.ics Normal file
View file

@ -0,0 +1,10 @@
asdfhlaksdfho;a
asdflgkasdfglsadg
asdfasdfgo;asdfasdfgo
adfiakhsbdf
asdfhilsadf