Skip to content

Commit b0dfa9b

Browse files
committed
button to randomize all of a user's seeds for one set
1 parent 8f8267b commit b0dfa9b

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

htdocs/js/ProblemSetDetail/problemsetdetail.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,25 @@
416416
});
417417

418418
// Set up seed randomization buttons.
419-
for (const btn of document.querySelectorAll('.randomize-seed-btn')) {
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) {
420436
const input = document.getElementById(btn.dataset.seedInput);
421437
if (input) btn.addEventListener('click', () => (input.value = Math.floor(Math.random() * 10000)));
422438
}
439+
423440
})();

lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,10 @@ sub fieldHTML ($c, $userID, $setID, $problemID, $globalRecord, $userRecord, $fie
958958
type => 'button',
959959
class => 'randomize-seed-btn btn btn-sm btn-secondary',
960960
title => 'randomize',
961-
data => { seed_input => "$recordType.$recordID.${field}_id" },
961+
data => {
962+
seed_input => "$recordType.$recordID.problem_seed_id",
963+
status_input => "$recordType.$recordID.status_id"
964+
},
962965
$c->tag('i', class => 'fa-solid fa-shuffle')
963966
)
964967
)->join('')

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)