aboutsummaryrefslogtreecommitdiff
path: root/resources
diff options
context:
space:
mode:
authortgloeggl <tgloeggl@uos.de>2022-01-13 14:38:39 +0100
committertgloeggl <tgloeggl@uos.de>2022-07-28 13:59:21 +0200
commitda3db0c846bd2c3498a487727ddb11b37324824f (patch)
tree4b0b13adb6a1f55716372b75887e139d7f94df85 /resources
parent7d087fcdf3218f8101e592b78f948479b3d02fe2 (diff)
working on creating plugin-api for im- and exportticket-334
fix bug fix passing of custom file to block fix custom-file creation on client side working on crud custom file api for courseware blocks create correct link for custom file add read part of CRUD add delete part of CRUD change behaviour of add a new file, contents are passed via separate route update custom-file content add route to patch metadata of custom-file changes to export for reference fix jsonapi for custom-files export custom-files correctly import custom files remove custom files from file-refs revert changes to block remove obsolte use statement in Block revert changes to BlockType and Download-Block remove obsolete implements from DownloadBlock add doku, fix exporting of blocks without custom-files remove debugging messages and now obsolete code cleaning up rework custom file check fix error and remove call to mime-type for custom files rename interface methods do not assign variables in function calls
Diffstat (limited to 'resources')
-rw-r--r--resources/vue/mixins/courseware/export.js30
-rw-r--r--resources/vue/mixins/courseware/import.js51
-rw-r--r--resources/vue/store/courseware/courseware.module.js36
3 files changed, 114 insertions, 3 deletions
diff --git a/resources/vue/mixins/courseware/export.js b/resources/vue/mixins/courseware/export.js
index f15c314..d4f6bd0 100644
--- a/resources/vue/mixins/courseware/export.js
+++ b/resources/vue/mixins/courseware/export.js
@@ -286,6 +286,7 @@ export default {
// export file data (if any)
if (block_ref.relationships['file-refs']?.links?.related) {
await this.exportFileRefs(block_ref.id);
+ await this.exportCustomFiles(block_ref.id);
}
delete block.relationships;
@@ -293,6 +294,34 @@ export default {
return block;
},
+ async exportCustomFiles(block_id) {
+ // load export data
+ let refs = []
+ try {
+ refs = await this.loadCustomFiles(block_id);
+ } catch(e) {
+ //TODO: Companion explains error
+ }
+
+ for (let ref_id in refs) {
+ console.log('custom-file-ref', refs[ref_id]);
+
+ let attributes = refs[ref_id].attributes;
+ delete attributes.content;
+
+ this.exportFiles.json.push({
+ 'id' : refs[ref_id].id,
+ 'attributes' : refs[ref_id].attributes,
+ 'related_block_id' : block_id,
+ 'type' : 'custom-file'
+ });
+
+ this.exportFiles.download[refs[ref_id].id] = {
+ url: refs[ref_id].meta['download-url']
+ };
+ }
+ },
+
async exportFileRefs(block_id) {
// load file-ref data
let refs = []
@@ -345,6 +374,7 @@ export default {
...mapActions([
'loadStructuralElement',
'loadFileRefs',
+ 'loadCustomFiles',
'loadFolder',
'companionInfo',
'setExportState',
diff --git a/resources/vue/mixins/courseware/import.js b/resources/vue/mixins/courseware/import.js
index 100a0e5..3a79108 100644
--- a/resources/vue/mixins/courseware/import.js
+++ b/resources/vue/mixins/courseware/import.js
@@ -9,6 +9,7 @@ export default {
elementCounter: 0,
importElementCounter: 0,
currentImportErrors: [],
+ customFiles: []
};
},
@@ -246,7 +247,7 @@ export default {
// update old id ids in payload part
for (var i = 0; i < files.length; i++) {
- if (files[i].related_block_id === block.id) {
+ if (files[i].related_block_id === block.id && files[i].type === undefined) {
let old_file = this.file_mapping[files[i].id].old;
let new_file = this.file_mapping[files[i].id].new;
let payload = JSON.stringify(block.attributes.payload);
@@ -274,6 +275,24 @@ export default {
}
+ this.setImportFilesProgress(0);
+ this.setImportFilesState('');
+
+ for (var i = 0; i < this.customFiles.length; i++) {
+ if (this.customFiles[i].related_block_id == block.id) {
+ await this.createCustomFile({
+ file: this.customFiles[i],
+ block_id: new_block.id
+ });
+ }
+
+ this.setImportFilesState(this.$gettext('Erzeuge Datei'));
+ this.setImportFilesProgress(parseInt(i / this.customFiles.length * 100));
+ }
+
+ this.setImportFilesProgress(100);
+ this.setImportFilesState('');
+
return new_block;
},
@@ -333,11 +352,14 @@ export default {
// upload all files to the newly created folder
if (main_folder) {
for (var i = 0; i < files.length; i++) {
+ let custom = files[i].type === 'custom-file';
+
// 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 (!custom && !folders[files[i].folder.id]) {
this.setImportFilesState(this.$gettext('Lege Ordner an') + ': ' + files[i].folder.name);
folders[files[i].folder.id] = await this.createFolder({
context: this.context,
@@ -355,7 +377,29 @@ export default {
}
// only upload files with the same id once
- if (this.file_mapping[files[i].id] === undefined) {
+ if (custom) {
+ let zip_filedata = await this.zip.file(files[i].id).async('blob');
+
+ // create new blob with correct type
+ let filedata = zip_filedata.slice(0, zip_filedata.size);
+
+ this.setImportFilesState(this.$gettext('Erzeuge Datei'));
+
+
+ let file = await this.createCustomFile({
+ 'file': files[i],
+ 'filedata' : filedata,
+ 'block_id' : files[i].attributes['block_id']
+ });
+
+ //file mapping
+ this.file_mapping[files[i].id] = {
+ old: files[i],
+ new: file
+ };
+
+ this.setImportFilesProgress(parseInt(i / files.length * 100));
+ } else if (this.file_mapping[files[i].id] === undefined) {
let zip_filedata = await this.zip.file(files[i].id).async('blob');
// create new blob with correct type
@@ -394,6 +438,7 @@ export default {
'createFolder',
'createRootFolder',
'createFile',
+ 'createCustomFile',
'lockObject',
'unlockObject',
'setImportFilesState',
diff --git a/resources/vue/store/courseware/courseware.module.js b/resources/vue/store/courseware/courseware.module.js
index 49ac520..59a94a7 100644
--- a/resources/vue/store/courseware/courseware.module.js
+++ b/resources/vue/store/courseware/courseware.module.js
@@ -305,6 +305,42 @@ export const actions = {
});
},
+ async createCustomFile(context, { file, filedata, block_id }) {
+ // create custom file for block
+ let url = `courseware-blocks/${block_id}/custom-files`;
+ let newFile = await state.httpClient.post(url, file).
+ then(({data }) => {
+ return data.data;
+ });
+
+ // set file data with separate call
+ let formData = new FormData();
+ formData.append('file', filedata, newFile.id);
+
+ url = `courseware-blocks/${block_id}/custom-files/${newFile.id}`;
+
+ await state.httpClient.post(url, formData, {
+ headers: {
+ 'Content-Type': 'multipart/form-data',
+ },
+ });
+
+ return newFile;
+ },
+
+ async loadCustomFiles(context, block_id) {
+ const parent = {
+ type: 'courseware-blocks',
+ id: block_id,
+ };
+
+ const url = `courseware-blocks/${block_id}/custom-files`
+ return state.httpClient.get(url)
+ .then(({ data }) => {
+ return data.data;
+ });
+ },
+
async createRootFolder({ dispatch, rootGetters }, { context, folder }) {
// get root folder for this context
await dispatch(