Skip to content

Commit faeef2a

Browse files
authored
Merge pull request #1747 from maths/iss1680
Iss1680 - Tweaks to dashboard
2 parents 0620f88 + 690293e commit faeef2a

8 files changed

Lines changed: 79 additions & 26 deletions

amd/build/dashboard.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/dashboard.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/dashboard.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,35 @@ define([], function () {
2727
*
2828
*/
2929
function init() {
30+
const warningTab = document.getElementById('warning-tab');
31+
if (document.querySelectorAll('.var-pane-fail').length) {
32+
const varTabWarning = document.getElementById('variants-pane-warning');
33+
varTabWarning.style.display = 'inline';
34+
warningTab.style.display = 'inline';
35+
}
36+
if (document.querySelectorAll('.test-pane-fail').length) {
37+
const testTab = document.getElementById('test-pane-warning');
38+
testTab.style.display = 'inline';
39+
warningTab.style.display = 'inline';
40+
}
41+
const variantCount = document.getElementById('variant-count').textContent;
42+
const variantTabLabel = document.getElementById('variants-tab-label');
43+
variantTabLabel.textContent = variantTabLabel.textContent + ' ' + variantCount;
44+
document.getElementById('dashboard-tab-content').style.display = 'block';
45+
46+
// Prevent page refresh loading old version.
47+
const url = new URL(location);
48+
if (url.searchParams.get('historic')) {
49+
url.searchParams.delete('historic');
50+
history.replaceState(null, null, url);
51+
} else {
52+
// Page reload will not reset dropdown. We have to do it manually.
53+
var options = document.querySelectorAll('.version-dropdown-option');
54+
for (var i = 0, l = options.length; i < l; i++) {
55+
options[i].selected = options[i].defaultSelected;
56+
}
57+
}
58+
3059
// Add simple client-side sorting for the first two columns.
3160
const variantsTable = document.getElementById('deployed-variants-table');
3261
if (!variantsTable) {
@@ -139,18 +168,6 @@ define([], function () {
139168
});
140169
});
141170
}
142-
143-
const warningTab = document.getElementById('warning-tab');
144-
if (document.querySelectorAll('.var-pane-fail').length) {
145-
const varTab = document.getElementById('variants-pane-warning');
146-
varTab.style.display = 'inline';
147-
warningTab.style.display = 'inline';
148-
}
149-
if (document.querySelectorAll('.test-pane-fail').length) {
150-
const testTab = document.getElementById('test-pane-warning');
151-
testTab.style.display = 'inline';
152-
warningTab.style.display = 'inline';
153-
}
154171
}
155172

156173
/** Export our entry point. */

deploy.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@
4848

4949
// Initialise $PAGE.
5050
$nexturl = new moodle_url('/question/type/stack/questiontestrun.php', $urlparams, 'variants-pane');
51+
$nexturl->param('hidetests', 1);
5152
$PAGE->set_url($nexturl); // Since this script always ends in a redirect.
5253
$PAGE->set_heading($COURSE->fullname);
5354
$PAGE->set_pagelayout('popup');
5455

5556
require_login();
57+
// Deploying lots of variants is time consuming, and we need a progress bar in some cases.
58+
$numforprogressbar = 10;
5659

5760
/**
5861
* Run tests on a given seed and stop deployment if a test fails.
@@ -200,13 +203,33 @@ function testseed($question, $seed, $context, $nexturl, $numberdeployed) {
200203

201204
// Deploy all new variants.
202205
$numberdeployed = 0;
206+
$newseeds = array_diff($newseeds, $question->deployedseeds);
207+
$deployhalt = optional_param('deployhalt', null, PARAM_TEXT);
208+
$newcount = count($newseeds);
209+
210+
// Output something if we need a progress bar.
211+
// (We have 10+ variants and we are running the tests.)
212+
if ($newcount >= $numforprogressbar && isset($deployhalt)) {
213+
echo $OUTPUT->header();
214+
flush();
215+
$a = ['total' => $newcount, 'done' => 0];
216+
$progressevery = (int) min(max(1, $newcount / 500), 100);
217+
$pbar = new progress_bar('deployedprogress', 500, true);
218+
}
219+
203220
foreach ($newseeds as $seed) {
204-
if (!in_array($seed, $question->deployedseeds)) {
205-
testseed($question, $seed, $context, $nexturl, $numberdeployed);
206-
$question->deploy_variant($seed);
207-
$numberdeployed++;
221+
testseed($question, $seed, $context, $nexturl, $numberdeployed);
222+
$question->deploy_variant($seed);
223+
$numberdeployed++;
224+
if ($newcount >= $numforprogressbar && isset($deployhalt)) {
225+
$a['done'] += 1;
226+
if ($a['done'] % $progressevery == 0 || $a['done'] == $a['total']) {
227+
core_php_time_limit::raise(60);
228+
$pbar->update($a['done'], $a['total'], get_string('deployedprogress', 'qtype_stack', $a));
229+
}
208230
}
209231
}
232+
$nexturl->param('deployfeedback', stack_string('deploymanysuccess', ['no' => $numberdeployed]));
210233
redirect($nexturl);
211234
}
212235

@@ -216,8 +239,7 @@ function testseed($question, $seed, $context, $nexturl, $numberdeployed) {
216239
// The number of seconds we devote to deploying before moving on. Prevents system hangging.
217240
// Note, in "safe mode" the set time limit function has no effect.
218241
$maxtime = 180;
219-
// Deploying lots of variants is time consuming, and we need a progress bar in some cases.
220-
$numforprogressbar = 10;
242+
221243
core_php_time_limit::raise($maxtime); // Prevent PHP timeouts.
222244
gc_collect_cycles(); // Because PHP's default memory management is rubbish.
223245

questiontestrun.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
$initialdata->general->cmid = $cmid;
173173
$initialdata->general->questionid = $questionid;
174174
$initialdata->general->seed = $seed;
175+
$initialdata->general->hidetests = optional_param('hidetests', '', PARAM_INT);
175176

176177
// Output the progress bars first.
177178
$dashboard->create_progress_bars();
@@ -265,7 +266,7 @@
265266
$variantdata->hastests = optional_param('testall', null, PARAM_INT);
266267
$testalllink = new moodle_url(
267268
'/question/type/stack/questiontestrun.php',
268-
$urlparams + ['testall' => '1', 'sesskey' => $sesskey, 'nocache' => time(), 'historic' => $historic],
269+
$urlparams + ['testall' => '1', 'sesskey' => $sesskey, 'nocache' => time(), 'historic' => $historic, 'hidetests' => 1],
269270
'variants-pane'
270271
);
271272
$variantdata->testalllink = $testalllink->out();

stack/questiondashboard.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ public function create_default_test() {
145145
*/
146146
public function create_progress_bars() {
147147
$this->testprogress = new progress_bar('testingquestiontests', 500, true);
148-
$this->variantprogress = new progress_bar('testingquestionvariants', 500, true);
148+
if (!empty($this->question->deployedseeds)) {
149+
$this->variantprogress = new progress_bar('testingquestionvariants', 500, true);
150+
}
149151
}
150152

