2017-12-26 21:26:11 +00:00
|
|
|
define(['d3-interpolate', 'snabbdom', 'utils/version', 'filters/genericnode', 'helper'],
|
|
|
|
function (d3Interpolate, V, versionCompare, Filter, helper) {
|
2017-01-29 23:51:08 +00:00
|
|
|
'use strict';
|
2017-11-05 15:58:41 +00:00
|
|
|
V = V.default;
|
2015-04-02 20:07:00 +00:00
|
|
|
|
2017-11-03 21:07:22 +00:00
|
|
|
return function (filterManager) {
|
2016-05-22 12:51:30 +00:00
|
|
|
var self = this;
|
2017-11-05 17:23:40 +00:00
|
|
|
var scale = d3Interpolate.interpolate(config.forceGraph.tqFrom, config.forceGraph.tqTo);
|
2017-11-06 17:54:50 +00:00
|
|
|
var time;
|
2015-03-30 00:58:47 +00:00
|
|
|
|
2017-02-18 22:13:29 +00:00
|
|
|
var statusTable;
|
|
|
|
var fwTable;
|
|
|
|
var hwTable;
|
|
|
|
var geoTable;
|
|
|
|
var autoTable;
|
2017-04-22 22:03:42 +00:00
|
|
|
var gatewayTable;
|
2017-10-29 15:10:25 +00:00
|
|
|
var gateway6Table;
|
2018-10-07 13:04:12 +00:00
|
|
|
var domainTable;
|
2015-07-18 14:28:07 +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) {
|
2017-02-18 22:13:29 +00:00
|
|
|
if (!table) {
|
|
|
|
table = document.createElement('table');
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
|
2017-02-18 23:15:36 +00:00
|
|
|
var max = Math.max.apply(Math, data.map(function (o) {
|
|
|
|
return o[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;
|
2016-03-12 15:24:57 +00:00
|
|
|
|
2017-01-28 14:33:13 +00:00
|
|
|
var filter = new Filter(_.t(name), d[2], d[0], d[3]);
|
2015-07-07 22:36:57 +00:00
|
|
|
|
2018-07-22 12:44:34 +00:00
|
|
|
var a = V.h('a', { on: { click: 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-10-31 09:16:04 +00:00
|
|
|
width: 'calc(25px + ' + Math.round(v * 90) + '%)',
|
|
|
|
backgroundColor: scale(v)
|
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-02-18 22:13:29 +00:00
|
|
|
var tableNew = V.h('table', { props: { className: 'proportion' } }, items);
|
|
|
|
return V.patch(table, tableNew);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.setData = function setData(data) {
|
2017-10-31 12:32:39 +00:00
|
|
|
var onlineNodes = data.nodes.online;
|
2016-05-22 12:51:30 +00:00
|
|
|
var nodes = onlineNodes.concat(data.nodes.lost);
|
2017-11-06 17:54:50 +00:00
|
|
|
time = data.timestamp;
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-10-29 15:10:25 +00:00
|
|
|
function hostnameOfNodeID(nodeid) {
|
|
|
|
var gateway = data.nodeDict[nodeid];
|
|
|
|
if (gateway) {
|
|
|
|
return gateway.hostname;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var gatewayDict = count(nodes, ['gateway'], hostnameOfNodeID);
|
|
|
|
var gateway6Dict = count(nodes, ['gateway6'], hostnameOfNodeID);
|
2016-03-12 15:24:57 +00:00
|
|
|
|
2017-10-29 14:11:24 +00:00
|
|
|
var statusDict = count(nodes, ['is_online'], function (d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
return d ? 'online' : 'offline';
|
2016-05-22 11:23:43 +00:00
|
|
|
});
|
2017-10-29 14:11:24 +00:00
|
|
|
var fwDict = count(nodes, ['firmware', 'release']);
|
|
|
|
var hwDict = count(nodes, ['model']);
|
|
|
|
var geoDict = count(nodes, ['location'], function (d) {
|
2017-01-28 14:33:13 +00:00
|
|
|
return d && d.longitude && d.latitude ? _.t('yes') : _.t('no');
|
2016-05-22 12:51:30 +00:00
|
|
|
});
|
|
|
|
|
2017-10-29 14:11:24 +00:00
|
|
|
var autoDict = count(nodes, ['autoupdater'], function (d) {
|
2017-11-01 18:51:30 +00:00
|
|
|
if (d.enabled) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return d.branch;
|
|
|
|
}
|
2017-01-28 14:33:13 +00:00
|
|
|
return _.t('node.deactivated');
|
2016-05-22 12:51:30 +00:00
|
|
|
});
|
|
|
|
|
2018-10-07 13:04:12 +00:00
|
|
|
var domainDict = count(nodes, ['domain'], function (d) {
|
|
|
|
if (config.domainNames) {
|
|
|
|
config.domainNames.forEach(function (t) {
|
|
|
|
if (d === t.domain) {
|
2017-04-22 22:03:42 +00:00
|
|
|
d = t.name;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-04-22 22:03:42 +00:00
|
|
|
return d;
|
2016-05-22 12:51:30 +00:00
|
|
|
});
|
|
|
|
|
2017-02-18 22:13:29 +00:00
|
|
|
statusTable = fillTable('node.status', statusTable, statusDict.sort(function (a, b) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return b[1] - a[1];
|
|
|
|
}));
|
2017-12-26 21:26:11 +00:00
|
|
|
fwTable = fillTable('node.firmware', fwTable, fwDict.sort(versionCompare));
|
2017-02-18 22:13:29 +00:00
|
|
|
hwTable = fillTable('node.hardware', hwTable, hwDict.sort(function (a, b) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return b[1] - a[1];
|
|
|
|
}));
|
2017-02-18 22:13:29 +00:00
|
|
|
geoTable = fillTable('node.visible', geoTable, geoDict.sort(function (a, b) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return b[1] - a[1];
|
|
|
|
}));
|
2017-02-18 22:13:29 +00:00
|
|
|
autoTable = fillTable('node.update', autoTable, autoDict.sort(function (a, b) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return b[1] - a[1];
|
|
|
|
}));
|
2017-10-29 15:10:25 +00:00
|
|
|
gatewayTable = fillTable('node.selectedGatewayIPv4', gatewayTable, gatewayDict.sort(function (a, b) {
|
|
|
|
return b[1] - a[1];
|
|
|
|
}));
|
|
|
|
gateway6Table = fillTable('node.selectedGatewayIPv6', gateway6Table, gateway6Dict.sort(function (a, b) {
|
2017-04-22 22:03:42 +00:00
|
|
|
return b[1] - a[1];
|
|
|
|
}));
|
2018-10-07 13:04:12 +00:00
|
|
|
domainTable = fillTable('node.domain', domainTable, domainDict.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) {
|
2017-01-28 14:33:13 +00:00
|
|
|
self.renderSingle(el, 'node.status', statusTable);
|
|
|
|
self.renderSingle(el, 'node.firmware', fwTable);
|
|
|
|
self.renderSingle(el, 'node.hardware', hwTable);
|
|
|
|
self.renderSingle(el, 'node.visible', geoTable);
|
|
|
|
self.renderSingle(el, 'node.update', autoTable);
|
2017-10-29 15:10:25 +00:00
|
|
|
self.renderSingle(el, 'node.selectedGatewayIPv4', gatewayTable);
|
|
|
|
self.renderSingle(el, 'node.selectedGatewayIPv6', gateway6Table);
|
2018-10-07 13:04:12 +00:00
|
|
|
self.renderSingle(el, 'node.domain', domainTable);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
if (config.globalInfos) {
|
2017-10-29 14:11:24 +00:00
|
|
|
var images = document.createElement('div');
|
|
|
|
el.appendChild(images);
|
|
|
|
var img = [];
|
2017-11-06 17:54:50 +00:00
|
|
|
var subst = {
|
|
|
|
'{TIME}': time,
|
|
|
|
'{LOCALE}': _.locale()
|
|
|
|
};
|
2016-05-22 12:51:30 +00:00
|
|
|
config.globalInfos.forEach(function (globalInfo) {
|
2017-10-29 14:11:24 +00:00
|
|
|
img.push(V.h('h2', globalInfo.name));
|
2017-11-06 17:54:50 +00:00
|
|
|
img.push(helper.showStat(V, globalInfo, subst));
|
2016-05-22 12:51:30 +00:00
|
|
|
});
|
2017-10-29 14:11:24 +00:00
|
|
|
V.patch(images, V.h('div', img));
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
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) {
|
2017-09-02 21:55:00 +00:00
|
|
|
if (table.children.length > 0) {
|
|
|
|
var h2 = document.createElement('h2');
|
|
|
|
h2.classList.add('proportion-header');
|
|
|
|
h2.textContent = _.t(heading);
|
|
|
|
h2.onclick = function onclick() {
|
|
|
|
table.elm.classList.toggle('hide');
|
|
|
|
};
|
|
|
|
el.appendChild(h2);
|
|
|
|
el.appendChild(table.elm);
|
|
|
|
}
|
2016-05-22 12:51:30 +00:00
|
|
|
};
|
|
|
|
return self;
|
|
|
|
};
|
|
|
|
});
|