Merge branch 'master' into prometheus-charts

This commit is contained in:
Milan Pässler 2016-03-29 02:57:28 +02:00
commit e685fe385f
8 changed files with 186 additions and 154 deletions

View file

@ -1,35 +1,9 @@
define(function () {
function showStatImg(o, source, target) {
var content, caption
if (o.thumbnail) {
content = document.createElement("img")
content.src = o.thumbnail.replace("{SOURCE}", source).replace("{TARGET}", target)
}
if (o.caption) {
caption = o.caption.replace("{SOURCE}", source).replace("{TARGET}", target)
if (!content)
content = document.createTextNode(caption)
}
var p = document.createElement("p")
if (o.href) {
var link = document.createElement("a")
link.target = "_blank"
link.href = o.href.replace("{SOURCE}", source).replace("{TARGET}", target)
link.appendChild(content)
if (caption && o.thumbnail)
link.title = caption
p.appendChild(link)
} else
p.appendChild(content)
return p
var subst = {}
subst["{SOURCE}"] = source
subst["{TARGET}"] = target
return showStat(o, subst)
}
return function (config, el, router, d) {

View file

@ -219,37 +219,11 @@ define(["moment", "numeral", "tablesort", "infobox/charts", "tablesort.numeric"]
return au.enabled ? "aktiviert (" + au.branch + ")" : "deaktiviert"
}
function showStatImg(o, nodeId) {
var content, caption
if (o.thumbnail) {
content = document.createElement("img")
content.src = o.thumbnail.replace("{NODE_ID}", nodeId)
}
if (o.caption) {
caption = o.caption.replace("{NODE_ID}", nodeId)
if (!content)
content = document.createTextNode(caption)
}
var p = document.createElement("p")
if (o.href) {
var link = document.createElement("a")
link.target = "_blank"
link.href = o.href.replace("{NODE_ID}", nodeId)
link.appendChild(content)
if (caption && o.thumbnail)
link.title = caption
p.appendChild(link)
} else
p.appendChild(content)
return p
function showStatImg(o, d) {
var subst = {}
subst["{NODE_ID}"] = d.nodeinfo.node_id ? d.nodeinfo.node_id : "unknown"
subst["{NODE_NAME}"] = d.nodeinfo.hostname ? d.nodeinfo.hostname : "unknown"
return showStat(o, subst)
}
return function(config, el, router, d) {
@ -294,7 +268,7 @@ define(["moment", "numeral", "tablesort", "infobox/charts", "tablesort.numeric"]
var h4 = document.createElement("h4")
h4.textContent = nodeInfo.name
el.appendChild(h4)
el.appendChild(showStatImg(nodeInfo, d.nodeinfo.node_id))
el.appendChild(showStatImg(nodeInfo, d))
})
if (d.neighbours.length > 0) {

View file

@ -447,7 +447,10 @@ define(["map/clientlayer", "map/labelslayer",
var lines = addLinksToMap(linkDict, linkScale, data.graph.links, router)
groupLines = L.featureGroup(lines).addTo(map)
barycenter = calcBarycenter(data.nodes.all.filter(has_location))
if (typeof config.fixedCenter === "undefined")
barycenter = calcBarycenter(data.nodes.all.filter(has_location))
else
barycenter = L.circle(L.latLng(new L.LatLng(config.fixedCenter.lat, config.fixedCenter.lng)), config.fixedCenter.radius * 1000)
var nodesOnline = subtract(data.nodes.all.filter(online), data.nodes.new)
var nodesOffline = subtract(data.nodes.all.filter(offline), data.nodes.lost)

View file

@ -23,43 +23,17 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc
var uplinkTable = document.createElement("table")
uplinkTable.classList.add("proportion")
var gwTable = document.createElement("table")
gwTable.classList.add("proportion")
var gwNodesTable = document.createElement("table")
gwNodesTable.classList.add("proportion")
var gwClientsTable = document.createElement("table")
gwClientsTable.classList.add("proportion")
var siteTable = document.createElement("table")
siteTable.classList.add("proportion")
function showStatGlobal(o) {
var content, caption
if (o.thumbnail) {
content = document.createElement("img")
content.src = o.thumbnail
}
if (o.caption) {
caption = o.caption
if (!content)
content = document.createTextNode(caption)
}
var p = document.createElement("p")
if (o.href) {
var link = document.createElement("a")
link.target = "_blank"
link.href = o.href
link.appendChild(content)
if (caption && o.thumbnail)
link.title = caption
p.appendChild(link)
} else
p.appendChild(content)
return p
return showStat(o)
}
function count(nodes, key, f) {
@ -80,6 +54,25 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc
return Object.keys(dict).map(function (d) { return [d, dict[d], key, f] })
}
function countClients(nodes, key, f) {
var dict = {}
nodes.forEach( function (d) {
var v = dictGet(d, key.slice(0))
if (f !== undefined)
v = f(v)
if (v === null)
return
dict[v] = d.statistics.clients + (v in dict ? dict[v] : 0)
})
return Object.keys(dict).map(function (d) { return [d, dict[d], key, f] })
}
function addFilter(filter) {
return function () {
filterManager.addFilter(filter)
@ -137,8 +130,9 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc
var fwDict = count(nodes, ["nodeinfo", "software", "firmware", "release"])
var hwDict = count(nodes, ["nodeinfo", "hardware", "model"])
var geoDict = count(nodes, ["nodeinfo", "location"], function (d) {
return d ? "ja" : "nein"
return d && d.longitude && d.latitude ? "ja" : "nein"
})
var autoDict = count(nodes, ["nodeinfo", "software", "autoupdater"], function (d) {
if (d === null)
return null
@ -147,11 +141,22 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc
else
return "(deaktiviert)"
})
var uplinkDict = count(nodes, ["flags", "uplink"], function (d) {
return d ? "ja" : "nein"
})
var gwDict = count(nodes, ["statistics", "gateway"], function (d) {
var gwNodesDict = count(nodes, ["statistics", "gateway"], function (d) {
if (d === null)
return null
if (d in nodeDict)
return nodeDict[d].nodeinfo.hostname
return d
})
var gwClientsDict = countClients(onlineNodes, ["statistics", "gateway"], function (d) {
if (d === null)
return null
@ -175,71 +180,45 @@ define(["chroma-js", "virtual-dom", "numeral-intl", "filters/genericnode", "verc
fillTable("Firmware", fwTable, fwDict.sort(function (a, b) { return vercomp(b[0], a[0]) }))
fillTable("Hardware", hwTable, hwDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Koordinaten", geoTable, geoDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Autom. Updates", autoTable, autoDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Uplink", uplinkTable, uplinkDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Gewähltes Gateway", gwTable, gwDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Autom. Updates", autoTable, autoDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Nodes an Gateway", gwNodesTable, gwNodesDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Clients an Gateway", gwClientsTable, gwClientsDict.sort(function (a, b) { return b[1] - a[1] }))
fillTable("Site", siteTable, siteDict.sort(function (a, b) { return b[1] - a[1] }))
}
self.render = function (el) {
var h2
h2 = document.createElement("h2")
h2.textContent = "Status"
el.appendChild(h2)
el.appendChild(statusTable)
h2 = document.createElement("h2")
h2.textContent = "Firmwareversionen"
el.appendChild(h2)
el.appendChild(fwTable)
if(config.siteNames || config.showSites) {
h2 = document.createElement("h2")
h2.textContent = "Orte"
el.appendChild(h2)
el.appendChild(siteTable)
}
h2 = document.createElement("h2")
h2.textContent = "Hardwaremodelle"
el.appendChild(h2)
el.appendChild(hwTable)
h2 = document.createElement("h2")
h2.textContent = "Auf der Karte sichtbar"
el.appendChild(h2)
el.appendChild(geoTable)
h2 = document.createElement("h2")
h2.textContent = "Autoupdater"
el.appendChild(h2)
el.appendChild(autoTable)
h2 = document.createElement("h2")
h2.textContent = "Uplink"
el.appendChild(h2)
el.appendChild(uplinkTable)
h2 = document.createElement("h2")
h2.textContent = "Gewählter Gateway"
el.appendChild(h2)
el.appendChild(gwTable)
h2 = document.createElement("h2")
h2.textContent = "Site"
el.appendChild(h2)
el.appendChild(siteTable)
self.renderSingle(el, "Status", statusTable)
self.renderSingle(el, "Nodes an Gateway", gwNodesTable)
self.renderSingle(el, "Clients an Gateway", gwClientsTable)
self.renderSingle(el, "Firmwareversionen", fwTable)
self.renderSingle(el, "Uplink", uplinkTable)
self.renderSingle(el, "Hardwaremodelle", hwTable)
self.renderSingle(el, "Auf der Karte sichtbar", geoTable)
self.renderSingle(el, "Autoupdater", autoTable)
self.renderSingle(el, "Site", siteTable)
if (config.globalInfos)
config.globalInfos.forEach( function (globalInfo) {
h2 = document.createElement("h2")
h2.textContent = globalInfo.name
el.appendChild(h2)
config.globalInfos.forEach(function (globalInfo) {
h2 = document.createElement("h2")
h2.textContent = globalInfo.name
el.appendChild(h2)
el.appendChild(showStatGlobal(globalInfo))
})
}
el.appendChild(showStatGlobal(globalInfo))
})
}
return self
self.renderSingle = function (el, heading, table) {
var h2
h2 = document.createElement("h2")
h2.textContent = heading
h2.onclick = function () {
table.classList.toggle("hidden")
}
el.appendChild(h2)
el.appendChild(table)
}
return self
}
})