var guiList = {}; (function(){ var container; var tbody; var sortReverse = false; var sortIndex; var hostnameFilter,nodeidFilter; function sort(a,b){ function sortNumber(a,b){ return a - b; } if(sortIndex === undefined) return a.node_id.localeCompare(b.node_id); switch (sortIndex.innerHTML) { case "Lastseen": return a.lastseen - b.lastseen; case "CurPower": return a._wireless.txpower24 - b._wireless.txpower24; case "Power": return a.wireless.txpower24 - b.wireless.txpower24; case "CurChannel": return a._wireless.channel24 - b._wireless.channel24; case "Channel": return a.wireless.channel24 - b.wireless.channel24; case "Clients": return a.statistics.clients.wifi24 - b.statistics.clients.wifi24; case "ChanUtil": var aMax = a.statistics.wireless.map(function(d){ return d.ChanUtil }).sort(sortNumber); var bMax = b.statistics.wireless.map(function(d){ return d.ChanUtil }).sort(sortNumber); if(!sortReverse){ aMax = aMax.reverse(); bMax = bMax.reverse(); } return bMax[0] - aMax[0]; case "Hostname": return a.hostname.localeCompare(b.hostname); default: return a.node_id.localeCompare(b.node_id); } } function renderRow(data){ var tr = document.createElement('tr'); var startdate = new Date(); startdate.setMinutes(startdate.getMinutes() - 1); if(new Date(data.lastseen) < startdate) tr.classList.add('offline') var td; domlib.newAt(tr,'td').innerHTML = moment(data.lastseen).fromNow(true); domlib.newAt(tr,'td').innerHTML = data.node_id; domlib.newAt(tr,'td').innerHTML = data.hostname; var freq = domlib.newAt(tr,'td'); domlib.newAt(freq,'span').innerHTML = '2.4 Ghz'; domlib.newAt(freq,'span').innerHTML = '5 Ghz'; var curchannel = domlib.newAt(tr,'td'); domlib.newAt(curchannel,'span').innerHTML = data._wireless.channel24||'-'; domlib.newAt(curchannel,'span').innerHTML = data._wireless.channel5||'-'; var channel = domlib.newAt(tr,'td'); domlib.newAt(channel,'span').innerHTML = data.wireless.channel24||'-'; domlib.newAt(channel,'span').innerHTML = data.wireless.channel5||'-'; var curpower = domlib.newAt(tr,'td'); domlib.newAt(curpower,'span').innerHTML = data._wireless.txpower24||'-'; domlib.newAt(curpower,'span').innerHTML = data._wireless.txpower5||'-'; var power = domlib.newAt(tr,'td'); domlib.newAt(power,'span').innerHTML = data.wireless.txpower24||'-'; domlib.newAt(power,'span').innerHTML = data.wireless.txpower5||'-'; var client = domlib.newAt(tr,'td'); domlib.newAt(client,'span').innerHTML = data.statistics.clients.wifi24; domlib.newAt(client,'span').innerHTML = data.statistics.clients.wifi5; var chanUtil = domlib.newAt(tr,'td'); var chanUtil24 = data.statistics.wireless.filter(function(d){ return d.frequency < 5000; })[0]; var chanUtil5 = data.statistics.wireless.filter(function(d){ return d.frequency > 5000; })[0]; domlib.newAt(chanUtil,'span').innerHTML = chanUtil24.ChanUtil||'-'; domlib.newAt(chanUtil,'span').innerHTML = chanUtil5.ChanUtil||'-'; var option = domlib.newAt(tr,'td'); edit = domlib.newAt(option,'div'); edit.classList.add('btn'); edit.innerHTML = 'Edit'; edit.addEventListener('click',function(){ router.navigate(router.generate('node', { nodeID: data.node_id })); }); return tr; } function updateTable(){ domlib.removeChildren(tbody); var data = store.will(); if(hostnameFilter && hostnameFilter.value != "") data = data.filter(function(d){ return d.hostname.toLowerCase().indexOf(hostnameFilter.value) > -1; }) if(nodeidFilter && nodeidFilter.value != "") data = data.filter(function(d){ return d.node_id.indexOf(nodeidFilter.value) > -1; }) data = data.sort(sort); if(sortReverse) data = data.reverse(); for(var i=0; i