2017-01-29 23:51:08 +00:00
|
|
|
define(['chroma-js', 'virtual-dom', 'filters/genericnode', 'helper'],
|
2016-05-26 16:37:24 +00:00
|
|
|
function (Chroma, V, Filter, helper) {
|
2017-01-29 23:51:08 +00:00
|
|
|
'use strict';
|
2015-04-02 20:07:00 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (config, filterManager) {
|
|
|
|
var self = this;
|
2017-01-29 23:51:08 +00:00
|
|
|
var scale = Chroma.scale('YlGnBu').mode('lab');
|
2015-03-30 00:58:47 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var statusTable = document.createElement('table');
|
|
|
|
statusTable.classList.add('proportion');
|
2015-07-07 22:30:29 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var fwTable = document.createElement('table');
|
|
|
|
fwTable.classList.add('proportion');
|
2015-07-07 15:42:41 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var hwTable = document.createElement('table');
|
|
|
|
hwTable.classList.add('proportion');
|
2015-07-07 15:42:41 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var geoTable = document.createElement('table');
|
|
|
|
geoTable.classList.add('proportion');
|
2015-07-07 15:42:41 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var autoTable = document.createElement('table');
|
|
|
|
autoTable.classList.add('proportion');
|
2015-07-07 15:42:41 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var siteTable = document.createElement('table');
|
|
|
|
siteTable.classList.add('proportion');
|
2015-07-18 14:28:07 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showStatGlobal(o) {
|
2016-05-26 16:37:24 +00:00
|
|
|
return helper.showStat(o);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-06-07 16:47:14 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function count(nodes, key, f) {
|
|
|
|
var dict = {};
|
2015-03-30 00:58:47 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
nodes.forEach(function (d) {
|
2016-05-26 16:37:24 +00:00
|
|
|
var v = helper.dictGet(d, key.slice(0));
|
2015-03-30 00:58:47 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (f !== undefined) {
|
|
|
|
v = f(v);
|
|
|
|
}
|
2015-03-30 00:58:47 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (v === null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-30 00:58:47 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
dict[v] = 1 + (v in dict ? dict[v] : 0);
|
|
|
|
});
|
2015-03-30 00:58:47 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return Object.keys(dict).map(function (d) {
|
|
|
|
return [d, dict[d], key, f];
|
|
|
|
});
|
|
|
|
}
|
2015-03-30 00:58:47 +00:00
|
|
|
|
2016-05-25 21:38:18 +00:00
|
|
|
function addFilter(filter) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return function () {
|
|
|
|
filterManager.addFilter(filter);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function fillTable(name, table, data) {
|
|
|
|
if (!table.last) {
|
2017-01-29 23:51:08 +00:00
|
|
|
table.last = V.h('table');
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var max = 0;
|
|
|
|
data.forEach(function (d) {
|
|
|
|
if (d[1] > max) {
|
|
|
|
max = d[1];
|
|
|
|
}
|
|
|
|
});
|
2016-03-12 15:24:57 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
var items = data.map(function (d) {
|
|
|
|
var v = d[1] / max;
|
2017-01-29 23:51:08 +00:00
|
|
|
var c1 = Chroma.contrast(scale(v), 'white');
|
|
|
|
var c2 = Chroma.contrast(scale(v), 'black');
|
2016-03-12 15:24:57 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
var filter = new Filter(name, d[2], d[0], d[3]);
|
2015-07-07 22:36:57 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var a = V.h('a', { href: '#', onclick: addFilter(filter) }, d[0]);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var th = V.h('th', a);
|
|
|
|
var td = V.h('td', V.h('span', {
|
2016-05-22 12:51:30 +00:00
|
|
|
style: {
|
2017-01-29 23:51:08 +00:00
|
|
|
width: Math.round(v * 100) + '%',
|
2016-05-22 12:51:30 +00:00
|
|
|
backgroundColor: scale(v).hex(),
|
2017-01-29 23:51:08 +00:00
|
|
|
color: c1 > c2 ? 'white' : 'black'
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2016-05-25 21:38:18 +00:00
|
|
|
}, d[1].toFixed(0)));
|
2015-03-30 00:58:47 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
return V.h('tr', [th, td]);
|
2016-05-22 12:51:30 +00:00
|
|
|
});
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var tableNew = V.h('table', items);
|
2016-05-22 12:51:30 +00:00
|
|
|
table = V.patch(table, V.diff(table.last, tableNew));
|
|
|
|
table.last = tableNew;
|
|
|
|
}
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.setData = function setData(data) {
|
2016-05-26 16:37:24 +00:00
|
|
|
var onlineNodes = data.nodes.all.filter(helper.online);
|
2016-05-22 12:51:30 +00:00
|
|
|
var nodes = onlineNodes.concat(data.nodes.lost);
|
|
|
|
var nodeDict = {};
|
|
|
|
|
|
|
|
data.nodes.all.forEach(function (d) {
|
|
|
|
nodeDict[d.nodeinfo.node_id] = d;
|
|
|
|
});
|
2016-03-12 15:24:57 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var statusDict = count(nodes, ['flags', 'online'], function (d) {
|
|
|
|
return d ? 'online' : 'offline';
|
2016-05-22 11:23:43 +00:00
|
|
|
});
|
2017-01-29 23:51:08 +00:00
|
|
|
var fwDict = count(nodes, ['nodeinfo', 'software', 'firmware', 'release']);
|
|
|
|
var hwDict = count(nodes, ['nodeinfo', 'hardware', 'model']);
|
|
|
|
var geoDict = count(nodes, ['nodeinfo', 'location'], function (d) {
|
|
|
|
return d && d.longitude && d.latitude ? 'ja' : 'nein';
|
2016-05-22 12:51:30 +00:00
|
|
|
});
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var autoDict = count(nodes, ['nodeinfo', 'software', 'autoupdater'], function (d) {
|
2016-05-22 12:51:30 +00:00
|
|
|
if (d === null) {
|
|
|
|
return null;
|
|
|
|
} else if (d.enabled) {
|
|
|
|
return d.branch;
|
|
|
|
}
|
2017-01-29 23:51:08 +00:00
|
|
|
return '(deaktiviert)';
|
2016-05-22 12:51:30 +00:00
|
|
|
});
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var siteDict = count(nodes, ['nodeinfo', 'system', 'site_code'], function (d) {
|
2016-05-22 12:51:30 +00:00
|
|
|
var rt = d;
|
|
|
|
if (config.siteNames) {
|
|
|
|
config.siteNames.forEach(function (t) {
|
|
|
|
if (d === t.site) {
|
|
|
|
rt = t.name;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return rt;
|
|
|
|
});
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
fillTable('Status', statusTable, statusDict.sort(function (a, b) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return b[1] - a[1];
|
|
|
|
}));
|
2017-01-29 23:51:08 +00:00
|
|
|
fillTable('Firmware', fwTable, fwDict.sort(function (a, b) {
|
2016-05-26 16:37:24 +00:00
|
|
|
if (b[0] < a[0]) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (b[0] > a[0]) {
|
|
|
|
return 1;
|
|
|
|
}
|
2016-05-25 21:53:46 +00:00
|
|
|
return 0;
|
2016-05-22 12:51:30 +00:00
|
|
|
}));
|
2017-01-29 23:51:08 +00:00
|
|
|
fillTable('Hardware', hwTable, hwDict.sort(function (a, b) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return b[1] - a[1];
|
|
|
|
}));
|
2017-01-29 23:51:08 +00:00
|
|
|
fillTable('Koordinaten', geoTable, geoDict.sort(function (a, b) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return b[1] - a[1];
|
|
|
|
}));
|
2017-01-29 23:51:08 +00:00
|
|
|
fillTable('Autom. Updates', autoTable, autoDict.sort(function (a, b) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return b[1] - a[1];
|
|
|
|
}));
|
2017-01-29 23:51:08 +00:00
|
|
|
fillTable('Site', siteTable, siteDict.sort(function (a, b) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return b[1] - a[1];
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.render = function render(el) {
|
2016-05-22 12:51:30 +00:00
|
|
|
var h2;
|
2017-01-29 23:51:08 +00:00
|
|
|
self.renderSingle(el, 'Status', statusTable);
|
|
|
|
self.renderSingle(el, 'Firmwareversionen', fwTable);
|
|
|
|
self.renderSingle(el, 'Hardwaremodelle', hwTable);
|
|
|
|
self.renderSingle(el, 'Auf der Karte sichtbar', geoTable);
|
|
|
|
self.renderSingle(el, 'Autoupdater', autoTable);
|
|
|
|
self.renderSingle(el, 'Site', siteTable);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
if (config.globalInfos) {
|
|
|
|
config.globalInfos.forEach(function (globalInfo) {
|
2017-01-29 23:51:08 +00:00
|
|
|
h2 = document.createElement('h2');
|
2016-05-22 12:51:30 +00:00
|
|
|
h2.textContent = globalInfo.name;
|
|
|
|
el.appendChild(h2);
|
|
|
|
el.appendChild(showStatGlobal(globalInfo));
|
|
|
|
});
|
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-03-30 00:58:47 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.renderSingle = function renderSingle(el, heading, table) {
|
2016-05-22 12:51:30 +00:00
|
|
|
var h2;
|
2017-01-29 23:51:08 +00:00
|
|
|
h2 = document.createElement('h2');
|
2016-05-22 12:51:30 +00:00
|
|
|
h2.textContent = heading;
|
2017-01-29 23:51:08 +00:00
|
|
|
h2.onclick = function onclick() {
|
|
|
|
table.classList.toggle('hidden');
|
2016-05-22 12:51:30 +00:00
|
|
|
};
|
|
|
|
el.appendChild(h2);
|
|
|
|
el.appendChild(table);
|
|
|
|
};
|
|
|
|
return self;
|
|
|
|
};
|
|
|
|
});
|