Skip to content
Snippets Groups Projects
Commit f3046f9a authored by Ron Lucke's avatar Ron Lucke Committed by Marcus Eibrink-Lunzenauer
Browse files

evaluate image type of structural element on import and export

Closes #3743

Merge request studip/studip!3175
parent 3271f73e
No related branches found
No related tags found
No related merge requests found
...@@ -134,7 +134,7 @@ export default { ...@@ -134,7 +134,7 @@ export default {
root_element.children = children; root_element.children = children;
} }
} }
root_element.imageId = await this.exportStructuralElementImage(root_element); [root_element.imageId, root_element.imageType ] = await this.exportStructuralElementImage(root_element);
delete root_element.relationships; delete root_element.relationships;
delete root_element.links; delete root_element.links;
...@@ -236,7 +236,7 @@ export default { ...@@ -236,7 +236,7 @@ export default {
} }
// export file data (if any) // export file data (if any)
content.imageId = await this.exportStructuralElementImage(element); [content.imageId, content.imageType ] = await this.exportStructuralElementImage(element);
delete content.relationships; delete content.relationships;
content.children = new_childs; content.children = new_childs;
...@@ -249,8 +249,11 @@ export default { ...@@ -249,8 +249,11 @@ export default {
}, },
async exportStructuralElementImage(element) { async exportStructuralElementImage(element) {
let fileId = element.relationships.image?.data?.id; const fileId = element.relationships.image?.data?.id;
const fileType = element.relationships.image?.data?.type;
if (fileId) { if (fileId) {
if (fileType === 'file-refs') {
await this.loadFileRefsById({id: fileId}); await this.loadFileRefsById({id: fileId});
let fileRef = this.fileRefsById({id: fileId}); let fileRef = this.fileRefsById({id: fileId});
...@@ -266,8 +269,9 @@ export default { ...@@ -266,8 +269,9 @@ export default {
url: fileRef.meta['download-url'] url: fileRef.meta['download-url']
}; };
} }
}
return fileId; return [fileId, fileType];
}, },
async exportContainer(container_ref) { async exportContainer(container_ref) {
......
...@@ -152,7 +152,7 @@ export default { ...@@ -152,7 +152,7 @@ export default {
} }
// compare image // compare image
if (element.imageId && root.relationships.image.data === null) { if (element.imageId && root.relationships.image.data === null) {
await this.setStructuralElementImage(root, element.imageId, files); await this.setStructuralElementImage(root, element, files);
} }
// add children // add children
...@@ -187,7 +187,7 @@ export default { ...@@ -187,7 +187,7 @@ export default {
if (element[i].imageId) { if (element[i].imageId) {
await this.setStructuralElementImage(new_element, element[i].imageId, files); await this.setStructuralElementImage(new_element, element[i], files);
} }
...@@ -205,11 +205,18 @@ export default { ...@@ -205,11 +205,18 @@ export default {
} }
}, },
async setStructuralElementImage(new_element, imageId, files) { async setStructuralElementImage(new_element, element, files) {
let imageFile = files.find((file) => { return file.id === imageId}); const imageId = element.imageId;
const imageType = element.imageType ?? 'file-refs';
if (imageType === 'file-refs') {
const imageFile = files.find((file) => { return file.id === imageId});
if (!(imageFile)) {
this.currentImportErrors.push(this.$gettext('Fehler beim Laden des Vorschaubildes.'));
return;
}
let zip_filedata = await this.zip.file(imageFile.id).async('blob'); let zip_filedata = await this.zip.file(imageFile.id).async('blob');
// create new blob with correct type // create new blob with correct type
let filedata = zip_filedata.slice(0, zip_filedata.size, imageFile.attributes['mime-type']); const filedata = zip_filedata.slice(0, zip_filedata.size, imageFile.attributes['mime-type']);
this.setImportStructuresState(this.$gettext('Lade Vorschaubild hoch')); this.setImportStructuresState(this.$gettext('Lade Vorschaubild hoch'));
this.uploadImageForStructuralElement({ this.uploadImageForStructuralElement({
structuralElement: new_element, structuralElement: new_element,
...@@ -218,6 +225,7 @@ export default { ...@@ -218,6 +225,7 @@ export default {
console.error(error); console.error(error);
this.currentImportErrors.push(this.$gettext('Fehler beim Hochladen des Vorschaubildes.')); this.currentImportErrors.push(this.$gettext('Fehler beim Hochladen des Vorschaubildes.'));
}); });
}
}, },
async importContainer(container, structuralElement, files) { async importContainer(container, structuralElement, files) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment