Skip to content

Commit 4c23789

Browse files
committed
Improve bulk test UI
1 parent 26d5a10 commit 4c23789

File tree

1 file changed

+65
-32
lines changed

1 file changed

+65
-32
lines changed

bulktestindex.php

+65-32
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Stack. If not, see <http://www.gnu.org/licenses/>.
1616

17-
/**
18-
* This script provides an index for running the question tests in bulk.
19-
* [A modified version of the script in qtype_stack with the same name.]
20-
*
21-
* @package qtype_coderunner
22-
* @copyright 2016, 2017 Richard Lobb, The University of Canterbury
23-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24-
*/
25-
2617
require_once(__DIR__ . '/../../../config.php');
2718
require_once($CFG->libdir . '/questionlib.php');
2819

@@ -51,7 +42,7 @@
5142
$contextname = $context->get_context_name(true, true);
5243
if ($contextname === "Question bank: System shared question bank") {
5344
$name = "$coursename: System shared question bank";
54-
} else if (strpos($contextname, 'Quiz:') === 0) { // Quiz-specific question category.
45+
} else if (strpos($contextname, 'Quiz:') === 0) {
5546
$name = "$coursename: $contextname";
5647
}
5748
$availablequestionsbycontext[$name] = [
@@ -65,6 +56,25 @@
6556
// Display.
6657
echo $OUTPUT->header();
6758

59+
// Add the configuration form
60+
echo <<<HTML
61+
<div class="bulk-test-config" style="margin-bottom: 20px; padding: 10px; background-color: #f5f5f5; border: 1px solid #ddd;">
62+
<h3>Test Configuration</h3>
63+
<div style="margin-bottom: 10px; display: grid; grid-template-columns: auto 80px; gap: 10px; align-items: center; max-width: 240px;">
64+
<label for="nruns">Number of runs:</label>
65+
<input type="number" id="nruns" value="{$nruns}" min="1" style="width: 80px;">
66+
67+
<label for="randomseed">Random seed:</label>
68+
<input type="number" id="randomseed" value="0" min="0" style="width: 80px;">
69+
70+
<label for="repeatrandomonly">Repeat random only:</label>
71+
<div>
72+
<input type="checkbox" id="repeatrandomonly" checked>
73+
</div>
74+
</div>
75+
</div>
76+
HTML;
77+
6878
// List all contexts available to the user.
6979
if (count($availablequestionsbycontext) == 0) {
7080
echo html_writer::tag('p', get_string('unauthorisedbulktest', 'qtype_coderunner'));
@@ -77,34 +87,28 @@
7787
foreach ($availablequestionsbycontext as $name => $info) {
7888
$contextid = $info['contextid'];
7989
$numcoderunnerquestions = $info['numquestions'];
80-
// Random seed of zero means randomseed is not set.
81-
$urlargs = ['contextid' => $contextid,
82-
'randomseed' => 0,
83-
'repeatrandomonly' => 1,
84-
'nruns' => $nruns];
8590

86-
$testallurl = new moodle_url('/question/type/coderunner/bulktest.php', $urlargs);
8791
$testallstr = get_string('bulktestallincontext', 'qtype_coderunner');
8892
$testalltitledetails = ['title' => get_string('testalltitle', 'qtype_coderunner'), 'style' => $buttonstyle];
89-
$testalllink = html_writer::link($testallurl, $testallstr, $testalltitledetails);
93+
$testallspan = html_writer::tag('span', $testallstr,
94+
['class' => 'test-link',
95+
'data-contextid' => $contextid,
96+
'style' => $buttonstyle . ';cursor:pointer;']);
9097

9198
$expandlink = html_writer::link(
9299
'#expand',
93100
get_string('expand', 'qtype_coderunner'),
94101
['class' => 'expander', 'title' => get_string('expandtitle', 'qtype_coderunner'), 'style' => $buttonstyle]
95102
);
96-
$litext = $name . ' (' . $numcoderunnerquestions . ') ' . $testalllink . ' ' . $expandlink;
97-
if (strpos($name, 'Quiz:') === 0) {
98-
$class = 'bulktest coderunner context quiz';
99-
} else {
100-
$class = 'bulktest coderunner context normal';
101-
}
102-
103+
104+
$litext = $name . ' (' . $numcoderunnerquestions . ') ' . $testallspan . ' ' . $expandlink;
105+
103106
if (strpos($name, ": Quiz: ") === false) {
104107
$class = 'bulktest coderunner context normal';
105108
} else {
106109
$class = 'bulktest coderunner context quiz';
107110
}
111+
108112
echo html_writer::start_tag('li', ['class' => $class]);
109113
echo $litext;
110114

@@ -114,15 +118,13 @@
114118
$titledetails = ['title' => get_string('testallincategory', 'qtype_coderunner')];
115119
foreach ($categories as $cat) {
116120
if ($cat->count > 0) {
117-
$urlargs = ['contextid' => $contextid,
118-
'categoryid' => $cat->id,
119-
'randomseed' => 0,
120-
'repeatrandomonly' => 1,
121-
'nruns' => $nruns];
122-
$url = new moodle_url('/question/type/coderunner/bulktest.php', $urlargs);
123121
$linktext = $cat->name . ' (' . $cat->count . ')';
124-
$link = html_writer::link($url, $linktext, ['style' => $buttonstyle]);
125-
echo html_writer::tag('li', $link, $titledetails);
122+
$span = html_writer::tag('span', $linktext,
123+
['class' => 'test-link',
124+
'data-contextid' => $contextid,
125+
'data-categoryid' => $cat->id,
126+
'style' => $buttonstyle . ';cursor:pointer;']);
127+
echo html_writer::tag('li', $span, $titledetails);
126128
}
127129
}
128130
echo html_writer::end_tag('ul');
@@ -142,10 +144,12 @@
142144
echo <<<SCRIPT_END
143145
<script>
144146
document.addEventListener("DOMContentLoaded", function(event) {
147+
// Handle expandable sections
145148
var expandables = document.getElementsByClassName('expandable');
146149
Array.from(expandables).forEach(function (expandable) {
147150
expandable.style.display = 'none';
148151
});
152+
149153
var expanders = document.getElementsByClassName('expander');
150154
Array.from(expanders).forEach(function(expander) {
151155
expander.addEventListener('click', function(event) {
@@ -159,6 +163,35 @@
159163
}
160164
});
161165
});
166+
167+
// Handle test links
168+
var testLinks = document.getElementsByClassName('test-link');
169+
Array.from(testLinks).forEach(function(link) {
170+
link.addEventListener('click', function(event) {
171+
event.preventDefault();
172+
173+
// Get configuration values
174+
var nruns = document.getElementById('nruns').value;
175+
var randomseed = document.getElementById('randomseed').value;
176+
var repeatrandomonly = document.getElementById('repeatrandomonly').checked ? 1 : 0;
177+
178+
// Build URL parameters
179+
var params = new URLSearchParams();
180+
params.append('contextid', link.dataset.contextid);
181+
params.append('randomseed', randomseed);
182+
params.append('repeatrandomonly', repeatrandomonly);
183+
params.append('nruns', nruns);
184+
185+
// Add category ID if present
186+
if (link.dataset.categoryid) {
187+
params.append('categoryid', link.dataset.categoryid);
188+
}
189+
190+
// Construct and navigate to URL
191+
var url = M.cfg.wwwroot + '/question/type/coderunner/bulktest.php?' + params.toString();
192+
window.location.href = url;
193+
});
194+
});
162195
});
163196
</script>
164197
SCRIPT_END;

0 commit comments

Comments
 (0)