151153
/**

templates/questiontestrun.mustache

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
"courseid": 7,
7575
"cmid": 7,
7676
"questionid": "6605",
77-
"seed": 182397542
77+
"seed": 182397542,
78+
"hidetests": ""
7879
},
7980
"istest": true
8081
}
@@ -86,7 +87,10 @@
8687
<p>{{#str}} version, qtype_stack {{/str}}
8788
<select onChange="window.location.href=this.value;">
8889
{{#question.versions}}
89-
<option value="{{{url}}}" {{#active}} selected="selected" {{/active}}>
90+
<option class="version-dropdown-option"
91+
value="{{{url}}}"
92+
{{#active}} selected=true defaultSelected=true {{/active}}
93+
{{^active}} defaultSelected=false {{/active}}>
9094
{{version}}
9195
</option>
9296
{{/question.versions}}
@@ -142,13 +146,16 @@
142146
<a class="nav-link stack-dash-tab-load disabled" href="#question-pane" id="question-tab" data-bs-toggle="tab" data-toggle="tab" role="tab" aria-controls="question-pane" aria-selected="false">{{#str}} question, core {{/str}}</a>
143147
</li>
144148
<li class="nav-item stack-dash-tab-load" role="presentation">
145-
<a class="nav-link stack-dash-tab-load disabled" href="#variants-pane" id="variants-tab" data-bs-toggle="tab" data-toggle="tab" role="tab" aria-controls="variants-pane" aria-selected="false"><span id="variants-pane-warning" style="display:none;">{{#pix}}req, core{{/pix}}</span>{{#str}} variants, qtype_stack {{/str}}</a>
149+
<a class="nav-link stack-dash-tab-load disabled" href="#variants-pane" id="variants-tab" data-bs-toggle="tab" data-toggle="tab" role="tab" aria-controls="variants-pane" aria-selected="false">
150+
<span id="variants-pane-warning" style="display:none;">{{#pix}}req, core{{/pix}}</span>
151+
<span id="variants-tab-label">{{#str}} variants, qtype_stack {{/str}}</span>
152+
</a>
146153
</li>
147154
<li id="warning-tab" class="nav-link stack-dash-tab-load disabled" style="border: none; border-radius: 0; display:none;">{{#pix}}req, core{{/pix}}{{#str}}dashboardissues, qtype_stack{{/str}}</li>
148155
</ul>
149156

150157
<!-- Tab panes -->
151-
<div class="tab-content">
158+
<div id="dashboard-tab-content" class="tab-content" {{#general.hidetests}}style="display: none"{{/general.hidetests}}>
152159
<!-- Question details panes -->
153160
<div class="tab-pane mt-3" id="question-pane" role="tabpanel" aria-labelledby="question-tab">
154161
<h3>{{question.name}}</h3>

templates/questiontestrunvariants.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
{{^hasrandomvariants}}
9999
<!-- No randomisation -->
100100
<p>{{#str}} questiondoesnotuserandomisation, qtype_stack {{/str}} <a href="{{{previewurl}}}">{{#pix}}t/preview, core, {{#str}} preview, core {{/str}}{{/pix}}</a></p>
101+
<span id="variant-count" hidden>(-)</span>
102+
{{/hasrandomvariants}}
103+
{{#hasrandomvariants}}
104+
<span id="variant-count" hidden>({{deployedcount}})</span>
101105
{{/hasrandomvariants}}
102106
{{^notes.0}}
103107
{{#hasrandomvariants}}

0 commit comments

Comments
 (0)