change code style to ffrgb/meshviewer fork

This commit is contained in:
Milan Pässler 2017-03-17 03:14:57 +01:00
commit 418b630e02
42 changed files with 3472 additions and 3121 deletions

View file

@ -11,6 +11,6 @@ trim_trailing_whitespace = true
end_of_line = lf end_of_line = lf
insert_final_newline = true insert_final_newline = true
[*.{js,html,scss,json}] [*.{js,html,scss,json,yml,md}]
indent_size = 2 indent_size = 2
indent_style = space indent_style = space

2
.gitignore vendored
View file

@ -3,3 +3,5 @@ node_modules/
build/ build/
.sass-cache/ .sass-cache/
config.json config.json
.idea/
.eslintrc

View file

@ -1,24 +1,24 @@
module.exports = function (grunt) { module.exports = function (grunt) {
grunt.loadNpmTasks("grunt-git-describe") grunt.loadNpmTasks("grunt-git-describe");
grunt.initConfig({ grunt.initConfig({
"git-describe": { "git-describe": {
options: {}, options: {},
default: {} default: {}
} }
}) });
grunt.registerTask("saveRevision", function() { grunt.registerTask("saveRevision", function () {
grunt.event.once("git-describe", function (rev) { grunt.event.once("git-describe", function (rev) {
grunt.option("gitRevision", rev) grunt.option("gitRevision", rev);
}) });
grunt.task.run("git-describe") grunt.task.run("git-describe");
}) });
grunt.loadTasks("tasks") grunt.loadTasks("tasks");
grunt.registerTask("default", ["bower-install-simple", "lint", "saveRevision", "copy", "sass", "postcss", "requirejs"]) grunt.registerTask("default", ["bower-install-simple", "lint", "saveRevision", "copy", "sass", "postcss", "requirejs"]);
grunt.registerTask("lint", ["eslint"]) grunt.registerTask("lint", ["eslint"]);
grunt.registerTask("dev", ["default", "connect:server", "watch"]) grunt.registerTask("dev", ["default", "connect:server", "watch"]);
} };

6
app.js
View file

@ -29,8 +29,8 @@ require.config({
"tablesort.numeric": ["tablesort"], "tablesort.numeric": ["tablesort"],
"helper": ["numeral-intl"] "helper": ["numeral-intl"]
} }
}) });
require(["main", "helper"], function (main) { require(["main", "helper"], function (main) {
getJSON("config.json").then(main) getJSON("config.json").then(main);
}) });

View file

@ -6,4 +6,4 @@
wrap: true, wrap: true,
optimize: "uglify", optimize: "uglify",
out: "app-combined.js" out: "app-combined.js"
}) });

247
helper.js
View file

@ -1,228 +1,241 @@
function get(url) { function get(url) {
return new Promise(function(resolve, reject) { return new Promise(function (resolve, reject) {
var req = new XMLHttpRequest() var req = new XMLHttpRequest();
req.open('GET', url) req.open('GET', url);
req.onload = function() { req.onload = function () {
if (req.status == 200) { if (req.status == 200) {
resolve(req.response) resolve(req.response);
} }
else { else {
reject(Error(req.statusText)) reject(Error(req.statusText));
}
} }
};
req.onerror = function() { req.onerror = function () {
reject(Error("Network Error")) reject(Error("Network Error"));
} };
req.send() req.send();
}) });
} }
function getJSON(url) { function getJSON(url) {
return get(url).then(JSON.parse) return get(url).then(JSON.parse);
} }
function sortByKey(key, d) { function sortByKey(key, d) {
return d.slice().sort( function (a, b) { return d.slice().sort(function (a, b) {
return a[key] - b[key] return a[key] - b[key];
}).reverse() }).reverse();
} }
function limit(key, m, d) { function limit(key, m, d) {
return d.filter( function (d) { return d.filter(function (d) {
return d[key].isAfter(m) return d[key].isAfter(m);
}) });
} }
function sum(a) { function sum(a) {
return a.reduce( function (a, b) { return a.reduce(function (a, b) {
return a + b return a + b;
}, 0) }, 0);
} }
function one() { function one() {
return 1 return 1;
} }
function trueDefault(d) { function trueDefault(d) {
return d === undefined ? true : d return d === undefined ? true : d;
} }
function dictGet(dict, key) { function dictGet(dict, key) {
var k = key.shift() var k = key.shift();
if (!(k in dict)) if (!(k in dict)) {
return null return null;
}
if (key.length == 0) if (key.length == 0) {
return dict[k] return dict[k];
}
return dictGet(dict[k], key) return dictGet(dict[k], key);
} }
function localStorageTest() { function localStorageTest() {
var test = 'test' var test = 'test';
try { try {
localStorage.setItem(test, test) localStorage.setItem(test, test);
localStorage.removeItem(test) localStorage.removeItem(test);
return true return true;
} catch(e) { } catch (e) {
return false return false;
} }
} }
function listReplace(s, subst) { function listReplace(s, subst) {
for (key in subst) { for (key in subst) {
var re = new RegExp(key, 'g') var re = new RegExp(key, 'g');
s = s.replace(re, subst[key]) s = s.replace(re, subst[key]);
} }
return s return s;
} }
/* Helpers working with nodes */ /* Helpers working with nodes */
function offline(d) { function offline(d) {
return !d.flags.online return !d.flags.online;
} }
function online(d) { function online(d) {
return d.flags.online return d.flags.online;
} }
function has_location(d) { function has_location(d) {
return "location" in d.nodeinfo && return "location" in d.nodeinfo &&
Math.abs(d.nodeinfo.location.latitude) < 90 && Math.abs(d.nodeinfo.location.latitude) < 90 &&
Math.abs(d.nodeinfo.location.longitude) < 180 Math.abs(d.nodeinfo.location.longitude) < 180;
} }
function subtract(a, b) { function subtract(a, b) {
var ids = {} var ids = {};
b.forEach( function (d) { b.forEach(function (d) {
ids[d.nodeinfo.node_id] = true ids[d.nodeinfo.node_id] = true;
}) });
return a.filter( function (d) { return a.filter(function (d) {
return !(d.nodeinfo.node_id in ids) return !(d.nodeinfo.node_id in ids);
}) });
} }
/* Helpers working with links */ /* Helpers working with links */
function showDistance(d) { function showDistance(d) {
if (isNaN(d.distance)) if (isNaN(d.distance)) {
return return;
}
return numeral(d.distance).format("0,0") + " m" return numeral(d.distance).format("0,0") + " m";
} }
function showTq(d) { function showTq(d) {
return numeral(1/d.tq).format("0%") return numeral(1 / d.tq).format("0%");
} }
/* Infobox stuff (XXX: move to module) */ /* Infobox stuff (XXX: move to module) */
function attributeEntry(el, label, value) { function attributeEntry(el, label, value) {
if (value === null || value == undefined) if (value === null || value == undefined) {
return return;
var tr = document.createElement("tr")
var th = document.createElement("th")
if (typeof label === "string")
th.textContent = label
else {
th.appendChild(label)
tr.className = "routerpic"
} }
tr.appendChild(th) var tr = document.createElement("tr");
var th = document.createElement("th");
if (typeof label === "string") {
th.textContent = label;
} else {
th.appendChild(label);
tr.className = "routerpic";
}
var td = document.createElement("td") tr.appendChild(th);
if (typeof value == "function") var td = document.createElement("td");
value(td)
else
td.appendChild(document.createTextNode(value))
tr.appendChild(td) if (typeof value == "function") {
value(td);
} else {
td.appendChild(document.createTextNode(value));
}
el.appendChild(tr) tr.appendChild(td);
return td el.appendChild(tr);
return td;
} }
function createIframe(opt, width, height) { function createIframe(opt, width, height) {
el = document.createElement("iframe") el = document.createElement("iframe");
width = typeof width !== 'undefined' ? width : '100%' width = typeof width !== 'undefined' ? width : '100%';
height = typeof height !== 'undefined' ? height : '350px' height = typeof height !== 'undefined' ? height : '350px';
if (opt.src) if (opt.src) {
el.src = opt.src el.src = opt.src;
else } else {
el.src = opt el.src = opt;
}
if (opt.frameBorder) if (opt.frameBorder) {
el.frameBorder = opt.frameBorder el.frameBorder = opt.frameBorder;
else } else {
el.frameBorder = 1 el.frameBorder = 1;
}
if (opt.width) if (opt.width) {
el.width = opt.width el.width = opt.width;
else } else {
el.width = width el.width = width;
}
if (opt.height) if (opt.height) {
el.height = opt.height el.height = opt.height;
else } else {
el.height = height el.height = height;
}
el.scrolling = "no" el.scrolling = "no";
el.seamless = "seamless" el.seamless = "seamless";
return el return el;
} }
function showStat(o, subst) { function showStat(o, subst) {
var content, caption var content, caption;
subst = typeof subst !== 'undefined' ? subst : {} subst = typeof subst !== 'undefined' ? subst : {};
if (o.thumbnail) { if (o.thumbnail) {
content = document.createElement("img") content = document.createElement("img");
content.src = listReplace(o.thumbnail, subst) content.src = listReplace(o.thumbnail, subst);
} }
if (o.caption) { if (o.caption) {
caption = listReplace(o.caption, subst) caption = listReplace(o.caption, subst);
if (!content) if (!content) {
content = document.createTextNode(caption) content = document.createTextNode(caption);
}
} }
if (o.iframe) { if (o.iframe) {
content = createIframe(o.iframe, o.width, o.height) content = createIframe(o.iframe, o.width, o.height);
if (o.iframe.src) if (o.iframe.src) {
content.src = listReplace(o.iframe.src, subst) content.src = listReplace(o.iframe.src, subst);
else } else {
content.src = listReplace(o.iframe, subst) content.src = listReplace(o.iframe, subst);
}
} }
var p = document.createElement("p") var p = document.createElement("p");
if (o.href) { if (o.href) {
var link = document.createElement("a") var link = document.createElement("a");
link.target = "_blank" link.target = "_blank";
link.href = listReplace(o.href, subst) link.href = listReplace(o.href, subst);
link.appendChild(content) link.appendChild(content);
if (caption && o.thumbnail) if (caption && o.thumbnail) {
link.title = caption link.title = caption;
}
p.appendChild(link) p.appendChild(link);
} else } else {
p.appendChild(content) p.appendChild(content);
}
return p return p;
} }

