diff --git a/contentcuration/contentcuration/frontend/channelEdit/views/CurrentTopicView.vue b/contentcuration/contentcuration/frontend/channelEdit/views/CurrentTopicView.vue index 6ec4ffee47..b696b1ae4e 100644 --- a/contentcuration/contentcuration/frontend/channelEdit/views/CurrentTopicView.vue +++ b/contentcuration/contentcuration/frontend/channelEdit/views/CurrentTopicView.vue @@ -41,34 +41,40 @@
- - - - - + this.getContentNode(id)); + const orderedNodes = selectedNodes.sort(this.compareNodeTitles); + + const reversedNodes = orderedNodes.reverse(); + + const nodeX = this.findNodeBeforeFirstSelected(orderedNodes, selected); + + const targetParent = this.node.id; + const targetNode = nodeX || targetParent; + const targetPosition = nodeX + ? RELATIVE_TREE_POSITIONS.RIGHT + : RELATIVE_TREE_POSITIONS.FIRST_CHILD; + + const nodeIdsToMove = reversedNodes.map(node => String(node.id)); + + this.moveContentNodes({ + id__in: nodeIdsToMove, + target: targetNode, + position: targetPosition, + }); + }, + + findNodeBeforeFirstSelected(nodes, selected) { + for (let i = 1; i < nodes.length; i++) { + if (selected.includes(nodes[i])) { + return nodes[i - 1]; + } + } + return null; + }, + + compareNodeTitles(nodeA, nodeB) { + const titleA = nodeA.title.toLowerCase(); + const titleB = nodeB.title.toLowerCase(); + return titleA.localeCompare(titleB); + }, updateTitleForPage() { let detailTitle; const topicTitle = this.getTitle(this.getContentNode(this.topicId)); @@ -707,6 +751,7 @@ }, $trs: { addTopic: 'New folder', + SortAlphabetically: 'Sort alphabetically', addExercise: 'New exercise', uploadFiles: 'Upload files', importFromChannels: 'Import from channels',