Skip to content

Commit 4375271

Browse files
committed
button to randomize individual seeds on set detail page for one user
1 parent a45ca4b commit 4375271

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,14 +937,35 @@ sub fieldHTML ($c, $userID, $setID, $problemID, $globalRecord, $userRecord, $fie
937937
my $value = $forUsers ? $userValue : $globalValue;
938938
$value = format_set_name_display($value =~ s/\s*,\s*/,/gr) if $field eq 'restricted_release';
939939

940-
$inputType = $c->text_field(
940+
my @field_args = (
941941
"$recordType.$recordID.$field", $value,
942942
id => "$recordType.$recordID.${field}_id",
943943
data => { override => "$recordType.$recordID.$field.override_id" },
944944
class => 'form-control form-control-sm',
945945
$forUsers && $check ? (aria_labelledby => "$recordType.$recordID.$field.label") : (),
946946
$field eq 'restricted_release' || $field eq 'source_file' ? (dir => 'ltr') : ()
947947
);
948+
if ($field eq 'problem_seed') {
949+
# Insert a randomization button
950+
$inputType = Mojo::ByteStream->new($c->tag(
951+
'div',
952+
class => 'input-group input-group-sm',
953+
style => 'min-width: 7rem',
954+
$c->number_field(@field_args, min => 0)->to_string
955+
. $c->tag(
956+
'button',
957+
type => 'button',
958+
class => 'btn btn-sm btn-secondary',
959+
title => 'randomize',
960+
onclick =>
961+
"(function() {document.getElementById('$recordType.$recordID.${field}_id').value = Math.floor(Math.random() * 10000);})();",
962+
$c->tag('i', class => 'fa-solid fa-shuffle')
963+
)
964+
))->html_unescape;
965+
warn(ref($inputType));
966+
} else {
967+
$inputType = $c->text_field(@field_args);
968+
}
948969
}
949970
} elsif ($choose) {
950971
# If $field matches /:/, then multiple fields are used.

0 commit comments

Comments
 (0)