-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
177 lines (166 loc) · 5.98 KB
/
index.html
File metadata and controls
177 lines (166 loc) · 5.98 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html>
<head>
<title>Bees!</title>
<!-- jquery -->
<script src="static/jquery-3.4.0.min.js"></script>
<script>
set_worker_state = function(hostname, new_state) {
$.ajax({
url: "worker",
type: "POST",
dataType: "json",
data: {hostname: hostname, new_state: new_state}});
};
get_worker_info = function() {
$.ajax({
url: "worker",
type: "POST",
dataType: "json",
}).done(new_worker_info);
};
fn_to_date = function(fn) {
if (fn == null) return new Date(0);
if (fn.length == 0) return new Date(0);
tokens = fn.split('/').pop().split('.')[0].split('_');
s = "20" + tokens[0].substring(0, 2) + "-"
+ tokens[0].substring(2, 4) + "-"
+ tokens[0].substring(4, 6) + "T"
+ tokens[1].substring(0, 2) + ":"
+ tokens[1].substring(2, 4);
var d = new Date(s);
return d
};
new_worker_info = function(json) {
// update document given new worker info
wul = $("ul#worker_list");
Object.keys(json)
.sort(function(a, b){
return parseInt(a.substring(6)) - parseInt(b.substring(6));
})
.forEach(function(hostname, i) {
// check if worker already listed
li = $("li#" + hostname);
if (li.length == 0) {
wul.append($("<li>").append().attr("id", hostname));
li = $("li#" + hostname);
li.append($("<img>"));
li.append($("<a>"));
li.append($("<span>"));
li.append(
$('<button>').on('click', function() {
set_worker_state(hostname, "recording");
}).text("Record").attr("class", "record_button"));
li.append(
$('<button>').on('click', function() {
set_worker_state(hostname, "continuous");
}).text("Continuous").attr("class", "continuous_button"));
li.append(
$('<button>').on('click', function() {
set_worker_state(hostname, "idle");
}).text("Stop").attr("class", "stop_button"));
};
//li.empty();
// update list item
state = json[hostname]['state'];
newest_filename = json[hostname]['newest_filename'];
transfer_duration = json[hostname]['transfer_duration'];
transfer_info = json[hostname]['transfer_info'];
var fnd = fn_to_date(newest_filename);
var d = new Date(0);
d.setUTCSeconds(state.timestamp);
var tt = new Date(0);
if (transfer_info['start'] != undefined) {
tt.setUTCSeconds(transfer_info['start']);
} else {
tt.setUTCSeconds(0);
};
// if tt, fnd, or d is more than ~5 min old, make them red
var cd = new Date();
if (
Math.max(
Math.abs(cd - d),
Math.abs(tt - d),
Math.abs(fnd - d)) >
(5 * 60 * 1000)) {
txt_color = "red";
} else {
txt_color = "black";
};
li.children("img").attr("src", "/static/" + hostname + ".jpg?" + new Date().getTime());
li.children("a").text(hostname).attr("href", "/static/" + hostname + ".h264");
li.children("span").text(
": " + state.state + " @ " +
d + " [disk:" + state.df + "] last transfer @" +
tt + " [took:" + transfer_duration + "] newest video: " +
newest_filename).css("color", txt_color);
// add config button
// TODO show/hide buttons by state
if (state.state == "idle") {
//li.children(".stream_button").show();
li.children(".record_button").show();
li.children(".continuous_button").show();
li.children(".stop_button").hide();
} else {
//li.children(".stream_button").hide();
li.children(".continuous_button").hide();
li.children(".record_button").hide();
li.children(".stop_button").show();
};
});
};
get_queen_info = function() {
$.ajax({
url: "queen",
type: "POST",
dataType: "json",
}).done(new_queen_info);
};
new_queen_info = function(json) {
// display transfer information
q = $("div#queen_info");
q.empty();
// display last_transfer details
var tt;
if (json.transfer_info.last_transfer.time == null) {
tt = null;
} else {
tt = new Date(0);
tt.setUTCSeconds(json.transfer_info.last_transfer.time);
};
q.append(
$("<p>").text(
"Last transfer at " + tt + " took " +
json.transfer_info.last_transfer.duration + " seconds"));
// display space left on disk
q.append(
$("<p>").text(
"Disk space on queen: total: " + json.transfer_info.space.total +
" used: " + json.transfer_info.space.used + "[" + json.transfer_info.space.percent_used + "]"));
// add force transfer button
q.append(
$("<button>").on('click', function() {
$.ajax({url: "queen", type: "POST", data: {"transfer": true}})
.done(get_queen_info);
}).text("Transfer videos"));
// display errors
$("#queen_errors").text(JSON.stringify(json.errors));
};
$(document).ready(function() {
// get worker info from queen
get_worker_info();
get_queen_info();
window.setInterval(get_worker_info, 1000);
window.setInterval(get_queen_info, 5000);
});
</script>
</head>
<body>
<!-- queen info -->
<div id="queen_info"></div>
<ul id="worker_list">
<!-- workers will get added here -->
</ul>
<div id="queen_errors"></div>
</body>
</html>