Router pics (#37)
* add a padding to sidebar for better use on mobile devices * allow other things as text in attributeEntry Now it is possible to use pictures and other stuff in this function * Show Router-Pic with double fallback 3 Möglichkeiten 1. in config wird externe Quelle angegeben 2. wenn nicht wird in ./nodes/ geseucht 3. ansonsten Knotenname + Knotenname in erster Zeile extern via: cdn "hwImg": [ { "thumbnail": "https://cdn.rawgit.com/Moorviper/meshviewer_hwpics/master/nodes/{MODELHASH}.svg", "caption": "Knoten {MODELHASH}" } ] aktueller nicht cdn: "hwImg": [ { "thumbnail": "https://rawgit.com/Moorviper/meshviewer_hwpics/master/nodes/{MODELHASH}.svg", "caption": "Knoten {MODELHASH}" } ]
This commit is contained in:
parent
f80ea1ca8f
commit
8435885e5c
4 changed files with 152 additions and 4 deletions
lib/infobox
|
@ -293,6 +293,40 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
|
|||
return au.enabled ? "aktiviert (" + au.branch + ")" : "deaktiviert"
|
||||
}
|
||||
|
||||
function showNodeImg(o, model) {
|
||||
if (!model)
|
||||
return undefined
|
||||
|
||||
var content, caption
|
||||
var modelhash = model.split("").reduce(function(a, b) {
|
||||
a = ((a << 5) - a) + b.charCodeAt(0)
|
||||
return a & a
|
||||
}, 0)
|
||||
|
||||
if (o.thumbnail) {
|
||||
content = document.createElement("img")
|
||||
content.id = "routerpicture"
|
||||
content.classList.add("nodeImg")
|
||||
content.src = o.thumbnail.replace("{MODELHASH}", modelhash)
|
||||
content.onerror = function() {
|
||||
console.log("Router-Bild nicht vorhanden !!! create an issue @ https://github.com/Moorviper/Freifunk-Router-Anleitungen/issues")
|
||||
document.getElementById("routerpicdiv").outerHTML = "Knotenname"
|
||||
}
|
||||
}
|
||||
|
||||
if (o.caption) {
|
||||
caption = o.caption.replace("{MODELHASH}", modelhash)
|
||||
|
||||
if (!content)
|
||||
content = document.createTextNode(caption)
|
||||
}
|
||||
|
||||
var p = document.createElement("p")
|
||||
p.appendChild(content)
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
function showStatImg(o, d) {
|
||||
var subst = {}
|
||||
subst["{NODE_ID}"] = d.nodeinfo.node_id ? d.nodeinfo.node_id : "unknown"
|
||||
|
@ -301,13 +335,44 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
|
|||
}
|
||||
|
||||
return function(config, el, router, d) {
|
||||
var h2 = document.createElement("h2")
|
||||
h2.textContent = d.nodeinfo.hostname
|
||||
el.appendChild(h2)
|
||||
var top = document.createElement("div")
|
||||
top.id = "routerpicdiv"
|
||||
try {
|
||||
if (config.hwImg)
|
||||
config.hwImg.forEach(function(hwImg) {
|
||||
try {
|
||||
top.appendChild(showNodeImg(hwImg, d.nodeinfo.hardware.model))
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err.message)
|
||||
}
|
||||
})
|
||||
|
||||
else
|
||||
{
|
||||
var localpic = [] // create fallback-config-data
|
||||
localpic.push({
|
||||
thumbnail: "./nodes/{MODELHASH}.svg",
|
||||
caption: "Knoten {MODELHASH}"
|
||||
})
|
||||
localpic.forEach(function(localpic) {
|
||||
try {
|
||||
top.appendChild(showNodeImg(localpic, d.nodeinfo.hardware.model))
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err.message)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err.message)
|
||||
}
|
||||
|
||||
var attributes = document.createElement("table")
|
||||
attributes.classList.add("attributes")
|
||||
|
||||
attributeEntry(attributes, top, d.nodeinfo.hostname)
|
||||
attributeEntry(attributes, "Status", showStatus(d))
|
||||
attributeEntry(attributes, "Gateway", d.flags.gateway ? "ja" : null)
|
||||
attributeEntry(attributes, "Koordinaten", showGeoURI(d))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue