generate nodeslist in javascript

This commit is contained in:
Nils Schneider 2015-03-23 00:10:09 +01:00
parent 13faaf5869
commit c5edef700e
2 changed files with 18 additions and 16 deletions

View File

@ -278,18 +278,6 @@
<p id="timestamp"> <p id="timestamp">
</p> </p>
<h2>Neue Knoten</h2>
<table>
<tbody id="newnodes">
</tbody>
</table>
<h2>Verschwundene Knoten</h2>
<table>
<tbody id="lostnodes">
</tbody>
</table>
</div> </div>
</div> </div>
</div> </div>

View File

@ -164,8 +164,8 @@ function handle_data(config, map) {
gotoAnything.addMarkers(markers) gotoAnything.addMarkers(markers)
addToList(document.getElementById("newnodes"), config.showContact, "firstseen", gotoAnything.node, newnodes) mkNodesList(document.getElementById("sidebardata"), config.showContact, "firstseen", gotoAnything.node, "Neue Knoten", newnodes)
addToList(document.getElementById("lostnodes"), config.showContact, "lastseen", gotoAnything.node, lostnodes) mkNodesList(document.getElementById("sidebardata"), config.showContact, "lastseen", gotoAnything.node, "Verschwundene Knoten", lostnodes)
mkLinkList(document.getElementById("sidebardata"), gotoAnything.link, links) mkLinkList(document.getElementById("sidebardata"), gotoAnything.link, links)
showMeshstats(document.getElementById("meshstats"), nodes) showMeshstats(document.getElementById("meshstats"), nodes)
@ -389,7 +389,18 @@ function mkLinkList(el, gotoProxy, links) {
el.appendChild(table) el.appendChild(table)
} }
function addToList(el, showContact, tf, gotoProxy, list) { function mkNodesList(el, showContact, tf, gotoProxy, title, list) {
if (list.length == 0)
return
var h2 = document.createElement("h2")
h2.textContent = title
el.appendChild(h2)
var table = document.createElement("table")
el.appendChild(table)
var tbody = document.createElement("tbody")
list.forEach( function (d) { list.forEach( function (d) {
var time = moment(d[tf]).fromNow() var time = moment(d[tf]).fromNow()
@ -420,8 +431,11 @@ function addToList(el, showContact, tf, gotoProxy, list) {
row.appendChild(td1) row.appendChild(td1)
row.appendChild(td2) row.appendChild(td2)
el.appendChild(row) tbody.appendChild(row)
}) })
table.appendChild(tbody)
el.appendChild(table)
} }
function sum(a) { function sum(a) {