Skip to content

Commit

Permalink
Merge pull request #2271 from Alex-Jordan/randomize-seeds
Browse files Browse the repository at this point in the history
button to randomize individual seeds on set detail page for one user
  • Loading branch information
drgrice1 authored Jan 15, 2024
2 parents a45ca4b + b0dfa9b commit 2ed01cf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
23 changes: 23 additions & 0 deletions htdocs/js/ProblemSetDetail/problemsetdetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,27 @@
comboBoxSelect.addEventListener('change',
() => comboBoxText.value = comboBoxSelect.options[comboBoxSelect.selectedIndex].value);
});

// Set up seed randomization buttons.
const randomize_seeds_button = document.getElementById('randomize_seeds');
const randomize_seed_buttons = document.querySelectorAll('.randomize-seed-btn');
if (randomize_seeds_button) {
randomize_seeds_button.addEventListener('click',
() => (randomize_seed_buttons.forEach((btn) => {
const exclude_correct = document.getElementById('excludeCorrect').checked;
const input = document.getElementById(btn.dataset.seedInput);
const stat = document.getElementById(btn.dataset.statusInput).value || 0;
if (input) {
if (!exclude_correct || (exclude_correct && stat < 1)) {
input.value = Math.floor(Math.random() * 10000);
}
}
}))
)
}
for (const btn of randomize_seed_buttons) {
const input = document.getElementById(btn.dataset.seedInput);
if (input) btn.addEventListener('click', () => (input.value = Math.floor(Math.random() * 10000)));
}

})();
26 changes: 25 additions & 1 deletion lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -937,14 +937,38 @@ sub fieldHTML ($c, $userID, $setID, $problemID, $globalRecord, $userRecord, $fie
my $value = $forUsers ? $userValue : $globalValue;
$value = format_set_name_display($value =~ s/\s*,\s*/,/gr) if $field eq 'restricted_release';

$inputType = $c->text_field(
my @field_args = (
"$recordType.$recordID.$field", $value,
id => "$recordType.$recordID.${field}_id",
data => { override => "$recordType.$recordID.$field.override_id" },
class => 'form-control form-control-sm',
$forUsers && $check ? (aria_labelledby => "$recordType.$recordID.$field.label") : (),
$field eq 'restricted_release' || $field eq 'source_file' ? (dir => 'ltr') : ()
);
if ($field eq 'problem_seed') {
# Insert a randomization button
$inputType = $c->tag(
'div',
class => 'input-group input-group-sm',
style => 'min-width: 7rem',
$c->c(
$c->number_field(@field_args, min => 0),
$c->tag(
'button',
type => 'button',
class => 'randomize-seed-btn btn btn-sm btn-secondary',
title => 'randomize',
data => {
seed_input => "$recordType.$recordID.problem_seed_id",
status_input => "$recordType.$recordID.status_id"
},
$c->tag('i', class => 'fa-solid fa-shuffle')
)
)->join('')
);
} else {
$inputType = $c->text_field(@field_args);
}
}
} elsif ($choose) {
# If $field matches /:/, then multiple fields are used.
Expand Down
11 changes: 11 additions & 0 deletions templates/ContentGenerator/Instructor/ProblemSetDetail.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@
<%= maketext('Hide All') =%>
</button>
</div>
% } else {
<div class="input-group d-inline-flex flex-nowrap w-auto py-1 me-3">
<button id="randomize_seeds" type="button" class="btn btn-secondary">
<%= maketext('Randomize Seeds') =%>
</button>
<label class="form-check-label input-group-text ps-0">
<%= check_box excludeCorrect => 0,
id => 'excludeCorrect', class => 'form-check-input mx-2' =%>
<%= maketext('if status less than 1') =%>
</label>
</div>
% }
% if (!@editForUser) {
<div class="btn-group w-auto me-3 py-1">
Expand Down

0 comments on commit 2ed01cf

Please sign in to comment.