Skip to content
Snippets Groups Projects
Commit 844e628a authored by Marcus Eibrink-Lunzenauer's avatar Marcus Eibrink-Lunzenauer Committed by Ron Lucke
Browse files

Courseware: Strukturelemente nur einmal laden

parent 4dc38db1
No related branches found
No related tags found
No related merge requests found
<template> <template>
<ul class="widget-list widget-links cw-action-widget"> <ul class="widget-list widget-links cw-action-widget" v-if="structuralElement">
<li v-show="canEdit" class="cw-action-widget-edit" @click="editElement"><translate>Seite bearbeiten</translate></li> <li v-show="canEdit" class="cw-action-widget-edit" @click="editElement">
<li v-show="canEdit" class="cw-action-widget-add" @click="addElement"><translate>Seite hinzufügen</translate></li> <translate>Seite bearbeiten</translate>
</li>
<li v-show="canEdit" class="cw-action-widget-add" @click="addElement">
<translate>Seite hinzufügen</translate>
</li>
<li class="cw-action-widget-info" @click="showElementInfo"><translate>Informationen anzeigen</translate></li> <li class="cw-action-widget-info" @click="showElementInfo"><translate>Informationen anzeigen</translate></li>
<li class="cw-action-widget-star" @click="createBookmark"><translate>Lesezeichen setzen</translate></li> <li class="cw-action-widget-star" @click="createBookmark"><translate>Lesezeichen setzen</translate></li>
<li v-show="canEdit" @click="exportElement" class="cw-action-widget-export"><translate>Seite exportieren</translate></li> <li v-show="canEdit" @click="exportElement" class="cw-action-widget-export">
<li v-show="canEdit && oerEnabled" @click="oerElement" class="cw-action-widget-oer"><translate>Seite auf %{oerTitle} veröffentlichen</translate></li> <translate>Seite exportieren</translate>
<li v-show="!isRoot && canEdit" class="cw-action-widget-trash" @click="deleteElement"><translate>Seite löschen</translate></li> </li>
<li v-show="canEdit && oerEnabled" @click="oerElement" class="cw-action-widget-oer">
<translate>Seite auf %{oerTitle} veröffentlichen</translate>
</li>
<li v-show="!isRoot && canEdit" class="cw-action-widget-trash" @click="deleteElement">
<translate>Seite löschen</translate>
</li>
</ul> </ul>
</template> </template>
...@@ -17,29 +27,16 @@ import { mapActions, mapGetters } from 'vuex'; ...@@ -17,29 +27,16 @@ import { mapActions, mapGetters } from 'vuex';
export default { export default {
name: 'courseware-action-widget', name: 'courseware-action-widget',
props: ['structuralElement'],
components: { components: {
StudipIcon StudipIcon,
}, },
mixins: [CoursewareExport], mixins: [CoursewareExport],
data() {
return {
currentId: null,
currentElement: {},
}
},
computed: { computed: {
...mapGetters({ ...mapGetters({
structuralElementById: 'courseware-structural-elements/byId',
oerEnabled: 'oerEnabled', oerEnabled: 'oerEnabled',
oerTitle: 'oerTitle', oerTitle: 'oerTitle',
}), }),
structuralElement() {
if (!this.currentId) {
return null;
}
return this.structuralElementById({ id: this.currentId });
},
isRoot() { isRoot() {
if (!this.structuralElement) { if (!this.structuralElement) {
return true; return true;
...@@ -53,15 +50,12 @@ export default { ...@@ -53,15 +50,12 @@ export default {
} }
return this.structuralElement.attributes['can-edit']; return this.structuralElement.attributes['can-edit'];
}, },
}, currentId() {
async mounted() { return this.structuralElement?.id;
if (!this.currentId) { },
this.setCurrentId(this.$route.params.id);
}
}, },
methods: { methods: {
...mapActions({ ...mapActions({
loadStructuralElement: 'loadStructuralElement',
showElementEditDialog: 'showElementEditDialog', showElementEditDialog: 'showElementEditDialog',
showElementAddDialog: 'showElementAddDialog', showElementAddDialog: 'showElementAddDialog',
showElementDeleteDialog: 'showElementDeleteDialog', showElementDeleteDialog: 'showElementDeleteDialog',
...@@ -70,19 +64,8 @@ export default { ...@@ -70,19 +64,8 @@ export default {
showElementOerDialog: 'showElementOerDialog', showElementOerDialog: 'showElementOerDialog',
companionInfo: 'companionInfo', companionInfo: 'companionInfo',
addBookmark: 'addBookmark', addBookmark: 'addBookmark',
lockObject: 'lockObject' lockObject: 'lockObject',
}), }),
async setCurrentId(id) {
this.currentId = id;
await this.loadStructuralElement(this.currentId);
this.initCurrent();
},
initCurrent() {
this.currentElement = JSON.parse(JSON.stringify(this.structuralElement));
if (!this.currentElement.attributes.payload.meta) {
this.currentElement.attributes.payload.meta = {};
}
},
async editElement() { async editElement() {
await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' }); await this.lockObject({ id: this.currentId, type: 'courseware-structural-elements' });
this.showElementEditDialog(true); this.showElementEditDialog(true);
...@@ -106,12 +89,7 @@ export default { ...@@ -106,12 +89,7 @@ export default {
}, },
oerElement() { oerElement() {
this.showElementOerDialog(true); this.showElementOerDialog(true);
}
},
watch: {
$route(to) {
this.setCurrentId(to.params.id);
}, },
}, },
} };
</script> </script>
\ No newline at end of file
<template> <template>
<div v-if="courseware"> <div v-if="courseware">
<courseware-structural-element <courseware-structural-element
:structural-element="selected"
:ordered-structural-elements="orderedStructuralElements" :ordered-structural-elements="orderedStructuralElements"
@select="selectStructuralElement"
></courseware-structural-element> ></courseware-structural-element>
<MountingPortal mountTo="#courseware-action-widget" name="sidebar-actions"> <MountingPortal mountTo="#courseware-action-widget" name="sidebar-actions">
<courseware-action-widget></courseware-action-widget> <courseware-action-widget :structural-element="selected"></courseware-action-widget>
</MountingPortal> </MountingPortal>
<MountingPortal mountTo="#courseware-view-widget" name="sidebar-views"> <MountingPortal mountTo="#courseware-view-widget" name="sidebar-views">
<courseware-view-widget></courseware-view-widget> <courseware-view-widget></courseware-view-widget>
</MountingPortal> </MountingPortal>
</div> </div>
<div v-else> <div v-else><translate>Inhalte werden geladen</translate>...</div>
<translate>Inhalte werden geladen</translate>...
</div>
</template> </template>
<script> <script>
...@@ -27,25 +27,48 @@ export default { ...@@ -27,25 +27,48 @@ export default {
CoursewareViewWidget, CoursewareViewWidget,
CoursewareActionWidget, CoursewareActionWidget,
}, },
data: () => ({ orderedStructuralElements: [] }), data: () => ({
selected: null,
orderedStructuralElements: [],
}),
computed: { computed: {
...mapGetters({ ...mapGetters({
courseware: 'courseware', courseware: 'courseware',
relatedStructuralElement: 'courseware-structural-elements/related', relatedStructuralElement: 'courseware-structural-elements/related',
structuralElements: 'courseware-structural-elements/all', structuralElements: 'courseware-structural-elements/all',
structuralElementById: 'courseware-structural-elements/byId',
userId: 'userId', userId: 'userId',
}), }),
}, },
methods: { methods: {
...mapActions(['loadCoursewareStructure', 'loadTeacherStatus', 'coursewareBlockAdder']), ...mapActions([
'coursewareBlockAdder',
'loadCoursewareStructure',
'loadStructuralElement',
'loadTeacherStatus',
]),
async selectStructuralElement(id) {
if (!id) {
return;
}
await this.loadStructuralElement(id);
this.selected = this.structuralElementById({ id });
},
}, },
async mounted() { async mounted() {
await this.loadCoursewareStructure(); await this.loadCoursewareStructure();
await this.loadTeacherStatus(this.userId); await this.loadTeacherStatus(this.userId);
const selectedId = this.$route.params?.id;
await this.selectStructuralElement(selectedId);
}, },
watch: { watch: {
$route() { $route(to) {
this.coursewareBlockAdder({}); //reset block adder on navigate // reset block adder on navigate
this.coursewareBlockAdder({});
const selectedId = to.params?.id;
this.selectStructuralElement(selectedId);
}, },
structuralElements(newElements, oldElements) { structuralElements(newElements, oldElements) {
const nodes = buildNodes(this.structuralElements, this.relatedStructuralElement.bind(this)); const nodes = buildNodes(this.structuralElements, this.relatedStructuralElement.bind(this));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment