Skip to content
Snippets Groups Projects
CoursewareBlockActions.vue 6.28 KiB
Newer Older
<template>
    <div class="cw-block-actions">
Moritz Strohm's avatar
Moritz Strohm committed
        <studip-action-menu
            :items="menuItems"
Moritz Strohm's avatar
Moritz Strohm committed
            :context="block.attributes.title"
Ron Lucke's avatar
Ron Lucke committed
            :collapseAt="1"
            @editBlock="editBlock"
            @setVisibility="setVisibility"
            @showInfo="showInfo"
            @deleteBlock="deleteBlock"
Ron Lucke's avatar
Ron Lucke committed
            @removeLock="removeLock"
            @copyToClipboard="copyToClipboard"
Ron Lucke's avatar
Ron Lucke committed
            @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,
\nrlucke's avatar
\nrlucke committed
        deleteOnly: {
            type: Boolean,
            default: false
        },
        block: Object,
    },
    computed: {
        ...mapGetters({
            userId: 'userId',
Ron Lucke's avatar
Ron Lucke committed
            userIsTeacher: 'userIsTeacher',
Ron Lucke's avatar
Ron Lucke committed
            getRelatedFeedback: 'courseware-block-feedback/related',
Ron Lucke's avatar
Ron Lucke committed
            return this.block?.relationships?.['edit-blocker']?.data !== null;
Ron Lucke's avatar
Ron Lucke committed
            return this.blocked ? this.block?.relationships?.['edit-blocker']?.data?.id : null;
Ron Lucke's avatar
Ron Lucke committed
        },
Ron Lucke's avatar
Ron Lucke committed
        blockedByThisUser() {
            return this.blocked && this.userId === this.blockerId;
        },
        blockedByAnotherUser() {
            return this.blocked && this.userId !== this.blockerId;
        },
Ron Lucke's avatar
Ron Lucke committed
        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;
        },
Ron Lucke's avatar
Ron Lucke committed
        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({
                            id: 3,
Ron Lucke's avatar
Ron Lucke committed
                            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',
                        });
Ron Lucke's avatar
Ron Lucke committed
                        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',
                            });
                        }
Ron Lucke's avatar
Ron Lucke committed
                    }
                    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'
                    });
Ron Lucke's avatar
Ron Lucke committed
                    menuItems.push({
                        id: 7,
                        label: this.$gettext('Informationen zum Block'),
                        icon: 'info',
                        emit: 'showInfo',
                    });
                }
\nrlucke's avatar
\nrlucke committed
            }
Ron Lucke's avatar
Ron Lucke committed
            menuItems.sort((a, b) => {
                return a.id > b.id ? 1 : b.id > a.id ? -1 : 0;
Ron Lucke's avatar
Ron Lucke committed

            return menuItems;
Elmar Ludwig's avatar
Elmar Ludwig committed

    },
    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');
        },
Ron Lucke's avatar
Ron Lucke committed
        removeLock() {
            this.$emit('removeLock');
        },
        copyToClipboard() {
            this.$emit('copyToClipboard');
Ron Lucke's avatar
Ron Lucke committed
        },
        activateComments() {
            this.$emit('activateComments')
        },
        deactivateComments() {
            this.$emit('deactivateComments')
        },
        showFeedback() {
            this.$emit('showFeedback');
Ron Lucke's avatar
Ron Lucke committed
        }