diff --git a/grade/report/grader/classes/output/action_bar.php b/grade/report/grader/classes/output/action_bar.php index fd1b72a034e..257870bb849 100644 --- a/grade/report/grader/classes/output/action_bar.php +++ b/grade/report/grader/classes/output/action_bar.php @@ -32,6 +32,9 @@ class action_bar extends \core_grades\output\action_bar { /** @var string $usersearch The content that the current user is looking for. */ protected string $usersearch = ''; + /** @var int $userid The ID of the user that the current user is looking for. */ + protected int $userid = 0; + /** * The class constructor. * @@ -40,7 +43,13 @@ class action_bar extends \core_grades\output\action_bar { public function __construct(\context_course $context) { parent::__construct($context); + $this->userid = optional_param('gpr_userid', 0, PARAM_INT); $this->usersearch = optional_param('gpr_search', '', PARAM_NOTAGS); + + if ($this->userid) { + $user = \core_user::get_user($this->userid); + $this->usersearch = fullname($user); + } } /** @@ -108,6 +117,11 @@ class action_bar extends \core_grades\output\action_bar { 'courseid' => $courseid, 'resetlink' => $resetlink->out(false), 'group' => 0, + 'name' => 'usersearch', + 'value' => json_encode([ + 'userid' => $this->userid, + 'search' => $this->usersearch, + ]), ]); $searchdropdown = new comboboxsearch( true, diff --git a/grade/report/grader/tests/behat/tertiary_navigation_searching.feature b/grade/report/grader/tests/behat/tertiary_navigation_searching.feature index 4a203a4c22a..1d99c40bab8 100644 --- a/grade/report/grader/tests/behat/tertiary_navigation_searching.feature +++ b/grade/report/grader/tests/behat/tertiary_navigation_searching.feature @@ -156,11 +156,11 @@ Feature: Within the grader report, test that we can search for users | Dummy User | Scenario: A teacher can quickly tell that a search is active on the current table - Given I click on "Turtle" in the "user" search widget - # The search input remains in the field on reload this is in keeping with other search implementations. - When the field "Search users" matches value "Turtle" + When I click on "Turtle" in the "user" search widget + # The search input should contain the name of the user we have selected, so that it is clear that the result pertains to a specific user. + Then the field "Search users" matches value "Turtle Manatee" # Test if we can then further retain the turtle result set and further filter from there. - Then I set the field "Search users" to "Turtle plagiarism" + And I set the field "Search users" to "Turtle plagiarism" And "Turtle Manatee" "list_item" should not be visible And I should see "No results for \"Turtle plagiarism\"" @@ -370,7 +370,7 @@ Feature: Within the grader report, test that we can search for users And I give the grade "80.00" to the user "Student test32" for the grade item "Test assignment one" And I press "Save changes" And I wait until the page is ready - Then the field "Search users" matches value "test32" + Then the field "Search users" matches value "Student test32" And the following should exist in the "user-grades" table: | -1- | | Student test32 | @@ -380,7 +380,7 @@ Feature: Within the grader report, test that we can search for users And I give the grade "70.00" to the user "Student test31" for the grade item "Test assignment one" And I press "Save changes" And I wait until the page is ready - Then the field "Search users" matches value "test3" + Then the field "Search users" matches value "Student test31" And the following should exist in the "user-grades" table: | -1- | | Student test31 | diff --git a/grade/report/singleview/renderer.php b/grade/report/singleview/renderer.php index 394cfb9b153..d852f02a1ae 100644 --- a/grade/report/singleview/renderer.php +++ b/grade/report/singleview/renderer.php @@ -46,12 +46,22 @@ class gradereport_singleview_renderer extends plugin_renderer_base { */ public function users_selector(object $course, ?int $userid = null, ?int $groupid = null): string { $resetlink = new moodle_url('/grade/report/singleview/index.php', ['id' => $course->id, 'group' => $groupid ?? 0]); + $submitteduserid = optional_param('userid', '', PARAM_INT); + + if ($submitteduserid) { + $user = core_user::get_user($submitteduserid); + $currentvalue = fullname($user); + } else { + $currentvalue = ''; + } + $data = [ - 'currentvalue' => optional_param('searchvalue', '', PARAM_NOTAGS), + 'currentvalue' => $currentvalue, 'courseid' => $course->id, 'group' => $groupid ?? 0, 'resetlink' => $resetlink->out(false), - 'userid' => $userid ?? 0 + 'name' => 'userid', + 'value' => $submitteduserid ?? '', ]; $dropdown = new comboboxsearch( true, diff --git a/grade/report/singleview/tests/behat/usersearch.feature b/grade/report/singleview/tests/behat/usersearch.feature index 92c5c9e8407..0540d5ce535 100644 --- a/grade/report/singleview/tests/behat/usersearch.feature +++ b/grade/report/singleview/tests/behat/usersearch.feature @@ -104,7 +104,7 @@ Feature: Within the singleview report, a teacher can search for users. Given I click on "Turtle" in the "user" search widget And I wait until the page is ready # The search input remains in the field on reload this is in keeping with other search implementations. - When the field "Search users" matches value "Turtle" + When the field "Search users" matches value "Turtle Manatee" # The users get preloaded for accessibility reasons. And "Turtle Manatee" "option_role" should exist # Test if we can then further retain the turtle result set and further filter from there. diff --git a/grade/report/user/renderer.php b/grade/report/user/renderer.php index 0f89e89df69..18b3ac0c163 100644 --- a/grade/report/user/renderer.php +++ b/grade/report/user/renderer.php @@ -93,12 +93,22 @@ class gradereport_user_renderer extends plugin_renderer_base { */ public function users_selector(object $course, ?int $userid = null, ?int $groupid = null): string { $resetlink = new moodle_url('/grade/report/user/index.php', ['id' => $course->id, 'group' => 0]); + $submitteduserid = optional_param('userid', '', PARAM_INT); + + if ($submitteduserid) { + $user = core_user::get_user($submitteduserid); + $currentvalue = fullname($user); + } else { + $currentvalue = ''; + } + $data = [ - 'currentvalue' => optional_param('searchvalue', '', PARAM_NOTAGS), + 'currentvalue' => $currentvalue, 'resetlink' => $resetlink->out(false), 'name' => 'userid', + 'value' => $submitteduserid ?? '', 'courseid' => $course->id, - 'groupid' => $groupid ?? 0, + 'group' => $groupid ?? 0, ]; $searchdropdown = new comboboxsearch( diff --git a/grade/report/user/tests/behat/usersearch.feature b/grade/report/user/tests/behat/usersearch.feature index 552f0431ef4..6f969081be2 100644 --- a/grade/report/user/tests/behat/usersearch.feature +++ b/grade/report/user/tests/behat/usersearch.feature @@ -107,8 +107,7 @@ Feature: Within the User report, a teacher can search for users. And "Student 1" "heading" should exist And "Turtle Manatee" "heading" should exist And "Teacher 1" "heading" should not exist - And I click on "Clear" "link" in the ".user-search" "css_element" - And I wait until the page is ready + And "Clear" "link" should not exist in the ".user-search" "css_element" And "Dummy User" "heading" should exist And "User Example" "heading" should exist And "User Test" "heading" should exist @@ -122,12 +121,12 @@ Feature: Within the User report, a teacher can search for users. And I should see "No results for \"a\"" Scenario: A teacher can quickly tell that a search is active on the current table - Given I click on "Turtle" in the "user" search widget - # The search input remains in the field on reload this is in keeping with other search implementations. - When the field "Search users" matches value "Turtle" + When I click on "Turtle" in the "user" search widget + # The search input should contain the name of the user we have selected, so that it is clear that the result pertains to a specific user. + Then the field "Search users" matches value "Turtle Manatee" And I wait until "View all results (5)" "link" does not exist # Test if we can then further retain the turtle result set and further filter from there. - Then I set the field "Search users" to "Turtle plagiarism" + And I set the field "Search users" to "Turtle plagiarism" And I wait until "Turtle Manatee" "list_item" does not exist And I should see "No results for \"Turtle plagiarism\"" diff --git a/user/templates/comboboxsearch/user_selector.mustache b/user/templates/comboboxsearch/user_selector.mustache index 479005f673d..0d65a46d292 100644 --- a/user/templates/comboboxsearch/user_selector.mustache +++ b/user/templates/comboboxsearch/user_selector.mustache @@ -20,6 +20,8 @@ The user selector trigger element. Context variables required for this template: + * name - The name of the input element representing the user search combobox. + * value - The value of the input element representing the user search combobox. * currentvalue - If the user has already searched, set the value to that. * courseid - The course ID. * group - The group ID. @@ -27,6 +29,8 @@ Example context (json): { + "name": "input-1", + "value": "0", "currentvalue": "bar", "courseid": 2, "group": 25, @@ -68,4 +72,4 @@ {{/additionalattributes}} {{/ core/search_input_auto }} {{/currentvalue}} - +