Merge branch 'MDL-81050-main' of https://github.com/roland04/moodle

This commit is contained in:
Ilya Tregubov
2024-03-21 10:52:39 +08:00
15 changed files with 96 additions and 14 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -994,7 +994,7 @@ define(
// The section and activity names are edited using inplace editable.
// The "update" jQuery event must be captured in order to update the course state.
$('body').on('updated', `${SELECTOR.SECTIONLI} ${SELECTOR.SECTIONITEM} [data-inplaceeditable]`, function(e) {
$('body').on('updated', `${SELECTOR.SECTIONITEM} [data-inplaceeditable]`, function(e) {
if (e.ajaxreturn && e.ajaxreturn.itemid) {
const state = courseeditor.state;
const section = state.section.get(e.ajaxreturn.itemid);
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+18
View File
@@ -63,6 +63,7 @@ export default class Component extends BaseComponent {
};
this.selectorGenerators = {
cmNameFor: (id) => `[data-cm-name-for='${id}']`,
sectionNameFor: (id) => `[data-section-name-for='${id}']`,
};
// Default classes to toggle on refresh.
this.classes = {
@@ -236,6 +237,7 @@ export default class Component extends BaseComponent {
{watch: `cm.name:updated`, handler: this._refreshCmName},
// Update section number and title.
{watch: `section.number:updated`, handler: this._refreshSectionNumber},
{watch: `section.title:updated`, handler: this._refreshSectionTitle},
// Collapse and expand sections.
{watch: `section.contentcollapsed:updated`, handler: this._refreshSectionCollapsed},
// Sections and cm sorting.
@@ -429,6 +431,22 @@ export default class Component extends BaseComponent {
}
}
/**
* Update a course section name on the whole page.
*
* @param {object} param
* @param {Object} param.element details the update details.
*/
_refreshSectionTitle({element}) {
// Replace the text content of the section name in the whole page.
const allSectionNamesFor = document.querySelectorAll(
this.selectorGenerators.sectionNameFor(element.id)
);
allSectionNamesFor.forEach((sectionNameFor) => {
sectionNameFor.textContent = element.title;
});
}
/**
* Refresh a section cm list.
*
@@ -374,3 +374,10 @@ Feature: Course index depending on role
And I should see "Activity sample 5" in the "courseindex-content" "region"
# Label intro text should be displayed if label name is not set.
And I should see "Test label 2" in the "courseindex-content" "region"
@javascript
Scenario: Change the section name inline in section page
When I am on the "Course 1 > Section 2" "course > section" page logged in as "teacher1"
And I turn editing mode on
When I set the field "Edit section name" in the "page-header" "region" to "Custom section name"
Then I should see "Custom section name" in the "courseindex-content" "region"
@@ -90,3 +90,13 @@ Feature: Single section course page
Given I turn editing mode on
When I click on "View" "link" in the "Section 1" "section"
Then "Add section" "link" should not exist in the "region-main" "region"
@javascript
Scenario: Change the section name inline
# The course index is hidden by default in small devices.
Given I change window size to "large"
And I turn editing mode on
And I open section "1" edit menu
And I click on "View" "link" in the "Section 1" "section"
When I set the field "Edit section name" in the "page-header" "region" to "Custom section name"
Then "Custom section name" "text" should exist in the ".breadcrumb" "css_element"
+4 -1
View File
@@ -148,7 +148,10 @@ if ($format->show_editor()) {
$renderable = $sectionclass->export_for_template($renderer);
$controlmenuhtml = $renderable->controlmenu->menu;
$PAGE->add_header_action($controlmenuhtml);
$sectionheading = $OUTPUT->render($format->inplace_editable_render_section_name($sectioninfo, false));
$sectionheading = $OUTPUT->container(
$OUTPUT->render($format->inplace_editable_render_section_name($sectioninfo, false)),
attributes: ['data-for' => 'section_title'],
);
$PAGE->set_heading($sectionheading, false, false);
} else {
$PAGE->set_heading($sectiontitle);
+13
View File
@@ -116,6 +116,8 @@ class navigation_node implements renderable {
public $forceopen = false;
/** @var array An array of CSS classes for the node */
public $classes = array();
/** @var array An array of HTML attributes for the node */
public $attributes = [];
/** @var navigation_node_collection An array of child nodes */
public $children = array();
/** @var bool If set to true the node will be recognised as active */
@@ -559,6 +561,16 @@ class navigation_node implements renderable {
return true;
}
/**
* Adds an HTML attribute to this node.
*
* @param string $name
* @param string $value
*/
public function add_attribute(string $name, string $value): void {
$this->attributes[] = ['name' => $name, 'value' => $value];
}
/**
* Removes a CSS class from this node.
*
@@ -2290,6 +2302,7 @@ class global_navigation extends navigation_node {
null, $section->id, new pix_icon('i/section', ''));
$sectionnode->nodetype = navigation_node::NODETYPE_BRANCH;
$sectionnode->hidden = (!$section->visible || !$section->available);
$sectionnode->add_attribute('data-section-name-for', $section->id);
if ($this->includesectionnum !== false && $this->includesectionnum == $section->section) {
$this->load_section_activities($sectionnode, $section->section, $activities);
}
+7 -5
View File
@@ -3410,10 +3410,11 @@ EOD;
* @param string $contents The contents of the box
* @param string $classes A space-separated list of CSS classes
* @param string $id An optional ID
* @param array $attributes Optional other attributes as array
* @return string the HTML to output.
*/
public function container($contents, $classes = null, $id = null) {
return $this->container_start($classes, $id) . $contents . $this->container_end();
public function container($contents, $classes = null, $id = null, $attributes = []) {
return $this->container_start($classes, $id, $attributes) . $contents . $this->container_end();
}
/**
@@ -3421,12 +3422,13 @@ EOD;
*
* @param string $classes A space-separated list of CSS classes
* @param string $id An optional ID
* @param array $attributes Optional other attributes as array
* @return string the HTML to output.
*/
public function container_start($classes = null, $id = null) {
public function container_start($classes = null, $id = null, $attributes = []) {
$this->opencontainers->push('container', html_writer::end_tag('div'));
return html_writer::start_tag('div', array('id' => $id,
'class' => renderer_base::prepare_classes($classes)));
$attributes = array_merge(['id' => $id, 'class' => renderer_base::prepare_classes($classes)], $attributes);
return html_writer::start_tag('div', $attributes);
}
/**
+12 -2
View File
@@ -68,11 +68,21 @@
}}{{#get_items}}
{{#has_action}}
<li class="breadcrumb-item{{#is_hidden}} dimmed_text{{/is_hidden}}">
<a href="{{{action}}}" {{#is_last}}aria-current="page"{{/is_last}} {{#get_title}}title="{{get_title}}"{{/get_title}}>{{{get_content}}}</a>
<a href="{{{action}}}"
{{#is_last}}aria-current="page"{{/is_last}}
{{#get_title}}title="{{get_title}}"{{/get_title}}
{{#attributes}}{{name}}="{{value}}" {{/attributes}}
>
{{{get_content}}}
</a>
</li>
{{/has_action}}
{{^has_action}}
<li class="breadcrumb-item{{#is_hidden}} dimmed_text{{/is_hidden}}"><span>{{{text}}}</span></li>
<li class="breadcrumb-item{{#is_hidden}} dimmed_text{{/is_hidden}}">
<span {{#attributes}}{{name}}="{{value}}" {{/attributes}}>
{{{text}}}
</span>
</li>
{{/has_action}}
{{/get_items}}{{!
}}</ol>
+16
View File
@@ -152,6 +152,22 @@ class navigationlib_test extends \advanced_testcase {
}
}
/**
* Test the add_attribute method.
* @covers \navigation_node::add_attribute
*/
public function test_node_add_attribute(): void {
$this->setup_node();
$node = $this->node->get('demo1');
$this->assertInstanceOf('navigation_node', $node);
if ($node !== false) {
$node->add_attribute('data-foo', 'bar');
$attribute = reset($node->attributes);
$this->assertEqualsCanonicalizing(['name' => 'data-foo', 'value' => 'bar'], $attribute);
}
}
public function test_node_check_if_active() {
$this->setup_node();
+3
View File
@@ -91,6 +91,9 @@ information provided here is intended especially for developers.
- `question_category_options`
- `question_add_context_in_key`
- `question_fix_top_names`
* Added a new parameter to `core_renderer::container` and `core_renderer::container_start` to allow for the addition of
custom attributes.
* Added a new method `navigation_node::add_attribute()` to allow adding HTML attributes to the node.
=== 4.3 ===
+1 -1
View File
@@ -2216,7 +2216,7 @@ class page_wiki_viewversion extends page_wiki {
$pageversion->content = file_rewrite_pluginfile_urls($pageversion->content, 'pluginfile.php', $this->modcontext->id, 'mod_wiki', 'attachments', $this->subwiki->id);
$parseroutput = wiki_parse_content($pageversion->contentformat, $pageversion->content, $options);
$content = $OUTPUT->container(format_text($parseroutput['parsed_text'], FORMAT_HTML, array('overflowdiv'=>true)), false, '', '', true);
$content = $OUTPUT->container(format_text($parseroutput['parsed_text'], FORMAT_HTML, ['overflowdiv' => true]));
echo $OUTPUT->box($content, 'generalbox wiki_contentbox');
} else {