Skip to content

Commit

Permalink
Merge branch 'MDL-71665-403' of https://github.com/laurentdavid/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_403_STABLE
  • Loading branch information
HuongNV13 committed Feb 1, 2024
2 parents 3c78b63 + 14503ba commit e991ae9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
10 changes: 7 additions & 3 deletions availability/classes/info.php
Expand Up @@ -298,6 +298,7 @@ protected function warn_about_invalid_availability(\coding_exception $e) {
// 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);
Expand Down Expand Up @@ -740,11 +741,14 @@ public static function format_info($inforenderable, $courseorid) {
$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',
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion course/format/amd/build/local/content.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion course/format/amd/build/local/content.min.js.map

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions course/format/amd/src/local/content.js
Expand Up @@ -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`,
Expand Down Expand Up @@ -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.
Expand All @@ -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.
*
Expand Down

0 comments on commit e991ae9

Please sign in to comment.