Newer
Older
<template>
<div class="cw-block-actions">
@editBlock="editBlock"
@setVisibility="setVisibility"
@showInfo="showInfo"
@deleteBlock="deleteBlock"
@deactivateComments="deactivateComments"
@activateComments="activateComments"
@showFeedback="showFeedback"
/>
</div>
</template>
<script>
import StudipActionMenu from '../../StudipActionMenu.vue';
import { mapActions, mapGetters } from 'vuex';
export default {
name: 'courseware-block-actions',
components: {
StudipActionMenu,
},
props: {
canEdit: Boolean,
block: Object,
},
computed: {
...mapGetters({
userId: 'userId',
return this.blocked ? this.block?.relationships?.['edit-blocker']?.data?.id : null;
blockedByThisUser() {
return this.blocked && this.userId === this.blockerId;
},
blockedByAnotherUser() {
return this.blocked && this.userId !== this.blockerId;
},
hasFeedback() {
const { id, type } = this.block;
const feedback = this.getRelatedFeedback({ parent: { id, type }, relationship: 'feedback' });
if (feedback === null || feedback.length === 0) {
return false;
}
return true;
},
menuItems() {
let menuItems = [];
if (this.canEdit) {
if (!this.deleteOnly) {
if (!this.blocked) {
menuItems.push({ id: 1, label: this.$gettext('Block bearbeiten'), icon: 'edit', emit: 'editBlock' });
menuItems.push({
label: this.block.attributes.visible
? this.$gettext('unsichtbar setzen')
: this.$gettext('sichtbar setzen'),
icon: this.block.attributes.visible ? 'visibility-visible' : 'visibility-invisible', // do we change the icons ?
emit: 'setVisibility',
});
if (this.userIsTeacher) {
menuItems.push({
id: 4,
label: this.block.attributes.commentable
? this.$gettext('Kommentare abschalten')
: this.$gettext('Kommentare aktivieren'),
icon: 'comment2',
emit: this.block.attributes.commentable ? 'deactivateComments' : 'activateComments',
});
}
}
if (this.blocked && this.blockedByAnotherUser && this.userIsTeacher) {
menuItems.push({
id: 8,
label: this.$gettext('Sperre aufheben'),
icon: 'lock-unlocked',
emit: 'removeLock',
});
}
if (!this.blocked || this.blockedByThisUser) {
menuItems.push({
id: 9,
label: this.$gettext('Block löschen'),
icon: 'trash',
emit: 'deleteBlock'
});
}
menuItems.push({
id: 2,
label: this.$gettext('Block merken'),
icon: 'clipboard',
emit: 'copyToClipboard'
});
menuItems.push({
id: 7,
label: this.$gettext('Informationen zum Block'),
icon: 'info',
emit: 'showInfo',
});
}
menuItems.sort((a, b) => {
return a.id > b.id ? 1 : b.id > a.id ? -1 : 0;
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
},
methods: {
...mapActions({
updateBlock: 'updateBlockInContainer',
lockObject: 'lockObject',
unlockObject: 'unlockObject',
}),
menuAction(action) {
this[action]();
},
editBlock() {
this.$emit('editBlock');
},
showInfo() {
this.$emit('showInfo');
},
showExportOptions() {
this.$emit('showExportOptions');
},
async setVisibility() {
if (!this.blocked) {
await this.lockObject({ id: this.block.id, type: 'courseware-blocks' });
} else {
if (this.blockerId !== this.userId) {
return false;
}
}
let attributes = {};
attributes.visible = !this.block.attributes.visible;
await this.updateBlock({
attributes: attributes,
blockId: this.block.id,
containerId: this.block.relationships.container.data.id,
});
await this.unlockObject({ id: this.block.id, type: 'courseware-blocks' });
},
deleteBlock() {
this.$emit('deleteBlock');
},
},
copyToClipboard() {
this.$emit('copyToClipboard');
},
activateComments() {
this.$emit('activateComments')
},
deactivateComments() {
this.$emit('deactivateComments')
},
showFeedback() {
this.$emit('showFeedback');