This commit is contained in:
Huong Nguyen
2024-02-01 11:06:35 +07:00
5 changed files with 54 additions and 5 deletions
+7 -3
View File
@@ -298,6 +298,7 @@ abstract class info {
// So instead use the numbers (cmid) from the tag.
$htmlname = preg_replace('~[^0-9]~', '', $name);
}
$htmlname = html_to_text($htmlname, 75, false);
$info = 'Error processing availability data for ‘' . $htmlname
. '’: ' . s($e->a);
debugging($info, DEBUG_DEVELOPER);
@@ -740,11 +741,14 @@ abstract class info {
$info = preg_replace_callback('~<AVAILABILITY_CMNAME_([0-9]+)/>~',
function($matches) use($modinfo, $context) {
$cm = $modinfo->get_cm($matches[1]);
if ($cm->has_view() and $cm->get_user_visible()) {
$modulename = format_string($cm->get_name(), true, ['context' => $context]);
// We make sure that we add a data attribute to the name so we can change it later if the
// original module name changes.
if ($cm->has_view() && $cm->get_user_visible()) {
// Help student by providing a link to the module which is preventing availability.
return \html_writer::link($cm->get_url(), format_string($cm->get_name(), true, ['context' => $context]));
return \html_writer::link($cm->get_url(), $modulename, ['data-cm-name-for' => $cm->id]);
} else {
return format_string($cm->get_name(), true, ['context' => $context]);
return \html_writer::span($modulename, '', ['data-cm-name-for' => $cm->id]);
}
}, $info);
$info = preg_replace_callback('~<AVAILABILITY_FORMAT_STRING>(.*?)</AVAILABILITY_FORMAT_STRING>~s',
@@ -20,6 +20,8 @@ Feature: availability_completion
| activity | course | name | completion |
| page | C1 | Page 1 | 1 |
| page | C1 | Page 2 | |
| page | C1 | Page 3 | 1 |
| page | C1 | Page 4 | |
@javascript
Scenario: Test condition
@@ -119,3 +121,25 @@ Feature: availability_completion
| must not be marked complete | False | True | should | should | should not |
| must be complete with pass grade | False | True | should not | should not | should |
| must be complete with fail grade | False | True | should not | should | should not |
@javascript
Scenario: Edit dependent activity name should also change the access restriction message
Given I am on the "Page 2" "page activity editing" page logged in as "teacher1"
And I expand all fieldsets
And I click on "Add restriction..." "button"
And I click on "Activity completion" "button" in the "Add restriction..." "dialogue"
And I click on ".availability-item .availability-eye img" "css_element"
And I set the field "Activity or resource" to "Page 1"
And I press "Save and return to course"
And I am on the "Page 4" "page activity editing" page
And I expand all fieldsets
And I click on "Add restriction..." "button"
And I click on "Activity completion" "button" in the "Add restriction..." "dialogue"
And I click on ".availability-item .availability-eye img" "css_element"
And I set the field "Activity or resource" to "Page 3"
And I press "Save and return to course"
And I switch editing mode on
And I set the field "Edit title" in the "Page 1" "activity" to "Page X"
And I wait until the page is ready
Then I should see "Not available unless: The activity Page X is marked complete" in the "Page 2" "activity"
Then I should see "Not available unless: The activity Page 3 is marked complete" in the "Page 4" "activity"
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+21
View File
@@ -61,6 +61,9 @@ export default class Component extends BaseComponent {
ACTIVITYTAG: 'li',
SECTIONTAG: 'li',
};
this.selectorGenerators = {
cmNameFor: (id) => `[data-cm-name-for='${id}']`,
};
// Default classes to toggle on refresh.
this.classes = {
COLLAPSED: `collapsed`,
@@ -230,6 +233,7 @@ export default class Component extends BaseComponent {
{watch: `cm.sectionid:updated`, handler: this._reloadCm},
{watch: `cm.indent:updated`, handler: this._reloadCm},
{watch: `cm.groupmode:updated`, handler: this._reloadCm},
{watch: `cm.name:updated`, handler: this._refreshCmName},
// Update section number and title.
{watch: `section.number:updated`, handler: this._refreshSectionNumber},
// Collapse and expand sections.
@@ -245,6 +249,23 @@ export default class Component extends BaseComponent {
];
}
/**
* Update a course module name on the whole page.
*
* @param {object} param
* @param {Object} param.element details the update details.
*/
_refreshCmName({element}) {
// Update classes.
// Replace the text content of the cm name.
const allCmNamesFor = this.getElements(
this.selectorGenerators.cmNameFor(element.id)
);
allCmNamesFor.forEach((cmNameFor) => {
cmNameFor.textContent = element.name;
});
}
/**
* Update section collapsed state via bootstrap 4 if necessary.
*