diff --git a/resources/vue/components/courseware/CoursewareActionWidget.vue b/resources/vue/components/courseware/CoursewareActionWidget.vue index f2a443631c9ce38fede623b3cd801b7dccea09c2..ca1859c9ff2aa8bd666e0edca650f6664edd0948 100644 --- a/resources/vue/components/courseware/CoursewareActionWidget.vue +++ b/resources/vue/components/courseware/CoursewareActionWidget.vue @@ -36,6 +36,7 @@ export default { ...mapGetters({ oerEnabled: 'oerEnabled', oerTitle: 'oerTitle', + userId: 'userId', }), isRoot() { if (!this.structuralElement) { @@ -53,6 +54,18 @@ export default { currentId() { return this.structuralElement?.id; }, + blocked() { + return this.structuralElement?.relationships['edit-blocker'].data !== null; + }, + blockerId() { + return this.blocked ? this.structuralElement?.relationships['edit-blocker'].data?.id : null; + }, + blockedByThisUser() { + return this.blocked && this.userId === this.blockerId; + }, + blockedByAnotherUser() { + return this.blocked && this.userId !== this.blockerId; + }, }, methods: { ...mapActions({ @@ -67,7 +80,22 @@ export default { lockObject: 'lockObject', }), async editElement() { - await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' }); + if (this.blockedByAnotherUser) { + this.companionInfo({ info: this.$gettext('Diese Seite wird bereits bearbeitet.') }); + + return false; + } + try { + await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' }); + } catch(error) { + if (error.status === 409) { + this.companionInfo({ info: this.$gettext('Diese Seite wird bereits bearbeitet.') }); + } else { + console.log(error); + } + + return false; + } this.showElementEditDialog(true); }, async deleteElement() { diff --git a/resources/vue/components/courseware/CoursewareDefaultBlock.vue b/resources/vue/components/courseware/CoursewareDefaultBlock.vue index 341168784ddaebdd06f95a68c443f8eb09121c4c..486d6219f348486a79762ea5dc631cdf52b8dfc8 100755 --- a/resources/vue/components/courseware/CoursewareDefaultBlock.vue +++ b/resources/vue/components/courseware/CoursewareDefaultBlock.vue @@ -150,10 +150,10 @@ export default { return this.blocked ? this.block?.relationships['edit-blocker'].data?.id : null; }, blockedByThisUser() { - return this.userId === this.blockerId; + return this.blocked && this.userId === this.blockerId; }, blockedByAnotherUser() { - return this.userId !== this.blockerId; + return this.blocked && this.userId !== this.blockerId; }, blockTitle() { const type = this.block.attributes['block-type']; @@ -181,6 +181,9 @@ export default { loadContainer: 'loadContainer', }), async displayFeature(element) { + if (this.showEdit && element === 'Edit') { + return false; + } this.showFeatures = false; this.showFeedback = false; this.showComments = false; @@ -190,8 +193,20 @@ export default { this.showContent = true; if (element) { if (element === 'Edit') { + await this.loadContainer(this.block.relationships.container.data.id); if (!this.blocked) { - await this.lockObject({ id: this.block.id, type: 'courseware-blocks' }); + try { + await this.lockObject({ id: this.block.id, type: 'courseware-blocks' }); + } catch(error) { + if (error.status === 403) { + this.companionInfo({ info: this.$gettext('Dieser Block wird bereits bearbeitet.') }); + } else { + console.log(error); + } + + return false; + } + if (!this.preview) { this.showContent = false; } diff --git a/resources/vue/components/courseware/CoursewareDefaultContainer.vue b/resources/vue/components/courseware/CoursewareDefaultContainer.vue index a1d41c3e35598d08ad54dcc50004d20cc1c65ecd..53acc421c2cdddcc38581dab266d4bd59f910639 100755 --- a/resources/vue/components/courseware/CoursewareDefaultContainer.vue +++ b/resources/vue/components/courseware/CoursewareDefaultContainer.vue @@ -50,7 +50,7 @@ <script> import CoursewareContainerActions from './CoursewareContainerActions.vue'; import StudipDialog from '../StudipDialog.vue'; -import { mapActions } from 'vuex'; +import { mapGetters, mapActions } from 'vuex'; export default { name: 'courseware-default-container', @@ -76,12 +76,27 @@ export default { }; }, computed: { + ...mapGetters({ + userId: 'userId', + }), showEditMode() { return this.$store.getters.viewMode === 'edit'; }, colSpan() { return this.container.attributes.payload.colspan ? this.container.attributes.payload.colspan : 'full'; }, + blocked() { + return this.container?.relationships['edit-blocker'].data !== null; + }, + blockerId() { + return this.blocked ? this.container?.relationships['edit-blocker'].data?.id : null; + }, + blockedByThisUser() { + return this.blocked && this.userId === this.blockerId; + }, + blockedByAnotherUser() { + return this.blocked && this.userId !== this.blockerId; + }, }, methods: { ...mapActions({ @@ -90,7 +105,23 @@ export default { unlockObject: 'unlockObject', }), async displayEditDialog() { - await this.lockObject({ id: this.container.id, type: 'courseware-containers' }); + if (this.blockedByAnotherUser) { + this.companionInfo({ info: this.$gettext('Dieser Abschnitt wird bereits bearbeitet.') }); + + return false; + } + try { + await this.lockObject({ id: this.container.id, type: 'courseware-containers' }); + } catch(error) { + if (error.status === 409) { + this.companionInfo({ info: this.$gettext('Dieser Abschnitt wird bereits bearbeitet.') }); + } else { + console.log(error); + } + + return false; + } + this.showEditDialog = true; }, async closeEdit() { diff --git a/resources/vue/components/courseware/CoursewareStructuralElement.vue b/resources/vue/components/courseware/CoursewareStructuralElement.vue index 564bff692c211ad4156a3fded3335945b72672e9..d52358a001c7ed8f36b7374227a61e354cf97008 100755 --- a/resources/vue/components/courseware/CoursewareStructuralElement.vue +++ b/resources/vue/components/courseware/CoursewareStructuralElement.vue @@ -555,6 +555,7 @@ export default { licenses: 'licenses', exportState: 'exportState', exportProgress: 'exportProgress', + userId: 'userId', }), currentId() { @@ -907,6 +908,18 @@ export default { return ''; }, + blocked() { + return this.structuralElement?.relationships['edit-blocker'].data !== null; + }, + blockerId() { + return this.blocked ? this.structuralElement?.relationships['edit-blocker'].data?.id : null; + }, + blockedByThisUser() { + return this.blocked && this.userId === this.blockerId; + }, + blockedByAnotherUser() { + return this.blocked && this.userId !== this.blockerId; + }, }, methods: { @@ -936,7 +949,22 @@ export default { async menuAction(action) { switch (action) { case 'editCurrentElement': - await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' }); + if (this.blockedByAnotherUser) { + this.companionInfo({ info: this.$gettext('Diese Seite wird bereits bearbeitet.') }); + + return false; + } + try { + await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' }); + } catch(error) { + if (error.status === 409) { + this.companionInfo({ info: this.$gettext('Diese Seite wird bereits bearbeitet.') }); + } else { + console.log(error); + } + + return false; + } this.showElementEditDialog(true); break; case 'addElement':