From b5ddb10998e869716086feb3a233edb8f81a7b0f Mon Sep 17 00:00:00 2001 From: Ron Lucke <lucke@elan-ev.de> Date: Wed, 20 Oct 2021 09:45:31 +0000 Subject: [PATCH] fixes #342 --- .../courseware/CoursewareDefaultBlock.vue | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/resources/vue/components/courseware/CoursewareDefaultBlock.vue b/resources/vue/components/courseware/CoursewareDefaultBlock.vue index 486d6219f34..84b5588a1ff 100755 --- a/resources/vue/components/courseware/CoursewareDefaultBlock.vue +++ b/resources/vue/components/courseware/CoursewareDefaultBlock.vue @@ -135,6 +135,7 @@ export default { userId: 'userId', viewMode: 'viewMode', getComments: 'courseware-block-comments/related', + containerById: 'courseware-containers/byId', }), showEditMode() { let show = this.viewMode === 'edit' || this.blockedByThisUser; @@ -179,6 +180,7 @@ export default { unlockObject: 'unlockObject', loadComments: 'courseware-block-comments/loadRelated', loadContainer: 'loadContainer', + updateContainer: 'updateContainer', }), async displayFeature(element) { if (this.showEdit && element === 'Edit') { @@ -252,11 +254,36 @@ export default { } }, async executeDelete() { - await this.deleteBlock({ + const containerId = this.block.relationships.container.data.id; + await this.loadContainer(containerId); + let container = this.containerById({id: containerId}); + const structuralElementId = container.relationships['structural-element'].data.id; + let containerBlocks = container.relationships.blocks.data.map(block => { + return block.id; + }); + let sections = container.attributes.payload.sections; + + // lock parent container + await this.lockObject({ id: containerId, type: 'courseware-containers' }); + // update container information + for (let i = 0; i < sections.length; i++) { + for (let j = 0; j < sections[i].blocks.length; j++) { + let blockId = sections[i].blocks[j]; + if (!containerBlocks.includes(blockId) || blockId === this.block.id) { + sections[i].blocks.splice(j, 1); + j--; + } + } + } + // update container + await this.updateContainer({ container, structuralElementId }); + // unlock container + await this.unlockObject({ id: containerId, type: 'courseware-containers' }); + await this.loadContainer(containerId); + this.deleteBlock({ blockId: this.block.id, - containerId: this.block.relationships.container.data.id, + containerId: containerId, }); - // this.showDeleteDialog = false; }, async loadComments() { -- GitLab