View file

@ -1,6 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no"> <meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" href="css/ionicons.min.css"> <link rel="stylesheet" href="css/ionicons.min.css">
@ -10,19 +10,19 @@
<script src="vendor/es6-shim/es6-shim.min.js"></script> <script src="vendor/es6-shim/es6-shim.min.js"></script>
<script src="app.js"></script> <script src="app.js"></script>
<script> <script>
console.log("Version: #revision#") console.log("Version: #revision#");
</script> </script>
</head> </head>
<body> <body>
<div class="loader"> <div class="loader">
<p> <p>
Lade<br /> Lade<br/>
<span class="spinner"></span><br /> <span class="spinner"></span><br/>
Karte &amp; Knoten... Karte &amp; Knoten...
</p> </p>
<noscript> <noscript>
<strong>JavaScript required</strong> <strong>JavaScript required</strong>
</noscript> </noscript>
</div> </div>
</body> </body>
</html> </html>

View file

@ -1,6 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no"> <meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" href="bower_components/roboto-slab-fontface/roboto-slab-fontface.css"> <link rel="stylesheet" href="bower_components/roboto-slab-fontface/roboto-slab-fontface.css">
@ -11,8 +11,8 @@
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<script src="bower_components/es6-shim/es6-shim.min.js"></script> <script src="bower_components/es6-shim/es6-shim.min.js"></script>
<script src="bower_components/requirejs/require.js" data-main="app"></script> <script src="bower_components/requirejs/require.js" data-main="app"></script>
</head> </head>
<body> <body>
<div class="loader"> <div class="loader">
<p> <p>
Lade<br/> Lade<br/>
@ -23,5 +23,5 @@
<strong>JavaScript required</strong> <strong>JavaScript required</strong>
</noscript> </noscript>
</div> </div>
</body> </body>
</html> </html>

View file

@ -1,38 +1,38 @@
define(function () { define(function () {
return function() { return function () {
this.render = function (d) { this.render = function (d) {
var el = document.createElement("div") var el = document.createElement("div");
d.appendChild(el) d.appendChild(el);
var s = "<h2>Über HopGlass</h2>" var s = "<h2>Über HopGlass</h2>";
s += "<p>Mit Doppelklick und Shift+Doppelklick kann man in der Karte " s += "<p>Mit Doppelklick und Shift+Doppelklick kann man in der Karte ";
s += "auch zoomen.</p>" s += "auch zoomen.</p>";
s += "<h3>AGPL 3</h3>" s += "<h3>AGPL 3</h3>";
s += "<p>Copyright (C) Milan Pässler</p>" s += "<p>Copyright (C) Milan Pässler</p>";
s += "<p>Copyright (C) Nils Schneider</p>" s += "<p>Copyright (C) Nils Schneider</p>";
s += "<p>This program is free software: you can redistribute it and/or " s += "<p>This program is free software: you can redistribute it and/or ";
s += "modify it under the terms of the GNU Affero General Public " s += "modify it under the terms of the GNU Affero General Public ";
s += "License as published by the Free Software Foundation, either " s += "License as published by the Free Software Foundation, either ";
s += "version 3 of the License, or (at your option) any later version.</p>" s += "version 3 of the License, or (at your option) any later version.</p>";
s += "<p>This program is distributed in the hope that it will be useful, " s += "<p>This program is distributed in the hope that it will be useful, ";
s += "but WITHOUT ANY WARRANTY; without even the implied warranty of " s += "but WITHOUT ANY WARRANTY; without even the implied warranty of ";
s += "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " s += "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ";
s += "GNU Affero General Public License for more details.</p>" s += "GNU Affero General Public License for more details.</p>";
s += "<p>You should have received a copy of the GNU Affero General " s += "<p>You should have received a copy of the GNU Affero General ";
s += "Public License along with this program. If not, see " s += "Public License along with this program. If not, see ";
s += "<a href=\"https://www.gnu.org/licenses/\">" s += "<a href=\"https://www.gnu.org/licenses/\">";
s += "https://www.gnu.org/licenses/</a>.</p>" s += "https://www.gnu.org/licenses/</a>.</p>";
s += "<p>The source code is available at " s += "<p>The source code is available at ";
s += "<a href=\"https://github.com/plumpudding/hopglass\">" s += "<a href=\"https://github.com/plumpudding/hopglass\">";
s += "https://github.com/plumpudding/hopglass</a>." s += "https://github.com/plumpudding/hopglass</a>.";
el.innerHTML = s el.innerHTML = s;
} };
} };
}) });

View file

@ -1,20 +1,21 @@
define([], function () { define([], function () {
return function (tag) { return function (tag) {
if (!tag) if (!tag) {
tag = "div" tag = "div";
}
var self = this var self = this;
var container = document.createElement(tag) var container = document.createElement(tag);
self.add = function (d) { self.add = function (d) {
d.render(container) d.render(container);
} };
self.render = function (el) { self.render = function (el) {
el.appendChild(container) el.appendChild(container);
} };
return self return self;
} };
}) });

View file

@ -1,80 +1,91 @@
define(["filters/nodefilter"], function (NodeFilter) { define(["filters/nodefilter"], function (NodeFilter) {
return function () { return function () {
var targets = [] var targets = [];
var filterObservers = [] var filterObservers = [];
var filters = [] var filters = [];
var filteredData var filteredData;
var data var data;
function remove(d) { function remove(d) {
targets = targets.filter( function (e) { return d !== e } ) targets = targets.filter(function (e) {
return d !== e;
});
} }
function add(d) { function add(d) {
targets.push(d) targets.push(d);
if (filteredData !== undefined) if (filteredData !== undefined) {
d.setData(filteredData) d.setData(filteredData);
}
} }
function setData(d) { function setData(d) {
data = d data = d;
refresh() refresh();
} }
function refresh() { function refresh() {
if (data === undefined) if (data === undefined) {
return return;
var filter = filters.reduce( function (a, f) {
return function (d) {
return a(d) && f.run(d)
} }
}, function () { return true })
filteredData = new NodeFilter(filter)(data) var filter = filters.reduce(function (a, f) {
return function (d) {
return a(d) && f.run(d);
};
}, function () {
return true;
});
targets.forEach( function (t) { filteredData = new NodeFilter(filter)(data);
t.setData(filteredData)
}) targets.forEach(function (t) {
t.setData(filteredData);
});
} }
function notifyObservers() { function notifyObservers() {
filterObservers.forEach( function (d) { filterObservers.forEach(function (d) {
d.filtersChanged(filters) d.filtersChanged(filters);
}) });
} }
function addFilter(d) { function addFilter(d) {
filters.push(d) filters.push(d);
notifyObservers() notifyObservers();
d.setRefresh(refresh) d.setRefresh(refresh);
refresh() refresh();
} }
function removeFilter(d) { function removeFilter(d) {
filters = filters.filter( function (e) { return d !== e } ) filters = filters.filter(function (e) {
notifyObservers() return d !== e;
refresh() });
notifyObservers();
refresh();
} }
function watchFilters(d) { function watchFilters(d) {
filterObservers.push(d) filterObservers.push(d);
d.filtersChanged(filters) d.filtersChanged(filters);
return function () { return function () {
filterObservers = filterObservers.filter( function (e) { return d !== e }) filterObservers = filterObservers.filter(function (e) {
} return d !== e;
});
};
} }
return { add: add, return {
add: add,
remove: remove, remove: remove,
setData: setData, setData: setData,
addFilter: addFilter, addFilter: addFilter,
removeFilter: removeFilter, removeFilter: removeFilter,
watchFilters: watchFilters, watchFilters: watchFilters,
refresh: refresh refresh: refresh
} };
} };
}) });

