Skip to content

Commit

Permalink
Use the array from getFiltersForClass directly instead of converting …
Browse files Browse the repository at this point in the history
…to hash.
  • Loading branch information
somiaj committed Feb 15, 2024
1 parent 009ebaa commit e9449f6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
12 changes: 6 additions & 6 deletions lib/WeBWorK/ContentGenerator/Instructor/Stats.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 4 additions & 5 deletions lib/WeBWorK/ContentGenerator/Instructor/StudentProgress.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
% last unless %$filters;
% last unless @$filters > 1;
%
% # Create a section/recitation "filter by" dropdown if there are sections or recitations.
<div class="btn-group student-nav-filter-selector mx-2">
<%= 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' } =%>
<ul class="dropdown-menu" role="menu" aria-labelledby="filter">
<li>
<%= link_to maketext('All students') => $c->systemLink(url_for),
class => 'dropdown-item', param('filter') ? () : (style => 'background-color:#8F8') =%>
</li>
% for (sort keys %$filters) {
% for (@$filters) {
<li>
<%= link_to $filters->{$_} => $c->systemLink(url_for, params => { %$params, filter => $_ }),
(param('filter') || '') eq $_ ? (style => 'background-color: #8F8') : (),
class => 'dropdown-item' =%>
<%= link_to $_->[0] => $c->systemLink(url_for, params => { %$params, filter => $_->[1] }),
$_->[1] eq $filter ? (style => 'background-color: #8F8') : (), class => 'dropdown-item' =%>
</li>
% }
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
% );
%
% # Filter selector.
% if (%$filters) {
% if (@$filters > 1) {
<div class="d-flex align-items-center mt-1 mb-3">
<%= maketext('Showing progress for:') =%>
<%= include 'ContentGenerator/Instructor/Stats/student_filter_menu',
Expand Down

0 comments on commit e9449f6

Please sign in to comment.