meshviewer/lib/infobox/link.js

62 lines
2.3 KiB
JavaScript
Raw Normal View History

define(['helper'], function (helper) {
'use strict';
2016-05-27 21:59:01 +00:00
2017-02-01 21:04:04 +00:00
function showStatImg(o, d, time) {
var subst = {};
2017-02-01 21:04:04 +00:00
subst['{SOURCE_ID}'] = d.source.node_id;
subst['{SOURCE_NAME}'] = d.source.node.nodeinfo.hostname ? d.source.node.nodeinfo.hostname.replace(/[^a-z0-9\-]/ig, '_') : _.t('unknown');
subst['{TARGET_ID}'] = d.target.node_id;
subst['{TARGET_NAME}'] = d.target.node.nodeinfo.hostname ? d.target.node.nodeinfo.hostname.replace(/[^a-z0-9\-]/ig, '_') : _.t('unknown');
subst['{TIME}'] = time;
2017-01-28 14:33:13 +00:00
subst['{LOCALE}'] = _.locale();
2016-05-26 16:37:24 +00:00
return helper.showStat(o, subst);
2016-03-08 19:01:38 +00:00
}
2015-03-25 18:45:21 +00:00
return function (config, el, router, d) {
var unknown = !d.source.node;
var h2 = document.createElement('h2');
var a1;
if (!unknown) {
a1 = document.createElement('a');
2017-02-04 15:14:24 +00:00
a1.href = router.getUrl({ n: d.source.node_id });
a1.onclick = router.node(d.source.node);
} else {
a1 = document.createElement('span');
}
a1.textContent = unknown ? d.source.id : d.source.node.nodeinfo.hostname;
h2.appendChild(a1);
2017-03-18 13:36:11 +00:00
var arrow = document.createElement('span');
arrow.classList.add('ion-arrow-right-c');
h2.appendChild(arrow);
var a2 = document.createElement('a');
2017-02-04 15:14:24 +00:00
a2.href = router.getUrl({ n: d.target.node_id });
a2.onclick = router.node(d.target.node);
a2.textContent = d.target.node.nodeinfo.hostname;
h2.appendChild(a2);
el.appendChild(h2);
2015-03-25 10:21:09 +00:00
var attributes = document.createElement('table');
attributes.classList.add('attributes');
2015-03-25 10:21:09 +00:00
2017-01-28 14:33:13 +00:00
helper.attributeEntry(attributes, 'node.tq', helper.showTq(d));
helper.attributeEntry(attributes, 'node.distance', helper.showDistance(d));
var hw1 = unknown ? null : helper.dictGet(d.source.node.nodeinfo, ['hardware', 'model']);
var hw2 = helper.dictGet(d.target.node.nodeinfo, ['hardware', 'model']);
2017-01-28 14:33:13 +00:00
helper.attributeEntry(attributes, 'node.hardware', (hw1 !== null ? hw1 : _.t('unknown')) + ' ' + (hw2 !== null ? hw2 : _.t('unknown')));
el.appendChild(attributes);
2016-03-08 19:01:38 +00:00
if (config.linkInfos) {
var time = d.target.node.lastseen.format('DDMMYYYYHmmss');
config.linkInfos.forEach(function (linkInfo) {
var h4 = document.createElement('h4');
h4.textContent = linkInfo.name;
el.appendChild(h4);
2017-02-01 21:04:04 +00:00
el.appendChild(showStatImg(linkInfo, d, time));
});
2016-03-08 19:01:38 +00:00
}
};
});