Skip to content

Commit

Permalink
Add more tools to Instructor Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Jordan committed Nov 30, 2023
1 parent 011bf55 commit 3a3f9e8
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 55 deletions.
2 changes: 1 addition & 1 deletion htdocs/js/SendMail/sendmail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(() => {
const previewUserNameSpan = document.getElementById('preview-user');
const classListSelect = document.getElementById('classList');
const classListSelect = document.getElementById('selected_users');
if (previewUserNameSpan && classListSelect) {
const setPreviewUser = () => {
if (classListSelect.selectedIndex !== -1)
Expand Down
19 changes: 14 additions & 5 deletions lib/WeBWorK/ContentGenerator/Instructor/Index.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pages
=cut

use WeBWorK::Utils qw(x format_set_name_internal);
use WeBWorK::Utils qw(x format_set_name_internal jitar_id_to_seq prob_id_sort);

use constant E_MAX_ONE_SET => x('Please select at most one set.');
use constant E_ONE_USER => x('Please select exactly one user.');
Expand Down Expand Up @@ -152,6 +152,19 @@ sub pre_header_initialize ($c) {
} else {
push @error, E_ONE_SET unless $nsets == 1;
}
} elsif (defined $c->param('show_answers')) {
my %all_problems;
for my $setID (@selectedSetIDs) {
my @problems = $db->listGlobalProblems($setID);
if ($db->getGlobalSet($setID)->assignment_type && $db->getGlobalSet($setID)->assignment_type eq 'jitar') {
@problems = map { join('.', jitar_id_to_seq($_)) } @problems;
}
@all_problems{@problems} = (1) x @problems;
}
$route = 'answer_log';
$params{selected_users} = \@selectedUserIDs;
$params{selected_sets} = \@selectedSetIDs;
$params{selected_problems} = [ prob_id_sort keys %all_problems ];
} elsif (defined $c->param('create_set')) {
my $setname = format_set_name_internal($c->param('new_set_name') // '');
if ($setname) {
Expand All @@ -169,10 +182,6 @@ sub pre_header_initialize ($c) {
} elsif (defined $c->param('add_users')) {
$route = 'instructor_add_users';
$params{number_of_students} = $c->param('number_of_students') // 1;
} elsif (defined $c->param('email_users')) {
$route = 'instructor_mail_merge';
} elsif (defined $c->param('transfer_files')) {
$route = 'instructor_file_manager';
}

push @error, x('You are not allowed to act as a student.')
Expand Down
4 changes: 2 additions & 2 deletions lib/WeBWorK/ContentGenerator/Instructor/SendMail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ sub initialize ($c) {
$c->{defaultSubject} = $c->stash('courseID') . ' notice';
$c->{merge_file} = $mergefile // '';

my @classList = $c->param('classList') // ($user);
my @classList = $c->param('selected_users') // ($user);
$c->{preview_user} = $c->db->getUser($classList[0] || $user);

# Gather database data
Expand Down Expand Up @@ -129,7 +129,7 @@ sub initialize ($c) {
if ($recipients eq 'all_students') {
@send_to = map { $_->user_id } @Users;
} elsif ($recipients eq 'studentID') {
@send_to = $c->param('classList');
@send_to = $c->param('selected_users');
}

$c->{ra_send_to} = \@send_to;
Expand Down
42 changes: 2 additions & 40 deletions lib/WeBWorK/ContentGenerator/Instructor/ShowAnswers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ WeBWorK::ContentGenerator::Instructor::ShowAnswers.pm -- display past answers o
use Text::CSV;
use Mojo::File;

use WeBWorK::Utils qw(sortByName jitar_id_to_seq);
use WeBWorK::Utils qw(sortByName jitar_id_to_seq prob_id_sort);
use WeBWorK::Utils::Rendering qw(renderPG);

use constant PAST_ANSWERS_FILENAME => 'past_answers';
Expand Down Expand Up @@ -312,47 +312,9 @@ sub getInstructorData ($c) {
return (
users => \@users,
expandedGlobalSetIDs => \@expandedGlobalSetIDs,
globalProblemIDs => [ sort prob_id_sort keys %all_problems ],
globalProblemIDs => [ prob_id_sort keys %all_problems ],
filename => PAST_ANSWERS_FILENAME . '.csv'
);
}

sub byData {
my ($A, $B) = ($a, $b);
$A =~ s/\|[01]*\t([^\t]+)\t.*/|$1/; # remove answers and correct/incorrect status
$B =~ s/\|[01]*\t([^\t]+)\t.*/|$1/;
return $A cmp $B;
}

# Sorts problem ID's so that all just-in-time like ids are at the bottom
# of the list in order and other problems
sub prob_id_sort {

my @seqa = split(/\./, $a);
my @seqb = split(/\./, $b);

# go through problem number sequence
for (my $i = 0; $i <= $#seqa; $i++) {
# if at some point two numbers are different return the comparison.
# e.g. 2.1.3 vs 1.2.6
if ($seqa[$i] != $seqb[$i]) {
return $seqa[$i] <=> $seqb[$i];
}

# if all of the values are equal but b is shorter then it comes first
# i.e. 2.1.3 vs 2.1
if ($i == $#seqb) {
return 1;
}
}

# if all of the values are equal and a and b are the same length then equal
# otherwise a was shorter than b so a comes first.
if ($#seqa == $#seqb) {
return 0;
} else {
return -1;
}
}

1;
38 changes: 38 additions & 0 deletions lib/WeBWorK/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ our @EXPORT_OK = qw(
runtime_use
sortAchievements
sortByName
prob_id_sort
surePathToFile
textDateTime
timeToSec
Expand Down Expand Up @@ -1256,6 +1257,43 @@ sub sortAchievements {

}

################################################################################
# Sorts problem ID's so that all just-in-time like ids are at the bottom
# of the list in order and other problems
################################################################################
sub prob_id_sort_comparator {

my @seqa = split(/\./, $a);
my @seqb = split(/\./, $b);

# go through problem number sequence
for (my $i = 0; $i <= $#seqa; $i++) {
# if at some point two numbers are different return the comparison.
# e.g. 2.1.3 vs 1.2.6
if ($seqa[$i] != $seqb[$i]) {
return $seqa[$i] <=> $seqb[$i];
}

# if all of the values are equal but b is shorter then it comes first
# i.e. 2.1.3 vs 2.1
if ($i == $#seqb) {
return 1;
}
}

# if all of the values are equal and a and b are the same length then equal
# otherwise a was shorter than b so a comes first.
if ($#seqa == $#seqb) {
return 0;
} else {
return -1;
}
}

sub prob_id_sort {
return sort prob_id_sort_comparator @_;
}

################################################################################
# Validate strings and labels
################################################################################
Expand Down
38 changes: 32 additions & 6 deletions templates/ContentGenerator/Instructor/Index.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<div class="row">
% # TODO: When bootstrap is upgraded to 5.3 switch the "column-gap" style to the "column-gap-3" class.
<div class="col-xl-10 col-md-12 d-flex justify-content-around flex-wrap" style="column-gap:1rem">
<div style="min-width:350px">
<div style="min-width:370px">
<hr class="divider pb-1 bg-dark mt-0 mb-2">
<div class="input-group input-group-sm mb-2">
<%= submit_button maketext('Edit'),
Expand All @@ -80,7 +80,7 @@
formaction => $c->systemLink(url_for 'instructor_user_list'),
data => { users_needed => 'at least one', error_users => maketext($E_MIN_ONE_USER) } =%>
<span class="input-group-text flex-grow-1" style="white-space:pre;">\
<%== maketext('account data for <b>all selected</b> users') =%>\
<%== maketext('account data for <b>selected</b> users') =%>\
</span>
</div>
<div class="input-group input-group-sm mb-2">
Expand All @@ -101,6 +101,15 @@
<%== maketext('progress for <strong>one</strong> user') =%>\
</span>
</div>
<div class="input-group input-group-sm mb-2">
<%= submit_button maketext('Email'),
name => 'email_users',
class => 'btn btn-sm btn-secondary w-25',
formaction => $c->systemLink(url_for 'instructor_mail_merge') =%>
<span class="input-group-text flex-grow-1" style="white-space:pre;">\
<%== maketext('<strong>selected</strong> users') =%>\
</span>
</div>
<div class="input-group input-group-sm mb-2">
<%= submit_button maketext('Add'), name => 'add_users', class => 'btn btn-sm btn-secondary w-25' =%>
<%= number_field number_of_students => 1, min => 1, max => 100,
Expand All @@ -110,7 +119,7 @@
</span>
</div>
</div>
<div style="min-width:350px">
<div style="min-width:370px">
<hr class="divider pb-1 bg-dark mt-0 mb-2">
<div class="input-group input-group-sm mb-2">
<%= submit_button maketext('Assign'),
Expand All @@ -126,7 +135,7 @@
error_sets => maketext($E_MIN_ONE_SET)
} =%>
<span class="input-group-text flex-grow-1" style="white-space:pre;">\
<%== maketext('<strong>all selected</strong> users to <strong>all selected</strong> sets') =%>\
<%== maketext('<strong>selected</strong> users to <strong>selected</strong> sets') =%>\
</span>
</div>
<div class="input-group input-group-sm mb-2">
Expand Down Expand Up @@ -155,18 +164,35 @@
<%== maketext(q{<strong>one</strong> set's details for <strong>some or all</strong> users}) =%>\
</span>
</div>
<div class="input-group input-group-sm mb-2">
<%= submit_button maketext('View'),
name => 'show_answers',
class => 'btn btn-sm btn-secondary w-25' =%>
<span class="input-group-text flex-grow-1" style="white-space:pre;">\
<%== maketext('answers for <strong>selected</strong> users, for <strong>selected</strong> sets') =%>\
</span>
</div>
<div class="input-group input-group-sm mb-2">
<%= submit_button maketext('Generate'),
name => 'hardcopy',
class => 'btn btn-sm btn-secondary w-25',
formaction => $c->systemLink(url_for 'hardcopy') =%>
<span class="input-group-text flex-grow-1" style="white-space:pre;">\
<%== maketext('PDF for <strong>selected</strong> users, for <strong>selected</strong> sets') =%>\
</span>
</div>
<div class="input-group input-group-sm mb-2">
<%= submit_button maketext('Score'),
name => 'score_sets',
class => 'btn btn-sm btn-secondary w-25',
formaction => $c->systemLink(url_for 'instructor_scoring'),
data => { sets_needed => 'at least one', error_sets => maketext($E_MIN_ONE_SET) } =%>
<span class="input-group-text flex-grow-1" style="white-space:pre;">\
<%== maketext('<strong>all selected</strong> sets for <strong>all</strong> users') =%>\
<%== maketext('<strong>selected</strong> sets for <strong>all</strong> users') =%>\
</span>
</div>
</div>
<div style="min-width:350px">
<div style="min-width:370px">
<hr class="divider pb-1 bg-dark mt-0 mb-2">
<div class="input-group input-group-sm mb-2">
<%= submit_button maketext('Edit'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
<div class="mb-2">
<%= scrollingRecordList(
{
name => 'classList',
name => 'selected_users',
controller => $c,
default_sort => 'lnfn',
default_format => 'lnfn_uid',
Expand Down

0 comments on commit 3a3f9e8

Please sign in to comment.