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 "
|
2018-12-15 11:35:00 +00:00
|
|
|
else if (interval > 1 && interval < 120) out = out + interval + " minutes ";
|
2018-11-28 15:38:35 +00:00
|
|
|
|
|
|
|
return out + "ago"
|
|
|
|
}
|
|
|
|
|
|
|
|
function styleStatus(msg, device) {
|
|
|
|
device_status = $("#" + device + "-indicator");
|
|
|
|
device_ip = $("#" + device + "-ip");
|
2018-12-15 11:35:00 +00:00
|
|
|
device_network = $("#" + device + "-network");
|
|
|
|
device_name = $("#" + device + "-name");
|
|
|
|
device_id = $("#" + device + "-id");
|
2018-11-28 15:38:35 +00:00
|
|
|
|
2018-12-15 11:35:00 +00:00
|
|
|
device_status.css("color", msg.status == 1 ? "green" : (msg.status == 0 ? ((new Date(msg.lastbeat) < new Date(msg.time) && (new Date() - new Date(msg.lastbeat) < 60)) ? "yellow" : "red") : "grey"));
|
2018-11-28 15:38:35 +00:00
|
|
|
|
|
|
|
if (msg.hasOwnProperty("ip")) {
|
|
|
|
device_ip.text(msg.ip + (msg.status == 1 ? "" :" (" + timeSince(msg.time) + ")"));
|
|
|
|
};
|
2018-12-15 11:35:00 +00:00
|
|
|
|
|
|
|
if (msg.hasOwnProperty("network")) {
|
2019-01-05 15:08:19 +00:00
|
|
|
device_network.text(msg.network.intip + " (" + msg.network.name + ")");
|
2018-12-15 11:35:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (msg.hasOwnProperty("reboot")) {
|
|
|
|
device_id.css("font-style", msg.reboot == 1 ? "italic" : "normal")
|
|
|
|
};
|
|
|
|
|
2018-12-26 01:24:36 +00:00
|
|
|
if (msg.hasOwnProperty("update")) {
|
|
|
|
device_id.css("font-weight", msg.update == 1 ? "bold" : "normal")
|
|
|
|
};
|
|
|
|
|
2018-12-15 11:35:00 +00:00
|
|
|
if (msg.hasOwnProperty("name")) {
|
|
|
|
device_name.text(msg.name);
|
|
|
|
};
|
2018-11-28 15:38:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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";
|
|
|
|
};
|
|
|
|
|
2019-01-06 18:15:13 +00:00
|
|
|
function askdeletewifi(wifi_id) {
|
|
|
|
if (confirm("Are you sure you want to delete this WiFi?")) window.location.href = "/wifi/" + wifi_id + "/delete";
|
|
|
|
};
|
|
|
|
|
2018-11-28 21:35:57 +00:00
|
|
|
function askreboot(device_id) {
|
|
|
|
if (confirm("Are you sure you want to reboot this device?")) window.location.href = "/devices/" + device_id + "/reboot";
|
|
|
|
};
|
2018-12-15 11:35:00 +00:00
|
|
|
|
|
|
|
function downloadnotice() {
|
|
|
|
alert("Your file is being prepared. This will take a minute, please be patient and do not leave this page. The download will start automatically.");
|
|
|
|
};
|
2019-01-13 10:48:05 +00:00
|
|
|
|
|
|
|
function showdevices() {
|
|
|
|
$("#devicespart").show();
|
|
|
|
$("#wifipart").hide();
|
|
|
|
};
|
|
|
|
|
|
|
|
function showwifi() {
|
|
|
|
$("#devicespart").hide();
|
|
|
|
$("#wifipart").show();
|
|
|
|
};
|