Skip to content

Commit

Permalink
Merge pull request #20 from drgrice1/instructor-tools-suggestions
Browse files Browse the repository at this point in the history
Implement suggestions made in my review of openwebwork#2266
  • Loading branch information
Alex-Jordan authored Nov 29, 2023
2 parents 35cf980 + 03dfdeb commit 011bf55
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 224 deletions.
6 changes: 3 additions & 3 deletions lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
package WeBWorK::ContentGenerator::Instructor::ProblemSetDetail;
use Mojo::Base 'WeBWorK::ContentGenerator', -signatures;

use Exporter qw(import);

=head1 NAME
WeBWorK::ContentGenerator::Instructor::ProblemSetDetail - Edit general set and
specific user/set information as well as problem information
=cut

use Exporter qw(import);

use WeBWorK::Utils qw(cryptPassword jitar_id_to_seq seq_to_jitar_id x format_set_name_internal format_set_name_display);
use WeBWorK::Utils::Instructor qw(assignProblemToAllSetUsers addProblemToSet);

our @EXPORT_OK = ('FIELD_PROPERTIES');
our @EXPORT_OK = qw(FIELD_PROPERTIES);

# These constants determine which fields belong to what type of record.
use constant SET_FIELDS => [
Expand Down
1 change: 1 addition & 0 deletions lib/WeBWorK/HTML/ScrollingRecordList.pm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ sub scrollingRecordList ($options, @records) {
}

$formattedRecords = formatRecords(
$c,
$c->param("$name!format") || $options{default_format},
sortRecords(
$c->param("$name!sort") || $options{default_sort} || (@$sorts ? $sorts->[0][1] : ''),
Expand Down
4 changes: 2 additions & 2 deletions lib/WeBWorK/Utils/FilterRecords.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use warnings;
use Carp;

use WeBWorK::Utils qw(sortByName);
use WeBWorK::ContentGenerator::Instructor::ProblemSetDetail qw/FIELD_PROPERTIES/;
use WeBWorK::ContentGenerator::Instructor::ProblemSetDetail qw(FIELD_PROPERTIES);

our @EXPORT_OK = qw(
getFiltersForClass
Expand Down Expand Up @@ -118,7 +118,7 @@ sub getFiltersForClass {

if (keys %visibles > 1) {
for my $vis (sortByName(undef, keys %visibles)) {
push @filters, [ ($vis ? 'Visible' : "Not Visible") => "visible:$vis" ];
push @filters, [ ($vis ? 'Visible' : 'Not Visible') => "visible:$vis" ];
}
}
}
Expand Down
32 changes: 20 additions & 12 deletions lib/WeBWorK/Utils/FormatRecords.pm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use warnings;

use Carp;

use WeBWorK::Utils qw/format_set_name_display formatDateTime/;
use WeBWorK::Utils qw/format_set_name_display/;
use WeBWorK::ContentGenerator::Instructor::ProblemSetDetail qw/FIELD_PROPERTIES/;

our @EXPORT_OK = qw(
Expand Down Expand Up @@ -115,9 +115,9 @@ use constant PRESET_FORMATS => {
field_order => [qw/assignment_type set_id due_date/],
format_function => sub {
join('',
FIELD_PROPERTIES()->{assignment_type}{labels}{ $_[0] },
': ', format_set_name_display($_[1]),
', ', formatDateTime($_[2]));
FIELD_PROPERTIES()->{assignment_type}{labels}{ $_[1] },
': ', format_set_name_display($_[2]),
', ', $_[0]->formatDateTime($_[3]));
}
}
],
Expand All @@ -126,15 +126,17 @@ use constant PRESET_FORMATS => {
name => 'due_date: set_id',
field_order => [qw/due_date set_id/],
format_function => sub {
join('', formatDateTime($_[0]), ': ', format_set_name_display($_[1]));
join('', $_[0]->formatDateTime($_[1]), ': ', format_set_name_display($_[2]));
}
}
],
[
'sid' => {
name => 'set_id',
field_order => [qw/set_id/],
format_function => \&format_set_name_display
format_function => sub {
return format_set_name_display($_[1]);
}
}
],
],
Expand Down Expand Up @@ -173,23 +175,24 @@ sub getFormatsForClass {
return \@presets;
}

=item formatRecords($preset_format, @records)
=item formatRecords($c, $preset_format, @records)
Given the name of a preset format and an array of database records, returns a
reference to a list of two element lists. The first element in each list is a
formatted string representing the record, and the second element is a string
that is obtained by joining the key fields of the database record with
exclamation marks.
The C<$preset_format> must be provided. It must either be one of the presets
defined above, or the name of a field in the database record class.
The arguments C<$c> and C<$preset_format> must be provided. C<$c> must be a
C<WeBWorK::Controller> object, and C<$preset_format> must either be one of the
presets defined above, or the name of a field in the database record class.
=back
=cut

sub formatRecords {
my ($preset_format, @records) = @_;
my ($c, $preset_format, @records) = @_;

return unless @records;

Expand Down Expand Up @@ -233,8 +236,13 @@ sub formatRecords {
if ($format_function) {
# If a format_function was passed, then call it on each record.
for my $value (@records) {
push(@formattedRecords,
[ $format_function->(map { $value->$_ } @field_order), join('!', map { $value->$_ } @keyfields) ]);
push(
@formattedRecords,
[
$format_function->($c, map { $value->$_ } @field_order),
join('!', map { $value->$_ } @keyfields)
]
);
}
} else {
# Otherwise, use sprintf and format_string.
Expand Down
Loading

0 comments on commit 011bf55

Please sign in to comment.