MDL-82541 core_courseformat: fix orphan sections sorting

This commit is contained in:
ferranrecio 2024-09-12 12:51:14 +02:00
parent 9f9f5f6821
commit 393d4f6043
5 changed files with 21 additions and 11 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -746,22 +746,22 @@ export default class Component extends BaseComponent {
}
});
// Dndupload add a fake element we need to keep.
let dndFakeActivity;
// Remove the remaining elements.
const orphanElements = [];
while (container.children.length > neworder.length) {
const lastchild = container.lastChild;
if (lastchild?.classList?.contains('dndupload-preview')) {
dndFakeActivity = lastchild;
// Any orphan element is always displayed after the listed elements.
// Also, some third-party plugins can use a fake dndupload-preview indicator.
if (lastchild?.classList?.contains('dndupload-preview') || lastchild.dataset?.orphan) {
orphanElements.push(lastchild);
} else {
dettachedelements[lastchild?.dataset?.id ?? 0] = lastchild;
}
container.removeChild(lastchild);
}
// Restore dndupload fake element.
if (dndFakeActivity) {
container.append(dndFakeActivity);
}
// Restore orphan elements.
orphanElements.forEach((element) => {
container.append(element);
});
}
}

View File

@ -97,6 +97,7 @@
data-id="{{id}}"
data-number="{{num}}"
data-sectionname="{{sectionname}}"
{{#isstealth}} data-orphan="true" {{/isstealth}}
>
<div class="section-item">
{{$ core_courseformat/local/content/section/content }}

View File

@ -129,3 +129,12 @@ Feature: Courses should not lose subsection contents when mod_subsection is disa
And I enable "subsection" "mod" plugin
Then I am on "Course 1" course homepage
And I should see "Hidden from students"
@javascript
Scenario: Orphaned sections should appear after any other section
Given I log in as "teacher1"
When I am on "Course 1" course homepage with editing mode on
And I click on "Add section" "link" in the "course-addsection" "region"
Then I should see "New section"
And "Section 2" "section" should appear before "New section" "section"
And "New section" "section" should appear before "Subsection1" "section"