meshviewer/lib/infobox/link.js

78 lines
2.4 KiB
JavaScript
Raw Normal View History

define(['helper', 'snabbdom'], function (helper, V) {
'use strict';
V = V.default;
2016-05-27 21:59:01 +00:00
2017-02-01 21:04:04 +00:00
function showStatImg(o, d, time) {
2017-11-06 17:54:50 +00:00
var subst = {
'{SOURCE_ID}': d.source.node_id,
'{SOURCE_NAME}': d.source.hostname.replace(/[^a-z0-9\-]/ig, '_'),
'{TARGET_ID}': d.target.node_id,
'{TARGET_NAME}': d.target.hostname.replace(/[^a-z0-9\-]/ig, '_'),
'{TIME}': time,
'{LOCALE}': _.locale()
};
return helper.showStat(V, o, subst);
2016-03-08 19:01:38 +00:00
}
return function (el, d, linkScale) {
var self = this;
var header = document.createElement('div');
var table = document.createElement('table');
var images = document.createElement('div');
el.appendChild(header);
el.appendChild(table);
el.appendChild(images);
self.render = function render() {
var children = [];
var headers = [];
headers.push(V.h('h2', [
V.h('a', {
props: { href: router.generateLink({ node: d.source.node_id }) }
}, d.source.hostname),
V.h('span', ' - '),
V.h('a', {
props: { href: router.generateLink({ node: d.target.node_id }) }
}, d.target.hostname)
]));
header = V.patch(header, V.h('div', headers));
2017-11-04 15:23:17 +00:00
helper.attributeEntry(V, children, 'node.connectionType', d.type);
helper.attributeEntry(V, children, 'node.tq', V.h('span',
{
style:
{
color: linkScale((d.source_tq + d.target_tq) / 2)
}
2017-11-04 15:23:17 +00:00
}, helper.showTq(d.source_tq) + ' - ' + helper.showTq(d.target_tq))
);
helper.attributeEntry(V, children, 'node.distance', helper.showDistance(d));
helper.attributeEntry(V, children, 'node.hardware', (d.source.model ? d.source.model + ' ' : '') +
(d.target.model ? d.target.model : ''));
var elNew = V.h('table', children);
table = V.patch(table, elNew);
table.elm.classList.add('attributes');
if (config.linkInfos) {
var time = d.target.lastseen.format('DDMMYYYYHmmss');
var img = [];
config.linkInfos.forEach(function (linkInfo) {
img.push(V.h('h4', linkInfo.name));
img.push(showStatImg(linkInfo, d, time));
});
images = V.patch(images, V.h('div', img));
}
};
self.setData = function setData(data) {
d = data.links.find(function (a) {
return a.id === d.id;
});
self.render();
};
return self;
};
});