-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
152 lines (148 loc) · 5.96 KB
/
Copy pathindex.html
File metadata and controls
152 lines (148 loc) · 5.96 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border:0px solid black;
}
th {
text-align: left;
}
</style>
<meta charset="utf-8" />
</head>
<body>
<hr/>
<div id="content"></div>
<script>
var source = new EventSource('/talk');
source.addEventListener('open', function(e) {
// document.getElementById('content').innerHTML += 'Connections to the server established..<br/>';
}, false);
source.onmessage = function(e) {
buildActionsTable(e.data);
// document.getElementById('Actions').innerHTML = e.data;
};
//actInfo bring current action status. for each action: <Action path> <phase> <server class> <status> <target nid> separated by blanks
var prevActInfo = '';
function buildActionsTable(actInfo)
{
if(actInfo == prevActInfo)
return; //Nothing changed
prevActInfo = actInfo;
const items = actInfo.split(';');
const numRows = (items.length-1) / 5;
try{
document.getElementById('ActionsTable').remove();
}catch(e){}
const tbl = document.createElement('table');
tbl.setAttribute('id', 'ActionsTable');
tbl.setAttribute('style', 'width:100%');
const tblBody = document.createElement('tbody');
const head = document.createElement('tr');
const title1 = document.createElement('th');
title1.appendChild(document.createTextNode('Action'));
head.appendChild(title1);
const title2 = document.createElement('th');
title2.appendChild(document.createTextNode('Phase'));
head.appendChild(title2);
const title3 = document.createElement('th');
title3.appendChild(document.createTextNode('Server'));
head.appendChild(title3);
const title4 = document.createElement('th');
title1.appendChild(document.createTextNode('Status'));
head.appendChild(title4);
tbl.appendChild(head);
var itemIdx = 0;
for (var i = 0; i < numRows; i++)
{
const status = items[itemIdx+3];
var color;
if (status == 'Done')
color = 'green';
else if (status == 'Not Dispatched')
color = 'grey';
else if (status == 'Doing')
color = 'blue';
else if (status == 'Doing' || status == 'Streaming')
color = 'blue';
else
color = 'red';
const row = document.createElement('tr');
row.setAttribute('style', 'color:'+color);
if (items[itemIdx] != 'none')
{
row.setAttribute('onclick','doAbort("'+items[itemIdx+4]+';'+items[itemIdx+2]+'")');
}
const actPath = document.createElement('td');
actPath.appendChild( document.createTextNode(items[itemIdx]));
row.appendChild(actPath);
const actPhase = document.createElement('td');
actPhase.appendChild( document.createTextNode(items[itemIdx+1]));
row.appendChild(actPhase);
const actServer = document.createElement('td');
actServer.appendChild( document.createTextNode(items[itemIdx+2]));
row.appendChild(actServer);
const actStatus = document.createElement('td');
actStatus.appendChild( document.createTextNode(items[itemIdx+3]));
row.appendChild(actStatus);
tblBody.appendChild(row);
itemIdx += 5;
}
tbl.appendChild(tblBody);
document.getElementById('Actions').appendChild(tbl);
}
function doAbort(abortInfo)
{
infos = abortInfo.split(';');
if(!confirm('Abort Action '+infos[0]+' on server '+infos[1]+'?'))
return;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
alert("Selected Action Aborted");
}
};
xhttp.open("GET", "/abort;"+abortInfo, true);
xhttp.send();
}
function buildTables()
{
const form = document.getElementById('BuildTables');
var experiment = form.elements['expname'].value;
var shot = form.elements['shot'].value;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("Phases").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/BuildTables:"+experiment+':'+shot, true);
xhttp.send();
}
function doPhase(phase)
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
}
};
xhttp.open("GET", "/DoPhase:"+phase, true);
xhttp.send();
}
</script>
<form id = "BuildTables">
<div>
<label>Experiment:</label>
<input id="expname" type="text">
<label>Shot:</label>
<input id="shot" type="text">
<input id="submit" type="button" onclick = "buildTables()" value = "Build Tables">
</div>
</form>
<div id = "Phases"></div>
<div id = "Actions">
<table id = "ActionsTable"style="width:100%"></table></table>
</div>
</body>
</html>