Skip to content

Commit 2ed01cf

Browse files
authored
Merge pull request #2271 from Alex-Jordan/randomize-seeds
button to randomize individual seeds on set detail page for one user
2 parents a45ca4b + b0dfa9b commit 2ed01cf

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

htdocs/js/ProblemSetDetail/problemsetdetail.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,27 @@
414414
comboBoxSelect.addEventListener('change',
415415
() => comboBoxText.value = comboBoxSelect.options[comboBoxSelect.selectedIndex].value);
416416
});
417+
418+
// Set up seed randomization buttons.
419+
const randomize_seeds_button = document.getElementById('randomize_seeds');
420+
const randomize_seed_buttons = document.querySelectorAll('.randomize-seed-btn');
421+
if (randomize_seeds_button) {
422+
randomize_seeds_button.addEventListener('click',
423+
() => (randomize_seed_buttons.forEach((btn) => {
424+
const exclude_correct = document.getElementById('excludeCorrect').checked;
425+
const input = document.getElementById(btn.dataset.seedInput);
426+
const stat = document.getElementById(btn.dataset.statusInput).value || 0;
427+
if (input) {
428+
if (!exclude_correct || (exclude_correct && stat < 1)) {
429+
input.value = Math.floor(Math.random() * 10000);
430+
}
431+
}
432+
}))
433+
)
434+
}
435+
for (const btn of randomize_seed_buttons) {
436+
const input = document.getElementById(btn.dataset.seedInput);
437+
if (input) btn.addEventListener('click', () => (input.value = Math.floor(Math.random() * 10000)));
438+
}
439+
417440
})();

lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,14 +937,38 @@ 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 = $c->tag(
951+
'div',
952+
class => 'input-group input-group-sm',
953+
style => 'min-width: 7rem',
954+
$c->c(
955+
$c->number_field(@field_args, min => 0),
956+
$c->tag(
957+
'button',
958+
type => 'button',
959+
class => 'randomize-seed-btn btn btn-sm btn-secondary',
960+
title => 'randomize',
961+
data => {
962+
seed_input => "$recordType.$recordID.problem_seed_id",
963+
status_input => "$recordType.$recordID.status_id"
964+
},
965+
$c->tag('i', class => 'fa-solid fa-shuffle')
966+
)
967+
)->join('')
968+
);
969+
} else {
970+
$inputType = $c->text_field(@field_args);
971+
}
948972
}
949973
} elsif ($choose) {
950974
# If $field matches /:/, then multiple fields are used.

templates/ContentGenerator/Instructor/ProblemSetDetail.html.ep

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,17 @@
348348
<%= maketext('Hide All') =%>
349349
</button>
350350
</div>
351+
% } else {
352+
<div class="input-group d-inline-flex flex-nowrap w-auto py-1 me-3">
353+
<button id="randomize_seeds" type="button" class="btn btn-secondary">
354+
<%= maketext('Randomize Seeds') =%>
355+
</button>
356+
<label class="form-check-label input-group-text ps-0">
357+
<%= check_box excludeCorrect => 0,
358+
id => 'excludeCorrect', class => 'form-check-input mx-2' =%>
359+
<%= maketext('if status less than 1') =%>
360+
</label>
361+
</div>
351362
% }
352363
% if (!@editForUser) {
353364
<div class="btn-group w-auto me-3 py-1">

0 commit comments

Comments
 (0)