make eslint happy
This commit is contained in:
parent
ecb65c9171
commit
3e143435e6
|
@ -1,5 +1,3 @@
|
||||||
"use strict"
|
|
||||||
|
|
||||||
module.exports = function (grunt) {
|
module.exports = function (grunt) {
|
||||||
grunt.loadTasks("tasks")
|
grunt.loadTasks("tasks")
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setData = function (links) {
|
self.setData = function (links) {
|
||||||
if (links.length == 0)
|
if (links.length === 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
var h2 = document.createElement("h2")
|
var h2 = document.createElement("h2")
|
||||||
|
|
34
lib/main.js
34
lib/main.js
|
@ -1,14 +1,14 @@
|
||||||
define(["config", "moment", "chroma-js", "router", "map", "sidebar", "tabs", "container", "meshstats", "linklist", "nodelist", "simplenodelist", "infobox/main"],
|
define(["config", "moment", "chroma-js", "router", "map", "sidebar", "tabs", "container", "meshstats", "linklist", "nodelist", "simplenodelist", "infobox/main", "leaflet"],
|
||||||
function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshstats, Linklist, Nodelist, SimpleNodelist, Infobox) {
|
function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshstats, Linklist, Nodelist, SimpleNodelist, Infobox, L) {
|
||||||
return function () {
|
return function () {
|
||||||
var linklist, lostnodeslist, map, meshstats, newnodeslist, nodelist, router
|
var linklist, lostnodeslist, map, meshstats, newnodeslist, nodelist, router
|
||||||
|
|
||||||
function createGUI() {
|
function createGUI() {
|
||||||
moment.locale("de")
|
moment.locale("de")
|
||||||
|
|
||||||
router = new Router(config)
|
router = new Router()
|
||||||
|
|
||||||
var linkScale = chroma.scale(chroma.interpolate.bezier(['green', 'yellow', 'red'])).domain([1, 5])
|
var linkScale = chroma.scale(chroma.interpolate.bezier(["green", "yellow", "red"])).domain([1, 5])
|
||||||
var sidebar = new Sidebar(document.body)
|
var sidebar = new Sidebar(document.body)
|
||||||
var infobox = new Infobox(config, sidebar, router)
|
var infobox = new Infobox(config, sidebar, router)
|
||||||
var tabs = new Tabs()
|
var tabs = new Tabs()
|
||||||
|
@ -36,16 +36,7 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta
|
||||||
router.addTarget(map)
|
router.addTarget(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
var urls = [ config.dataPath + 'nodes.json',
|
function handleData(data) {
|
||||||
config.dataPath + 'graph.json'
|
|
||||||
]
|
|
||||||
|
|
||||||
Promise.all(urls.map(getJSON))
|
|
||||||
.then(function (d) { createGUI(); return d })
|
|
||||||
.then(handle_data)
|
|
||||||
.then(function () { router.start() })
|
|
||||||
|
|
||||||
function handle_data(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] })
|
||||||
|
|
||||||
|
@ -59,7 +50,7 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta
|
||||||
})
|
})
|
||||||
|
|
||||||
var now = moment()
|
var now = moment()
|
||||||
var age = moment(now).subtract(14, 'days')
|
var age = moment(now).subtract(14, "days")
|
||||||
|
|
||||||
var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online))
|
var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online))
|
||||||
var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline))
|
var lostnodes = limit("lastseen", age, sortByKey("lastseen", nodes).filter(offline))
|
||||||
|
@ -116,5 +107,18 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta
|
||||||
lostnodeslist.setData(lostnodes)
|
lostnodeslist.setData(lostnodes)
|
||||||
router.setData(nodes, links)
|
router.setData(nodes, links)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var urls = [ config.dataPath + "nodes.json",
|
||||||
|
config.dataPath + "graph.json"
|
||||||
|
]
|
||||||
|
|
||||||
|
Promise.all(urls.map(getJSON))
|
||||||
|
.then(function (d) {
|
||||||
|
createGUI()
|
||||||
|
return d
|
||||||
|
})
|
||||||
|
.then(handleData)
|
||||||
|
.then(function () { router.start() })
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
44
lib/map.js
44
lib/map.js
|
@ -10,7 +10,7 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
|
||||||
m.setStyle(iconFunc(d))
|
m.setStyle(iconFunc(d))
|
||||||
}
|
}
|
||||||
|
|
||||||
m.on('click', router.node(d))
|
m.on("click", router.node(d))
|
||||||
m.bindLabel(d.nodeinfo.hostname)
|
m.bindLabel(d.nodeinfo.hostname)
|
||||||
|
|
||||||
dict[d.nodeinfo.node_id] = m
|
dict[d.nodeinfo.node_id] = m
|
||||||
|
@ -38,7 +38,7 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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', router.link(d))
|
line.on("click", router.link(d))
|
||||||
|
|
||||||
dict[linkId(d)] = line
|
dict[linkId(d)] = line
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
|
||||||
var self = this
|
var self = this
|
||||||
|
|
||||||
var el = document.createElement("div")
|
var el = document.createElement("div")
|
||||||
el.classList.add("map")
|
el.classList.add("map")
|
||||||
self.div = el
|
self.div = el
|
||||||
|
|
||||||
var map = L.map(el, options)
|
var map = L.map(el, options)
|
||||||
|
@ -88,17 +88,17 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
|
||||||
var nodesOffline = subtract(nodes.filter(offline), lostnodes)
|
var nodesOffline = subtract(nodes.filter(offline), lostnodes)
|
||||||
|
|
||||||
var markersOnline = nodesOnline.filter(has_location)
|
var markersOnline = nodesOnline.filter(has_location)
|
||||||
.map(mkMarker(nodeDict, function (d) { return iconOnline }, router))
|
.map(mkMarker(nodeDict, function () { return iconOnline }, router))
|
||||||
|
|
||||||
var markersOffline = nodesOffline.filter(has_location)
|
var markersOffline = nodesOffline.filter(has_location)
|
||||||
.map(mkMarker(nodeDict, function (d) { return iconOffline }, router))
|
.map(mkMarker(nodeDict, function () { return iconOffline }, router))
|
||||||
|
|
||||||
var markersNew = newnodes.filter(has_location)
|
var markersNew = newnodes.filter(has_location)
|
||||||
.map(mkMarker(nodeDict, function (d) { return iconNew }, router))
|
.map(mkMarker(nodeDict, function () { return iconNew }, router))
|
||||||
|
|
||||||
var markersLost = lostnodes.filter(has_location)
|
var markersLost = lostnodes.filter(has_location)
|
||||||
.map(mkMarker(nodeDict, function (d) {
|
.map(mkMarker(nodeDict, function (d) {
|
||||||
if (d.lastseen.isAfter(moment(now).subtract(3, 'days')))
|
if (d.lastseen.isAfter(moment(now).subtract(3, "days")))
|
||||||
return iconAlert
|
return iconAlert
|
||||||
|
|
||||||
return iconLost
|
return iconLost
|
||||||
|
@ -110,6 +110,20 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
|
||||||
groupLost = L.featureGroup(markersLost).addTo(map)
|
groupLost = L.featureGroup(markersLost).addTo(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetMarkerStyles(nodes, links) {
|
||||||
|
Object.keys(nodes).forEach( function (d) {
|
||||||
|
nodes[d].resetStyle()
|
||||||
|
})
|
||||||
|
|
||||||
|
Object.keys(links).forEach( function (d) {
|
||||||
|
links[d].resetStyle()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function setView(bounds) {
|
||||||
|
map.fitBounds(bounds, {paddingTopLeft: [sidebar.getWidth(), 0]})
|
||||||
|
}
|
||||||
|
|
||||||
function resetView() {
|
function resetView() {
|
||||||
resetMarkerStyles(nodeDict, linkDict)
|
resetMarkerStyles(nodeDict, linkDict)
|
||||||
|
|
||||||
|
@ -127,24 +141,10 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
|
||||||
setView(bounds)
|
setView(bounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setView(bounds) {
|
|
||||||
map.fitBounds(bounds, {paddingTopLeft: [sidebar.getWidth(), 0]})
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetMarkerStyles(nodes, links) {
|
|
||||||
Object.keys(nodes).forEach( function (d) {
|
|
||||||
nodes[d].resetStyle()
|
|
||||||
})
|
|
||||||
|
|
||||||
Object.keys(links).forEach( function (d) {
|
|
||||||
links[d].resetStyle()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function goto(dict, id) {
|
function goto(dict, id) {
|
||||||
var m = dict[id]
|
var m = dict[id]
|
||||||
if (m === undefined)
|
if (m === undefined)
|
||||||
return
|
return undefined
|
||||||
|
|
||||||
var bounds
|
var bounds
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,34 @@
|
||||||
define(["tablesort", "tablesort.numeric"], function (Tablesort) {
|
define(["tablesort", "tablesort.numeric"], function (Tablesort) {
|
||||||
return function(router) {
|
return function(router) {
|
||||||
|
function showUptime(el, now, d) {
|
||||||
|
var uptime
|
||||||
|
if (d.flags.online && "uptime" in d.statistics)
|
||||||
|
uptime = Math.round(d.statistics.uptime / 3600)
|
||||||
|
else if (!d.flags.online && "lastseen" in d)
|
||||||
|
uptime = Math.round(-(now - d.lastseen) / 3600000)
|
||||||
|
|
||||||
|
var s = ""
|
||||||
|
|
||||||
|
if (uptime !== undefined)
|
||||||
|
if (Math.abs(uptime) >= 24)
|
||||||
|
s = Math.round(uptime / 24) + "d"
|
||||||
|
else
|
||||||
|
s = uptime + "h"
|
||||||
|
|
||||||
|
el.textContent = s
|
||||||
|
el.setAttribute("data-sort", uptime !== undefined ? -uptime : 0)
|
||||||
|
}
|
||||||
|
|
||||||
var self = this
|
var self = this
|
||||||
var el
|
var el
|
||||||
|
|
||||||
self.render = function (d) {
|
self.render = function (d) {
|
||||||
el = document.createElement("div")
|
el = document.createElement("div")
|
||||||
d.appendChild(el)
|
d.appendChild(el)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setData = function (now, nodes) {
|
self.setData = function (now, nodes) {
|
||||||
if (nodes.length == 0)
|
if (nodes.length === 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
var h2 = document.createElement("h2")
|
var h2 = document.createElement("h2")
|
||||||
|
@ -60,7 +79,7 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var td2 = document.createElement("td")
|
var td2 = document.createElement("td")
|
||||||
showUptime(td2, d)
|
showUptime(td2, now, d)
|
||||||
row.appendChild(td2)
|
row.appendChild(td2)
|
||||||
|
|
||||||
var td3 = document.createElement("td")
|
var td3 = document.createElement("td")
|
||||||
|
@ -75,26 +94,6 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) {
|
||||||
new Tablesort(table)
|
new Tablesort(table)
|
||||||
|
|
||||||
el.appendChild(table)
|
el.appendChild(table)
|
||||||
|
}
|
||||||
function showUptime(el, d) {
|
|
||||||
var uptime
|
|
||||||
if (d.flags.online && "uptime" in d.statistics)
|
|
||||||
uptime = Math.round(d.statistics.uptime / 3600)
|
|
||||||
else if (!d.flags.online && "lastseen" in d)
|
|
||||||
uptime = Math.round(-(now - d.lastseen) / 3600000)
|
|
||||||
|
|
||||||
var s = ""
|
|
||||||
|
|
||||||
if (uptime !== undefined) {
|
|
||||||
if (Math.abs(uptime) >= 24)
|
|
||||||
s = Math.round(uptime/24) + "d"
|
|
||||||
else
|
|
||||||
s = uptime + "h"
|
|
||||||
}
|
|
||||||
|
|
||||||
el.textContent = s
|
|
||||||
el.setAttribute("data-sort", uptime !== undefined ? -uptime : 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,9 +1,23 @@
|
||||||
define(function () {
|
define(function () {
|
||||||
return function (config) {
|
return function () {
|
||||||
var objects = { nodes: {}, links: {} }
|
var objects = { nodes: {}, links: {} }
|
||||||
var targets = []
|
var targets = []
|
||||||
var self = this
|
var self = this
|
||||||
|
|
||||||
|
function saveState(d) {
|
||||||
|
var s = "#!"
|
||||||
|
|
||||||
|
if (d) {
|
||||||
|
if ("node" in d)
|
||||||
|
s += "n:" + d.node.nodeinfo.node_id
|
||||||
|
|
||||||
|
if ("link" in d)
|
||||||
|
s += "l:" + linkId(d.link)
|
||||||
|
}
|
||||||
|
|
||||||
|
window.history.pushState(s, undefined, s)
|
||||||
|
}
|
||||||
|
|
||||||
function resetView(push) {
|
function resetView(push) {
|
||||||
push = trueDefault(push)
|
push = trueDefault(push)
|
||||||
|
|
||||||
|
@ -27,20 +41,6 @@ define(function () {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveState(d) {
|
|
||||||
var s = "#!"
|
|
||||||
|
|
||||||
if (d) {
|
|
||||||
if ("node" in d)
|
|
||||||
s += "n:" + d.node.nodeinfo.node_id
|
|
||||||
|
|
||||||
if ("link" in d)
|
|
||||||
s += "l:" + linkId(d.link)
|
|
||||||
}
|
|
||||||
|
|
||||||
window.history.pushState(s, undefined, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadState(s) {
|
function loadState(s) {
|
||||||
if (!s)
|
if (!s)
|
||||||
return false
|
return false
|
||||||
|
@ -49,9 +49,10 @@ define(function () {
|
||||||
return false
|
return false
|
||||||
|
|
||||||
var args = s.slice(2).split(":")
|
var args = s.slice(2).split(":")
|
||||||
|
var id
|
||||||
|
|
||||||
if (args[0] === "n") {
|
if (args[0] === "n") {
|
||||||
var id = args[1]
|
id = args[1]
|
||||||
|
|
||||||
if (id in objects.nodes) {
|
if (id in objects.nodes) {
|
||||||
gotoNode(objects.nodes[id])
|
gotoNode(objects.nodes[id])
|
||||||
|
@ -60,7 +61,7 @@ define(function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[0] === "l") {
|
if (args[0] === "l") {
|
||||||
var id = args[1]
|
id = args[1]
|
||||||
|
|
||||||
if (id in objects.links) {
|
if (id in objects.links) {
|
||||||
gotoLink(objects.links[id])
|
gotoLink(objects.links[id])
|
||||||
|
@ -102,9 +103,6 @@ define(function () {
|
||||||
saveState()
|
saveState()
|
||||||
}
|
}
|
||||||
|
|
||||||
self.addMarkers = function (d) {
|
|
||||||
markers = d
|
|
||||||
}
|
|
||||||
self.addTarget = function (d) { targets.push(d) }
|
self.addTarget = function (d) { targets.push(d) }
|
||||||
|
|
||||||
self.setData = function (nodes, links) {
|
self.setData = function (nodes, links) {
|
||||||
|
|
|
@ -19,7 +19,7 @@ define([], function () {
|
||||||
sidebar.appendChild(container)
|
sidebar.appendChild(container)
|
||||||
|
|
||||||
self.getWidth = function () {
|
self.getWidth = function () {
|
||||||
var small = window.matchMedia("(max-width: 60em)");
|
var small = window.matchMedia("(max-width: 60em)")
|
||||||
return small.matches ? 0 : sidebar.offsetWidth
|
return small.matches ? 0 : sidebar.offsetWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,13 @@ define(["moment"], function (moment) {
|
||||||
var self = this
|
var self = this
|
||||||
var el
|
var el
|
||||||
|
|
||||||
self.render = function (d) {
|
self.render = function (d) {
|
||||||
el = document.createElement("div")
|
el = document.createElement("div")
|
||||||
d.appendChild(el)
|
d.appendChild(el)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setData = function (list) {
|
self.setData = function (list) {
|
||||||
if (list.length == 0)
|
if (list.length === 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
var h2 = document.createElement("h2")
|
var h2 = document.createElement("h2")
|
||||||
|
|
|
@ -7,7 +7,7 @@ define([], function () {
|
||||||
|
|
||||||
var container = document.createElement("div")
|
var container = document.createElement("div")
|
||||||
|
|
||||||
function switchTab(ev) {
|
function switchTab() {
|
||||||
for (var i = 0; i < tabs.children.length; i++) {
|
for (var i = 0; i < tabs.children.length; i++) {
|
||||||
var el = tabs.children[i]
|
var el = tabs.children[i]
|
||||||
el.classList.remove("visible")
|
el.classList.remove("visible")
|
||||||
|
|
25
package.json
25
package.json
|
@ -13,6 +13,29 @@
|
||||||
"grunt-contrib-requirejs": "^0.4.4",
|
"grunt-contrib-requirejs": "^0.4.4",
|
||||||
"grunt-contrib-uglify": "^0.5.1",
|
"grunt-contrib-uglify": "^0.5.1",
|
||||||
"grunt-contrib-watch": "^0.6.1",
|
"grunt-contrib-watch": "^0.6.1",
|
||||||
"grunt-eslint": "^1.1.0"
|
"grunt-eslint": "^10.0.0"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"amd": true,
|
||||||
|
"es6": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"getJSON": false,
|
||||||
|
"has_location": false,
|
||||||
|
"limit": false,
|
||||||
|
"linkId": false,
|
||||||
|
"offline": false,
|
||||||
|
"one": false,
|
||||||
|
"online": false,
|
||||||
|
"showDistance": false,
|
||||||
|
"showTq": false,
|
||||||
|
"sortByKey": false,
|
||||||
|
"subtract": false,
|
||||||
|
"sum": false,
|
||||||
|
"trueDefault": false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
"use strict"
|
|
||||||
|
|
||||||
module.exports = function(grunt) {
|
module.exports = function(grunt) {
|
||||||
grunt.config.merge({
|
grunt.config.merge({
|
||||||
copy: {
|
copy: {
|
||||||
|
@ -31,7 +29,7 @@ module.exports = function(grunt) {
|
||||||
],
|
],
|
||||||
expand: true,
|
expand: true,
|
||||||
dest: "build/",
|
dest: "build/",
|
||||||
cwd: "bower_components/ionicons/",
|
cwd: "bower_components/ionicons/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cssmin: {
|
cssmin: {
|
||||||
|
@ -61,5 +59,5 @@ module.exports = function(grunt) {
|
||||||
|
|
||||||
grunt.loadNpmTasks("grunt-contrib-copy")
|
grunt.loadNpmTasks("grunt-contrib-copy")
|
||||||
grunt.loadNpmTasks("grunt-contrib-requirejs")
|
grunt.loadNpmTasks("grunt-contrib-requirejs")
|
||||||
grunt.loadNpmTasks('grunt-contrib-cssmin')
|
grunt.loadNpmTasks("grunt-contrib-cssmin")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
"use strict"
|
|
||||||
|
|
||||||
module.exports = function (grunt) {
|
module.exports = function (grunt) {
|
||||||
grunt.config.merge({
|
grunt.config.merge({
|
||||||
clean: {
|
clean: {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
"use strict"
|
|
||||||
|
|
||||||
module.exports = function (grunt) {
|
module.exports = function (grunt) {
|
||||||
grunt.config.merge({
|
grunt.config.merge({
|
||||||
connect: {
|
connect: {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
"use strict"
|
|
||||||
|
|
||||||
module.exports = function (grunt) {
|
module.exports = function (grunt) {
|
||||||
grunt.config.merge({
|
grunt.config.merge({
|
||||||
checkDependencies: {
|
checkDependencies: {
|
||||||
|
@ -15,10 +13,13 @@ module.exports = function (grunt) {
|
||||||
},
|
},
|
||||||
eslint: {
|
eslint: {
|
||||||
options: {
|
options: {
|
||||||
rule: {
|
rules: {
|
||||||
semi: [2, "never"],
|
"semi": [2, "never"],
|
||||||
strict: [2, "never"],
|
"curly": [2, "multi"],
|
||||||
curly: [2, "multi"]
|
"strict": [2, "never"],
|
||||||
|
"no-multi-spaces": 0,
|
||||||
|
"no-new": 0,
|
||||||
|
"no-shadow": 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sources: {
|
sources: {
|
||||||
|
|
Loading…
Reference in a new issue