-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.html
116 lines (96 loc) · 4.1 KB
/
ui.html
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
<html>
<head>
<title>COMP30050 Project UI</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/static/css/main.css">
<script type="text/javascript">
var ws;
function init() {
console.log("init.");
var response = document.getElementById("response");
var status = document.getElementById("status");
var numClients = 0;
var numSenders = 0;
function onOpen() {
status.innerText = "connected";
};
function onClose() {
status.innerHTML = "connection closed";
};
function updateStatus() {
status.innerHTML = "connected<br>(" + numClients + " browsers)";
return;
};
function onMessage(e) {
var m = JSON.parse(e.data);
if (m.NumClients != null) {
numClients = m.NumClients;
updateStatus();
return;
}
console.log(m);
var md = document.createElement("div");
switch (m.MessageType) {
case "":
default:
return;
case "InputMeta":
md.innerHTML = "<table class='table'>" +
"<tr class='messageType'><th>Response Type:</th><td> Meta Information about Input </td></tr>" +
"<tr class='gist'><th>Title:</th><td>" + m.Gist + "</td></tr>" +
"<tr class='stat'><th>Body:</th><td>" + m.Body + "</td></tr>" +
"</table>";
break;
case "Result":
var b64data = btoa(unescape(encodeURIComponent(generateExportFile(m.Body))));
md.innerHTML = "<table class='table'>" +
"<tr class='messageType'><th>Response Type:</th><td> Solution Result (" +
"<a href='data:application/octet-stream;charset=utf-8;base64," + b64data +
"' download='results.tsv'>Download results</a>)</td></tr>" +
"<tr class='gist'><th>Title:</th><td>" + m.Gist + "</td></tr>" +
"<tr class='stat'><th>Body:</th><td>" + m.Body + "</td></tr>" +
"</table>";
break;
}
response.insertBefore(md, response.firstChild)
};
function connect() {
if (ws != null) {
ws.close();
ws = null;
}
status.innerText = "connecting...";
var url = "wss://{{.WSAddr}}/watch";
ws = new WebSocket(url);
ws.onopen = onOpen;
ws.onclose = onClose;
ws.onmessage = onMessage;
};
connect();
}
function generateExportFile(data) {
var work = data.slice(data.indexOf("<tbody>"), data.lastIndexOf("</tbody>"));
work = work.slice(work.indexOf("<tr>"));
work = work.replace(/<tr><td>/g, "");
work = work.replace(/<\/td><td>/g, "\t");
work = work.replace(/<\/td><\/tr>/g, "\n");
var output = "Student Name\tAssigned Project\n" + work;
return output;
}
</script>
</head>
<body onLoad="init();">
<div class="container-fluid bg-2 text-center">
<h3> Quintet UI </h3>
<div class="row">
<div class="col-sm-12" id="status"></div>
</div>
<h4> Project Results </h4>
</div>
<div class="container-fluid bg-3 text-center" id="response"></div>
</body>
</html>