Skip to content

Commit

Permalink
Add scope back to UserList edit, password, and export.
Browse files Browse the repository at this point in the history
  When dealing with large classes (>200 users), having to filter
  before acting on all users is an extra step which can slow
  things down, so in these cases there is a scope to choose between
  all users or selected users. Compared to the previous scope,
  there is no longer a 'visible' option, as that can be done via
  selecting all visible users.
  • Loading branch information
somiaj committed Feb 13, 2024
1 parent 92ade16 commit b3bd8b7
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 10 deletions.
35 changes: 32 additions & 3 deletions htdocs/js/UserList/userlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,45 @@
{ once: true }
);
}
} else if (action === 'edit' || action === 'password') {
if (!is_user_selected()) {
} else if (action === 'edit') {
const edit_select = document.getElementById('edit_select');
if (edit_select.value === 'selected' && !is_user_selected()) {
e.preventDefault();
e.stopPropagation();
edit_select.addEventListener(
'change',
() => {
document.getElementById('select_user_err_msg')?.classList.add('d-none');
},
{ once: true }
);
}
} else if (action === 'password') {
const password_select = document.getElementById('password_select');
if (password_select.value === 'selected' && !is_user_selected()) {
e.preventDefault();
e.stopPropagation();
password_select.addEventListener(
'change',
() => {
document.getElementById('select_user_err_msg')?.classList.add('d-none');
},
{ once: true }
);
}
} else if (action == 'export') {
const export_filename = document.getElementById('export_filename');
if (!is_user_selected()) {
const export_select = document.getElementById('export_select_scope');
if (export_select.value === 'selected' && !is_user_selected()) {
e.preventDefault();
e.stopPropagation();
export_select.addEventListener(
'change',
() => {
document.getElementById('select_user_err_msg')?.classList.add('d-none');
},
{ once: true }
);
} else if (
document.getElementById('export_select_target')?.value === 'new' &&
export_filename.value === ''
Expand Down
17 changes: 12 additions & 5 deletions lib/WeBWorK/ContentGenerator/Instructor/UserList.pm
Original file line number Diff line number Diff line change
Expand Up @@ -347,19 +347,25 @@ sub sort_handler ($c) {
}

sub edit_handler ($c) {
my @usersToEdit = grep { $c->{userIsEditable}{$_} } (keys %{ $c->{selectedUserIDs} });
my $scope = $c->param('action.edit.scope');
my @usersToEdit =
grep { $c->{userIsEditable}{$_} } ($scope eq 'all' ? @{ $c->{allUserIDs} } : (keys %{ $c->{selectedUserIDs} }));
$c->{visibleUserIDs} = { map { $_ => 1 } @usersToEdit };
$c->{editMode} = 1;

return $c->maketext('Editing selected users.');
return $scope eq 'all' ? $c->maketext('Editing all users.') : $c->maketext('Editing selected users.');
}

sub password_handler ($c) {
my @usersToEdit = grep { $c->{userIsEditable}{$_} } (keys %{ $c->{selectedUserIDs} });
my $scope = $c->param('action.password.scope');
my @usersToEdit =
grep { $c->{userIsEditable}{$_} } ($scope eq 'all' ? @{ $c->{allUserIDs} } : (keys %{ $c->{selectedUserIDs} }));
$c->{visibleUserIDs} = { map { $_ => 1 } @usersToEdit };
$c->{passwordMode} = 1;

return $c->maketext('Giving new passwords to selected users.');
return $scope eq 'all'
? $c->maketext('Giving new passwords to all users.')
: $c->maketext('Giving new passwords to selected users.');
}

sub delete_handler ($c) {
Expand Down Expand Up @@ -451,6 +457,7 @@ sub export_handler ($c) {
my $ce = $c->ce;
my $dir = $ce->{courseDirs}{templates};

my $scope = $c->param('action.export.scope');
my $target = $c->param('action.export.target');
my $new = $c->param('action.export.new');

Expand All @@ -466,7 +473,7 @@ sub export_handler ($c) {

$fileName .= '.lst' unless $fileName =~ m/\.lst$/;

my @userIDsToExport = keys %{ $c->{selectedUserIDs} };
my @userIDsToExport = $scope eq 'all' ? @{ $c->{allUserIDs} } : keys %{ $c->{selectedUserIDs} };
$c->exportUsersToCSV($fileName, @userIDsToExport);

return $c->maketext('[_1] users exported to file [_2]', scalar @userIDsToExport, "$dir/$fileName");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<div class="row mb-2">
<p><%= maketext('Select users to edit.') =%></p>
<%= label_for edit_select => maketext('Edit which users?'), class => 'col-form-label col-form-label-sm col-auto' =%>
<div class="col-auto">
<%= select_field 'action.edit.scope' => [
[ maketext('all users') => 'all' ],
[ maketext('selected users') => 'selected', selected => undef ]
],
id => 'edit_select', class => 'form-select form-select-sm' =%>
</div>
</div>
11 changes: 11 additions & 0 deletions templates/ContentGenerator/Instructor/UserList/export_form.html.ep
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<div>
<div class="row mb-2">
<%= label_for export_select_scope => maketext('Export which users?'),
class => 'col-form-label col-form-label-sm col-sm-auto' =%>
<div class="col-auto">
<%= select_field 'action.export.scope' => [
[ maketext('all users') => 'all' ],
[ maketext('selected users') => 'selected', selected => undef ],
],
id => 'export_select_scope', class => 'form-select form-select-sm' =%>
</div>
</div>
<div class="row mb-2">
<%= label_for export_select_target => maketext('Export to what kind of file?'),
class => 'col-form-label col-form-label-sm col-sm-auto' =%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<div class="row mb-2">
<p><%= maketext('Select users to give a new password.') =%></p>
<%= label_for password_select => maketext('Give new password to which users?'),
class => 'col-form-label col-form-label-sm col-auto' =%>
<div class="col-auto">
<%= select_field 'action.password.scope' => [
[ maketext('all users') => 'all' ],
[ maketext('selected users') => 'selected', selected => undef ]
],
id => 'password_select', class => 'form-select form-select-sm' =%>
</div>
</div>

0 comments on commit b3bd8b7

Please sign in to comment.