Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New helper nodeName to allow centralized formatting of hostnames #6

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ function has_location(d) {
Math.abs(d.nodeinfo.location.longitude) < 180
}

function nodeName(d, trim) {
var name = ''
if (d && d.nodeinfo && d.nodeinfo.hostname)
name = d.nodeinfo.hostname
else if (d && d.nodeinfo && d.nodeinfo.node_id)
name = '[' + d.nodeinfo.node_id + ']'
if (trim && name.length > 48)
name = name.substring(0,48) + "..."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be the Unicode character "…" instead of three single "."?

return name
}

function subtract(a, b) {
var ids = {}

Expand Down
6 changes: 4 additions & 2 deletions lib/infobox/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ define(function () {
var a1 = document.createElement("a")
a1.href = "#"
a1.onclick = router.node(d.source.node)
a1.textContent = d.source.node.nodeinfo.hostname
a1.textContent = nodeName(d.source.node, true)
a1.title = nodeName(d.source.node)
h2.appendChild(a1)
h2.appendChild(document.createTextNode(" – "))
var a2 = document.createElement("a")
a2.href = "#"
a2.onclick = router.node(d.target.node)
a2.textContent = d.target.node.nodeinfo.hostname
a2.textContent = nodeName(d.target.node, true)
a2.title = nodeName(d.target.node)
h2.appendChild(a2)
el.appendChild(h2)

Expand Down
6 changes: 4 additions & 2 deletions lib/infobox/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],

return function(config, el, router, d) {
var h2 = document.createElement("h2")
h2.textContent = d.nodeinfo.hostname
h2.textContent = nodeName(d, true)
h2.title = nodeName(d)
el.appendChild(h2)

var attributes = document.createElement("table")
Expand Down Expand Up @@ -242,7 +243,8 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
var td1 = document.createElement("td")
var a1 = document.createElement("a")
a1.classList.add("hostname")
a1.textContent = d.node.nodeinfo.hostname
a1.textContent = nodeName(d.node, true)
a1.title = nodeName(d.node)
a1.href = "#"
a1.onclick = router.node(d.node)
td1.appendChild(a1)
Expand Down
6 changes: 3 additions & 3 deletions lib/linklist.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
define(["sorttable", "virtual-dom"], function (SortTable, V) {
function linkName(d) {
return d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname
function linkName(d, trim) {
return nodeName(d.source.node, trim) + " – " + nodeName(d.target.node, trim)
}

var headings = [{ name: "Knoten",
Expand All @@ -25,7 +25,7 @@ define(["sorttable", "virtual-dom"], function (SortTable, V) {
var table = new SortTable(headings, 2, renderRow)

function renderRow(d) {
var td1Content = [V.h("a", {href: "#", onclick: router.link(d)}, linkName(d))]
var td1Content = [V.h("a", {href: "#", onclick: router.link(d), title: linkName(d)}, linkName(d, true))]

if (d.vpn)
td1Content.push(" (VPN)")
Expand Down
4 changes: 2 additions & 2 deletions lib/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ define(["map/clientlayer", "map/labelslayer",
}

m.on("click", router.node(d))
m.bindLabel(d.nodeinfo.hostname)
m.bindLabel(nodeName(d))

dict[d.nodeinfo.node_id] = m

Expand All @@ -103,7 +103,7 @@ define(["map/clientlayer", "map/labelslayer",
line.setStyle(opts)
}

line.bindLabel(d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>")
line.bindLabel(nodeName(d.source.node) + " – " + nodeName(d.target.node) + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>")
line.on("click", router.link(d))

dict[d.id] = line
Expand Down
4 changes: 2 additions & 2 deletions lib/map/labelslayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ define(["leaflet", "rbush"],
return function (d) {
var font = fontSize + "px " + fontFamily
return { position: L.latLng(d.nodeinfo.location.latitude, d.nodeinfo.location.longitude),
label: d.nodeinfo.hostname,
label: nodeName(d),
offset: offset,
fillStyle: fillStyle,
height: fontSize * 1.2,
font: font,
stroke: stroke,
minZoom: minZoom,
width: measureText(font, d.nodeinfo.hostname).width
width: measureText(font, nodeName(d)).width
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions lib/nodelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ define(["sorttable", "virtual-dom", "numeral"], function (SortTable, V, numeral)

var headings = [{ name: "Knoten",
sort: function (a, b) {
return a.nodeinfo.hostname.localeCompare(b.nodeinfo.hostname)
return nodeName(a).localeCompare(nodeName(b))
},
reverse: false
},
Expand All @@ -46,8 +46,9 @@ define(["sorttable", "virtual-dom", "numeral"], function (SortTable, V, numeral)

td1Content.push(V.h("a", { className: aClass.join(" "),
onclick: router.node(d),
href: "#"
}, d.nodeinfo.hostname))
href: "#",
title: nodeName(d)
}, nodeName(d, true)))

if (has_location(d))
td1Content.push(V.h("span", {className: "icon ion-location"}))
Expand Down
5 changes: 3 additions & 2 deletions lib/simplenodelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ define(["moment", "virtual-dom"], function (moment, V) {

td1Content.push(V.h("a", { className: aClass.join(" "),
onclick: router.node(d),
href: "#"
}, d.nodeinfo.hostname))
href: "#",
title: nodeName(d)
}, nodeName(d, true)))

if (has_location(d))
td1Content.push(V.h("span", {className: "icon ion-location"}))
Expand Down
4 changes: 2 additions & 2 deletions lib/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ define(function () {

this.gotoNode = function (d) {
if (d)
setTitle(d.nodeinfo.hostname)
setTitle(nodeName(d))
}

this.gotoLink = function (d) {
if (d)
setTitle(d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname)
setTitle(nodeName(d.source.node) + " – " + nodeName(d.target.node))
}

this.destroy = function () {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"offline": false,
"one": false,
"online": false,
"nodeName": false,
"showDistance": false,
"showTq": false,
"sortByKey": false,
Expand Down