2017-02-18 22:13:29 +00:00
|
|
|
|
define(['sorttable', 'snabbdom', 'helper'], function (SortTable, V, helper) {
|
2017-01-29 23:51:08 +00:00
|
|
|
|
'use strict';
|
2016-05-27 21:59:01 +00:00
|
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
|
function linkName(d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
|
return (d.source ? d.source.hostname : d.source.id) + ' – ' + d.target.hostname;
|
2015-04-07 15:41:17 +00:00
|
|
|
|
}
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
|
var headings = [{
|
2017-01-28 14:33:13 +00:00
|
|
|
|
name: 'node.nodes',
|
2016-05-22 12:51:30 +00:00
|
|
|
|
sort: function (a, b) {
|
|
|
|
|
return linkName(a).localeCompare(linkName(b));
|
|
|
|
|
},
|
|
|
|
|
reverse: false
|
2017-01-29 23:51:08 +00:00
|
|
|
|
}, {
|
2017-01-28 14:33:13 +00:00
|
|
|
|
name: 'node.tq',
|
2017-02-04 19:01:49 +00:00
|
|
|
|
class: 'ion-connection-bars',
|
2017-01-29 23:51:08 +00:00
|
|
|
|
sort: function (a, b) {
|
2017-10-29 14:11:24 +00:00
|
|
|
|
return (a.source_tq + a.target_tq) / 2 - (b.source_tq + b.target_tq) / 2;
|
2017-01-29 23:51:08 +00:00
|
|
|
|
},
|
|
|
|
|
reverse: true
|
|
|
|
|
}, {
|
2017-01-28 14:33:13 +00:00
|
|
|
|
name: 'node.distance',
|
2017-02-04 19:01:49 +00:00
|
|
|
|
class: 'ion-arrow-resize',
|
2017-01-29 23:51:08 +00:00
|
|
|
|
sort: function (a, b) {
|
|
|
|
|
return (a.distance === undefined ? -1 : a.distance) -
|
|
|
|
|
(b.distance === undefined ? -1 : b.distance);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
},
|
2017-01-29 23:51:08 +00:00
|
|
|
|
reverse: true
|
|
|
|
|
}];
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
|
|
return function (linkScale, router) {
|
2016-05-22 11:23:43 +00:00
|
|
|
|
var table = new SortTable(headings, 2, renderRow);
|
2017-02-18 22:13:29 +00:00
|
|
|
|
V = V.default;
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
|
function renderRow(d) {
|
2017-03-05 11:29:21 +00:00
|
|
|
|
var td1Content = [V.h('a', {
|
2017-02-18 22:13:29 +00:00
|
|
|
|
props: {
|
|
|
|
|
href: router.generateLink({ link: d.id })
|
|
|
|
|
}, on: {
|
|
|
|
|
click: function (e) {
|
|
|
|
|
router.fullUrl({ link: d.id }, e);
|
|
|
|
|
}
|
2017-03-05 11:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
}, linkName(d))];
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2017-10-29 19:52:17 +00:00
|
|
|
|
return V.h('tr', [
|
|
|
|
|
V.h('td', td1Content),
|
|
|
|
|
V.h('td', { style: { color: linkScale((d.source_tq + d.target_tq) / 2) } }, helper.showTq(d.source_tq) + ' - ' + helper.showTq(d.target_tq)),
|
|
|
|
|
V.h('td', helper.showDistance(d))
|
|
|
|
|
]);
|
2015-04-07 15:41:17 +00:00
|
|
|
|
}
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +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');
|
2016-05-26 23:34:42 +00:00
|
|
|
|
d.appendChild(h2);
|
2017-02-18 22:13:29 +00:00
|
|
|
|
table.el.elm.classList.add('link-list');
|
|
|
|
|
d.appendChild(table.el.elm);
|
2016-05-22 11:23:43 +00:00
|
|
|
|
};
|
2015-03-25 15:04:23 +00:00
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
|
this.setData = function setData(d) {
|
2017-10-29 14:11:24 +00:00
|
|
|
|
table.setData(d.links);
|
2016-05-22 11:23:43 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
});
|