Red/green/yellow dot to tell slave status on /nodeDetails/

This commit is contained in:
Danielv123 committed 2017-05-26 09:06:04 +02:00
1 parent 74348be0a8
commit b520d9611b
1 file changed
+23
+23
View File
@@ -12,6 +12,7 @@ function post(url, data, callback) {
} }
xhr.send(JSON.stringify(data)); xhr.send(JSON.stringify(data));
} }
// callback(err, json)
function getJSON(url, callback) { function getJSON(url, callback) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open('GET', url, true); xhr.open('GET', url, true);
@@ -24,6 +25,10 @@ function getJSON(url, callback) {
callback(status); callback(status);
} }
}; };
// triggers if connection is refused
xhr.onerror = function(e){
callback(e);
};
xhr.send(); xhr.send();
}; };
// function to sort arrays of objects after a keys value // function to sort arrays of objects after a keys value
@@ -43,6 +48,24 @@ function getParameterByName(name, url) {
return decodeURIComponent(results[2].replace(/\+/g, " ")); return decodeURIComponent(results[2].replace(/\+/g, " "));
} }
/// code below here
// update the online indicator dot
setInterval(function(){
getJSON("/api/slaves", function(err, slaveData){
if(err){
document.querySelector("#onlineIndicator").style.backgroundColor = "yellow";
// compare with Math.floor(x/100000) allows us to check if they are within 10s of each other
} else if(Math.floor(slaveData[getParameterByName("slaveID")].time/100000) == Math.floor(Date.now()/100000)){
document.querySelector("#onlineIndicator").style.backgroundColor = "green";
} else {
document.querySelector("#onlineIndicator").style.backgroundColor = "red";
}
});
}, 1000);
function populateSlaveInfo(){ function populateSlaveInfo(){
let slaveID = getParameterByName("slaveID"); let slaveID = getParameterByName("slaveID");
if(!slaveID){ if(!slaveID){