From e9449f6189075e013dbd2daea6cd4c0eb4ce1c98 Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Sun, 11 Feb 2024 12:38:05 -0700 Subject: [PATCH] Use the array from getFiltersForClass directly instead of converting to hash. --- .../ContentGenerator/Instructor/Stats.pm | 12 +++++----- .../Instructor/StudentProgress.pm | 9 ++++---- .../Stats/student_filter_menu.html.ep | 23 +++++++++---------- .../StudentProgress/set_progress.html.ep | 2 +- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/WeBWorK/ContentGenerator/Instructor/Stats.pm b/lib/WeBWorK/ContentGenerator/Instructor/Stats.pm index d71643e514..91bdc75eb9 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/Stats.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/Stats.pm @@ -102,15 +102,15 @@ sub siblings ($c) { } # Apply the currently selected filter to the student records, and return a reference to the -# list of students and a reference to a hash of section/recitation filters. +# list of students and a reference to the array of section/recitation filters. sub filter_students ($c) { - my $filter = $c->param('filter'); - my @students = $filter ? filterRecords($c, 0, [$filter], @{ $c->{student_records} }) : @{ $c->{student_records} }; + my $filter = $c->param('filter') || 'all'; + my @students = + $filter eq 'all' ? @{ $c->{student_records} } : filterRecords($c, 0, [$filter], @{ $c->{student_records} }); - # convert the array from getFiltersForClass to a hash, after removing the first 'all' filter. + # Change visible name of the first 'all' filter. my $filters = getFiltersForClass($c, [ 'section', 'recitation' ], @{ $c->{student_records} }); - shift(@$filters); - $filters = { map { $_->[1] => $_->[0] } @$filters }; + $filters->[0][0] = $c->maketext('All students'); return (\@students, $filters); } diff --git a/lib/WeBWorK/ContentGenerator/Instructor/StudentProgress.pm b/lib/WeBWorK/ContentGenerator/Instructor/StudentProgress.pm index feaf6a5e93..45af2e115c 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/StudentProgress.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/StudentProgress.pm @@ -116,14 +116,13 @@ sub displaySets ($c) { : (date => 0, testtime => 0, timeleft => 0, problems => 1, section => 1, recit => 1, login => 1); my $showBestOnly = $setIsVersioned ? $c->param('show_best_only') : 0; - my $filter = $c->param('filter'); + my $filter = $c->param('filter') || 'all'; my @student_records = - $filter ? filterRecords($c, 0, [$filter], @{ $c->{student_records} }) : @{ $c->{student_records} }; + $filter eq 'all' ? @{ $c->{student_records} } : filterRecords($c, 0, [$filter], @{ $c->{student_records} }); - # convert the array from getFiltersForClass to a hash, after removing the first 'all' filter. + # Change visible name of the first 'all' filter. my $filters = getFiltersForClass($c, [ 'section', 'recitation' ], @{ $c->{student_records} }); - shift(@$filters); - $filters = { map { $_->[1] => $_->[0] } @$filters }; + $filters->[0][0] = $c->maketext('All students'); my @score_list; my @user_set_list; diff --git a/templates/ContentGenerator/Instructor/Stats/student_filter_menu.html.ep b/templates/ContentGenerator/Instructor/Stats/student_filter_menu.html.ep index 5dcecaf5e6..98ba7f083e 100644 --- a/templates/ContentGenerator/Instructor/Stats/student_filter_menu.html.ep +++ b/templates/ContentGenerator/Instructor/Stats/student_filter_menu.html.ep @@ -1,20 +1,19 @@ -% last unless %$filters; +% last unless @$filters > 1; % % # Create a section/recitation "filter by" dropdown if there are sections or recitations.
- <%= link_to param('filter') ? $filters->{param('filter')} : maketext('All students') => '#', - id => 'filter', class => 'btn btn-primary dropdown-toggle', role => 'button', 'aria-expanded' => 'false', - data => { bs_toggle => 'dropdown' } =%> + % my $filter = param('filter') || 'all'; + % my $current_filter = $filters->[0][0]; + % for (@$filters) { + % $current_filter = $_->[0] if $_->[1] eq $filter; + % } + <%= link_to $current_filter => '#', id => 'filter', class => 'btn btn-primary dropdown-toggle', + role => 'button', 'aria-expanded' => 'false', data => { bs_toggle => 'dropdown' } =%> diff --git a/templates/ContentGenerator/Instructor/StudentProgress/set_progress.html.ep b/templates/ContentGenerator/Instructor/StudentProgress/set_progress.html.ep index 4a84d4d756..3f71ede160 100644 --- a/templates/ContentGenerator/Instructor/StudentProgress/set_progress.html.ep +++ b/templates/ContentGenerator/Instructor/StudentProgress/set_progress.html.ep @@ -21,7 +21,7 @@ % ); % % # Filter selector. -% if (%$filters) { +% if (@$filters > 1) {
<%= maketext('Showing progress for:') =%> <%= include 'ContentGenerator/Instructor/Stats/student_filter_menu',