Skip to content
Snippets Groups Projects
Commit c42a5c1f authored by Ron Lucke's avatar Ron Lucke Committed by Elmar Ludwig
Browse files

fix #846

Closes #846
parent bbe96a3c
No related branches found
No related tags found
No related merge requests found
...@@ -232,7 +232,7 @@ export default { ...@@ -232,7 +232,7 @@ export default {
methods: { methods: {
...mapActions({ ...mapActions({
loadCoursewareStructure: 'loadCoursewareStructure', loadCoursewareStructure: 'courseware-structure/load',
createStructuralElement: 'createStructuralElement', createStructuralElement: 'createStructuralElement',
updateStructuralElement: 'updateStructuralElement', updateStructuralElement: 'updateStructuralElement',
deleteStructuralElement: 'deleteStructuralElement', deleteStructuralElement: 'deleteStructuralElement',
......
...@@ -27,7 +27,13 @@ export default { ...@@ -27,7 +27,13 @@ export default {
}, },
methods: { methods: {
initData() {
this.exportFiles = { json: [], download: [] };
this.elementCounter = 0;
this.exportElementCounter = 0;
},
async sendExportZip(root_id = null, options) { async sendExportZip(root_id = null, options) {
this.initData();
let view = this; let view = this;
let zip = await this.createExportFile(root_id, options); let zip = await this.createExportFile(root_id, options);
this.setExportState(this.$gettext('Erstelle Zip-Archiv')); this.setExportState(this.$gettext('Erstelle Zip-Archiv'));
...@@ -123,6 +129,7 @@ export default { ...@@ -123,6 +129,7 @@ export default {
root_element.children = children; root_element.children = children;
} }
} }
root_element.imageId = await this.exportStructuralElementImage(root_element);
delete root_element.relationships; delete root_element.relationships;
delete root_element.links; delete root_element.links;
...@@ -211,6 +218,9 @@ export default { ...@@ -211,6 +218,9 @@ export default {
} }
} }
// export file data (if any)
content.imageId = await this.exportStructuralElementImage(element);
delete content.relationships; delete content.relationships;
content.children = new_childs; content.children = new_childs;
...@@ -221,6 +231,28 @@ export default { ...@@ -221,6 +231,28 @@ export default {
return children; return children;
}, },
async exportStructuralElementImage(element) {
let fileId = element.relationships.image?.data?.id;
if (fileId) {
await this.$store.dispatch('file-refs/loadById', {id: fileId});
let fileRef = this.$store.getters['file-refs/byId']({id: fileId});
let fileRefData = {};
fileRefData.id = fileRef.id;
fileRefData.attributes = fileRef.attributes;
fileRefData.related_element_id = element.id;
fileRefData.folder = null;
this.exportFiles.json.push(fileRefData);
this.exportFiles.download[fileRef.id] = {
folder: null,
url: fileRef.meta['download-url']
};
}
return fileId;
},
async exportContainer(container_ref) { async exportContainer(container_ref) {
// make a local copy of the container // make a local copy of the container
let container = { ...container_ref }; let container = { ...container_ref };
......
...@@ -63,7 +63,7 @@ export default { ...@@ -63,7 +63,7 @@ export default {
async importStructuralElement(element, parent_id, files) { async importStructuralElement(element, parent_id, files) {
if (element.length) { if (element.length) {
for (var i = 0; i < element.length; i++) { for (var i = 0; i < element.length; i++) {
this.setImportStructuresState('Lege Seite an: ' + element[i].attributes.title); this.setImportStructuresState(this.$gettext('Lege Seite an:') + ' ' + element[i].attributes.title);
await this.createStructuralElement({ await this.createStructuralElement({
attributes: element[i].attributes, attributes: element[i].attributes,
parentId: parent_id, parentId: parent_id,
...@@ -72,6 +72,23 @@ export default { ...@@ -72,6 +72,23 @@ export default {
this.importElementCounter++; this.importElementCounter++;
let new_element = this.$store.getters['courseware-structural-elements/lastCreated']; let new_element = this.$store.getters['courseware-structural-elements/lastCreated'];
if (element[i].imageId) {
let imageFile = files.find((file) => { return file.id === element[i].imageId});
let zip_filedata = await this.zip.file(imageFile.id).async('blob');
// create new blob with correct type
let filedata = zip_filedata.slice(0, zip_filedata.size, imageFile.attributes['mime-type']);
this.setImportStructuresState(this.$gettext('Lade Vorschaubild hoch'));
this.uploadImageForStructuralElement({
structuralElement: new_element,
file: filedata,
}).catch((error) => {
console.error(error);
this.currentImportErrors.push(this.$gettext('Fehler beim Hochladen des Vorschaubildes.'));
});
}
if (element[i].children?.length > 0) { if (element[i].children?.length > 0) {
await this.importStructuralElement(element[i].children, new_element.id, files); await this.importStructuralElement(element[i].children, new_element.id, files);
} }
...@@ -80,7 +97,7 @@ export default { ...@@ -80,7 +97,7 @@ export default {
for (var j = 0; j < element[i].containers.length; j++) { for (var j = 0; j < element[i].containers.length; j++) {
let container = element[i].containers[j]; let container = element[i].containers[j];
// TODO: create element on server and fetch new id // TODO: create element on server and fetch new id
this.setImportStructuresState('Lege Abschnitt an: ' + container.attributes.title); this.setImportStructuresState(this.$gettext('Lege Abschnitt an:') + ' ' + container.attributes.title);
await this.createContainer({ await this.createContainer({
attributes: container.attributes, attributes: container.attributes,
structuralElementId: new_element.id, structuralElementId: new_element.id,
...@@ -108,7 +125,7 @@ export default { ...@@ -108,7 +125,7 @@ export default {
}, },
async importBlock(block, block_container, files) { async importBlock(block, block_container, files) {
this.setImportStructuresState('Lege neuen Block an: ' + block.attributes.title); this.setImportStructuresState(this.$gettext('Lege neuen Block an:') + ' ' + block.attributes.title);
try { try {
await this.createBlockInContainer({ await this.createBlockInContainer({
container: {type: block_container.type, id: block_container.id}, container: {type: block_container.type, id: block_container.id},
...@@ -135,7 +152,7 @@ export default { ...@@ -135,7 +152,7 @@ export default {
block.attributes.payload = JSON.parse(payload); block.attributes.payload = JSON.parse(payload);
} }
} }
this.setImportStructuresState('Aktualisiere neuen Block: ' + block.attributes.title); this.setImportStructuresState(this.$gettext('Aktualisiere neuen Block:') + ' ' + block.attributes.title);
await this.updateBlockInContainer({ await this.updateBlockInContainer({
attributes: block.attributes, attributes: block.attributes,
blockId: new_block.id, blockId: new_block.id,
...@@ -168,7 +185,7 @@ export default { ...@@ -168,7 +185,7 @@ export default {
this.setImportFilesProgress(0); this.setImportFilesProgress(0);
this.setImportFilesState(''); this.setImportFilesState('');
let now = new Date(); let now = new Date();
this.setImportFilesState('Lege Import Ordner an...'); this.setImportFilesState(this.$gettext('Lege Import Ordner an...'));
let main_folder = await this.createRootFolder({ let main_folder = await this.createRootFolder({
context: this.context, context: this.context,
folder: { folder: {
...@@ -185,6 +202,9 @@ export default { ...@@ -185,6 +202,9 @@ export default {
if (main_folder) { if (main_folder) {
for (var i = 0; i < files.length; i++) { for (var i = 0; i < files.length; i++) {
// if the subfolder with the referenced id does not exist yet, create it // if the subfolder with the referenced id does not exist yet, create it
if (!files[i].folder) {
continue;
}
if (!folders[files[i].folder.id]) { if (!folders[files[i].folder.id]) {
this.setImportFilesState(this.$gettext('Lege Ordner an') + ': ' + files[i].folder.name); this.setImportFilesState(this.$gettext('Lege Ordner an') + ': ' + files[i].folder.name);
folders[files[i].folder.id] = await this.createFolder({ folders[files[i].folder.id] = await this.createFolder({
...@@ -249,6 +269,7 @@ export default { ...@@ -249,6 +269,7 @@ export default {
'setImportStructuresState', 'setImportStructuresState',
'setImportStructuresProgress', 'setImportStructuresProgress',
'setImportErrors', 'setImportErrors',
'uploadImageForStructuralElement'
]), ]),
}, },
watch: { watch: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment