MDL-87031 gradereport: Fixed clear button issue

This commit is contained in:
Santosh Nagargoje
2025-11-21 23:39:15 +05:30
parent a280753085
commit db2dfb91e0
6 changed files with 33 additions and 3 deletions
+2 -1
View File
@@ -31,6 +31,7 @@ require_once($CFG->dirroot.'/grade/report/lib.php');
$courseid = required_param('id', PARAM_INT);
$groupid = optional_param('group', null, PARAM_INT);
$reset = optional_param('reset', 0, PARAM_BOOL);
// Making this work with profile reports.
$userid = optional_param('userid', null, PARAM_INT);
@@ -105,7 +106,7 @@ switch ($itemtype) {
}
// If the item id (user id) cannot be defined or the user id is not part of the list of gradable users,
// display the user select zero state.
if (is_null($itemid) || !array_key_exists($itemid, grade_report::get_gradable_users($courseid, $currentgroup))) {
if (is_null($itemid) || !array_key_exists($itemid, grade_report::get_gradable_users($courseid, $currentgroup)) || $reset) {
$itemtype = 'user_select';
unset($SESSION->gradereport_singleview["useritem-{$context->id}"]);
}
+5 -1
View File
@@ -46,7 +46,11 @@ class gradereport_singleview_renderer extends plugin_renderer_base {
*/
public function users_selector(object $course, ?int $userid = null, ?int $groupid = null): string {
$courserenderer = $this->page->get_renderer('core', 'course');
$resetlink = new moodle_url('/grade/report/singleview/index.php', ['id' => $course->id, 'group' => $groupid ?? 0]);
$resetlink = new moodle_url('/grade/report/singleview/index.php', [
'id' => $course->id,
'group' => $groupid ?? 0,
'reset' => 1,
]);
$usersearch = '';
if ($userid) {
@@ -220,3 +220,13 @@ Feature: Within the singleview report, a teacher can search for users.
And the focused element is "Clear search input" "button" in the ".user-search" "css_element"
And I press the enter key
And I confirm "Turtle Manatee" does not exist in the "Search users" search combo box
Scenario: A teacher can clear the user search.
# A teacher searches for and selects a specific user.
Given I click on "Turtle" in the "Search users" search combo box
And "Turtle Manatee" "heading" should exist
When I click on "Clear" "link"
# Page reloads with search field cleared and no student details displayed (empty state).
And I wait until the page is ready
Then the field "Search users" matches value ""
And "Turtle Manatee" "heading" should not exist
@@ -97,7 +97,7 @@ class action_bar extends \core_grades\output\action_bar {
$data['groupselector'] = $groupselector->export_for_template($output);
}
$resetlink = new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'group' => 0]);
$resetlink = new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'group' => 0, 'reset' => 1]);
$baseurl = new moodle_url('/grade/report/user/index.php', ['id' => $courseid]);
$PAGE->requires->js_call_amd('gradereport_user/user', 'init', [$baseurl->out(false)]);
+5
View File
@@ -31,6 +31,7 @@ $courseid = required_param('id', PARAM_INT);
// 0 - view all reports. null - view own report. non-zero and non-null - view other user report.
$userid = optional_param('userid', null, PARAM_INT);
$userview = optional_param('userview', 0, PARAM_INT);
$reset = optional_param('reset', 0, PARAM_BOOL);
$PAGE->set_url(new moodle_url('/grade/report/user/index.php', ['id' => $courseid]));
@@ -130,6 +131,10 @@ if (has_capability('moodle/grade:viewall', $context)) {
$userid = $USER->id;
}
// If the reset parameter is set, clear any stored (last viewed) user in a session variable.
if ($reset) {
unset($SESSION->gradereport_user["useritem-{$context->id}"]);
}
// If there is a stored (last viewed) user in a session variable, bypass the user select zero state and display the
// report for that user.
$lastvieweduserid = $SESSION->gradereport_user["useritem-{$context->id}"] ?? null;
@@ -261,3 +261,13 @@ Feature: Within the User report, a teacher can search for users.
And "User Test" "heading" should not exist
And "Teacher 1" "heading" should not exist
And "Turtle Manatee" "heading" should not exist
Scenario: A teacher can clear the user search.
# A teacher searches for and selects a specific user.
Given I click on "Dummy" in the "Search users" search combo box
And "Dummy User" "heading" should exist
When I click on "Clear" "link"
# Page reloads with search field cleared and no student details displayed (empty state).
And I wait until the page is ready
Then the field "Search users" matches value ""
And "Dummy User" "heading" should not exist