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';
|
2017-02-18 22:13:29 +00:00
|
|
|
V = V.default;
|
2016-05-27 21:59:01 +00:00
|
|
|
|
2015-04-07 15:41:17 +00:00
|
|
|
function showUptime(uptime) {
|
2017-10-26 13:58:28 +00:00
|
|
|
// 1000ms are 1 second and 60 second are 1min: 60 * 1000 = 60000
|
|
|
|
var s = uptime / 60000;
|
|
|
|
if (Math.abs(s) < 60) {
|
|
|
|
return Math.round(s) + ' m';
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2017-10-26 13:58:28 +00:00
|
|
|
s /= 60;
|
|
|
|
if (Math.abs(s) < 24) {
|
|
|
|
return Math.round(s) + ' h';
|
|
|
|
}
|
|
|
|
s /= 24;
|
|
|
|
return Math.round(s) + ' d';
|
2015-04-07 15:41:17 +00:00
|
|
|
}
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
var headings = [{
|
2016-05-26 23:34:42 +00:00
|
|
|
name: ''
|
|
|
|
}, {
|
2017-01-28 14:33:13 +00:00
|
|
|
name: 'node.nodes',
|
2016-05-22 12:51:30 +00:00
|
|
|
sort: function (a, b) {
|
2017-10-29 14:11:24 +00:00
|
|
|
return a.hostname.localeCompare(b.hostname);
|
2016-05-22 12:51:30 +00:00
|
|
|
},
|
|
|
|
reverse: false
|
2017-02-04 15:14:24 +00:00
|
|
|
}, {
|
2017-01-28 14:33:13 +00:00
|
|
|
name: 'node.uptime',
|
2017-02-04 19:01:49 +00:00
|
|
|
class: 'ion-time',
|
2017-01-29 23:51:08 +00:00
|
|
|
sort: function (a, b) {
|
|
|
|
return a.uptime - b.uptime;
|
2016-05-22 12:51:30 +00:00
|
|
|
},
|
2017-01-29 23:51:08 +00:00
|
|
|
reverse: true
|
2017-02-04 15:14:24 +00:00
|
|
|
}, {
|
2017-01-28 14:33:13 +00:00
|
|
|
name: 'node.links',
|
2017-02-04 19:01:49 +00:00
|
|
|
class: 'ion-share-alt',
|
2017-01-29 23:51:08 +00:00
|
|
|
sort: function (a, b) {
|
2017-05-09 13:22:32 +00:00
|
|
|
return a.neighbours.length - b.neighbours.length;
|
2017-01-29 23:51:08 +00:00
|
|
|
},
|
|
|
|
reverse: true
|
2017-02-04 15:14:24 +00:00
|
|
|
}, {
|
2017-01-28 14:33:13 +00:00
|
|
|
name: 'node.clients',
|
2017-02-04 19:01:49 +00:00
|
|
|
class: 'ion-people',
|
2017-01-29 23:51:08 +00:00
|
|
|
sort: function (a, b) {
|
2017-10-29 19:52:17 +00:00
|
|
|
return a.clients - b.clients;
|
2016-05-22 12:51:30 +00:00
|
|
|
},
|
2017-01-29 23:51:08 +00:00
|
|
|
reverse: true
|
|
|
|
}];
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (router) {
|
2015-04-07 15:41:17 +00:00
|
|
|
function renderRow(d) {
|
2017-10-29 19:52:17 +00:00
|
|
|
var td0Content = '';
|
|
|
|
if (helper.hasLocation(d)) {
|
|
|
|
td0Content = V.h('span', { props: { className: 'icon ion-location' } });
|
|
|
|
}
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2017-10-29 19:52:17 +00:00
|
|
|
var td1Content = V.h('a', {
|
2017-02-18 22:13:29 +00:00
|
|
|
props: {
|
2017-10-29 19:52:17 +00:00
|
|
|
className: ['hostname', d.is_online ? 'online' : 'offline'].join(' '),
|
2017-10-29 14:11:24 +00:00
|
|
|
href: router.generateLink({ node: d.node_id })
|
2017-02-18 22:13:29 +00:00
|
|
|
}, on: {
|
|
|
|
click: function (e) {
|
2017-10-29 14:11:24 +00:00
|
|
|
router.fullUrl({ node: d.node_id }, e);
|
2017-02-18 22:13:29 +00:00
|
|
|
}
|
2017-03-05 11:29:21 +00:00
|
|
|
}
|
2017-10-29 19:52:17 +00:00
|
|
|
}, d.hostname);
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2017-10-29 19:52:17 +00:00
|
|
|
return V.h('tr', [
|
|
|
|
V.h('td', td0Content),
|
|
|
|
V.h('td', td1Content),
|
|
|
|
V.h('td', showUptime(d.uptime)),
|
|
|
|
V.h('td', d.neighbours.length),
|
|
|
|
V.h('td', d.clients)
|
|
|
|
]);
|
2015-04-07 15:41:17 +00:00
|
|
|
}
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2016-05-26 23:34:42 +00:00
|
|
|
var table = new SortTable(headings, 1, renderRow);
|
2015-03-26 00:31:46 +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.all');
|
2016-05-26 23:34:42 +00:00
|
|
|
d.appendChild(h2);
|
2017-02-18 22:13:29 +00:00
|
|
|
table.el.elm.classList.add('node-list');
|
|
|
|
d.appendChild(table.el.elm);
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
this.setData = function setData(d) {
|
2015-04-07 15:41:17 +00:00
|
|
|
var data = d.nodes.all.map(function (e) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var n = Object.create(e);
|
2017-10-26 13:58:28 +00:00
|
|
|
if (e.is_online) {
|
|
|
|
n.uptime = d.now - new Date(e.uptime).getTime();
|
|
|
|
} else {
|
|
|
|
n.uptime = e.lastseen - d.now;
|
|
|
|
}
|
2017-05-09 13:22:32 +00:00
|
|
|
n.neighbours = e.neighbours;
|
2016-05-22 11:23:43 +00:00
|
|
|
return n;
|
|
|
|
});
|
2015-03-26 00:31:46 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
table.setData(data);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|