MDL-73952 core_course: update section badges using JS

This commit is contained in:
Bas Brands 2022-03-09 15:46:09 +01:00
parent 967d9b2546
commit c3f0f59134
6 changed files with 38 additions and 21 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

@ -616,13 +616,13 @@ define(
replaceActionItem(actionItem, 'i/marked',
'highlightoff', 'core', 'removemarker');
courseeditor.dispatch('legacySectionAction', action, sectionid);
setSectionBadge(sectionElement[0], 'highlighted', true);
setSectionBadge(sectionElement[0], 'iscurrent', true);
} else if (action === 'removemarker') {
sectionElement.removeClass('current');
replaceActionItem(actionItem, 'i/marker',
'highlight', 'core', 'setmarker');
courseeditor.dispatch('legacySectionAction', action, sectionid);
setSectionBadge(sectionElement[0], 'highlighted', false);
setSectionBadge(sectionElement[0], 'iscurrent', false);
}
};
@ -739,15 +739,17 @@ define(
if (!sectionbadges) {
return;
}
const badge = sectionbadges.querySelector('[data-type="' + badgetype + '"]');
if (!badge) {
return;
}
if (add) {
templates.render('core_courseformat/local/content/section/badges', {[badgetype]: 1})
.then(function(html, js) {
templates.prependNodeContents(sectionbadges, html, js);
return true;
}).catch(notification.exception);
document.querySelectorAll('[data-type="' + badgetype + '"]').forEach((b) => {
b.classList.add('d-none');
});
badge.classList.remove('d-none');
} else {
const badge = sectionbadges.querySelector('[data-type="' + badgetype + '"]');
badge.remove();
badge.classList.add('d-none');
}
};

View File

@ -129,7 +129,7 @@ class section implements named_templatable, renderable {
* @return stdClass data context for a mustache template
*/
public function export_for_template(renderer_base $output): stdClass {
global $USER;
global $USER, $PAGE;
$format = $this->format;
$course = $format->get_course();
@ -145,6 +145,7 @@ class section implements named_templatable, renderable {
'summary' => $summary->export_for_template($output),
'highlightedlabel' => $format->get_section_highlighted_name(),
'sitehome' => $course->id == SITEID,
'editing' => $PAGE->user_is_editing()
];
$haspartials = [];

View File

@ -29,12 +29,25 @@
"highlightedlabel" : "Highlighted"
}
}}
{{#iscurrent}}
<span class="badge badge-pill badge-primary order-1" data-type="highlighted">{{ highlightedlabel }}</span>
{{/iscurrent}}
{{#hiddenfromstudents}}
<span class="badge badge-pill badge-warning order-2" data-type="hiddenfromstudents">{{#str}}hiddenfromstudents{{/str}}</span>
{{/hiddenfromstudents}}
{{#notavailable}}
<span class="badge badge-pill badge-secondary order-3">{{#str}}notavailable{{/str}}</span>
{{/notavailable}}
{{#editing}}
<span class="badge badge-pill badge-primary order-1 {{^iscurrent}}d-none{{/iscurrent}}" data-type="iscurrent">
{{ highlightedlabel }}
</span>
<span class="badge badge-pill badge-warning order-2 {{^hiddenfromstudents}}d-none{{/hiddenfromstudents}}" data-type="hiddenfromstudents">
{{#str}}hiddenfromstudents{{/str}}
</span>
<span class="badge badge-pill badge-secondary order-3 {{^notavailable}}d-none{{/notavailable}}">
{{#str}}notavailable{{/str}}
</span>
{{/editing}}
{{^editing}}
{{#iscurrent}}
<span class="badge badge-pill badge-primary order-1">{{ highlightedlabel }}</span>
{{/iscurrent}}
{{#hiddenfromstudents}}
<span class="badge badge-pill badge-warning order-2">{{#str}}hiddenfromstudents{{/str}}</span>
{{/hiddenfromstudents}}
{{#notavailable}}
<span class="badge badge-pill badge-secondary order-3">{{#str}}notavailable{{/str}}</span>
{{/notavailable}}
{{/editing}}

View File

@ -444,6 +444,7 @@ class behat_course extends behat_base {
// Ensures the section exists.
$xpath = $this->section_exists($sectionnumber);
$this->execute('behat_general::should_exist_in_the', ['Highlighted', 'text', $xpath, 'xpath_element']);
// The important checking, we can not check the img.
$this->execute('behat_general::should_exist_in_the', ['Remove highlight', 'link', $xpath, 'xpath_element']);
}