make eslint happy

This commit is contained in:
Nils Schneider 2015-03-29 16:14:10 +02:00
parent ecb65c9171
commit 3e143435e6
14 changed files with 120 additions and 103 deletions

View file

@ -1,5 +1,3 @@
"use strict"
module.exports = function (grunt) {
grunt.loadTasks("tasks")

View file

@ -9,7 +9,7 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) {
}
self.setData = function (links) {
if (links.length == 0)
if (links.length === 0)
return
var h2 = document.createElement("h2")

View file

@ -1,14 +1,14 @@
define(["config", "moment", "chroma-js", "router", "map", "sidebar", "tabs", "container", "meshstats", "linklist", "nodelist", "simplenodelist", "infobox/main"],
function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshstats, Linklist, Nodelist, SimpleNodelist, Infobox) {
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, L) {
return function () {
var linklist, lostnodeslist, map, meshstats, newnodeslist, nodelist, router
function createGUI() {
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 infobox = new Infobox(config, sidebar, router)
var tabs = new Tabs()
@ -36,16 +36,7 @@ function (config, moment, chroma, Router, Map, Sidebar, Tabs, Container, Meshsta
router.addTarget(map)
}
var urls = [ config.dataPath + 'nodes.json',
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) {
function handleData(data) {
var nodedict = data[0]
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 age = moment(now).subtract(14, 'days')
var age = moment(now).subtract(14, "days")
var newnodes = limit("firstseen", age, sortByKey("firstseen", nodes).filter(online))
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)
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() })
}
})

View file

@ -10,7 +10,7 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
m.setStyle(iconFunc(d))
}
m.on('click', router.node(d))
m.on("click", router.node(d))
m.bindLabel(d.nodeinfo.hostname)
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.on('click', router.link(d))
line.on("click", router.link(d))
dict[linkId(d)] = line
@ -60,7 +60,7 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
var self = this
var el = document.createElement("div")
el.classList.add("map")
el.classList.add("map")
self.div = el
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 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)
.map(mkMarker(nodeDict, function (d) { return iconOffline }, router))
.map(mkMarker(nodeDict, function () { return iconOffline }, router))
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)
.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 iconLost
@ -110,6 +110,20 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
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() {
resetMarkerStyles(nodeDict, linkDict)
@ -127,24 +141,10 @@ define(["leaflet", "moment", "leaflet.label"], function (L, moment) {
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) {
var m = dict[id]
if (m === undefined)
return
return undefined
var bounds

View file

@ -1,15 +1,34 @@
define(["tablesort", "tablesort.numeric"], function (Tablesort) {
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 el
self.render = function (d) {
self.render = function (d) {
el = document.createElement("div")
d.appendChild(el)
}
self.setData = function (now, nodes) {
if (nodes.length == 0)
if (nodes.length === 0)
return
var h2 = document.createElement("h2")
@ -60,7 +79,7 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) {
}
var td2 = document.createElement("td")
showUptime(td2, d)
showUptime(td2, now, d)
row.appendChild(td2)
var td3 = document.createElement("td")
@ -75,26 +94,6 @@ define(["tablesort", "tablesort.numeric"], function (Tablesort) {
new Tablesort(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)
}
}
}
}
})

View file

@ -1,9 +1,23 @@
define(function () {
return function (config) {
return function () {
var objects = { nodes: {}, links: {} }
var targets = []
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) {
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) {
if (!s)
return false
@ -49,9 +49,10 @@ define(function () {
return false
var args = s.slice(2).split(":")
var id
if (args[0] === "n") {
var id = args[1]
id = args[1]
if (id in objects.nodes) {
gotoNode(objects.nodes[id])
@ -60,7 +61,7 @@ define(function () {
}
if (args[0] === "l") {
var id = args[1]
id = args[1]
if (id in objects.links) {
gotoLink(objects.links[id])
@ -102,9 +103,6 @@ define(function () {
saveState()
}
self.addMarkers = function (d) {
markers = d
}
self.addTarget = function (d) { targets.push(d) }
self.setData = function (nodes, links) {

View file

@ -19,7 +19,7 @@ define([], function () {
sidebar.appendChild(container)
self.getWidth = function () {
var small = window.matchMedia("(max-width: 60em)");
var small = window.matchMedia("(max-width: 60em)")
return small.matches ? 0 : sidebar.offsetWidth
}

View file

@ -3,13 +3,13 @@ define(["moment"], function (moment) {
var self = this
var el
self.render = function (d) {
self.render = function (d) {
el = document.createElement("div")
d.appendChild(el)
}
self.setData = function (list) {
if (list.length == 0)
if (list.length === 0)
return
var h2 = document.createElement("h2")

View file

@ -7,7 +7,7 @@ define([], function () {
var container = document.createElement("div")
function switchTab(ev) {
function switchTab() {
for (var i = 0; i < tabs.children.length; i++) {
var el = tabs.children[i]
el.classList.remove("visible")

View file

@ -13,6 +13,29 @@
"grunt-contrib-requirejs": "^0.4.4",
"grunt-contrib-uglify": "^0.5.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
}
}
}

View file

@ -1,5 +1,3 @@
"use strict"
module.exports = function(grunt) {
grunt.config.merge({
copy: {
@ -31,7 +29,7 @@ module.exports = function(grunt) {
],
expand: true,
dest: "build/",
cwd: "bower_components/ionicons/",
cwd: "bower_components/ionicons/"
}
},
cssmin: {
@ -61,5 +59,5 @@ module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-contrib-copy")
grunt.loadNpmTasks("grunt-contrib-requirejs")
grunt.loadNpmTasks('grunt-contrib-cssmin')
grunt.loadNpmTasks("grunt-contrib-cssmin")
}

View file

@ -1,5 +1,3 @@
"use strict"
module.exports = function (grunt) {
grunt.config.merge({
clean: {

View file

@ -1,5 +1,3 @@
"use strict"
module.exports = function (grunt) {
grunt.config.merge({
connect: {

View file

@ -1,5 +1,3 @@
"use strict"
module.exports = function (grunt) {
grunt.config.merge({
checkDependencies: {
@ -15,10 +13,13 @@ module.exports = function (grunt) {
},
eslint: {
options: {
rule: {
semi: [2, "never"],
strict: [2, "never"],
curly: [2, "multi"]
rules: {
"semi": [2, "never"],
"curly": [2, "multi"],
"strict": [2, "never"],
"no-multi-spaces": 0,
"no-new": 0,
"no-shadow": 0
}
},
sources: {