history: introduce config.json
This commit is contained in:
parent
c0be742802
commit
420a11e72d
5
config.json
Normal file
5
config.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"dataPath": "https://map.luebeck.freifunk.net/data/",
|
||||||
|
"longLinkPercentile": 0.1,
|
||||||
|
"showContact": true
|
||||||
|
}
|
50
history.js
50
history.js
@ -29,31 +29,33 @@ function getJSON(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
var options = { worldCopyJump: true,
|
getJSON("config.json").then( function (config) {
|
||||||
zoomControl: false
|
var options = { worldCopyJump: true,
|
||||||
}
|
zoomControl: false
|
||||||
|
}
|
||||||
|
|
||||||
var map = L.map(document.getElementById("map"), options)
|
var map = L.map(document.getElementById("map"), options)
|
||||||
|
|
||||||
var sh = document.getElementById("sidebarhandle")
|
var sh = document.getElementById("sidebarhandle")
|
||||||
sh.onclick = function () {
|
sh.onclick = function () {
|
||||||
var sb = document.getElementById("sidebar")
|
var sb = document.getElementById("sidebar")
|
||||||
|
|
||||||
if (sb.classList.contains("hidden"))
|
if (sb.classList.contains("hidden"))
|
||||||
sb.classList.remove("hidden")
|
sb.classList.remove("hidden")
|
||||||
else
|
else
|
||||||
sb.classList.add("hidden")
|
sb.classList.add("hidden")
|
||||||
|
|
||||||
map.invalidateSize()
|
map.invalidateSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var urls = [ 'https://map.luebeck.freifunk.net/data/nodes.json',
|
var urls = [ config.dataPath + 'nodes.json',
|
||||||
'https://map.luebeck.freifunk.net/data/graph.json'
|
config.dataPath + 'graph.json'
|
||||||
]
|
]
|
||||||
|
|
||||||
var p = Promise.all(urls.map(getJSON))
|
var p = Promise.all(urls.map(getJSON))
|
||||||
p.then(handle_data(map))
|
p.then(handle_data(config, map))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function sort(key, d) {
|
function sort(key, d) {
|
||||||
@ -92,7 +94,7 @@ function subtract(a, b) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_data(map) {
|
function handle_data(config, map) {
|
||||||
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] })
|
||||||
@ -113,8 +115,8 @@ function handle_data(map) {
|
|||||||
|
|
||||||
var onlinenodes = subtract(nodes.filter(online).filter(has_location), newnodes)
|
var onlinenodes = subtract(nodes.filter(online).filter(has_location), newnodes)
|
||||||
|
|
||||||
addToList(document.getElementById("newnodes"), "firstseen", newnodes)
|
addToList(document.getElementById("newnodes"), config.showContact, "firstseen", newnodes)
|
||||||
addToList(document.getElementById("lostnodes"), "lastseen", lostnodes)
|
addToList(document.getElementById("lostnodes"), config.showContact, "lastseen", lostnodes)
|
||||||
|
|
||||||
var graph = data[1].batadv
|
var graph = data[1].batadv
|
||||||
var nodes = data[0].nodes
|
var nodes = data[0].nodes
|
||||||
@ -151,7 +153,7 @@ function handle_data(map) {
|
|||||||
|
|
||||||
longlinks = graph.slice().sort( function (a, b) {
|
longlinks = graph.slice().sort( function (a, b) {
|
||||||
return a.distance - b.distance
|
return a.distance - b.distance
|
||||||
}).reverse().slice(0, Math.ceil(0.1 * graph.length))
|
}).reverse().slice(0, Math.ceil(config.longLinkPercentile * graph.length))
|
||||||
|
|
||||||
addToLongLinksList(document.getElementById("longlinks"), longlinks)
|
addToLongLinksList(document.getElementById("longlinks"), longlinks)
|
||||||
|
|
||||||
@ -260,7 +262,7 @@ function addToLongLinksList(el, links) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function addToList(el, tf, list) {
|
function addToList(el, showContact, tf, list) {
|
||||||
list.forEach( function (d) {
|
list.forEach( function (d) {
|
||||||
var time = moment(d[tf]).fromNow()
|
var time = moment(d[tf]).fromNow()
|
||||||
|
|
||||||
@ -279,7 +281,7 @@ function addToList(el, tf, list) {
|
|||||||
td1.appendChild(span)
|
td1.appendChild(span)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("owner" in d.nodeinfo) {
|
if ("owner" in d.nodeinfo && showContact) {
|
||||||
var contact = d.nodeinfo.owner.contact
|
var contact = d.nodeinfo.owner.contact
|
||||||
td1.appendChild(document.createTextNode(" – " + contact + ""))
|
td1.appendChild(document.createTextNode(" – " + contact + ""))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user