View file

@ -1,40 +1,43 @@
define([], function () { define([], function () {
return function (distributor) { return function (distributor) {
var container = document.createElement("ul") var container = document.createElement("ul");
container.classList.add("filters") container.classList.add("filters");
var div = document.createElement("div") var div = document.createElement("div");
function render(el) { function render(el) {
el.appendChild(div) el.appendChild(div);
} }
function filtersChanged(filters) { function filtersChanged(filters) {
while (container.firstChild) while (container.firstChild) {
container.removeChild(container.firstChild) container.removeChild(container.firstChild);
}
filters.forEach( function (d) { filters.forEach(function (d) {
var li = document.createElement("li") var li = document.createElement("li");
var div = document.createElement("div") var div = document.createElement("div");
container.appendChild(li) container.appendChild(li);
li.appendChild(div) li.appendChild(div);
d.render(div) d.render(div);
var button = document.createElement("button") var button = document.createElement("button");
button.textContent = "" button.textContent = "";
button.onclick = function () { button.onclick = function () {
distributor.removeFilter(d) distributor.removeFilter(d);
} };
li.appendChild(button) li.appendChild(button);
}) });
if (container.parentNode === div && filters.length === 0) if (container.parentNode === div && filters.length === 0) {
div.removeChild(container) div.removeChild(container);
else if (filters.length > 0) } else if (filters.length > 0) {
div.appendChild(container) div.appendChild(container);
}
} }
return { render: render, return {
render: render,
filtersChanged: filtersChanged filtersChanged: filtersChanged
} };
} };
}) });

View file

@ -1,52 +1,56 @@
define([], function () { define([], function () {
return function (name, key, value, f) { return function (name, key, value, f) {
var negate = false var negate = false;
var refresh var refresh;
var label = document.createElement("label") var label = document.createElement("label");
var strong = document.createElement("strong") var strong = document.createElement("strong");
label.textContent = name + " " label.textContent = name + " ";
label.appendChild(strong) label.appendChild(strong);
function run(d) { function run(d) {
var o = dictGet(d, key.slice(0)) var o = dictGet(d, key.slice(0));
if (f) if (f) {
o = f(o) o = f(o);
}
return o === value ? !negate : negate return o === value ? !negate : negate;
} }
function setRefresh(f) { function setRefresh(f) {
refresh = f refresh = f;
} }
function draw(el) { function draw(el) {
if (negate) if (negate) {
el.parentNode.classList.add("not") el.parentNode.classList.add("not");
else } else {
el.parentNode.classList.remove("not") el.parentNode.classList.remove("not");
}
strong.textContent = (negate ? "¬" : "" ) + value strong.textContent = (negate ? "¬" : "" ) + value;
} }
function render(el) { function render(el) {
el.appendChild(label) el.appendChild(label);
draw(el) draw(el);
label.onclick = function () { label.onclick = function () {
negate = !negate negate = !negate;
draw(el) draw(el);
if (refresh) if (refresh) {
refresh() refresh();
} }
};
} }
return { run: run, return {
run: run,
setRefresh: setRefresh, setRefresh: setRefresh,
render: render render: render
} };
} };
}) });

View file

@ -1,33 +1,36 @@
define([], function () { define([], function () {
return function (filter) { return function (filter) {
return function (data) { return function (data) {
var n = Object.create(data) var n = Object.create(data);
n.nodes = {} n.nodes = {};
for (var key in data.nodes) for (var key in data.nodes) {
n.nodes[key] = data.nodes[key].filter(filter) n.nodes[key] = data.nodes[key].filter(filter);
var filteredIds = new Set()
n.graph = {}
n.graph.nodes = data.graph.nodes.filter( function (d) {
var r
if (d.node)
r = filter(d.node)
else
r = filter({})
if (r)
filteredIds.add(d.id)
return r
})
n.graph.links = data.graph.links.filter( function (d) {
return filteredIds.has(d.source.id) && filteredIds.has(d.target.id)
})
return n
} }
var filteredIds = new Set();
n.graph = {};
n.graph.nodes = data.graph.nodes.filter(function (d) {
var r;
if (d.node) {
r = filter(d.node);
} else {
r = filter({});
} }
})
if (r) {
filteredIds.add(d.id);
}
return r;
});
n.graph.links = data.graph.links.filter(function (d) {
return filteredIds.has(d.source.id) && filteredIds.has(d.target.id);
});
return n;
};
};
});

File diff suppressed because it is too large Load diff

View file

@ -1,125 +1,127 @@
define([ "chroma-js", "map", "sidebar", "tabs", "container", "meshstats", define(["chroma-js", "map", "sidebar", "tabs", "container", "meshstats",
"legend", "linklist", "nodelist", "simplenodelist", "infobox/main", "legend", "linklist", "nodelist", "simplenodelist", "infobox/main",
"proportions", "forcegraph", "title", "about", "datadistributor", "proportions", "forcegraph", "title", "about", "datadistributor",
"filters/filtergui" ], "filters/filtergui"],
function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Legend, Linklist, function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Legend, Linklist,
Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph, Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph,
Title, About, DataDistributor, FilterGUI) { Title, About, DataDistributor, FilterGUI) {
return function (config, router) { return function (config, router) {
var self = this var self = this;
var content var content;
var contentDiv var contentDiv;
var linkScale = chroma.scale(chroma.interpolate.bezier(["#04C714", "#FF5500", "#F02311"])).domain([1, 5]) var linkScale = chroma.scale(chroma.interpolate.bezier(["#04C714", "#FF5500", "#F02311"])).domain([1, 5]);
var sidebar var sidebar;
var buttons = document.createElement("div") var buttons = document.createElement("div");
buttons.classList.add("buttons") buttons.classList.add("buttons");
var fanout = new DataDistributor() var fanout = new DataDistributor();
var fanoutUnfiltered = new DataDistributor() var fanoutUnfiltered = new DataDistributor();
fanoutUnfiltered.add(fanout) fanoutUnfiltered.add(fanout);
function removeContent() { function removeContent() {
if (!content) if (!content) {
return return;
}
router.removeTarget(content) router.removeTarget(content);
fanout.remove(content) fanout.remove(content);
content.destroy() content.destroy();
content = null content = null;
} }
function addContent(K) { function addContent(K) {
removeContent() removeContent();
content = new K(config, linkScale, sidebar.getWidth, router, buttons) content = new K(config, linkScale, sidebar.getWidth, router, buttons);
content.render(contentDiv) content.render(contentDiv);
fanout.add(content) fanout.add(content);
router.addTarget(content) router.addTarget(content);
} }
function mkView(K) { function mkView(K) {
return function () { return function () {
addContent(K) addContent(K);
} };
} }
var loader = document.getElementsByClassName("loader")[0] var loader = document.getElementsByClassName("loader")[0];
loader.classList.add("hide") loader.classList.add("hide");
contentDiv = document.createElement("div") contentDiv = document.createElement("div");
contentDiv.classList.add("content") contentDiv.classList.add("content");
document.body.appendChild(contentDiv) document.body.appendChild(contentDiv);
sidebar = new Sidebar(document.body) sidebar = new Sidebar(document.body);
contentDiv.appendChild(buttons) contentDiv.appendChild(buttons);
var buttonToggle = document.createElement("button") var buttonToggle = document.createElement("button");
buttonToggle.textContent = "\uF133" buttonToggle.textContent = "\uF133";
buttonToggle.onclick = function () { buttonToggle.onclick = function () {
if (content.constructor === Map) if (content.constructor === Map) {
router.view("g") router.view("g");
else } else {
router.view("m") router.view("m");
} }
};
buttons.appendChild(buttonToggle) buttons.appendChild(buttonToggle);
var title = new Title(config) var title = new Title(config);
var header = new Container("header") var header = new Container("header");
var infobox = new Infobox(config, sidebar, router) var infobox = new Infobox(config, sidebar, router);
var tabs = new Tabs() var tabs = new Tabs();
var overview = new Container() var overview = new Container();
var meshstats = new Meshstats(config) var meshstats = new Meshstats(config);
var legend = new Legend() var legend = new Legend();
var newnodeslist = new SimpleNodelist("new", "firstseen", router, "Neue Knoten") var newnodeslist = new SimpleNodelist("new", "firstseen", router, "Neue Knoten");
var lostnodeslist = new SimpleNodelist("lost", "lastseen", router, "Verschwundene Knoten") var lostnodeslist = new SimpleNodelist("lost", "lastseen", router, "Verschwundene Knoten");
var nodelist = new Nodelist(router) var nodelist = new Nodelist(router);
var linklist = new Linklist(linkScale, router) var linklist = new Linklist(linkScale, router);
var statistics = new Proportions(config, fanout) var statistics = new Proportions(config, fanout);
var about = new About() var about = new About();
fanoutUnfiltered.add(meshstats) fanoutUnfiltered.add(meshstats);
fanoutUnfiltered.add(newnodeslist) fanoutUnfiltered.add(newnodeslist);
fanoutUnfiltered.add(lostnodeslist) fanoutUnfiltered.add(lostnodeslist);
fanout.add(nodelist) fanout.add(nodelist);
fanout.add(linklist) fanout.add(linklist);
fanout.add(statistics) fanout.add(statistics);
sidebar.add(header) sidebar.add(header);
header.add(meshstats) header.add(meshstats);
header.add(legend) header.add(legend);
overview.add(newnodeslist) overview.add(newnodeslist);
overview.add(lostnodeslist) overview.add(lostnodeslist);
var filterGUI = new FilterGUI(fanout) var filterGUI = new FilterGUI(fanout);
fanout.watchFilters(filterGUI) fanout.watchFilters(filterGUI);
header.add(filterGUI) header.add(filterGUI);
sidebar.add(tabs) sidebar.add(tabs);
tabs.add("Aktuelles", overview) tabs.add("Aktuelles", overview);
tabs.add("Knoten", nodelist) tabs.add("Knoten", nodelist);
tabs.add("Verbindungen", linklist) tabs.add("Verbindungen", linklist);
tabs.add("Statistiken", statistics) tabs.add("Statistiken", statistics);
tabs.add("Über", about) tabs.add("Über", about);
router.addTarget(title) router.addTarget(title);
router.addTarget(infobox) router.addTarget(infobox);
router.addView("m", mkView(Map)) router.addView("m", mkView(Map));
router.addView("g", mkView(ForceGraph)) router.addView("g", mkView(ForceGraph));
router.view("m") router.view("m");
self.setData = fanoutUnfiltered.setData self.setData = fanoutUnfiltered.setData;
return self return self;
} };
}) });

