aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/components/courseware/structural-element/CoursewareToolsUnits.vue
blob: 61778684f73e7c0dced45bbc4ea936b87843bb92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<template>
    <StudipProgressIndicator v-if="loadingUnits" :description="$gettext('Vorgang wird bearbeitet...')" />
    <ul v-else class="cw-ribbon-tools-units">
        <li v-for="unit in units" :key="unit.id">
            <CoursewareToolsUnitsItem :unit="unit" :element="getUnitElement(unit)" />
        </li>
        <li v-if="emptyUnits">
            <CoursewareCompanionBox mood="sad" :msgCompanion="emptyUnitsMessage" :border="false"/>
        </li>
    </ul>
</template>

<script>
import CoursewareToolsUnitsItem from './CoursewareToolsUnitsItem.vue';
import CoursewareCompanionBox from '../layouts/CoursewareCompanionBox.vue';
import StudipProgressIndicator from '../../StudipProgressIndicator.vue';
import { mapActions, mapGetters } from 'vuex';
export default {
    name: 'CoursewareToolsUnits',
    components: {
        CoursewareToolsUnitsItem,
        CoursewareCompanionBox,
        StudipProgressIndicator,
    },
    data() {
        return {
            loadingUnits: false,
        };
    },
    computed: {
        ...mapGetters({
            context: 'context',
            coursewareUnits: 'courseware-units/all',
            currentUnit: 'currentUnit',
            elementById: 'courseware-structural-elements/byId',
            userId: 'userId',
        }),
        units() {
            return (
                this.coursewareUnits
                    .filter(
                        (unit) =>
                            unit.relationships.range.data.id === this.context.id
                    )
                    .sort((a, b) => a.attributes.position - b.attributes.position) ?? []
            );
        },
        inCourseContext() {
            return  this.context.type === 'courses';
        },
        inUserContext() {
            return this.context.type === 'users';
        },
        emptyUnits() {
            return this.units.length === 0;
        },
        emptyUnitsMessage() {
            if (this.inCourseContext) {
                return this.$gettext('Es wurden keine weiteren Lernmaterialien in dieser Veranstaltung gefunden.');
            }
            if (this.inUserContext) {
                return this.$gettext('Es wurden keine weiteren Lernmaterialien gefunden.');
            }

            return '';
        }
    },
    methods: {
        ...mapActions({
            loadCourseUnits: 'loadCourseUnits',
            loadUserUnits: 'loadUserUnits',
        }),
        getUnitElement(unit) {
            const elementId = unit.relationships['structural-element'].data.id;
            return this.elementById({ id: elementId });
        },
    },
    async beforeMount() {
        if (this.coursewareUnits.length === 0) {
            this.loadingUnits = true;
        }

        if (this.inCourseContext) {
            await this.loadCourseUnits(this.context.id);
        }
        if (this.inUserContext) {
            await this.loadUserUnits(this.userId);
        }

        this.loadingUnits = false;
    },
};
</script>
<style lang="scss">
.cw-ribbon-tools-units {
    list-style: none;
    padding: 0;

    li {
        margin-bottom: 2em;
    }
}
</style>