diff --git a/resources/vue/components/courseware/structural-element/CoursewareStructuralElementDialogImport.vue b/resources/vue/components/courseware/structural-element/CoursewareStructuralElementDialogImport.vue index 60b404ef4613be090e15045dfa897ff140a69b2a..019bbf2b98efc26b15cb255ea70a9da324042055 100644 --- a/resources/vue/components/courseware/structural-element/CoursewareStructuralElementDialogImport.vue +++ b/resources/vue/components/courseware/structural-element/CoursewareStructuralElementDialogImport.vue @@ -130,7 +130,6 @@ export default { this.importZipFile = event.target.files[0]; this.setImportFilesProgress(0); this.setImportStructuresProgress(0); - this.setImportErrors([]); }, async importCoursewareArchiv() { this.importAborted = false; @@ -199,6 +198,9 @@ export default { await this.importCourseware(courseware, this.currentElement, files, this.importBehavior, null); } + }, + mounted() { + this.setImportErrors([]); } } </script> diff --git a/resources/vue/mixins/courseware/import.js b/resources/vue/mixins/courseware/import.js index a7c94201dffac5804b61d6711c8948f42f7a45c4..547280f2b35cc6e965876da603489fd5c9c81a17 100644 --- a/resources/vue/mixins/courseware/import.js +++ b/resources/vue/mixins/courseware/import.js @@ -53,7 +53,6 @@ export default { this.elementCounter = await this.countImportElements([element]); this.setImportStructuresState(''); this.importElementCounter = 0; - this.setImportErrors([]); if (importBehavior === 'default') { await this.importStructuralElement([element], rootId, files); @@ -286,8 +285,14 @@ export default { let new_file = this.file_mapping[files[i].id].new; let payload = JSON.stringify(block.attributes.payload); - payload = payload.replaceAll(old_file.id, new_file.id); - payload = payload.replaceAll(old_file.folder.id, new_file.relationships.parent.data.id); + if (new_file) { + payload = payload.replaceAll(old_file.id, new_file.id); + payload = payload.replaceAll(old_file.folder.id, new_file.relationships.parent.data.id); + } else { + payload = payload.replaceAll(old_file.id, ''); + payload = payload.replaceAll(old_file.folder.id, ''); + } + block.attributes.payload = JSON.parse(payload); } @@ -395,13 +400,20 @@ export default { // create new blob with correct type let filedata = zip_filedata.slice(0, zip_filedata.size, files[i].attributes['mime-type']); - - let file = await this.createFile({ - file: files[i], - filedata: filedata, - folder: folders[files[i].folder.id] - }); - this.setImportFilesState(this.$gettext('Erzeuge Datei') + ': ' + files[i].attributes.name); + let file = null; + try { + file = await this.createFile({ + file: files[i], + filedata: filedata, + folder: folders[files[i].folder.id] + }); + } catch (error) { + this.currentImportErrors.push(this.$gettext('Import einer Datei fehlgeschlagen.')); + this.setImportFilesState(this.$gettext('Fehler beim Anlegen der Datei')); + } + if (file !== null) { + this.setImportFilesState(this.$gettext('Erzeuge Datei') + ': ' + files[i].attributes.name); + } this.setImportFilesProgress(parseInt(i / files.length * 100)); //file mapping