diff --git a/static/index.html b/static/index.html index c734eedf..4386f494 100644 --- a/static/index.html +++ b/static/index.html @@ -20,6 +20,9 @@ +
@@ -35,5 +38,11 @@
+
+

Slaves

+
+ +
+
\ No newline at end of file diff --git a/static/main.js b/static/main.js index c2bb3b98..56342d91 100644 --- a/static/main.js +++ b/static/main.js @@ -95,22 +95,24 @@ function drawcharts() { } // this is ugly, don't judge me var updateData = function(oldData){ - //console.log(piedata) - var labels = oldData["labels"]; - var dataSetA = oldData["datasets"][0]["data"]; - var dataSetB = oldData["datasets"][1]["data"]; - - labels.shift(); - count++; - labels.push(count.toString()); - // this is where we generate new data - var newDataA = piedata[0].value - piedataOld[0].value; - var newDataB = piedata[1].value - piedataOld[1].value; - // not quite sure how this works, where is dataSetA placed in data/the graph? - dataSetA.push(newDataA); - dataSetB.push(newDataB); - dataSetA.shift(); - dataSetB.shift(); + if(piedataOld[0]){ + //console.log(piedata) + var labels = oldData["labels"]; + var dataSetA = oldData["datasets"][0]["data"]; + var dataSetB = oldData["datasets"][1]["data"]; + + labels.shift(); + count++; + labels.push(count.toString()); + // this is where we generate new data + var newDataA = piedata[0].value - piedataOld[0].value; + var newDataB = piedata[1].value - piedataOld[1].value; + // not quite sure how this works, where is dataSetA placed in data/the graph? + dataSetA.push(newDataA); + dataSetB.push(newDataB); + dataSetA.shift(); + dataSetB.shift(); + } }; // Not sure why the scaleOverride isn't working... @@ -144,7 +146,9 @@ setTimeout(function(){ drawcharts(); },10) -var piedata = false; +var piedata = {}; +var piedataOld = {}; +// get cluster inventory from master setInterval(function() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { @@ -181,6 +185,30 @@ setInterval(function() { xmlhttp.open("GET", "inventory", true); xmlhttp.send(); }, 500) +// get all slaves recently connected to master +Date.prototype.yyyymmdd = function() { // http://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object + var mm = this.getMonth() + 1; // getMonth() is zero-based + var dd = this.getDate(); + return [this.getFullYear(), !mm[1] && '0', mm, !dd[1] && '0', dd].join(''); // padding +}; +var date = new Date(); +setInterval(function() { + var xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = function() { + if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { + var slaveData = JSON.parse(xmlhttp.responseText); + var HTML = "

Latest connections:

" + for(i=0;i

Last seen: "+date.yyyymmdd(slaveData[key].time)+"

Port: "+slaveData[key].serverPort+"

Host: "+slaveData[key].mac+"

" + } + document.querySelector("#slaves > #display").innerHTML = HTML + } + } + xmlhttp.open("GET", "slaves", true); + xmlhttp.send(); +}, 500) // image data // key is the name of the item in the database, value is the name of the image on wiki.factorio.com/images/* diff --git a/static/style.css b/static/style.css index 995fcd40..ccb4648b 100644 --- a/static/style.css +++ b/static/style.css @@ -30,6 +30,22 @@ #contentGraph { float:left; } +/* Slave stuff */ +.slaveBox { + float:left; + width:200px; + height:110px; + background-color:#EEE; + border-radius: 10px; + margin-left:5px; + margin-right:5px; +} +.slaveBox > p { + margin:5px; +} +.slaveBox > h2 { + margin:5px; +} .button-black { width:100%; height:40px;