freifunkmanager/js/controller/aliases.js

141 lines
5.0 KiB
JavaScript
Raw Normal View History

2016-07-02 10:23:33 +02:00
define(["tablesort", "tablesort.numeric"],function(){
2016-07-02 02:11:17 +02:00
var data;
return function(el,map){
var title = document.createElement("h1"),
table = document.createElement("table"),
thead = document.createElement("thead"),
2016-07-02 10:23:33 +02:00
tbody = document.createElement("tbody"),
sort;
2016-07-02 02:11:17 +02:00
title.textContent = "Undone Changes";
table.appendChild(thead);
table.appendChild(tbody);
table.classList.add("table");
2016-07-02 10:23:33 +02:00
thead.innerHTML = "<tr><th>Node</th><th class=\"no-sort\">Freq</th><th>Channel</th><th>Power</th><th>Location</th></tr>";
console.log(Tablesort);
var toChangeIcon = function(el){
var icon = document.createElement("i");
icon.classList.add("icon");
icon.textContent = "\uf096";
el.appendChild(icon);
};
2016-07-02 02:11:17 +02:00
var row = function(nodeid,alias,node){
2016-07-02 10:23:33 +02:00
var icon,td,split1,split2,text,
2016-07-02 02:11:17 +02:00
tr = document.createElement("tr");
//Node
td = document.createElement("td");
td.classList.add("text");
if(alias.hostname && alias.hostname != node.nodeinfo.hostname){
2016-07-02 10:23:33 +02:00
toChangeIcon(td);
2016-07-02 02:11:17 +02:00
}
td.appendChild(document.createTextNode((alias.hostname)?alias.hostname:node.nodeinfo.hostname));
2016-07-02 10:23:33 +02:00
text = document.createElement("small");
text.textContent = nodeid;
td.appendChild(text);
2016-07-02 02:11:17 +02:00
tr.appendChild(td);
td = document.createElement("td");
td.classList.add("split");
2016-07-02 10:23:33 +02:00
var freq24 = document.createElement("span");
freq24.textContent = "2.4 Ghz";
var freq5 = document.createElement("span");
freq5.textContent = "5 Ghz";
2016-07-02 02:11:17 +02:00
td.appendChild(freq24);
td.appendChild(freq5);
tr.appendChild(td);
td = document.createElement("td");
td.classList.add("split");
2016-07-02 10:23:33 +02:00
split1 = document.createElement("span");
split2 = document.createElement("span");
text = document.createTextNode((alias && alias.wireless !== undefined && alias.wireless.channel24)?alias.wireless.channel24:((node.nodeinfo.wireless && node.nodeinfo.wireless.channel24)?node.nodeinfo.wireless.channel24:'-'));
if(alias && alias.wireless !== undefined && alias.wireless.channel24 &&
node.nodeinfo.wireless && node.nodeinfo.wireless.channel24 &&
alias.wireless.channel24 != node.nodeinfo.wireless.channel24){
toChangeIcon(text);
}
split1.appendChild(text);
text = document.createTextNode((alias && alias.wireless !== undefined && alias.wireless.channel5)?alias.wireless.channel5:((node.nodeinfo.wireless && node.nodeinfo.wireless.channel5)?node.nodeinfo.wireless.channel5:'-'));
if(alias && alias.wireless !== undefined && alias.wireless.channel5 &&
node.nodeinfo.wireless && node.nodeinfo.wireless.channel5 &&
alias.wireless.channel5 != node.nodeinfo.wireless.channel5){
toChangeIcon(text);
}
split2.appendChild(text);
td.appendChild(split1);
td.appendChild(split2);
2016-07-02 02:11:17 +02:00
tr.appendChild(td);
td = document.createElement("td");
2016-07-02 10:23:33 +02:00
td.classList.add("split");
split1 = document.createElement("span");
split2 = document.createElement("span");
text = document.createTextNode((alias && alias.wireless !== undefined && alias.wireless.txpower24)?alias.wireless.txpower24:((node.nodeinfo.wireless && node.nodeinfo.wireless.txpower24)?node.nodeinfo.wireless.txpower24:'-'));
if(alias && alias.wireless !== undefined && alias.wireless.txpower24 &&
node.nodeinfo.wireless && node.nodeinfo.wireless.txpower24 &&
alias.wireless.txpower24 != node.nodeinfo.wireless.txpower24){
toChangeIcon(text);
}
split1.appendChild(text);
text = document.createTextNode((alias && alias.wireless !== undefined && alias.wireless.txpower5)?alias.wireless.txpower5:((node.nodeinfo.wireless && node.nodeinfo.wireless.txpower5)?node.nodeinfo.wireless.txpower5:'-'));
if(alias && alias.wireless !== undefined && alias.wireless.txpower5 &&
node.nodeinfo.wireless && node.nodeinfo.wireless.txpower5 &&
alias.wireless.txpower5 != node.nodeinfo.wireless.txpower5){
toChangeIcon(text);
}
split2.appendChild(text);
td.appendChild(split1);
td.appendChild(split2);
2016-07-02 02:11:17 +02:00
tr.appendChild(td);
//Location
td = document.createElement("td");
if(alias.location !== undefined &&
node.nodeinfo.location !== undefined &&
node.nodeinfo.location.latitude != alias.location.latitude &&
node.nodeinfo.location.longitude != alias.location.longitude
){
2016-07-02 10:23:33 +02:00
toChangeIcon(td);
2016-07-02 02:11:17 +02:00
}
td.classList.add("text");
icon = document.createElement("i");
icon.classList.add("icon");
icon.textContent = "\uf124";
icon.onclick = function () {
window.location.href = "#map/"+nodeid;
map.render(nodeid);
};
td.appendChild(icon);
tr.appendChild(td);
tbody.appendChild(tr);
2016-07-02 10:23:33 +02:00
if(sort === undefined)
sort = new Tablesort(table);
sort.refresh();
2016-07-02 02:11:17 +02:00
};
var render = function() {
tbody.textContent = "";
if(data !== undefined)
Object.keys(data.aliases).map(function(key){
row(key,data.aliases[key],data.nodes[key]);
});
};
return {
storageNotify: function(d){
data = d;
render();
},
controller: function(){
el.textContent = "";
el.appendChild(title);
el.appendChild(table);
render();
}
};
};
});