Merge branch 'MDL-56993-master' of git://github.com/damyon/moodle

This commit is contained in:
David Monllao
2016-11-24 09:50:31 +08:00
4 changed files with 167 additions and 43 deletions
+9 -1
View File
@@ -3724,8 +3724,16 @@ class flat_navigation extends navigation_node_collection {
$flat = new flat_navigation_node(navigation_node::create($course->shortname, $url), 0);
$flat->key = 'coursehome';
$courseformat = course_get_format($course);
$coursenode = $PAGE->navigation->find_active_node();
while (!empty($coursenode) && ($coursenode->type != navigation_node::TYPE_COURSE)) {
$targettype = navigation_node::TYPE_COURSE;
// Single activity format has no course node - the course node is swapped for the activity node.
if (!$courseformat->has_view_page()) {
$targettype = navigation_node::TYPE_ACTIVITY;
}
while (!empty($coursenode) && ($coursenode->type != $targettype)) {
$coursenode = $coursenode->parent;
}
// There is one very strange page in mod/feedback/view.php which thinks it is both site and course
+83 -42
View File
@@ -545,53 +545,94 @@ class core_renderer extends \core_renderer {
public function context_header_settings_menu() {
$context = $this->page->context;
$menu = new action_menu();
if ($context->contextlevel == CONTEXT_COURSE) {
// Get the course admin node from the settings navigation.
$items = $this->page->navbar->get_items();
$node = end($items);
$settingsnode = false;
if (!empty($node) && $node->key === 'home') {
$settingsnode = $this->page->settingsnav->find('frontpage', navigation_node::TYPE_SETTING);
if ($settingsnode) {
// Build an action menu based on the visible nodes from this navigation tree.
$skipped = $this->build_action_menu_from_navigation($menu, $settingsnode, false, true);
// We only add a list to the full settings menu if we didn't include every node in the short menu.
if ($skipped) {
$text = get_string('morenavigationlinks');
$url = new moodle_url('/course/admin.php', array('courseid' => $this->page->course->id));
$link = new action_link($url, $text, null, null, new pix_icon('t/edit', $text));
$menu->add_secondary_action($link);
}
}
} else if (!empty($node) &&
($node->type == navigation_node::TYPE_COURSE || $node->type == navigation_node::TYPE_SECTION)) {
$settingsnode = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE);
if ($settingsnode) {
// Build an action menu based on the visible nodes from this navigation tree.
$skipped = $this->build_action_menu_from_navigation($menu, $settingsnode, false, true);
$items = $this->page->navbar->get_items();
$currentnode = end($items);
// We only add a list to the full settings menu if we didn't include every node in the short menu.
if ($skipped) {
$text = get_string('morenavigationlinks');
$url = new moodle_url('/course/admin.php', array('courseid' => $this->page->course->id));
$link = new action_link($url, $text, null, null, new pix_icon('t/edit', $text));
$menu->add_secondary_action($link);
}
}
}
} else if ($context->contextlevel == CONTEXT_USER) {
$items = $this->page->navbar->get_items();
$node = end($items);
if (!empty($node) && ($node->key === 'myprofile')) {
// Get the course admin node from the settings navigation.
$node = $this->page->settingsnav->find('useraccount', navigation_node::TYPE_CONTAINER);
if ($node) {
// Build an action menu based on the visible nodes from this navigation tree.
$this->build_action_menu_from_navigation($menu, $node);
$showcoursemenu = false;
$showfrontpagemenu = false;
$showusermenu = false;
// We are on the course home page.
if (($context->contextlevel == CONTEXT_COURSE) &&
!empty($currentnode) &&
($currentnode->type == navigation_node::TYPE_COURSE || $currentnode->type == navigation_node::TYPE_SECTION)) {
$showcoursemenu = true;
}
$courseformat = course_get_format($this->page->course);
// This is a single activity course format, always show the course menu on the activity main page.
if ($context->contextlevel == CONTEXT_MODULE &&
!$courseformat->has_view_page()) {
$this->page->navigation->initialise();
$activenode = $this->page->navigation->find_active_node();
// If the settings menu has been forced then show the menu.
if ($this->page->is_settings_menu_forced()) {
$showcoursemenu = true;
} else if (!empty($activenode) && ($activenode->type == navigation_node::TYPE_ACTIVITY ||
$activenode->type == navigation_node::TYPE_RESOURCE)) {
// We only want to show the menu on the first page of the activity. This means
// the breadcrumb has no additional nodes.
if ($currentnode && ($currentnode->key == $activenode->key && $currentnode->type == $activenode->type)) {
$showcoursemenu = true;
}
}
}
// This is the site front page.
if ($context->contextlevel == CONTEXT_COURSE &&
!empty($currentnode) &&
$currentnode->key === 'home') {
$showfrontpagemenu = true;
}
// This is the user profile page.
if ($context->contextlevel == CONTEXT_USER &&
!empty($currentnode) &&
($currentnode->key === 'myprofile')) {
$showusermenu = true;
}
if ($showfrontpagemenu) {
$settingsnode = $this->page->settingsnav->find('frontpage', navigation_node::TYPE_SETTING);
if ($settingsnode) {
// Build an action menu based on the visible nodes from this navigation tree.
$skipped = $this->build_action_menu_from_navigation($menu, $settingsnode, false, true);
// We only add a list to the full settings menu if we didn't include every node in the short menu.
if ($skipped) {
$text = get_string('morenavigationlinks');
$url = new moodle_url('/course/admin.php', array('courseid' => $this->page->course->id));
$link = new action_link($url, $text, null, null, new pix_icon('t/edit', $text));
$menu->add_secondary_action($link);
}
}
} else if ($showcoursemenu) {
$settingsnode = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE);
if ($settingsnode) {
// Build an action menu based on the visible nodes from this navigation tree.
$skipped = $this->build_action_menu_from_navigation($menu, $settingsnode, false, true);
// We only add a list to the full settings menu if we didn't include every node in the short menu.
if ($skipped) {
$text = get_string('morenavigationlinks');
$url = new moodle_url('/course/admin.php', array('courseid' => $this->page->course->id));
$link = new action_link($url, $text, null, null, new pix_icon('t/edit', $text));
$menu->add_secondary_action($link);
}
}
} else if ($showusermenu) {
// Get the course admin node from the settings navigation.
$settingsnode = $this->page->settingsnav->find('useraccount', navigation_node::TYPE_CONTAINER);
if ($settingsnode) {
// Build an action menu based on the visible nodes from this navigation tree.
$this->build_action_menu_from_navigation($menu, $settingsnode);
}
}
return $this->render($menu);
}
@@ -0,0 +1,32 @@
@javascript @theme_boost
Feature: Context settings menu
To navigate in boost theme I need to use the context settings menu
Background:
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
Scenario: Teacher can use the context settings menu
And I log in as "teacher1"
And I am on site homepage
And I follow "Course 1"
And I click on ".context-header-settings-menu [role=button]" "css_element"
And I choose "Edit settings" in the open action menu
And I should see "Edit course settings"
And I log out
Scenario: Student cannot use the context settings menu
And I log in as "student1"
And I am on site homepage
And I follow "Course 1"
And ".context-header-settings-menu [role=button]" "css_element" should not exist
And I log out
@@ -0,0 +1,43 @@
@javascript @theme_boost
Feature: Region main settings menu
To navigate in boost theme I need to use the region main settings menu
Background:
Given the following "courses" exist:
| fullname | shortname | newsitems |
| Course 1 | C1 | 5 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | name | intro | course | idnumber | option |
| choice | Choice name | Test choice description | C1 | choice1 | Option 1, Option 2, Option 3 |
Scenario: Teacher can use the region main settings menu
And I log in as "teacher1"
And I am on site homepage
And I follow "Course 1"
And "#region-main-settings-menu [role=button]" "css_element" should not exist
And I follow "Choice name"
And I click on "#region-main-settings-menu [role=button]" "css_element"
And I choose "Edit settings" in the open action menu
And I should see "Updating: Choice"
And I follow "Participants"
And I click on "#region-main-settings-menu [role=button]" "css_element"
And I choose "Enrolment methods" in the open action menu
And I should see "Enrolment methods"
And I log out
Scenario: Student cannot use all options in the region main settings menu
And I log in as "student1"
And I am on site homepage
And I follow "Course 1"
And "#region-main-settings-menu [role=button]" "css_element" should not exist
And I follow "Choice name"
And "#region-main-settings-menu [role=button]" "css_element" should not exist
And I log out