rename gotoAnything to router
This commit is contained in:
parent
a2669373a0
commit
265cb2e5eb
@ -1,15 +1,15 @@
|
|||||||
define(function () {
|
define(function () {
|
||||||
return function (config, el, gotoAnything, d) {
|
return function (config, el, router, d) {
|
||||||
var h2 = document.createElement("h2")
|
var h2 = document.createElement("h2")
|
||||||
a1 = document.createElement("a")
|
a1 = document.createElement("a")
|
||||||
a1.href = "#"
|
a1.href = "#"
|
||||||
a1.onclick = gotoAnything.node(d.source.node)
|
a1.onclick = router.node(d.source.node)
|
||||||
a1.textContent = d.source.node.nodeinfo.hostname
|
a1.textContent = d.source.node.nodeinfo.hostname
|
||||||
h2.appendChild(a1)
|
h2.appendChild(a1)
|
||||||
h2.appendChild(document.createTextNode(" – "))
|
h2.appendChild(document.createTextNode(" – "))
|
||||||
a2 = document.createElement("a")
|
a2 = document.createElement("a")
|
||||||
a2.href = "#"
|
a2.href = "#"
|
||||||
a2.onclick = gotoAnything.node(d.target.node)
|
a2.onclick = router.node(d.target.node)
|
||||||
a2.textContent = d.target.node.nodeinfo.hostname
|
a2.textContent = d.target.node.nodeinfo.hostname
|
||||||
h2.appendChild(a2)
|
h2.appendChild(a2)
|
||||||
el.appendChild(h2)
|
el.appendChild(h2)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
define(["infobox/link", "infobox/node"], function (Link, Node) {
|
define(["infobox/link", "infobox/node"], function (Link, Node) {
|
||||||
return function (config, sidebar, gotoAnything) {
|
return function (config, sidebar, router) {
|
||||||
var self = this
|
var self = this
|
||||||
el = undefined
|
el = undefined
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ define(["infobox/link", "infobox/node"], function (Link, Node) {
|
|||||||
|
|
||||||
var closeButton = document.createElement("button")
|
var closeButton = document.createElement("button")
|
||||||
closeButton.classList.add("close")
|
closeButton.classList.add("close")
|
||||||
closeButton.onclick = gotoAnything.reset
|
closeButton.onclick = router.reset
|
||||||
el.appendChild(closeButton)
|
el.appendChild(closeButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,12 +30,12 @@ define(["infobox/link", "infobox/node"], function (Link, Node) {
|
|||||||
|
|
||||||
self.gotoNode = function (d) {
|
self.gotoNode = function (d) {
|
||||||
create()
|
create()
|
||||||
new Node(config, el, gotoAnything, d)
|
new Node(config, el, router, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.gotoLink = function (d) {
|
self.gotoLink = function (d) {
|
||||||
create()
|
create()
|
||||||
new Link(config, el, gotoAnything, d)
|
new Link(config, el, router, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
define(function () {
|
define(function () {
|
||||||
return function(config, el, gotoAnything, d) {
|
return function(config, el, router, d) {
|
||||||
var h2 = document.createElement("h2")
|
var h2 = document.createElement("h2")
|
||||||
h2.textContent = d.nodeinfo.hostname
|
h2.textContent = d.nodeinfo.hostname
|
||||||
var span = document.createElement("span")
|
var span = document.createElement("span")
|
||||||
@ -62,7 +62,7 @@ define(function () {
|
|||||||
a1.classList.add("hostname")
|
a1.classList.add("hostname")
|
||||||
a1.textContent = d.node.nodeinfo.hostname
|
a1.textContent = d.node.nodeinfo.hostname
|
||||||
a1.href = "#"
|
a1.href = "#"
|
||||||
a1.onclick = gotoAnything.node(d.node)
|
a1.onclick = router.node(d.node)
|
||||||
td1.appendChild(a1)
|
td1.appendChild(a1)
|
||||||
|
|
||||||
if (d.link.vpn)
|
if (d.link.vpn)
|
||||||
@ -81,7 +81,7 @@ define(function () {
|
|||||||
var a2 = document.createElement("a")
|
var a2 = document.createElement("a")
|
||||||
a2.href = "#"
|
a2.href = "#"
|
||||||
a2.textContent = showTq(d.link)
|
a2.textContent = showTq(d.link)
|
||||||
a2.onclick = gotoAnything.link(d.link)
|
a2.onclick = router.link(d.link)
|
||||||
td2.appendChild(a2)
|
td2.appendChild(a2)
|
||||||
tr.appendChild(td2)
|
tr.appendChild(td2)
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ define(function () {
|
|||||||
var a3 = document.createElement("a")
|
var a3 = document.createElement("a")
|
||||||
a3.href = "#"
|
a3.href = "#"
|
||||||
a3.textContent = showDistance(d.link)
|
a3.textContent = showDistance(d.link)
|
||||||
a3.onclick = gotoAnything.link(d.link)
|
a3.onclick = router.link(d.link)
|
||||||
td3.appendChild(a3)
|
td3.appendChild(a3)
|
||||||
td3.setAttribute("data-sort", d.link.distance !== undefined ? -d.link.distance : 1)
|
td3.setAttribute("data-sort", d.link.distance !== undefined ? -d.link.distance : 1)
|
||||||
tr.appendChild(td3)
|
tr.appendChild(td3)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
define(function () {
|
define(function () {
|
||||||
return function(linkScale, gotoAnything) {
|
return function(linkScale, router) {
|
||||||
var self = this
|
var self = this
|
||||||
var el
|
var el
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ define(function () {
|
|||||||
var a = document.createElement("a")
|
var a = document.createElement("a")
|
||||||
a.textContent = d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname
|
a.textContent = d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname
|
||||||
a.href = "#"
|
a.href = "#"
|
||||||
a.onclick = gotoAnything.link(d)
|
a.onclick = router.link(d)
|
||||||
td1.appendChild(a)
|
td1.appendChild(a)
|
||||||
row.appendChild(td1)
|
row.appendChild(td1)
|
||||||
|
|
||||||
|
32
lib/main.js
32
lib/main.js
@ -10,25 +10,25 @@ function (Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
|||||||
|
|
||||||
var sidebar = new Sidebar(document.body)
|
var sidebar = new Sidebar(document.body)
|
||||||
|
|
||||||
var gotoAnything = new Router(config)
|
var router = new Router(config)
|
||||||
|
|
||||||
var infobox = new Infobox(config, sidebar, gotoAnything)
|
var infobox = new Infobox(config, sidebar, router)
|
||||||
gotoAnything.addTarget(infobox)
|
router.addTarget(infobox)
|
||||||
|
|
||||||
var map = new Map(linkScale, sidebar, gotoAnything)
|
var map = new Map(linkScale, sidebar, router)
|
||||||
document.body.insertBefore(map.div, document.body.firstChild)
|
document.body.insertBefore(map.div, document.body.firstChild)
|
||||||
gotoAnything.addTarget(map)
|
router.addTarget(map)
|
||||||
|
|
||||||
var meshstats = new Meshstats()
|
var meshstats = new Meshstats()
|
||||||
sidebar.add(meshstats)
|
sidebar.add(meshstats)
|
||||||
|
|
||||||
var newnodeslist = new SimpleNodelist(config, "firstseen", gotoAnything, "Neue Knoten")
|
var newnodeslist = new SimpleNodelist(config, "firstseen", router, "Neue Knoten")
|
||||||
sidebar.add(newnodeslist)
|
sidebar.add(newnodeslist)
|
||||||
|
|
||||||
var lostnodeslist = new SimpleNodelist(config, "lastseen", gotoAnything, "Verschwundene Knoten")
|
var lostnodeslist = new SimpleNodelist(config, "lastseen", router, "Verschwundene Knoten")
|
||||||
sidebar.add(lostnodeslist)
|
sidebar.add(lostnodeslist)
|
||||||
|
|
||||||
var linklist = new Linklist(linkScale, gotoAnything)
|
var linklist = new Linklist(linkScale, router)
|
||||||
sidebar.add(linklist)
|
sidebar.add(linklist)
|
||||||
|
|
||||||
var urls = [ config.dataPath + 'nodes.json',
|
var urls = [ config.dataPath + 'nodes.json',
|
||||||
@ -36,11 +36,11 @@ function (Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
|||||||
]
|
]
|
||||||
|
|
||||||
var p = Promise.all(urls.map(getJSON))
|
var p = Promise.all(urls.map(getJSON))
|
||||||
p.then(handle_data(sidebar, meshstats, linklist, newnodeslist, lostnodeslist, infobox, map, gotoAnything))
|
p.then(handle_data(sidebar, meshstats, linklist, newnodeslist, lostnodeslist, infobox, map, router))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_data(sidebar, meshstats, linklist, newnodeslist, lostnodeslist, infobox, map, gotoAnything) {
|
function handle_data(sidebar, meshstats, linklist, newnodeslist, lostnodeslist, infobox, map, router) {
|
||||||
return function (data) {
|
return function (data) {
|
||||||
var nodedict = data[0]
|
var nodedict = data[0]
|
||||||
var nodes = Object.keys(nodedict.nodes).map(function (key) { return nodedict.nodes[key] })
|
var nodes = Object.keys(nodedict.nodes).map(function (key) { return nodedict.nodes[key] })
|
||||||
@ -122,12 +122,12 @@ function (Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
|||||||
historyDict.links[linkId(d)] = d
|
historyDict.links[linkId(d)] = d
|
||||||
})
|
})
|
||||||
|
|
||||||
gotoAnything.reset(false)
|
router.reset(false)
|
||||||
|
|
||||||
gotoHistory(gotoAnything, historyDict, window.location.hash)
|
gotoHistory(router, historyDict, window.location.hash)
|
||||||
|
|
||||||
window.onpopstate = function (d) {
|
window.onpopstate = function (d) {
|
||||||
gotoHistory(gotoAnything, historyDict, d.state)
|
gotoHistory(router, historyDict, d.state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ function (Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
|||||||
window.history.pushState(s, undefined, s)
|
window.history.pushState(s, undefined, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
function gotoHistory(gotoAnything, dict, s) {
|
function gotoHistory(router, dict, s) {
|
||||||
if (!s.startsWith("#!"))
|
if (!s.startsWith("#!"))
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -158,14 +158,14 @@ function (Map, Sidebar, Meshstats, Linklist, SimpleNodelist, Infobox) {
|
|||||||
var id = args[1]
|
var id = args[1]
|
||||||
|
|
||||||
if (id in dict.nodes)
|
if (id in dict.nodes)
|
||||||
gotoAnything.node(dict.nodes[id], true, false)()
|
router.node(dict.nodes[id], true, false)()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0] === "l") {
|
if (args[0] === "l") {
|
||||||
var id = args[1]
|
var id = args[1]
|
||||||
|
|
||||||
if (id in dict.links)
|
if (id in dict.links)
|
||||||
gotoAnything.link(dict.links[id], true, false)()
|
router.link(dict.links[id], true, false)()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
lib/map.js
16
lib/map.js
@ -2,7 +2,7 @@ define(function () {
|
|||||||
var options = { worldCopyJump: true,
|
var options = { worldCopyJump: true,
|
||||||
zoomControl: false
|
zoomControl: false
|
||||||
}
|
}
|
||||||
function mkMarker(dict, iconFunc, gotoAnything) {
|
function mkMarker(dict, iconFunc, router) {
|
||||||
return function (d) {
|
return function (d) {
|
||||||
var m = L.circleMarker([d.nodeinfo.location.latitude, d.nodeinfo.location.longitude], iconFunc(d))
|
var m = L.circleMarker([d.nodeinfo.location.latitude, d.nodeinfo.location.longitude], iconFunc(d))
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ define(function () {
|
|||||||
m.setStyle(iconFunc(d))
|
m.setStyle(iconFunc(d))
|
||||||
}
|
}
|
||||||
|
|
||||||
m.on('click', gotoAnything.node(d, false))
|
m.on('click', router.node(d, false))
|
||||||
m.bindLabel(d.nodeinfo.hostname)
|
m.bindLabel(d.nodeinfo.hostname)
|
||||||
|
|
||||||
dict[d.nodeinfo.node_id] = m
|
dict[d.nodeinfo.node_id] = m
|
||||||
@ -19,7 +19,7 @@ define(function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLinksToMap(dict, linkScale, graph, gotoAnything) {
|
function addLinksToMap(dict, linkScale, graph, router) {
|
||||||
graph = graph.filter( function (d) {
|
graph = graph.filter( function (d) {
|
||||||
return "distance" in d
|
return "distance" in d
|
||||||
})
|
})
|
||||||
@ -38,7 +38,7 @@ define(function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
line.bindLabel(d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>")
|
line.bindLabel(d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname + "<br><strong>" + showDistance(d) + " / " + showTq(d) + "</strong>")
|
||||||
line.on('click', gotoAnything.link(d, false))
|
line.on('click', router.link(d, false))
|
||||||
|
|
||||||
dict[linkId(d)] = line
|
dict[linkId(d)] = line
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ define(function () {
|
|||||||
|
|
||||||
var groupOnline, group
|
var groupOnline, group
|
||||||
|
|
||||||
return function (linkScale, sidebar, gotoAnything) {
|
return function (linkScale, sidebar, router) {
|
||||||
var self = this
|
var self = this
|
||||||
|
|
||||||
var el = document.createElement("div")
|
var el = document.createElement("div")
|
||||||
@ -80,7 +80,7 @@ define(function () {
|
|||||||
nodeDict = {}
|
nodeDict = {}
|
||||||
linkDict = {}
|
linkDict = {}
|
||||||
|
|
||||||
var lines = addLinksToMap(linkDict, linkScale, links, gotoAnything)
|
var lines = addLinksToMap(linkDict, linkScale, links, router)
|
||||||
|
|
||||||
var nodes = newnodes.concat(lostnodes).filter(has_location)
|
var nodes = newnodes.concat(lostnodes).filter(has_location)
|
||||||
|
|
||||||
@ -92,10 +92,10 @@ define(function () {
|
|||||||
return iconAlert
|
return iconAlert
|
||||||
|
|
||||||
return iconOffline
|
return iconOffline
|
||||||
}, gotoAnything))
|
}, router))
|
||||||
|
|
||||||
var onlinemarkers = subtract(onlinenodes.filter(has_location), newnodes)
|
var onlinemarkers = subtract(onlinenodes.filter(has_location), newnodes)
|
||||||
.map(mkMarker(nodeDict, function (d) { return iconOnline }, gotoAnything))
|
.map(mkMarker(nodeDict, function (d) { return iconOnline }, router))
|
||||||
|
|
||||||
var groupLines = L.featureGroup(lines).addTo(map)
|
var groupLines = L.featureGroup(lines).addTo(map)
|
||||||
groupOnline = L.featureGroup(onlinemarkers).addTo(map)
|
groupOnline = L.featureGroup(onlinemarkers).addTo(map)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
define(function () {
|
define(function () {
|
||||||
return function(config, field, gotoAnything, title) {
|
return function(config, field, router, title) {
|
||||||
var self = this
|
var self = this
|
||||||
var el
|
var el
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ define(function () {
|
|||||||
a.classList.add(d.flags.online ? "online" : "offline")
|
a.classList.add(d.flags.online ? "online" : "offline")
|
||||||
a.textContent = d.nodeinfo.hostname
|
a.textContent = d.nodeinfo.hostname
|
||||||
a.href = "#"
|
a.href = "#"
|
||||||
a.onclick = gotoAnything.node(d)
|
a.onclick = router.node(d)
|
||||||
td1.appendChild(a)
|
td1.appendChild(a)
|
||||||
|
|
||||||
if (has_location(d)) {
|
if (has_location(d)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user