"...javascripts/git@gitlab.studip.de:tleilax/studip.git" did not exist on "ef6f0e8f193ebcfd78d0afb9e01e514ff660a217"
Newer
Older
<div class="cw-tree" ref="tree">
<template v-if="editMode">
<span aria-live="assertive" class="assistive-text">{{ assistiveLive }}</span>
<span id="operation" class="assistive-text">
{{$gettext('Drücken Sie die Leertaste, um neu anzuordnen.')}}
</span>
</template>
<ol v-if="!processing" class="cw-tree-root-list" role="listbox">
<courseware-tree-item
class="cw-tree-item"
:element="rootElementWithNestedChildren"
:currentElement="currentElement"
@sort="sort"
@moveItemUp="moveItemUp"
@moveItemDown="moveItemDown"
@moveItemPrevLevel="moveItemPrevLevel"
@moveItemNextLevel="moveItemNextLevel"
@childrenUpdated="updateNestedChildren"
></courseware-tree-item>
</ol>
<studip-progress-indicator
v-else
:description="$gettext('Vorgang wird bearbeitet...')"
/>
</div>
</template>
<script>
import CoursewareTreeItem from './CoursewareTreeItem.vue';
import StudipProgressIndicator from '../StudipProgressIndicator.vue';
import { mapActions, mapGetters } from 'vuex';
components: {
CoursewareTreeItem,
StudipProgressIndicator
},
data() {
return {
nestedChildren: [],
processing: false,
rootElementWithNestedChildren: {},
}
},
computed: {
...mapGetters({
context: 'context',
courseware: 'courseware',
relatedStructuralElement: 'courseware-structural-elements/related',
structuralElementById: 'courseware-structural-elements/byId',
childrenById: 'courseware-structure/children',
viewMode: 'viewMode',
structuralElements: 'courseware-structural-elements/all',
assistiveLive: 'assistiveLiveContents'
}),
currentElement() {
const id = this.$route?.params?.id;
if (!id) {
return null;
}
return this.structuralElementById({ id }) ?? null;
},
rootElement() {
if (this.context.type !== 'public') {
const root = this.relatedStructuralElement({
parent: { id: this.courseware.id, type: this.courseware.type },
relationship: 'root',
});
return root;
} else {
return this.structuralElementById({ id: this.context.rootId });
}
editMode() {
return this.viewMode === 'edit';
},
},
methods: {
...mapActions({
updateStructuralElement: 'updateStructuralElement',
lockObject: 'lockObject',
unlockObject: 'unlockObject',
sortChildrenInStructualElements: 'sortChildrenInStructualElements',
loadStructuralElement: 'loadStructuralElement',
setAssistiveLiveContents: 'setAssistiveLiveContents',
companionError: 'companionError',
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
}),
updateNestedChildren() {
this.nestedChildren = this.getNestedChildren(this.rootElement);
this.setRootElementWithNestedChildren();
},
setRootElementWithNestedChildren() {
let element = { id: this.rootElement.id, attributes: this.rootElement.attributes };
element.nestedChildren = this.nestedChildren;
this.rootElementWithNestedChildren = element;
},
getNestedChildren(structuralElement) {
let children = _.cloneDeep(this.structuralElements
.filter(
element => element.relationships.parent?.data?.id === structuralElement.id
)).sort((a,b) => a.attributes.position - b.attributes.position);
let nestedChildren = [];
for (let child of children) {
child.nestedChildren = this.getNestedChildren(child);
nestedChildren.push(child);
}
return nestedChildren;
},
async sort(data) {
const tree = this.$refs.tree;
const currentScrollPosition = tree.offsetParent.scrollTop;
this.processing = true;
await this.loadStructuralElement(data.newParent);
const newParent = this.structuralElementById({ id: data.newParent });
if (!newParent.attributes['can-edit']) {
this.processing = false;
this.updateNestedChildren();
this.companionError({
info: this.$gettext('Verschieben nicht möglich. Sie haben keine Schreibrechte für die Ziel-Seite.')
});
return;
}
if (data.oldParent !== data.newParent) {
await this.lockObject({ id: data.id, type: 'courseware-structural-elements' });
let element = this.structuralElementById({ id: data.id });
await this.updateStructuralElement({
element: element,
id: element.id,
});
await this.unlockObject({ id: data.id, type: 'courseware-structural-elements' });
await this.loadStructuralElement(data.id);
}
await this.loadStructuralElement(newParent.id);
const parent = this.structuralElementById({ id: newParent.id });
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
await this.sortChildrenInStructualElements({parent: parent, children: data.sortArray});
this.updateNestedChildren();
this.processing = false;
this.$nextTick(() => {
tree.offsetParent.scrollTop = currentScrollPosition;
});
},
moveItemUp(data) {
data.direction = 'up';
this.reorderNestedChildren(data);
},
moveItemDown(data) {
data.direction = 'down';
this.reorderNestedChildren(data);
},
moveItemPrevLevel(data) {
data.direction = 'prev';
this.reorderNestedChildren(data);
},
moveItemNextLevel(data) {
data.direction = 'next';
this.reorderNestedChildren(data);
},
reorderNestedChildren(data) {
this.rootElementWithNestedChildren = this.recursiveNestedChildrenUpdate(this.rootElementWithNestedChildren, data);
},
recursiveNestedChildrenUpdate(element, data) {
if (data.direction === 'prev' && data.parents[1] && element.id === data.parents[1]) {
//element is grandparent
let parentIndex = element.nestedChildren.findIndex((e) => e.id === data.parents[0]);
let movingElementIndex = element.nestedChildren[parentIndex].nestedChildren.findIndex((e) => e.id === data.element.id);
const newPos = parentIndex + 1;
element.nestedChildren.splice(newPos, 0, element.nestedChildren[parentIndex].nestedChildren[movingElementIndex]);
element.nestedChildren[parentIndex].nestedChildren.splice(movingElementIndex, 1);
element.nestedChildren[newPos].newPos = newPos;
element.nestedChildren[newPos].newParentId = parseInt(element.id);
element.nestedChildren[newPos].sortArray = element.nestedChildren.map(c => {return {id: c.id, type: 'courseware-structural-elements'}});
element.nestedChildren[newPos].moveDirection = data.direction;
const assistiveLive = this.$gettextInterpolate(
this.$gettext('%{elementTitle} eine Ebene nach oben bewegt. Übergeordnete Seite: %{parentTitle}. Aktuelle Position in der Liste: %{pos} von %{listLength}'),
{ elementTitle: data.element.attributes.title, parentTitle: element.attributes.title, pos: newPos + 1, listLength: element.nestedChildren[newPos].sortArray.length }
);
this.setAssistiveLiveContents(assistiveLive);
}
if (element.id === data.parents[0]) {
if (data.direction === 'up' || data.direction === 'down') {
const elementIndex = element.nestedChildren.findIndex((e) => e.id === data.element.id);
let vertical = data.direction === 'up' ? -1 : data.direction === 'down' ? 1 : 0;
const newPos = elementIndex + vertical;
if (newPos >= 0 && newPos < element.nestedChildren.length) {
element.nestedChildren.splice(newPos, 0, element.nestedChildren.splice(elementIndex, 1)[0]);
element.nestedChildren[newPos].newPos = newPos;
element.nestedChildren[newPos].newParentId = parseInt(element.id);
element.nestedChildren[newPos].sortArray = element.nestedChildren.map(c => {return {id: c.id, type: 'courseware-structural-elements'}});
element.nestedChildren[newPos].moveDirection = data.direction;
const assistiveLive = this.$gettextInterpolate(
this.$gettext('%{elementTitle} bewegt. Aktuelle Position in der Liste: %{pos} von %{listLength}'),
{ elementTitle: data.element.attributes.title, pos: newPos + 1, listLength: element.nestedChildren[newPos].sortArray.length }
);
this.setAssistiveLiveContents(assistiveLive);
}
}
if (data.direction === 'next') {
const elementIndex = element.nestedChildren.findIndex((e) => e.id === data.element.id);
if (elementIndex !== 0) {
const newParentIndex = elementIndex - 1;
element.nestedChildren[newParentIndex].nestedChildren.push(element.nestedChildren[elementIndex]);
element.nestedChildren.splice(elementIndex, 1);
const newPos = element.nestedChildren[newParentIndex].nestedChildren.length - 1;
element.nestedChildren[newParentIndex].nestedChildren[newPos].newPos = newPos;
const newParentId = element.nestedChildren[newParentIndex].id;
element.nestedChildren[newParentIndex].nestedChildren[newPos].newParentId = parseInt(newParentId);
element.nestedChildren[newParentIndex].nestedChildren[newPos].sortArray = element.nestedChildren[newParentIndex].nestedChildren.map(c => {return {id: c.id, type: 'courseware-structural-elements'}});
const assistiveLive = this.$gettextInterpolate(
this.$gettext('%{elementTitle} eine Ebene nach unten bewegt. Übergeordnete Seite: %{parentTitle}. Aktuelle Position in der Liste: %{pos} von %{listLength}'),
{ elementTitle: data.element.attributes.title, parentTitle: element.nestedChildren[newParentIndex].attributes.title, pos: newPos + 1, listLength: element.nestedChildren[newParentIndex].nestedChildren[newPos].sortArray.length }
);
this.setAssistiveLiveContents(assistiveLive);
}
}
} else {
element.nestedChildren.forEach((child,index) => {
element.nestedChildren[index] = this.recursiveNestedChildrenUpdate(child, data);
});
}
return element;
},
mounted() {
this.updateNestedChildren();
},
watch: {
structuralElements() {
this.updateNestedChildren();
}