|
13 | 13 | //
|
14 | 14 | // You should have received a copy of the GNU General Public License
|
15 | 15 | // along with Stack. If not, see <http://www.gnu.org/licenses/>.
|
| 16 | +namespace qtype_coderunner; |
| 17 | + |
| 18 | +use context_system; |
| 19 | +use context; |
| 20 | +use html_writer; |
| 21 | +use moodle_url; |
16 | 22 |
|
17 | 23 | require_once(__DIR__ . '/../../../config.php');
|
18 | 24 | require_once($CFG->libdir . '/questionlib.php');
|
|
32 | 38 | }
|
33 | 39 |
|
34 | 40 | // Find in which contexts the user can edit questions.
|
35 |
| -$questionsbycontext = qtype_coderunner_bulk_tester::get_num_coderunner_questions_by_context(); |
| 41 | +$questionsbycontext = bulk_tester::get_num_coderunner_questions_by_context(); |
36 | 42 | $availablequestionsbycontext = [];
|
37 | 43 | foreach ($questionsbycontext as $contextid => $numcoderunnerquestions) {
|
38 | 44 | $context = context::instance_by_id($contextid);
|
|
56 | 62 | echo <<<HTML
|
57 | 63 | <div class="bulk-test-config" style="margin-bottom: 20px; padding: 10px; background-color: #f5f5f5; border: 1px solid #ddd;">
|
58 | 64 | <h3>Test Configuration</h3>
|
59 |
| - <div style="margin-bottom: 10px; display: grid; grid-template-columns: auto 80px; gap: 10px; align-items: center; max-width: 240px;"> |
| 65 | + <div style="margin-bottom: 10px; display: grid; grid-template-columns: auto 80px; gap: 10px; align-items: center; max-width:400px;"> |
60 | 66 | <label for="nruns">Number of runs:</label>
|
61 | 67 | <input type="number" id="nruns" value="{$nruns}" min="1" style="width: 80px;">
|
62 | 68 |
|
|
67 | 73 | <div>
|
68 | 74 | <input type="checkbox" id="repeatrandomonly" checked>
|
69 | 75 | </div>
|
| 76 | + <label for="clearcachefirst">Clear course grading cache first (be careful):</label> |
| 77 | + <div> |
| 78 | + <input type="checkbox" id="clearcachefirst" onchange="confirmCheckboxChange(this)"> |
| 79 | + </div> |
70 | 80 | </div>
|
71 | 81 | </div>
|
72 | 82 | HTML;
|
|
77 | 87 | } else {
|
78 | 88 | echo get_string('bulktestinfo', 'qtype_coderunner');
|
79 | 89 | echo $OUTPUT->heading(get_string('coderunnercontexts', 'qtype_coderunner'));
|
80 |
| - |
| 90 | + $jobehost = get_config('qtype_coderunner', 'jobe_host'); |
| 91 | + echo html_writer::tag('p', '<b>jobe_host:</b> ' . $jobehost); |
81 | 92 | echo html_writer::start_tag('ul');
|
82 | 93 | $buttonstyle = 'background-color: #FFFFD0; padding: 2px 2px 0px 2px;border: 4px solid white';
|
83 | 94 | foreach ($availablequestionsbycontext as $name => $info) {
|
|
87 | 98 | $testallstr = get_string('bulktestallincontext', 'qtype_coderunner');
|
88 | 99 | $testalltitledetails = ['title' => get_string('testalltitle', 'qtype_coderunner'), 'style' => $buttonstyle];
|
89 | 100 | $testallspan = html_writer::tag(
|
90 |
| - 'span', $testallstr, |
| 101 | + 'span', |
| 102 | + $testallstr, |
91 | 103 | ['class' => 'test-link',
|
92 | 104 | 'data-contextid' => $contextid,
|
93 | 105 | 'style' => $buttonstyle . ';cursor:pointer;']
|
|
106 | 118 | echo html_writer::start_tag('li', ['class' => $class]);
|
107 | 119 | echo $litext;
|
108 | 120 |
|
109 |
| - $categories = qtype_coderunner_bulk_tester::get_categories_for_context($contextid); |
| 121 | + $categories = bulk_tester::get_categories_for_context($contextid); |
110 | 122 | echo html_writer::start_tag('ul', ['class' => 'expandable']);
|
111 | 123 |
|
112 | 124 | $titledetails = ['title' => get_string('testallincategory', 'qtype_coderunner')];
|
113 | 125 | foreach ($categories as $cat) {
|
114 | 126 | if ($cat->count > 0) {
|
115 | 127 | $linktext = $cat->name . ' (' . $cat->count . ')';
|
116 |
| - $span = html_writer::tag('span', $linktext, |
| 128 | + $span = html_writer::tag( |
| 129 | + 'span', |
| 130 | + $linktext, |
117 | 131 | ['class' => 'test-link',
|
118 | 132 | 'data-contextid' => $contextid,
|
119 | 133 | 'data-categoryid' => $cat->id,
|
|
127 | 141 | }
|
128 | 142 |
|
129 | 143 | echo html_writer::end_tag('ul');
|
130 |
| - |
| 144 | + echo html_writer::empty_tag('br'); |
| 145 | + echo html_writer::tag('hr', ''); |
| 146 | + echo html_writer::empty_tag('br'); |
131 | 147 | if (has_capability('moodle/site:config', context_system::instance())) {
|
132 | 148 | echo html_writer::tag('p', html_writer::link(
|
133 | 149 | new moodle_url('/question/type/coderunner/bulktestall.php'),
|
|
138 | 154 |
|
139 | 155 | echo <<<SCRIPT_END
|
140 | 156 | <script>
|
| 157 | +function confirmCheckboxChange(checkbox) { |
| 158 | + if (checkbox.checked) { |
| 159 | + var prompt = "Are you sure you want to clear the cache for the selected course?"; |
| 160 | + prompt = prompt + " This will clear the cache for all attempts on all questions!"; |
| 161 | + const confirmed = confirm(prompt); |
| 162 | + if (!confirmed) { |
| 163 | + checkbox.checked = false; |
| 164 | + } |
| 165 | + } |
| 166 | +} |
| 167 | +
|
141 | 168 | document.addEventListener("DOMContentLoaded", function(event) {
|
142 | 169 | // Handle expandable sections
|
143 | 170 | var expandables = document.getElementsByClassName('expandable');
|
|
169 | 196 | var nruns = document.getElementById('nruns').value;
|
170 | 197 | var randomseed = document.getElementById('randomseed').value;
|
171 | 198 | var repeatrandomonly = document.getElementById('repeatrandomonly').checked ? 1 : 0;
|
| 199 | + var clearcachefirst = document.getElementById('clearcachefirst').checked ? 1 : 0; |
172 | 200 |
|
173 | 201 | // Build URL parameters
|
174 | 202 | var params = new URLSearchParams();
|
175 | 203 | params.append('contextid', link.dataset.contextid);
|
176 |
| - params.append('randomseed', randomseed); |
177 |
| - params.append('repeatrandomonly', repeatrandomonly); |
178 |
| - params.append('nruns', nruns); |
179 |
| -
|
180 | 204 | // Add category ID if present
|
181 | 205 | if (link.dataset.categoryid) {
|
182 | 206 | params.append('categoryid', link.dataset.categoryid);
|
183 | 207 | }
|
| 208 | + params.append('nruns', nruns); |
| 209 | + params.append('randomseed', randomseed); |
| 210 | + params.append('repeatrandomonly', repeatrandomonly); |
| 211 | + params.append('clearcachefirst', clearcachefirst); |
184 | 212 |
|
185 | 213 | // Construct and navigate to URL
|
186 | 214 | var url = M.cfg.wwwroot + '/question/type/coderunner/bulktest.php?' + params.toString();
|
|
0 commit comments