Move all Javascript to static

This commit is contained in:
Kumi 2019-01-13 17:28:52 +01:00
parent a81d1211b1
commit 5c6121e630
2 changed files with 21 additions and 22 deletions

View file

@ -90,13 +90,4 @@
<script src="/js/devices.js"></script>
<script>
showdevices();
{% for device in devices %}
updateStatus({{ device.id }});
setInterval(updateStatus, 10000, {{ device.id }});
{% endfor %}
</script>
{% endblock %}

View file

@ -1,18 +1,18 @@
function timeSince(obj) {
last = new Date(obj)
var seconds = Math.floor((new Date() - last) / 1000);
interval = Math.floor(seconds / 3600);
out = "";
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 ";
if (interval > 24) return "at " + last.toDateString().substr(4) + " " + last.toLocaleTimeString();
if (interval > 1) out = interval + " hours ";
interval = Math.floor(seconds / 60);
interval = Math.floor(seconds / 60);
if (seconds < 120) out = seconds + " seconds "
else if (interval > 1 && interval < 120) out = out + interval + " minutes ";
if (seconds < 120) out = seconds + " seconds "
else if (interval > 1 && interval < 120) out = out + interval + " minutes ";
return out + "ago"
return out + "ago"
}
function styleStatus(msg, device) {
@ -78,7 +78,15 @@ function showwifi() {
};
function showusers() {
$("#devicespart").hide();
$("#wifipart").hide();
$("#userpart").show();
$("#devicespart").hide();
$("#wifipart").hide();
$("#userpart").show();
};
showdevices();
$("div[id$='-indicator']").each(function() {
device_id = this.id.split("-")[0];
updateStatus(device_id);
setInterval(updateStatus, 10000, device_id);
});