Merge branch 'mdl-83857_500' of https://github.com/james-cnz/moodle into MOODLE_500_STABLE

This commit is contained in:
Mihail Geshoski
2025-09-19 09:54:02 +08:00
12 changed files with 41 additions and 20 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+14 -8
View File
@@ -79,8 +79,9 @@ export default class Component extends BaseComponent {
// Index of sections and cms components.
this.sections = {};
this.cms = {};
// The page section return.
this.sectionReturn = descriptor.sectionReturn ?? null;
// The section number and ID of the displayed page.
this.sectionReturn = descriptor?.sectionReturn ?? null;
this.pageSectionId = descriptor?.pageSectionId ?? null;
this.debouncedReloads = new Map();
}
@@ -89,10 +90,11 @@ export default class Component extends BaseComponent {
*
* @param {string} target the DOM main element or its ID
* @param {object} selectors optional css selector overrides
* @param {number} sectionReturn the content section return
* @param {number} sectionReturn the section number of the displayed page
* @param {number} pageSectionId the section ID of the displayed page
* @return {Component}
*/
static init(target, selectors, sectionReturn) {
static init(target, selectors, sectionReturn, pageSectionId) {
let element = document.querySelector(target);
// TODO Remove this if condition as part of MDL-83851.
if (!element) {
@@ -104,6 +106,7 @@ export default class Component extends BaseComponent {
reactive: getCurrentCourseEditor(),
selectors,
sectionReturn,
pageSectionId,
});
}
@@ -225,7 +228,8 @@ export default class Component extends BaseComponent {
getWatchers() {
// Section return is a global page variable but most formats define it just before start printing
// the course content. This is the reason why we define this page setting here.
this.reactive.sectionReturn = this.sectionReturn;
this.reactive.sectionReturn = this?.sectionReturn ?? null;
this.reactive.pageSectionId = this?.pageSectionId ?? null;
// Check if the course format is compatible with reactive components.
if (!this.reactive.supportComponents) {
@@ -498,7 +502,7 @@ export default class Component extends BaseComponent {
*/
_refreshCourseSectionlist({state}) {
// If we have a section return means we only show a single section so no need to fix order.
if (this.reactive.sectionReturn !== null) {
if ((this.reactive?.sectionReturn ?? this.reactive?.pageSectionId) !== null) {
return;
}
const sectionlist = this.reactive.getExporter().listedSectionIds(state);
@@ -607,7 +611,8 @@ export default class Component extends BaseComponent {
{
id: cmId,
courseid: Config.courseId,
sr: this.reactive.sectionReturn ?? null,
sr: this.reactive?.sectionReturn ?? null,
pagesectionid: this.reactive?.pageSectionId ?? null,
}
);
promise.then((html, js) => {
@@ -674,7 +679,8 @@ export default class Component extends BaseComponent {
{
id: element.id,
courseid: Config.courseId,
sr: this.reactive.sectionReturn ?? null,
sr: this.reactive?.sectionReturn ?? null,
pagesectionid: this.reactive?.pageSectionId ?? null,
}
);
promise.then((html, js) => {
@@ -120,7 +120,7 @@ export default class extends DndSection {
*/
validateDropData(dropdata) {
// If the format uses one section per page sections dropping in the content is ignored.
if (dropdata?.type === 'section' && this.reactive.sectionReturn !== null) {
if (dropdata?.type === 'section' && (this.reactive?.sectionReturn ?? this.reactive?.pageSectionId) !== null) {
return false;
}
return super.validateDropData(dropdata);
@@ -50,13 +50,21 @@ export default class extends Reactive {
stateKey = 1;
/**
* The current page section return
* The section number of the current page
* @attribute sectionReturn
* @type number
* @default null
*/
sectionReturn = null;
/**
* The section ID of the current page
* @attribute pageSectionId
* @type number
* @default null
*/
pageSectionId = null;
/**
* Set up the course editor when the page is ready.
*
@@ -91,7 +91,8 @@ class content implements named_templatable, renderable {
'initialsection' => $initialsection,
'sections' => $sections,
'format' => $format->get_format(),
'sectionreturn' => null,
'sectionreturn' => 'null', // Mustache templates don't display NULL, so pass a string value.
'pagesectionid' => $this->format->get_sectionid() ?? 'null', // Pass a string value if NULL.
];
// The single section format has extra navigation.
+6 -2
View File
@@ -242,7 +242,9 @@ function core_courseformat_output_fragment_cmitem($args): string {
}
$format = course_get_format($course);
if (!is_null($args['sr'])) {
if (isset($args['pagesectionid'])) {
$format->set_sectionid($args['pagesectionid']);
} else if (isset($args['sr'])) {
$format->set_sectionnum($args['sr']);
}
$renderer = $format->get_renderer($PAGE);
@@ -269,7 +271,9 @@ function core_courseformat_output_fragment_section($args): string {
}
$format = course_get_format($course);
if (!is_null($args['sr'])) {
if (isset($args['pagesectionid'])) {
$format->set_sectionid($args['pagesectionid']);
} else if (isset($args['sr'])) {
$format->set_sectionnum($args['sr']);
}
@@ -220,6 +220,8 @@
</div>
{{#js}}
require(['core_courseformat/local/content'], function(component) {
component.init('#page', {}, {{sectionreturn}});
component.init(
'#page', {}, {{sectionreturn}}, {{#pagesectionid}}{{.}}{{/pagesectionid}}{{^pagesectionid}}null{{/pagesectionid}}
);
});
{{/js}}