View file

@ -1,48 +1,49 @@
define(function () { define(function () {
function showStatImg(o, d) { function showStatImg(o, d) {
var subst = {} var subst = {};
subst["{SOURCE}"] = d.source.node_id subst["{SOURCE}"] = d.source.node_id;
subst["{SOURCE_NAME}"] = d.source.node.nodeinfo.hostname ? d.source.node.nodeinfo.hostname : "unknown" subst["{SOURCE_NAME}"] = d.source.node.nodeinfo.hostname ? d.source.node.nodeinfo.hostname : "unknown";
subst["{TARGET}"] = d.target.node_id subst["{TARGET}"] = d.target.node_id;
subst["{TARGET_NAME}"] = d.target.node.nodeinfo.hostname ? d.target.node.nodeinfo.hostname : "unknown" subst["{TARGET_NAME}"] = d.target.node.nodeinfo.hostname ? d.target.node.nodeinfo.hostname : "unknown";
return showStat(o, subst) return showStat(o, subst);
} }
return function (config, el, router, d) { return function (config, el, router, d) {
var unknown = !(d.source.node) var unknown = !(d.source.node);
var h2 = document.createElement("h2") var h2 = document.createElement("h2");
var a1 = document.createElement("a") var a1 = document.createElement("a");
if (!unknown) { if (!unknown) {
a1.href = "#" a1.href = "#";
a1.onclick = router.node(d.source.node) a1.onclick = router.node(d.source.node);
} }
a1.textContent = unknown ? d.source.id : d.source.node.nodeinfo.hostname a1.textContent = unknown ? d.source.id : d.source.node.nodeinfo.hostname;
h2.appendChild(a1) h2.appendChild(a1);
h2.appendChild(document.createTextNode(" → ")) h2.appendChild(document.createTextNode(" → "));
var a2 = document.createElement("a") var a2 = document.createElement("a");
a2.href = "#" a2.href = "#";
a2.onclick = router.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);
var attributes = document.createElement("table") var attributes = document.createElement("table");
attributes.classList.add("attributes") attributes.classList.add("attributes");
attributeEntry(attributes, "TQ", showTq(d)) attributeEntry(attributes, "TQ", showTq(d));
attributeEntry(attributes, "Entfernung", showDistance(d)) attributeEntry(attributes, "Entfernung", showDistance(d));
attributeEntry(attributes, "Typ", d.type) attributeEntry(attributes, "Typ", d.type);
var hw1 = unknown ? null : dictGet(d.source.node.nodeinfo, ["hardware", "model"]) var hw1 = unknown ? null : dictGet(d.source.node.nodeinfo, ["hardware", "model"]);
var hw2 = dictGet(d.target.node.nodeinfo, ["hardware", "model"]) var hw2 = dictGet(d.target.node.nodeinfo, ["hardware", "model"]);
attributeEntry(attributes, "Hardware", (hw1 != null ? hw1 : "unbekannt") + " – " + (hw2 != null ? hw2 : "unbekannt")) attributeEntry(attributes, "Hardware", (hw1 != null ? hw1 : "unbekannt") + " – " + (hw2 != null ? hw2 : "unbekannt"));
el.appendChild(attributes) el.appendChild(attributes);
if (config.linkInfos) if (config.linkInfos) {
config.linkInfos.forEach( function (linkInfo) { config.linkInfos.forEach(function (linkInfo) {
var h4 = document.createElement("h4") var h4 = document.createElement("h4");
h4.textContent = linkInfo.name h4.textContent = linkInfo.name;
el.appendChild(h4) el.appendChild(h4);
el.appendChild(showStatImg(linkInfo, d)) el.appendChild(showStatImg(linkInfo, d));
}) });
} }
}) };
});

View file

@ -1,100 +1,103 @@
define(function () { define(function () {
return function (config, el, router, d) { return function (config, el, router, d) {
var sidebarTitle = document.createElement("h2") var sidebarTitle = document.createElement("h2");
sidebarTitle.textContent = "Location: " + d.toString() sidebarTitle.textContent = "Location: " + d.toString();
el.appendChild(sidebarTitle) el.appendChild(sidebarTitle);
getJSON("https://nominatim.openstreetmap.org/reverse?format=json&lat=" + d.lat + "&lon=" + d.lng + "&zoom=18&addressdetails=0") getJSON("https://nominatim.openstreetmap.org/reverse?format=json&lat=" + d.lat + "&lon=" + d.lng + "&zoom=18&addressdetails=0")
.then(function(result) { .then(function (result) {
if(result.display_name) if (result.display_name) {
sidebarTitle.textContent = result.display_name sidebarTitle.textContent = result.display_name;
}) }
});
var editLat = document.createElement("input") var editLat = document.createElement("input");
editLat.type = "text" editLat.type = "text";
editLat.value = d.lat.toFixed(9) editLat.value = d.lat.toFixed(9);
el.appendChild(createBox("lat", "Breitengrad", editLat)) el.appendChild(createBox("lat", "Breitengrad", editLat));
var editLng = document.createElement("input") var editLng = document.createElement("input");
editLng.type = "text" editLng.type = "text";
editLng.value = d.lng.toFixed(9) editLng.value = d.lng.toFixed(9);
el.appendChild(createBox("lng", "Längengrad", editLng)) el.appendChild(createBox("lng", "Längengrad", editLng));
var editUci = document.createElement("textarea") var editUci = document.createElement("textarea");
editUci.value = editUci.value =
"uci set gluon-node-info.@location[0]='location'; " + "uci set gluon-node-info.@location[0]='location'; " +
"uci set gluon-node-info.@location[0].share_location='1';" + "uci set gluon-node-info.@location[0].share_location='1';" +
"uci set gluon-node-info.@location[0].latitude='" + d.lat.toFixed(9) + "';" + "uci set gluon-node-info.@location[0].latitude='" + d.lat.toFixed(9) + "';" +
"uci set gluon-node-info.@location[0].longitude='" + d.lng.toFixed(9) + "';" + "uci set gluon-node-info.@location[0].longitude='" + d.lng.toFixed(9) + "';" +
"uci commit gluon-node-info" "uci commit gluon-node-info";
el.appendChild(createBox("uci", "Befehl", editUci, false)) el.appendChild(createBox("uci", "Befehl", editUci, false));
var linkPlain = document.createElement("a") var linkPlain = document.createElement("a");
linkPlain.textContent = "plain" linkPlain.textContent = "plain";
linkPlain.onclick = function() { linkPlain.onclick = function () {
switch2plain() switch2plain();
return false return false;
} };
linkPlain.href = "#" linkPlain.href = "#";
var linkUci = document.createElement("a") var linkUci = document.createElement("a");
linkUci.textContent = "uci" linkUci.textContent = "uci";
linkUci.onclick = function() { linkUci.onclick = function () {
switch2uci() switch2uci();
return false return false;
} };
linkUci.href = "#" linkUci.href = "#";
var hintText = document.createElement("p") var hintText = document.createElement("p");
hintText.appendChild(document.createTextNode("Du kannst zwischen ")) hintText.appendChild(document.createTextNode("Du kannst zwischen "));
hintText.appendChild(linkPlain) hintText.appendChild(linkPlain);
hintText.appendChild(document.createTextNode(" und ")) hintText.appendChild(document.createTextNode(" und "));
hintText.appendChild(linkUci) hintText.appendChild(linkUci);
hintText.appendChild(document.createTextNode(" wechseln.")) hintText.appendChild(document.createTextNode(" wechseln."));
el.appendChild(hintText) el.appendChild(hintText);
function createBox(name, title, inputElem, isVisible) { function createBox(name, title, inputElem, isVisible) {
var visible = typeof isVisible !== "undefined" ? isVisible : true var visible = typeof isVisible !== "undefined" ? isVisible : true;
var box = document.createElement("div") var box = document.createElement("div");
var heading = document.createElement("h3") var heading = document.createElement("h3");
heading.textContent = title heading.textContent = title;
box.appendChild(heading) box.appendChild(heading);
var btn = document.createElement("button") var btn = document.createElement("button");
btn.className = "ion-ios-copy" btn.className = "ion-ios-copy";
btn.title = "Kopieren" btn.title = "Kopieren";
btn.onclick = function() { copy2clip(inputElem.id) } btn.onclick = function () {
inputElem.id = "location-" + name copy2clip(inputElem.id);
inputElem.readOnly = true };
var line = document.createElement("p") inputElem.id = "location-" + name;
line.appendChild(inputElem) inputElem.readOnly = true;
line.appendChild(btn) var line = document.createElement("p");
box.appendChild(line) line.appendChild(inputElem);
box.id = "box-" + name line.appendChild(btn);
box.style.display = visible ? "block" : "none" box.appendChild(line);
return box box.id = "box-" + name;
box.style.display = visible ? "block" : "none";
return box;
} }
function copy2clip(id) { function copy2clip(id) {
var copyField = document.querySelector("#" + id) var copyField = document.querySelector("#" + id);
copyField.select() copyField.select();
try { try {
document.execCommand("copy") document.execCommand("copy");
} catch (err) { } catch (err) {
console.log(err) console.log(err);
} }
} }
function switch2plain() { function switch2plain() {
document.getElementById("box-uci").style.display = "none" document.getElementById("box-uci").style.display = "none";
document.getElementById("box-lat").style.display = "block" document.getElementById("box-lat").style.display = "block";
document.getElementById("box-lng").style.display = "block" document.getElementById("box-lng").style.display = "block";
} }
function switch2uci() { function switch2uci() {
document.getElementById("box-uci").style.display = "block" document.getElementById("box-uci").style.display = "block";
document.getElementById("box-lat").style.display = "none" document.getElementById("box-lat").style.display = "none";
document.getElementById("box-lng").style.display = "none" document.getElementById("box-lng").style.display = "none";
} }
} };
}) });

