meshviewer/lib/linklist.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

define(['sorttable', 'virtual-dom', 'helper'], function (SortTable, V, helper) {
'use strict';
2016-05-27 21:59:01 +00:00
2015-04-07 15:41:17 +00:00
function linkName(d) {
return (d.source.node ? d.source.node.nodeinfo.hostname : d.source.id) + ' ' + d.target.node.nodeinfo.hostname;
2015-04-07 15:41:17 +00:00
}
2015-03-25 15:04:23 +00:00
var headings = [{
2017-01-28 14:33:13 +00:00
name: 'node.nodes',
sort: function (a, b) {
return linkName(a).localeCompare(linkName(b));
},
reverse: false
}, {
2017-01-28 14:33:13 +00:00
name: 'node.tq',
class: 'ion-connection-bars',
sort: function (a, b) {
return a.tq - b.tq;
},
reverse: true
}, {
2017-01-28 14:33:13 +00:00
name: 'node.distance',
class: 'ion-arrow-resize',
sort: function (a, b) {
return (a.distance === undefined ? -1 : a.distance) -
(b.distance === undefined ? -1 : b.distance);
},
reverse: true
}];
return function (linkScale, router) {
var table = new SortTable(headings, 2, renderRow);
table.el.classList.add('link-list');
2015-03-25 15:04:23 +00:00
2015-04-07 15:41:17 +00:00
function renderRow(d) {
2017-02-04 15:14:24 +00:00
var td1Content = [V.h('a', { href: router.getUrl({ l: d.id }), onclick: router.link(d) }, linkName(d))];
2015-03-25 15:04:23 +00:00
var td1 = V.h('td', td1Content);
2017-03-09 23:53:23 +00:00
var td2 = V.h('td', { style: { color: linkScale(1 / d.tq) } }, helper.showTq(d));
var td3 = V.h('td', helper.showDistance(d));
2015-04-03 00:32:32 +00:00
return V.h('tr', [td1, td2, td3]);
2015-04-07 15:41:17 +00:00
}
2015-03-25 15:04:23 +00:00
this.render = function render(d) {
var h2 = document.createElement('h2');
2017-01-28 14:33:13 +00:00
h2.textContent = _.t('node.links');
d.appendChild(h2);
2015-03-25 15:04:23 +00:00
d.appendChild(table.el);
};
2015-03-25 15:04:23 +00:00
this.setData = function setData(d) {
table.setData(d.graph.links);
};
};
});