MDL-78885 comboboxesearch: user search should have value as well

This commit is contained in:
Shamim Rezaie
2024-03-22 04:23:26 +11:00
parent b4bb1cde97
commit bc6a3f5a8d
7 changed files with 55 additions and 18 deletions
@@ -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,
@@ -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 |
+12 -2
View File
@@ -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,
@@ -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.
+12 -2
View File
@@ -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(
@@ -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\""
@@ -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}}
<input type="hidden" name="search" id="user-input-{{uniqid}}"/>
<input type="hidden" name="{{name}}" value="{{value}}" id="user-input-{{uniqid}}"/>