View file

@ -1,51 +1,51 @@
define(["infobox/link", "infobox/node", "infobox/location"], function (Link, Node, Location) { define(["infobox/link", "infobox/node", "infobox/location"], function (Link, Node, Location) {
return function (config, sidebar, router) { return function (config, sidebar, router) {
var self = this var self = this;
var el var el;
function destroy() { function destroy() {
if (el && el.parentNode) { if (el && el.parentNode) {
el.parentNode.removeChild(el) el.parentNode.removeChild(el);
el = undefined el = undefined;
sidebar.reveal() sidebar.reveal();
} }
} }
function create() { function create() {
destroy() destroy();
sidebar.ensureVisible() sidebar.ensureVisible();
sidebar.hide() sidebar.hide();
el = document.createElement("div") el = document.createElement("div");
sidebar.container.insertBefore(el, sidebar.container.firstChild) sidebar.container.insertBefore(el, sidebar.container.firstChild);
el.scrollIntoView(false) el.scrollIntoView(false);
el.classList.add("infobox") el.classList.add("infobox");
el.destroy = destroy el.destroy = destroy;
var closeButton = document.createElement("button") var closeButton = document.createElement("button");
closeButton.classList.add("close") closeButton.classList.add("close");
closeButton.onclick = router.reset closeButton.onclick = router.reset;
el.appendChild(closeButton) el.appendChild(closeButton);
} }
self.resetView = destroy self.resetView = destroy;
self.gotoNode = function (d) { self.gotoNode = function (d) {
create() create();
new Node(config, el, router, d) new Node(config, el, router, d);
} };
self.gotoLink = function (d) { self.gotoLink = function (d) {
create() create();
new Link(config, el, router, d) new Link(config, el, router, d);
} };
self.gotoLocation = function (d) { self.gotoLocation = function (d) {
create() create();
new Location(config, el, router, d) new Location(config, el, router, d);
} };
return self return self;
} };
}) });

View file

