2017-10-29 14:11:24 +00:00
|
|
|
|
define(['helper', 'snabbdom'], function (helper, V) {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
'use strict';
|
2017-10-29 14:11:24 +00:00
|
|
|
|
V = V.default;
|
2016-05-27 21:59:01 +00:00
|
|
|
|
|
2017-11-14 16:37:20 +00:00
|
|
|
|
function showStatImg(img, 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, '_'),
|
2017-11-14 16:37:20 +00:00
|
|
|
|
'{SOURCE_MAC}': d.source_mac,
|
2017-11-06 17:54:50 +00:00
|
|
|
|
'{TARGET_ID}': d.target.node_id,
|
|
|
|
|
'{TARGET_NAME}': d.target.hostname.replace(/[^a-z0-9\-]/ig, '_'),
|
2017-11-14 16:37:20 +00:00
|
|
|
|
'{TARGET_MAC}': d.target_mac,
|
|
|
|
|
'{TYPE}': d.type,
|
2017-11-06 17:54:50 +00:00
|
|
|
|
'{TIME}': time,
|
|
|
|
|
'{LOCALE}': _.locale()
|
|
|
|
|
};
|
2017-11-14 16:37:20 +00:00
|
|
|
|
|
|
|
|
|
img.push(V.h('h4', helper.listReplace(o.name, subst)));
|
|
|
|
|
img.push(helper.showStat(V, o, subst));
|
2016-03-08 19:01:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-03 21:07:22 +00:00
|
|
|
|
return function (el, d, linkScale) {
|
2017-10-29 14:11:24 +00:00
|
|
|
|
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 = [];
|
2017-11-14 16:37:20 +00:00
|
|
|
|
var img = [];
|
|
|
|
|
var time = d[0].target.lastseen.format('DDMMYYYYHmmss');
|
|
|
|
|
|
|
|
|
|
header = V.patch(header, V.h('div', V.h('h2', [
|
2017-10-29 14:11:24 +00:00
|
|
|
|
V.h('a', {
|
2017-11-14 16:37:20 +00:00
|
|
|
|
props: { href: router.generateLink({ node: d[0].source.node_id }) }
|
|
|
|
|
}, d[0].source.hostname),
|
2017-10-29 14:11:24 +00:00
|
|
|
|
V.h('span', ' - '),
|
|
|
|
|
V.h('a', {
|
2017-11-14 16:37:20 +00:00
|
|
|
|
props: { href: router.generateLink({ node: d[0].target.node_id }) }
|
|
|
|
|
}, d[0].target.hostname)
|
|
|
|
|
])));
|
2017-10-29 14:11:24 +00:00
|
|
|
|
|
2017-11-14 16:37:20 +00:00
|
|
|
|
helper.attributeEntry(V, children, 'node.hardware', (d[0].source.model ? d[0].source.model + ' – ' : '') +
|
|
|
|
|
(d[0].target.model ? d[0].target.model : ''));
|
|
|
|
|
helper.attributeEntry(V, children, 'node.distance', helper.showDistance(d[0]));
|
2017-10-29 14:11:24 +00:00
|
|
|
|
|
2017-11-14 16:37:20 +00:00
|
|
|
|
d.forEach(function (link) {
|
|
|
|
|
children.push(V.h('tr', { props: { className: 'header' } }, [
|
|
|
|
|
V.h('th', _.t('node.connectionType')),
|
|
|
|
|
V.h('th', link.type)
|
|
|
|
|
]));
|
|
|
|
|
helper.attributeEntry(V, children, 'node.tq', V.h('span',
|
|
|
|
|
{ style: { color: linkScale((link.source_tq + link.target_tq) / 2) } },
|
|
|
|
|
helper.showTq(link.source_tq) + ' - ' + helper.showTq(link.target_tq))
|
|
|
|
|
);
|
2017-10-29 14:11:24 +00:00
|
|
|
|
|
2017-11-14 16:37:20 +00:00
|
|
|
|
if (config.linkTypeInfos) {
|
|
|
|
|
config.linkTypeInfos.forEach(function (o) {
|
|
|
|
|
showStatImg(img, o, link, time);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-10-29 14:11:24 +00:00
|
|
|
|
|
|
|
|
|
if (config.linkInfos) {
|
2017-11-14 16:37:20 +00:00
|
|
|
|
config.linkInfos.forEach(function (o) {
|
|
|
|
|
showStatImg(img, o, d[0], time);
|
2017-10-29 14:11:24 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2017-11-14 16:37:20 +00:00
|
|
|
|
|
|
|
|
|
var elNew = V.h('table', children);
|
|
|
|
|
table = V.patch(table, elNew);
|
|
|
|
|
table.elm.classList.add('attributes');
|
|
|
|
|
images = V.patch(images, V.h('div', img));
|
2017-10-29 14:11:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.setData = function setData(data) {
|
2017-11-14 16:37:20 +00:00
|
|
|
|
d = data.links.filter(function (a) {
|
|
|
|
|
return a.id === d[0].id;
|
2016-05-22 11:23:43 +00:00
|
|
|
|
});
|
2017-10-29 14:11:24 +00:00
|
|
|
|
self.render();
|
|
|
|
|
};
|
|
|
|
|
return self;
|
2016-05-22 11:23:43 +00:00
|
|
|
|
};
|
|
|
|
|
});
|