forked from techtonik/OnlinePythonTutor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
132 lines (113 loc) · 4.24 KB
/
admin.html
File metadata and controls
132 lines (113 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional. dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OPT live help admin panel</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script>
</head>
<script>
function setBtnLabel(dat) {
if (dat.helpAvailable) {
$('#readyToHelpBtn').html('Available to help -- Click to STOP');
}
else {
$('#readyToHelpBtn').html('Not available to help -- Click to START');
}
}
function appendDiv(dat) {
$("div#queue").append('<div class="entry" id="div_' + dat.id + '"/>');
var d = $('div#queue div.entry').last();
document.title = "(" + $("div.entry").length + ") OPT live help admin panel";
var linkURL = dat.url + '&role=tutor';
function removeHelpQueueElt(reason) {
var p = confirm("Confirm remove " + dat.id + " for " + reason);
if (!p) {
return;
}
$.get('/remove-help-queue-element',
{id: dat.id, reason: reason},
function(ret) {
if (ret == "success") {
d.remove();
document.title = "(" + $("div.entry").length +
") OPT live help admin panel";
}
else {
alert("Unknown error :(");
}
});
}
d.html('<button type="button" id="eraseBtnNoShow">No-show</button>' +
'<button type="button" id="eraseBtnFled">Fled</button>' +
'<button type="button" id="eraseBtnSuccess">Success</button>' +
'<button type="button" id="eraseBtnFail">Fail</button>' +
'<button type="button" id="eraseBtnGeneric">(No reason)</button>' +
' ' + dat.date + ' <a href="' + linkURL + '" target="_blank">' +
linkURL + '</a>');
d.find('button#eraseBtnNoShow').click(function() {removeHelpQueueElt('no-show')});
d.find('button#eraseBtnFled').click(function() {removeHelpQueueElt('learner-fled')});
d.find('button#eraseBtnSuccess').click(function() {removeHelpQueueElt('tutoring-success')});
d.find('button#eraseBtnFail').click(function() {removeHelpQueueElt('tutoring-fail')});
d.find('button#eraseBtnGeneric').click(function() {removeHelpQueueElt()});
}
$(document).ready(function() {
var source = new EventSource('/admin-SSE');
source.onmessage = function(e) {
var dat = JSON.parse(e.data);
// might trigger on page load or when browser loses connection and
// needs to reconnect. in either case, clear and re-render the
// entire help queue.
if (dat.type == 'firstTime') {
setBtnLabel(dat);
$('span#numLearners').html(dat.numLearners);
$('span#fetchTime').html(dat.fetchTime);
$('div#queue').empty();
document.title = "(0) OPT live help admin panel";
$.each(dat.helpQueue, function(i, e) {
appendDiv(e);
});
}
else if (dat.type == 'help-available') {
setBtnLabel(dat);
}
else if (dat.type == 'new-help-request') {
$('#rikerRedAlertSound').get(0).play();
appendDiv(dat);
}
};
$('#readyToHelpBtn').click(function() {
var p = confirm("Are you sure?");
if (p == true) {
// no callback, rely on SSE for push update
$.get('/toggle-help-available', {}, null);
}
});
$('#clearQueueBtn').click(function() {
var p = confirm("Are you sure you want to clear the queue?");
if (p == true) {
$.get('/clear-help-queue', {}, function(dat) {
if (dat == 'success') {
$('div#queue').empty();
document.title = "(0) OPT live help admin panel";
}
else {
alert('Unknown error with /clear-help-queue');
}
});
}
});
});
</script>
<body>
<audio id="rikerRedAlertSound" controls style="display: none;">
<source src="https://raw.githubusercontent.com/pgbovine/PythonCompilerWorkbench/master/sounds/redalert.mp3" type="audio/mpeg"/>
</audio>
<h2>OPT live help admin panel</h2>
<div style="margin-bottom: 10pt;">
<span id="numLearners">?</span> learners currently online,
loaded on <span id="fetchTime">?</span>
</div>
<button style="margin-bottom: 20px;" type="button" id="readyToHelpBtn">xxx</button>
<button style="margin-bottom: 20px;" type="button" id="clearQueueBtn">Clear Help Queue</button>
<div id="queue"></div>
</body>
</html>