2019-09-22 03:11:19 +02:00
|
|
|
requirejs.config({
|
|
|
|
paths: {
|
|
|
|
'socket.io': 'https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io',
|
|
|
|
'jquery': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min',
|
|
|
|
},
|
|
|
|
waitSeconds: 3
|
|
|
|
});
|
|
|
|
|
|
|
|
require(['jquery', 'socket.io'], function(jq, io) {
|
|
|
|
|
|
|
|
function getDurationString(link_data) {
|
|
|
|
// Print time diff in following format
|
|
|
|
// 1s
|
|
|
|
// 11s
|
|
|
|
// 1:11s
|
|
|
|
// 1:01s
|
|
|
|
let duration = new Date((link_data["handoff"] - link_data["start"]) * 1000);
|
|
|
|
let minutes = duration.getMinutes();
|
|
|
|
let seconds = minutes > 0 ? (duration.getSeconds() > 9 ? duration.getSeconds() : "0" + duration.getSeconds()) : duration.getSeconds();
|
|
|
|
let durationString = (minutes > 0 ? (minutes + "m") : "") + seconds + "s";
|
|
|
|
return durationString;
|
|
|
|
}
|
2019-09-20 17:16:45 +02:00
|
|
|
|
2019-09-20 23:50:13 +02:00
|
|
|
|
2019-09-22 03:11:19 +02:00
|
|
|
$(function() {
|
|
|
|
const socket = io('localhost:5000');
|
|
|
|
socket.on('start_run', function(run_index) {});
|
|
|
|
|
|
|
|
socket.on('link_start', function(link_data) {
|
|
|
|
addLink(link_data["id"], link_data);
|
|
|
|
});
|
|
|
|
socket.on('link_handoff', function(link_data) {
|
|
|
|
stop = new Date(link_data["handoff"] * 1000);
|
|
|
|
let stopString = stop.getHours() + ":" + stop.getMinutes();
|
|
|
|
|
|
|
|
$(`#link-${link_data["id"]} .link-status`).css("color", "green").removeClass("fa-question").addClass("fa-check");
|
|
|
|
$(`#link-${link_data["id"]} .link-time`).text(`Time: ${getDurationString(link_data)}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('sync_current_run', function(run_data) {
|
|
|
|
$('#current_run>div:gt(0)').remove();
|
|
|
|
for (link_id in run_data["data"]) {
|
|
|
|
addLink(link_id, run_data["data"][link_id]);
|
|
|
|
}
|
|
|
|
});
|
2019-09-23 18:21:28 +02:00
|
|
|
socket.on('live_request', function(request_data) {
|
2019-09-26 17:47:25 +02:00
|
|
|
console.log("live request");
|
2019-09-23 18:21:28 +02:00
|
|
|
request_time = new Date(request_data["time"] * 1000);
|
|
|
|
addLiveRequest(request_data["hostname"], request_time);
|
|
|
|
});
|
2019-09-20 17:16:45 +02:00
|
|
|
});
|
2019-09-22 03:11:19 +02:00
|
|
|
|
2019-09-23 18:21:28 +02:00
|
|
|
function addLiveRequest(request_host, request_time) {
|
|
|
|
alert("yes");
|
|
|
|
let hostname = request_host;
|
|
|
|
let timesting = request_time.getHours() + ":" + request_time.getMinutes();
|
|
|
|
|
|
|
|
let html = `
|
|
|
|
<div class="item">
|
|
|
|
<div>
|
|
|
|
${hostname}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
${timesting}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
$('#live_requests').prepend($(html));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-22 03:11:19 +02:00
|
|
|
function addLink(link_id, link_data) {
|
2019-09-22 03:16:48 +02:00
|
|
|
let stop = "handoff" in link_data;
|
2019-09-22 03:11:19 +02:00
|
|
|
|
2019-09-22 03:16:48 +02:00
|
|
|
let time = (stop ? "Time: " + getDurationString(link_data) : "Running");
|
|
|
|
let icon = (stop ? "check" : "question");
|
|
|
|
let style = (stop ? "style=\"color:green\"" : "");
|
2019-09-22 03:11:19 +02:00
|
|
|
let html = `
|
|
|
|
<div id='link-${link_id}' class="item">
|
|
|
|
<div>${link_id}</div>
|
2019-09-22 03:16:48 +02:00
|
|
|
<div class="link-time">${time}</div>
|
2019-09-22 03:11:19 +02:00
|
|
|
<div>
|
2019-09-22 03:16:48 +02:00
|
|
|
<i class="link-status fas fa-${icon}" ${style}></i>
|
2019-09-22 03:11:19 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
$('#current_run').append($(html));
|
|
|
|
}
|
2019-09-20 17:16:45 +02:00
|
|
|
});
|