mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Red/green/yellow dot to tell slave status on /nodeDetails/
This commit is contained in:
1 parent
74348be0a8
commit
b520d9611b
1 file changed
+35
-12
+35
-12
@@ -12,19 +12,24 @@ function post(url, data, callback) {
|
||||
}
|
||||
xhr.send(JSON.stringify(data));
|
||||
}
|
||||
// callback(err, json)
|
||||
function getJSON(url, callback) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'json';
|
||||
xhr.onload = function() {
|
||||
var status = xhr.status;
|
||||
if (status == 200) {
|
||||
callback(null, xhr.response);
|
||||
} else {
|
||||
callback(status);
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'json';
|
||||
xhr.onload = function() {
|
||||
var status = xhr.status;
|
||||
if (status == 200) {
|
||||
callback(null, xhr.response);
|
||||
} else {
|
||||
callback(status);
|
||||
}
|
||||
};
|
||||
// triggers if connection is refused
|
||||
xhr.onerror = function(e){
|
||||
callback(e);
|
||||
};
|
||||
xhr.send();
|
||||
};
|
||||
// function to sort arrays of objects after a keys value
|
||||
function sortByKey(array, key) {
|
||||
@@ -43,6 +48,24 @@ function getParameterByName(name, url) {
|
||||
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(){
|
||||
let slaveID = getParameterByName("slaveID");
|
||||
if(!slaveID){
|
||||
|
||||
Reference in new issue
Block a user