2018-11-28 15:38:35 +00:00
|
|
|
function timeSince(obj) {
|
|
|
|
last = new Date(obj)
|
|
|
|
var seconds = Math.floor((new Date() - last) / 1000);
|
|
|
|
interval = Math.floor(seconds / 3600);
|
|
|
|
out = "";
|
|
|
|
|
|
|
|
if (interval > 24) return "at " + last.toDateString().substr(4) + " " + last.toLocaleTimeString();
|
|
|
|
if (interval > 1) out = interval + " hours ";
|
|
|
|
|
|
|
|
interval = Math.floor(seconds / 60);
|
|
|
|
|
|
|
|
if (seconds < 120) out = seconds + " seconds "
|
|
|
|
else if (interval > 1) out = out + interval + " minutes ";
|
|
|
|
|
|
|
|
return out + "ago"
|
|
|
|
}
|
|
|
|
|
|
|
|
function styleStatus(msg, device) {
|
|
|
|
device_status = $("#" + device + "-indicator");
|
|
|
|
device_ip = $("#" + device + "-ip");
|
|
|
|
|
|
|
|
device_status.css("color", msg.status == 1 ? "green" : (msg.status == 0 ? "red" : "grey"))
|
|
|
|
|
|
|
|
if (msg.hasOwnProperty("ip")) {
|
|
|
|
device_ip.text(msg.ip + (msg.status == 1 ? "" :" (" + timeSince(msg.time) + ")"));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
function updateStatus(device_id) {
|
|
|
|
$.getJSON( "/devices/" + device_id + "/ping/", function(json) { styleStatus(json, device_id); });
|
|
|
|
};
|
2018-11-28 21:35:57 +00:00
|
|
|
|
|
|
|
function askdelete(device_id) {
|
|
|
|
if (confirm("Are you sure you want to delete this device?")) window.location.href = "/devices/" + device_id + "/delete";
|
|
|
|
};
|
|
|
|
|
|
|
|
function askreboot(device_id) {
|
|
|
|
if (confirm("Are you sure you want to reboot this device?")) window.location.href = "/devices/" + device_id + "/reboot";
|
|
|
|
};
|