Skip to content

Commit

Permalink
button to randomize all of a user's seeds for one set
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Jordan committed Dec 5, 2023
1 parent 78f8c41 commit 3b5fef5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
19 changes: 18 additions & 1 deletion htdocs/js/ProblemSetDetail/problemsetdetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,25 @@
});

// Set up seed randomization buttons.
for (const btn of document.querySelectorAll('.randomize-seed-btn')) {
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)));
}

})();
5 changes: 4 additions & 1 deletion lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,10 @@ sub fieldHTML ($c, $userID, $setID, $problemID, $globalRecord, $userRecord, $fie
type => 'button',
class => 'randomize-seed-btn btn btn-sm btn-secondary',
title => 'randomize',
data => { seed_input => "$recordType.$recordID.${field}_id" },
data => {
seed_input => "$recordType.$recordID.problem_seed_id",
status_input => "$recordType.$recordID.status_id"
},
$c->tag('i', class => 'fa-solid fa-shuffle')
)
)->join('')
Expand Down
14 changes: 13 additions & 1 deletion 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 All @@ -370,7 +381,8 @@
</div>
% }
<div class="input-group d-inline-flex flex-nowrap w-auto py-1">
<%= label_for problem_displaymode => maketext('Display Mode:'), class => 'input-group-text' =%>
<%= label_for problem_displaymode => maketext('Display Mode:'),
class => 'input-group-text form-control form-control-sm' =%>
<%= select_field 'problem_displaymode' => [
grep { exists $display_modes->{$_} } @{ $ce->{pg}{displayModes} }
],
Expand Down

0 comments on commit 3b5fef5

Please sign in to comment.