From 3b5fef50619e5726fde5923cf6cd6d65e28c353f Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Tue, 5 Dec 2023 14:25:11 -0800 Subject: [PATCH] button to randomize all of a user's seeds for one set --- .../js/ProblemSetDetail/problemsetdetail.js | 19 ++++++++++++++++++- .../Instructor/ProblemSetDetail.pm | 5 ++++- .../Instructor/ProblemSetDetail.html.ep | 14 +++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/htdocs/js/ProblemSetDetail/problemsetdetail.js b/htdocs/js/ProblemSetDetail/problemsetdetail.js index 2f46256fc0..e0a480163a 100644 --- a/htdocs/js/ProblemSetDetail/problemsetdetail.js +++ b/htdocs/js/ProblemSetDetail/problemsetdetail.js @@ -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))); } + })(); diff --git a/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm b/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm index 9c1bf712a2..5f85ad38d3 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm @@ -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('') diff --git a/templates/ContentGenerator/Instructor/ProblemSetDetail.html.ep b/templates/ContentGenerator/Instructor/ProblemSetDetail.html.ep index 5ca01ece78..07ae86a925 100644 --- a/templates/ContentGenerator/Instructor/ProblemSetDetail.html.ep +++ b/templates/ContentGenerator/Instructor/ProblemSetDetail.html.ep @@ -348,6 +348,17 @@ <%= maketext('Hide All') =%> + % } else { +
+ + +
% } % if (!@editForUser) {
@@ -370,7 +381,8 @@
% }
- <%= 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} } ],