@ -2,83 +2,90 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
function (moment, numeral, Tablesort) { function (moment, numeral, Tablesort) {
function showGeoURI(d) { function showGeoURI(d) {
function showLatitude(d) { function showLatitude(d) {
var suffix = Math.sign(d) > -1 ? "' N" : "' S" var suffix = Math.sign(d) > -1 ? "' N" : "' S";
d = Math.abs(d) d = Math.abs(d);
var a = Math.floor(d) var a = Math.floor(d);
var min = (d * 60) % 60 var min = (d * 60) % 60;
a = (a < 10 ? "0" : "") + a a = (a < 10 ? "0" : "") + a;
return a + "° " + numeral(min).format("0.000") + suffix return a + "° " + numeral(min).format("0.000") + suffix;
} }
function showLongitude(d) { function showLongitude(d) {
var suffix = Math.sign(d) > -1 ? "' E" : "' W" var suffix = Math.sign(d) > -1 ? "' E" : "' W";
d = Math.abs(d) d = Math.abs(d);
var a = Math.floor(d) var a = Math.floor(d);
var min = (d * 60) % 60 var min = (d * 60) % 60;
a = (a < 100 ? "0" + (a < 10 ? "0" : "") : "") + a a = (a < 100 ? "0" + (a < 10 ? "0" : "") : "") + a;
return a + "° " + numeral(min).format("0.000") + suffix return a + "° " + numeral(min).format("0.000") + suffix;
} }
if (!has_location(d)) if (!has_location(d)) {
return undefined return undefined;
}
return function (el) { return function (el) {
var latitude = d.nodeinfo.location.latitude var latitude = d.nodeinfo.location.latitude;
var longitude = d.nodeinfo.location.longitude var longitude = d.nodeinfo.location.longitude;
var a = document.createElement("a") var a = document.createElement("a");
a.textContent = showLatitude(latitude) + " " + a.textContent = showLatitude(latitude) + " " +
showLongitude(longitude) showLongitude(longitude);
a.href = "geo:" + latitude + "," + longitude a.href = "geo:" + latitude + "," + longitude;
el.appendChild(a) el.appendChild(a);
} };
} }
function showStatus(d) { function showStatus(d) {
return function (el) { return function (el) {
el.classList.add(d.flags.unseen ? "unseen" : (d.flags.online ? "online" : "offline")) el.classList.add(d.flags.unseen ? "unseen" : (d.flags.online ? "online" : "offline"));
if (d.flags.online) if (d.flags.online) {
el.textContent = "online, letzte Nachricht " + d.lastseen.fromNow() + " (" + d.lastseen.format("DD.MM.YYYY, H:mm:ss") + ")" el.textContent = "online, letzte Nachricht " + d.lastseen.fromNow() + " (" + d.lastseen.format("DD.MM.YYYY, H:mm:ss") + ")";
else } else {
el.textContent = "offline, letzte Nachricht " + d.lastseen.fromNow() + " (" + d.lastseen.format("DD.MM.YYYY, H:mm:ss") + ")" el.textContent = "offline, letzte Nachricht " + d.lastseen.fromNow() + " (" + d.lastseen.format("DD.MM.YYYY, H:mm:ss") + ")";
} }
};
} }
function showFirmware(d) { function showFirmware(d) {
var release = dictGet(d.nodeinfo, ["software", "firmware", "release"]) var release = dictGet(d.nodeinfo, ["software", "firmware", "release"]);
var base = dictGet(d.nodeinfo, ["software", "firmware", "base"]) var base = dictGet(d.nodeinfo, ["software", "firmware", "base"]);
if (release === null || base === null) if (release === null || base === null) {
return undefined return undefined;
}
return release + " / " + base return release + " / " + base;
} }
function showSite(d, config) { function showSite(d, config) {
var site = dictGet(d.nodeinfo, ["system", "site_code"]) var site = dictGet(d.nodeinfo, ["system", "site_code"]);
var rt = site var rt = site;
if (config.siteNames) if (config.siteNames) {
config.siteNames.forEach( function (t) { config.siteNames.forEach(function (t) {
if(site === t.site) if (site === t.site) {
rt = t.name rt = t.name;
}) }
return rt });
}
return rt;
} }
function showUptime(d) { function showUptime(d) {
if (!("uptime" in d.statistics)) if (!("uptime" in d.statistics)) {
return undefined return undefined;
}
return moment.duration(d.statistics.uptime, "seconds").humanize() return moment.duration(d.statistics.uptime, "seconds").humanize();
} }
function showFirstseen(d) { function showFirstseen(d) {
if (!("firstseen" in d)) if (!("firstseen" in d)) {
return undefined return undefined;
}
return d.firstseen.fromNow(true) return d.firstseen.fromNow(true);
} }
function wifiChannelAlias(ch) { function wifiChannelAlias(ch) {
@ -115,467 +122,510 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
"132": "5660 MHz (DFS) !!", "132": "5660 MHz (DFS) !!",
"136": "5680 MHz (DFS) !!", "136": "5680 MHz (DFS) !!",
"140": "5700 MHz (DFS) !!" "140": "5700 MHz (DFS) !!"
};
if (!(ch in chlist)) {
return "";
} else {
return chlist[ch];
} }
if (!(ch in chlist))
return ""
else
return chlist[ch]
} }
function showWifiChannel(ch) { function showWifiChannel(ch) {
if (!ch) if (!ch) {
return undefined return undefined;
}
return ch + " (" + wifiChannelAlias(ch) + ")" return ch + " (" + wifiChannelAlias(ch) + ")";
} }
function showClients(d) { function showClients(d) {
if (!d.flags.online) if (!d.flags.online) {
return undefined return undefined;
var meshclients = getMeshClients(d)
resetMeshClients(d)
var before = " ("
var after = " in der lokalen Wolke)"
return function (el) {
el.appendChild(document.createTextNode(d.statistics.clients > 0 ? d.statistics.clients : "keine"))
el.appendChild(document.createTextNode(before))
el.appendChild(document.createTextNode(meshclients > 0 ? meshclients : "keine"))
el.appendChild(document.createTextNode(after))
el.appendChild(document.createElement("br"))
var span = document.createElement("span")
span.classList.add("clients")
span.textContent = " ".repeat(d.statistics.clients)
el.appendChild(span)
var spanmesh = document.createElement("span")
spanmesh.classList.add("clientsMesh")
spanmesh.textContent = " ".repeat(meshclients - d.statistics.clients)
el.appendChild(spanmesh)
} }
var meshclients = getMeshClients(d);
resetMeshClients(d);
var before = " (";
var after = " in der lokalen Wolke)";
return function (el) {
el.appendChild(document.createTextNode(d.statistics.clients > 0 ? d.statistics.clients : "keine"));
el.appendChild(document.createTextNode(before));
el.appendChild(document.createTextNode(meshclients > 0 ? meshclients : "keine"));
el.appendChild(document.createTextNode(after));
el.appendChild(document.createElement("br"));
var span = document.createElement("span");
span.classList.add("clients");
span.textContent = " ".repeat(d.statistics.clients);
el.appendChild(span);
var spanmesh = document.createElement("span");
spanmesh.classList.add("clientsMesh");
spanmesh.textContent = " ".repeat(meshclients - d.statistics.clients);
el.appendChild(spanmesh);
};
} }
function getMeshClients(node) { function getMeshClients(node) {
var meshclients = 0 var meshclients = 0;
if (node.statistics && !isNaN(node.statistics.clients)) if (node.statistics && !isNaN(node.statistics.clients)) {
meshclients = node.statistics.clients meshclients = node.statistics.clients;
}
if (!node) if (!node) {
return 0 return 0;
}
if (node.parsed) if (node.parsed) {
return 0 return 0;
}
node.parsed = 1 node.parsed = 1;
node.neighbours.forEach(function (neighbour) { node.neighbours.forEach(function (neighbour) {
if (!neighbour.link.isVPN && neighbour.node) if (!neighbour.link.isVPN && neighbour.node) {
meshclients += getMeshClients(neighbour.node) meshclients += getMeshClients(neighbour.node);
}) }
});
return meshclients return meshclients;
} }
function resetMeshClients(node) { function resetMeshClients(node) {
if (!node.parsed) if (!node.parsed) {
return return;
}
node.parsed = 0 node.parsed = 0;
node.neighbours.forEach(function (neighbour) { node.neighbours.forEach(function (neighbour) {
if (!neighbour.link.isVPN && neighbour.node) if (!neighbour.link.isVPN && neighbour.node) {
resetMeshClients(neighbour.node) resetMeshClients(neighbour.node);
}) }
});
return
} }
function showMeshClients(d) { function showMeshClients(d) {
if (!d.flags.online) if (!d.flags.online) {
return undefined return undefined;
var meshclients = getMeshClients(d)
resetMeshClients(d)
return function (el) {
el.appendChild(document.createTextNode(meshclients > 0 ? meshclients : "keine"))
el.appendChild(document.createElement("br"))
} }
var meshclients = getMeshClients(d);
resetMeshClients(d);
return function (el) {
el.appendChild(document.createTextNode(meshclients > 0 ? meshclients : "keine"));
el.appendChild(document.createElement("br"));
};
} }
function showIPs(d) { function showIPs(d) {
var ips = dictGet(d.nodeinfo, ["network", "addresses"]) var ips = dictGet(d.nodeinfo, ["network", "addresses"]);
if (ips === null) if (ips === null) {
return undefined return undefined;
}
ips.sort() ips.sort();
return function (el) { return function (el) {
ips.forEach( function (ip, i) { ips.forEach(function (ip, i) {
var link = !ip.startsWith("fe80:") var link = !ip.startsWith("fe80:");
if (i > 0) if (i > 0) {
el.appendChild(document.createElement("br")) el.appendChild(document.createElement("br"));
}
if (link) { if (link) {
var a = document.createElement("a") var a = document.createElement("a");
if (ip.includes(".")) if (ip.includes(".")) {
a.href = "http://" + ip + "/" a.href = "http://" + ip + "/";
else } else {
a.href = "http://[" + ip + "]/" a.href = "http://[" + ip + "]/";
a.textContent = ip
el.appendChild(a)
} else
el.appendChild(document.createTextNode(ip))
})
} }
a.textContent = ip;
el.appendChild(a);
} else {
el.appendChild(document.createTextNode(ip));
}
});
};
} }
function showBar(className, v) { function showBar(className, v) {
var span = document.createElement("span") var span = document.createElement("span");
span.classList.add("bar") span.classList.add("bar");
span.classList.add(className) span.classList.add(className);
var bar = document.createElement("span") var bar = document.createElement("span");
bar.style.width = (v * 100) + "%" bar.style.width = (v * 100) + "%";
span.appendChild(bar) span.appendChild(bar);
var label = document.createElement("label") var label = document.createElement("label");
label.textContent = (Math.round(v * 100)) + " %" label.textContent = (Math.round(v * 100)) + " %";
span.appendChild(label) span.appendChild(label);
return span return span;
} }
function showLoadBar(className, v) { function showLoadBar(className, v) {
var span = document.createElement("span") var span = document.createElement("span");
span.classList.add("bar") span.classList.add("bar");
span.classList.add(className) span.classList.add(className);
var bar = document.createElement("span") var bar = document.createElement("span");
if (v >= 1) { if (v >= 1) {
bar.style.width = ((v * 100) % 100) + "%" bar.style.width = ((v * 100) % 100) + "%";
bar.style.background = "rgba(255, 50, 50, 0.9)" bar.style.background = "rgba(255, 50, 50, 0.9)";
span.style.background = "rgba(255, 50, 50, 0.6)" span.style.background = "rgba(255, 50, 50, 0.6)";
span.appendChild(bar) span.appendChild(bar);
} }
else else {
{ bar.style.width = (v * 100) + "%";
bar.style.width = (v * 100) + "%" span.appendChild(bar);
span.appendChild(bar)
} }
var label = document.createElement("label") var label = document.createElement("label");
label.textContent = +(Math.round(v + "e+2") + "e-2") label.textContent = +(Math.round(v + "e+2") + "e-2");
span.appendChild(label) span.appendChild(label);
return span return span;
} }
function showLoad(d) { function showLoad(d) {
if (!("loadavg" in d.statistics)) if (!("loadavg" in d.statistics)) {
return undefined return undefined;
}
return function (el) { return function (el) {
el.appendChild(showLoadBar("load-avg", d.statistics.loadavg)) el.appendChild(showLoadBar("load-avg", d.statistics.loadavg));
} };
} }
function showRAM(d) { function showRAM(d) {
if (!("memory_usage" in d.statistics)) if (!("memory_usage" in d.statistics)) {
return undefined return undefined;
}
return function (el) { return function (el) {
el.appendChild(showBar("memory-usage", d.statistics.memory_usage)) el.appendChild(showBar("memory-usage", d.statistics.memory_usage));
} };
} }
function showAirtime(band, val) { function showAirtime(band, val) {
if (!val) if (!val) {
return undefined return undefined;
}
return function (el) { return function (el) {
el.appendChild(showBar("airtime" + band.toString(), val)) el.appendChild(showBar("airtime" + band.toString(), val));
} };
} }
function createLink(target, router) { function createLink(target, router) {
if (!target) return document.createTextNode("unknown") if (!target) {
var unknown = !(target.node) return document.createTextNode("unknown");
var text = unknown ? (target.id ? target.id : target) : target.node.nodeinfo.hostname
if (!unknown) {
var link = document.createElement("a")
link.classList.add("hostname-link")
link.href = "#"
link.onclick = router.node(target.node)
link.textContent = text
return link
} }
return document.createTextNode(text) var unknown = !(target.node);
var text = unknown ? (target.id ? target.id : target) : target.node.nodeinfo.hostname;
if (!unknown) {
var link = document.createElement("a");
link.classList.add("hostname-link");
link.href = "#";
link.onclick = router.node(target.node);
link.textContent = text;
return link;
}
return document.createTextNode(text);
} }
function showGateway(d, router) { function showGateway(d, router) {
var nh var nh;
if (dictGet(d.statistics, ["nexthop"])) if (dictGet(d.statistics, ["nexthop"])) {
nh = dictGet(d.statistics, ["nexthop"]) nh = dictGet(d.statistics, ["nexthop"]);
if (dictGet(d.statistics, ["gateway_nexthop"])) }
nh = dictGet(d.statistics, ["gateway_nexthop"]) if (dictGet(d.statistics, ["gateway_nexthop"])) {
var gw = dictGet(d.statistics, ["gateway"]) nh = dictGet(d.statistics, ["gateway_nexthop"]);
}
var gw = dictGet(d.statistics, ["gateway"]);
if (!gw) return null if (!gw) {
return null;
}
return function (el) { return function (el) {
var num = 0 var num = 0;
while (gw && nh && gw.id !== nh.id && num < 10) { while (gw && nh && gw.id !== nh.id && num < 10) {
if (num !== 0) el.appendChild(document.createTextNode(" -> ")) if (num !== 0) {
el.appendChild(createLink(nh, router)) el.appendChild(document.createTextNode(" -> "));
num++ }
if (!nh.node || !nh.node.statistics) break el.appendChild(createLink(nh, router));
if (!dictGet(nh.node.statistics, ["gateway"]) || !dictGet(nh.node.statistics, ["gateway"]).id) break num++;
if (dictGet(nh.node.statistics, ["gateway"]).id !== gw.id) break if (!nh.node || !nh.node.statistics) {
if (dictGet(nh.node.statistics, ["gateway_nexthop"])) break;
nh = dictGet(nh.node.statistics, ["gateway_nexthop"]) }
else if (dictGet(nh.node.statistics, ["nexthop"])) if (!dictGet(nh.node.statistics, ["gateway"]) || !dictGet(nh.node.statistics, ["gateway"]).id) {
nh = dictGet(nh.node.statistics, ["nexthop"]) break;
else }
break if (dictGet(nh.node.statistics, ["gateway"]).id !== gw.id) {
break;
}
if (dictGet(nh.node.statistics, ["gateway_nexthop"])) {
nh = dictGet(nh.node.statistics, ["gateway_nexthop"]);
} else if (dictGet(nh.node.statistics, ["nexthop"])) {
nh = dictGet(nh.node.statistics, ["nexthop"]);
} else {
break;
}
} }
if (gw && nh && gw.id !== nh.id) { if (gw && nh && gw.id !== nh.id) {
if (num !== 0) el.appendChild(document.createTextNode(" -> ")) if (num !== 0) {
num++ el.appendChild(document.createTextNode(" -> "));
el.appendChild(document.createTextNode("..."))
} }
if (num !== 0) el.appendChild(document.createTextNode(" -> ")) num++;
el.appendChild(createLink(gw, router)) el.appendChild(document.createTextNode("..."));
} }
if (num !== 0) {
el.appendChild(document.createTextNode(" -> "));
}
el.appendChild(createLink(gw, router));
};
} }
function showPages(d) { function showPages(d) {
var webpages = dictGet(d.nodeinfo, ["pages"]) var webpages = dictGet(d.nodeinfo, ["pages"]);
if (webpages === null) if (webpages === null) {
return undefined return undefined;
}
webpages.sort() webpages.sort();
return function (el) { return function (el) {
webpages.forEach( function (webpage, i) { webpages.forEach(function (webpage, i) {
if (i > 0) if (i > 0) {
el.appendChild(document.createElement("br")) el.appendChild(document.createElement("br"));
}
var a = document.createElement("span") var a = document.createElement("span");
var link = document.createElement("a") var link = document.createElement("a");
link.href = webpage link.href = webpage;
if (webpage.search(/^https:\/\//i) !== -1) { if (webpage.search(/^https:\/\//i) !== -1) {
var lock = document.createElement("span") var lock = document.createElement("span");
lock.className = "ion-android-lock" lock.className = "ion-android-lock";
a.appendChild(lock) a.appendChild(lock);
var t1 = document.createTextNode(" ") var t1 = document.createTextNode(" ");
a.appendChild(t1) a.appendChild(t1);
link.textContent = webpage.replace(/^https:\/\//i, "") link.textContent = webpage.replace(/^https:\/\//i, "");
} }
else else {
link.textContent = webpage.replace(/^http:\/\//i, "") link.textContent = webpage.replace(/^http:\/\//i, "");
a.appendChild(link)
el.appendChild(a)
})
} }
a.appendChild(link);
el.appendChild(a);
});
};
} }
function showAutoupdate(d) { function showAutoupdate(d) {
var au = dictGet(d.nodeinfo, ["software", "autoupdater"]) var au = dictGet(d.nodeinfo, ["software", "autoupdater"]);
if (!au) if (!au) {
return undefined return undefined;
}
return au.enabled ? "aktiviert (" + au.branch + ")" : "deaktiviert" return au.enabled ? "aktiviert (" + au.branch + ")" : "deaktiviert";
} }
function showNodeImg(o, model) { function showNodeImg(o, model) {
if (!model) if (!model) {
return document.createTextNode("Knotenname") return document.createTextNode("Knotenname");
var content, caption
var modelhash = model.split("").reduce(function(a, b) {
a = ((a << 5) - a) + b.charCodeAt(0)
return a & a
}, 0)
content = document.createElement("img")
content.id = "routerpicture"
content.classList.add("nodeImg")
content.src = o.thumbnail.replace("{MODELHASH}", modelhash)
content.onerror = function() {
document.getElementById("routerpicdiv").outerHTML = "Knotenname"
} }
var content, caption;
var modelhash = model.split("").reduce(function (a, b) {
a = ((a << 5) - a) + b.charCodeAt(0);
return a & a;
}, 0);
content = document.createElement("img");
content.id = "routerpicture";
content.classList.add("nodeImg");
content.src = o.thumbnail.replace("{MODELHASH}", modelhash);
content.onerror = function () {
document.getElementById("routerpicdiv").outerHTML = "Knotenname";
};
if (o.caption) { if (o.caption) {
caption = o.caption.replace("{MODELHASH}", modelhash) caption = o.caption.replace("{MODELHASH}", modelhash);
if (!content) if (!content) {
content = document.createTextNode(caption) content = document.createTextNode(caption);
}
} }
var p = document.createElement("p") var p = document.createElement("p");
p.appendChild(content) p.appendChild(content);
return content return content;
} }
function showStatImg(o, d) { function showStatImg(o, d) {
var subst = {} var subst = {};
subst["{NODE_ID}"] = d.nodeinfo.node_id ? d.nodeinfo.node_id : "unknown" subst["{NODE_ID}"] = d.nodeinfo.node_id ? d.nodeinfo.node_id : "unknown";
subst["{NODE_NAME}"] = d.nodeinfo.hostname ? d.nodeinfo.hostname : "unknown" subst["{NODE_NAME}"] = d.nodeinfo.hostname ? d.nodeinfo.hostname : "unknown";
return showStat(o, subst) return showStat(o, subst);
} }
return function(config, el, router, d) { return function (config, el, router, d) {
var attributes = document.createElement("table") var attributes = document.createElement("table");
attributes.classList.add("attributes") attributes.classList.add("attributes");
if (config.hwImg) { if (config.hwImg) {
var top = document.createElement("div") var top = document.createElement("div");
top.id = "routerpicdiv" top.id = "routerpicdiv";
try { try {
config.hwImg.forEach(function(hwImg) { config.hwImg.forEach(function (hwImg) {
try { try {
top.appendChild(showNodeImg(hwImg, dictGet(d, ["nodeinfo", "hardware", "model"]))) top.appendChild(showNodeImg(hwImg, dictGet(d, ["nodeinfo", "hardware", "model"])));
} catch (err) { } catch (err) {
console.log(err.message) console.log(err.message);
} }
}) });
} catch (err) { } catch (err) {
console.log(err.message) console.log(err.message);
} }
attributeEntry(attributes, top, d.nodeinfo.hostname) attributeEntry(attributes, top, d.nodeinfo.hostname);
} else { } else {
var h2 = document.createElement("h2") var h2 = document.createElement("h2");
h2.textContent = d.nodeinfo.hostname h2.textContent = d.nodeinfo.hostname;
el.appendChild(h2) el.appendChild(h2);
} }
attributeEntry(attributes, "Status", showStatus(d)) attributeEntry(attributes, "Status", showStatus(d));
attributeEntry(attributes, "Gateway", d.flags.gateway ? "ja" : null) attributeEntry(attributes, "Gateway", d.flags.gateway ? "ja" : null);
attributeEntry(attributes, "Koordinaten", showGeoURI(d)) attributeEntry(attributes, "Koordinaten", showGeoURI(d));
if (config.showContact) if (config.showContact) {
attributeEntry(attributes, "Kontakt", dictGet(d.nodeinfo, ["owner", "contact"])) attributeEntry(attributes, "Kontakt", dictGet(d.nodeinfo, ["owner", "contact"]));
}
attributeEntry(attributes, "Hardware", dictGet(d.nodeinfo, ["hardware", "model"])) attributeEntry(attributes, "Hardware", dictGet(d.nodeinfo, ["hardware", "model"]));
attributeEntry(attributes, "Primäre MAC", dictGet(d.nodeinfo, ["network", "mac"])) attributeEntry(attributes, "Primäre MAC", dictGet(d.nodeinfo, ["network", "mac"]));
attributeEntry(attributes, "Node ID", dictGet(d.nodeinfo, ["node_id"])) attributeEntry(attributes, "Node ID", dictGet(d.nodeinfo, ["node_id"]));
attributeEntry(attributes, "Firmware", showFirmware(d)) attributeEntry(attributes, "Firmware", showFirmware(d));
attributeEntry(attributes, "Site", showSite(d, config)) attributeEntry(attributes, "Site", showSite(d, config));
attributeEntry(attributes, "Uptime", showUptime(d)) attributeEntry(attributes, "Uptime", showUptime(d));
attributeEntry(attributes, "Teil des Netzes", showFirstseen(d)) attributeEntry(attributes, "Teil des Netzes", showFirstseen(d));
attributeEntry(attributes, "Kanal 2.4 GHz", showWifiChannel(dictGet(d.nodeinfo, ["wireless", "chan2"]))) attributeEntry(attributes, "Kanal 2.4 GHz", showWifiChannel(dictGet(d.nodeinfo, ["wireless", "chan2"])));
attributeEntry(attributes, "Kanal 5 GHz", showWifiChannel(dictGet(d.nodeinfo, ["wireless", "chan5"]))) attributeEntry(attributes, "Kanal 5 GHz", showWifiChannel(dictGet(d.nodeinfo, ["wireless", "chan5"])));
attributeEntry(attributes, "Airtime 2.4 GHz", showAirtime(2, dictGet(d.statistics, ["wireless", "airtime2"]))) attributeEntry(attributes, "Airtime 2.4 GHz", showAirtime(2, dictGet(d.statistics, ["wireless", "airtime2"])));
attributeEntry(attributes, "Airtime 5 GHz", showAirtime(5, dictGet(d.statistics, ["wireless", "airtime5"]))) attributeEntry(attributes, "Airtime 5 GHz", showAirtime(5, dictGet(d.statistics, ["wireless", "airtime5"])));
attributeEntry(attributes, "Systemlast", showLoad(d)) attributeEntry(attributes, "Systemlast", showLoad(d));
attributeEntry(attributes, "Arbeitsspeicher", showRAM(d)) attributeEntry(attributes, "Arbeitsspeicher", showRAM(d));
attributeEntry(attributes, "IP Adressen", showIPs(d)) attributeEntry(attributes, "IP Adressen", showIPs(d));
attributeEntry(attributes, "Webseite", showPages(d)) attributeEntry(attributes, "Webseite", showPages(d));
attributeEntry(attributes, "Gewähltes Gateway", showGateway(d, router)) attributeEntry(attributes, "Gewähltes Gateway", showGateway(d, router));
attributeEntry(attributes, "Autom. Updates", showAutoupdate(d)) attributeEntry(attributes, "Autom. Updates", showAutoupdate(d));
attributeEntry(attributes, "Clients", showClients(d), showMeshClients(d)) attributeEntry(attributes, "Clients", showClients(d), showMeshClients(d));
el.appendChild(attributes) el.appendChild(attributes);
if (config.nodeInfos) if (config.nodeInfos) {
config.nodeInfos.forEach( function (nodeInfo) { config.nodeInfos.forEach(function (nodeInfo) {
var h4 = document.createElement("h4") var h4 = document.createElement("h4");
h4.textContent = nodeInfo.name h4.textContent = nodeInfo.name;
el.appendChild(h4) el.appendChild(h4);
el.appendChild(showStatImg(nodeInfo, d)) el.appendChild(showStatImg(nodeInfo, d));
}) });
}
if (d.neighbours.length > 0) { if (d.neighbours.length > 0) {
var h3 = document.createElement("h3") var h3 = document.createElement("h3");
h3.textContent = "Links (" + d.neighbours.length + ")" h3.textContent = "Links (" + d.neighbours.length + ")";
el.appendChild(h3) el.appendChild(h3);
var table = document.createElement("table") var table = document.createElement("table");
var thead = document.createElement("thead") var thead = document.createElement("thead");
var tr = document.createElement("tr") var tr = document.createElement("tr");
var th1 = document.createElement("th") var th1 = document.createElement("th");
th1.textContent = " " th1.textContent = " ";
tr.appendChild(th1) tr.appendChild(th1);
var th2 = document.createElement("th") var th2 = document.createElement("th");
th2.textContent = "Knoten" th2.textContent = "Knoten";
th2.classList.add("sort-default") th2.classList.add("sort-default");
tr.appendChild(th2) tr.appendChild(th2);
var th3 = document.createElement("th") var th3 = document.createElement("th");
th3.textContent = "TQ" th3.textContent = "TQ";
tr.appendChild(th3) tr.appendChild(th3);
var th4 = document.createElement("th") var th4 = document.createElement("th");
th4.textContent = "Typ" th4.textContent = "Typ";
tr.appendChild(th4) tr.appendChild(th4);
var th5 = document.createElement("th") var th5 = document.createElement("th");
th5.textContent = "Entfernung" th5.textContent = "Entfernung";
tr.appendChild(th5) tr.appendChild(th5);
thead.appendChild(tr) thead.appendChild(tr);
table.appendChild(thead) table.appendChild(thead);
var tbody = document.createElement("tbody") var tbody = document.createElement("tbody");
d.neighbours.forEach( function (d) { d.neighbours.forEach(function (d) {
var unknown = !(d.node) var unknown = !(d.node);
var tr = document.createElement("tr") var tr = document.createElement("tr");
var td1 = document.createElement("td") var td1 = document.createElement("td");
td1.appendChild(document.createTextNode(d.incoming ? " ← " : " → ")) td1.appendChild(document.createTextNode(d.incoming ? " ← " : " → "));
tr.appendChild(td1) tr.appendChild(td1);
var td2 = document.createElement("td") var td2 = document.createElement("td");
td2.appendChild(createLink(d, router)) td2.appendChild(createLink(d, router));
if (!unknown && has_location(d.node)) { if (!unknown && has_location(d.node)) {
var span = document.createElement("span") var span = document.createElement("span");
span.classList.add("icon") span.classList.add("icon");
span.classList.add("ion-location") span.classList.add("ion-location");
td2.appendChild(span) td2.appendChild(span);
} }
tr.appendChild(td2) tr.appendChild(td2);
var td3 = document.createElement("td") var td3 = document.createElement("td");
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 = router.link(d.link) a2.onclick = router.link(d.link);
td3.appendChild(a2) td3.appendChild(a2);
tr.appendChild(td3) tr.appendChild(td3);
var td4 = document.createElement("td") var td4 = document.createElement("td");
var a3 = document.createElement("a") var a3 = document.createElement("a");
a3.href = "#" a3.href = "#";
a3.textContent = d.link.type a3.textContent = d.link.type;
a3.onclick = router.link(d.link) a3.onclick = router.link(d.link);
td4.appendChild(a3) td4.appendChild(a3);
tr.appendChild(td4) tr.appendChild(td4);
var td5 = document.createElement("td") var td5 = document.createElement("td");
var a4 = document.createElement("a") var a4 = document.createElement("a");
a4.href = "#" a4.href = "#";
a4.textContent = showDistance(d.link) a4.textContent = showDistance(d.link);
a4.onclick = router.link(d.link) a4.onclick = router.link(d.link);
td5.appendChild(a4) td5.appendChild(a4);
td5.setAttribute("data-sort", d.link.distance !== undefined ? -d.link.distance : 1) td5.setAttribute("data-sort", d.link.distance !== undefined ? -d.link.distance : 1);
tr.appendChild(td5) tr.appendChild(td5);
tbody.appendChild(tr) tbody.appendChild(tr);
}) });
table.appendChild(tbody) table.appendChild(tbody);
table.className = "node-links" table.className = "node-links";
new Tablesort(table) new Tablesort(table);
el.appendChild(table) el.appendChild(table);
} }
} };
}) });

Some files were not shown because too many files have changed in this diff Show more