From 1f8cb5203e55baf6cbfbe1199ba9249a492512f7 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Mon, 30 Mar 2015 03:20:43 +0200 Subject: [PATCH] make eslint happier --- lib/infobox/link.js | 4 +- lib/infobox/main.js | 2 +- lib/infobox/node.js | 194 ++++++++++++++++++++++---------------------- package.json | 2 + tasks/linting.js | 2 +- 5 files changed, 103 insertions(+), 101 deletions(-) diff --git a/lib/infobox/link.js b/lib/infobox/link.js index 9cb367d..1b83e7e 100644 --- a/lib/infobox/link.js +++ b/lib/infobox/link.js @@ -1,13 +1,13 @@ define(function () { return function (config, el, router, d) { var h2 = document.createElement("h2") - a1 = document.createElement("a") + var a1 = document.createElement("a") a1.href = "#" a1.onclick = router.node(d.source.node) a1.textContent = d.source.node.nodeinfo.hostname h2.appendChild(a1) h2.appendChild(document.createTextNode(" – ")) - a2 = document.createElement("a") + var a2 = document.createElement("a") a2.href = "#" a2.onclick = router.node(d.target.node) a2.textContent = d.target.node.nodeinfo.hostname diff --git a/lib/infobox/main.js b/lib/infobox/main.js index 5e2e07c..5a12a67 100644 --- a/lib/infobox/main.js +++ b/lib/infobox/main.js @@ -1,7 +1,7 @@ define(["infobox/link", "infobox/node"], function (Link, Node) { return function (config, sidebar, router) { var self = this - el = undefined + var el function destroy() { if (el && el.parentNode) { diff --git a/lib/infobox/node.js b/lib/infobox/node.js index c46a020..57502d9 100644 --- a/lib/infobox/node.js +++ b/lib/infobox/node.js @@ -1,4 +1,101 @@ define(["moment", "tablesort", "tablesort.numeric"], function (moment, Tablesort) { + function showFirmware(d) { + var release = dictGet(d.nodeinfo, ["software", "firmware", "release"]) + var base = dictGet(d.nodeinfo, ["software", "firmware", "base"]) + + if (release === null || base === null) + return undefined + + return release + " / " + base + } + + function showUptime(d) { + if (!("uptime" in d.statistics)) + return undefined + + return moment.duration(d.statistics.uptime, "seconds").humanize() + } + + function showFirstseen(d) { + if (!("firstseen" in d)) + return undefined + + return d.firstseen.fromNow(true) + } + + function showClients(d) { + if (!d.flags.online) + return undefined + + return function (el) { + el.appendChild(document.createTextNode(d.statistics.clients > 0 ? d.statistics.clients : "keine")) + el.appendChild(document.createElement("br")) + + var span = document.createElement("span") + span.classList.add("clients") + span.textContent = " ".repeat(d.statistics.clients) + el.appendChild(span) + } + } + + function showIPs(d) { + var ips = dictGet(d.nodeinfo, ["network", "addresses"]) + if (ips === null) + return undefined + + ips.sort() + + return function (el) { + ips.forEach( function (ip, i) { + var link = !ip.startsWith("fe80:") + + if (i > 0) + el.appendChild(document.createElement("br")) + + if (link) { + var a = document.createElement("a") + a.href = "http://[" + ip + "]/" + a.textContent = ip + el.appendChild(a) + } else + el.appendChild(document.createTextNode(ip)) + }) + } + } + + function showBar(className, v) { + var span = document.createElement("span") + span.classList.add("bar") + span.classList.add(className) + + var bar = document.createElement("span") + bar.style.width = (v * 100) + "%" + span.appendChild(bar) + + var label = document.createElement("label") + label.textContent = (Math.round(v * 100)) + " %" + span.appendChild(label) + + return span + } + + function showRAM(d) { + if (!("memory_usage" in d.statistics)) + return undefined + + return function (el) { + el.appendChild(showBar("memory-usage", d.statistics.memory_usage)) + } + } + + function showAutoupdate(d) { + var au = dictGet(d.nodeinfo, ["software", "autoupdater"]) + if (!au) + return undefined + + return au.enabled ? "aktiviert (" + au.branch + ")" : "deaktiviert" + } + return function(config, el, router, d) { var h2 = document.createElement("h2") h2.textContent = d.nodeinfo.hostname @@ -104,102 +201,5 @@ define(["moment", "tablesort", "tablesort.numeric"], function (moment, Tablesort el.appendChild(table) } - - function showFirmware(d) { - var release = dictGet(d.nodeinfo, ["software", "firmware", "release"]) - var base = dictGet(d.nodeinfo, ["software", "firmware", "base"]) - - if (release === null || base === null) - return - - return release + " / " + base - } - - function showUptime(d) { - if (!("uptime" in d.statistics)) - return - - return moment.duration(d.statistics.uptime, "seconds").humanize() - } - - function showFirstseen(d) { - if (!("firstseen" in d)) - return - - return d.firstseen.fromNow(true) - } - - function showClients(d) { - if (!d.flags.online) - return - - return function (el) { - el.appendChild(document.createTextNode(d.statistics.clients > 0 ? d.statistics.clients : "keine")) - el.appendChild(document.createElement("br")) - - var span = document.createElement("span") - span.classList.add("clients") - span.textContent = " ".repeat(d.statistics.clients) - el.appendChild(span) - } - } - - function showIPs(d) { - var ips = dictGet(d.nodeinfo, ["network", "addresses"]) - if (ips === null) - return - - ips.sort() - - return function (el) { - ips.forEach( function (ip, i) { - var link = !ip.startsWith("fe80:") - - if (i > 0) - el.appendChild(document.createElement("br")) - - if (link) { - var a = document.createElement("a") - a.href = "http://[" + ip + "]/" - a.textContent = ip - el.appendChild(a) - } else - el.appendChild(document.createTextNode(ip)) - }) - } - } - - function showRAM(d) { - if (!("memory_usage" in d.statistics)) - return - - return function (el) { - el.appendChild(showBar("memory-usage", d.statistics.memory_usage)) - } - } - - function showBar(className, v) { - var span = document.createElement("span") - span.classList.add("bar") - span.classList.add(className) - - var bar = document.createElement("span") - bar.style.width = (v * 100) + "%" - span.appendChild(bar) - - var label = document.createElement("label") - label.textContent = (Math.round(v * 100)) + " %" - span.appendChild(label) - - return span - } - - function showAutoupdate(d) { - var au = dictGet(d.nodeinfo, ["software", "autoupdater"]) - if (!au) - return - - return au.enabled ? "aktiviert (" + au.branch + ")" : "deaktiviert" - } } }) diff --git a/package.json b/package.json index 4af7708..b9112c7 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,8 @@ "node": true }, "globals": { + "attributeEntry": false, + "dictGet": false, "getJSON": false, "has_location": false, "limit": false, diff --git a/tasks/linting.js b/tasks/linting.js index fac4eef..974029d 100644 --- a/tasks/linting.js +++ b/tasks/linting.js @@ -23,7 +23,7 @@ module.exports = function (grunt) { } }, sources: { - src: ["app.js", "!Gruntfile.js", "lib/*.js"] + src: ["app.js", "!Gruntfile.js", "lib/**/*.js"] }, grunt: { src: ["Gruntfile.js", "tasks/*.js"]