2017-02-18 22:13:29 +00:00
|
|
|
define(['moment', 'snabbdom', 'helper'], function (moment, 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
|
|
|
|
2017-11-03 21:07:22 +00:00
|
|
|
return function (nodes, field, title) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var self = this;
|
2017-01-29 23:51:08 +00:00
|
|
|
var el;
|
|
|
|
var tbody;
|
2015-03-25 15:28:36 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.render = function render(d) {
|
2016-05-26 23:34:42 +00:00
|
|
|
el = d;
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-03-25 15:28:36 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.setData = function setData(data) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var list = data.nodes[nodes];
|
2015-03-29 15:48:25 +00:00
|
|
|
|
2015-04-02 17:59:07 +00:00
|
|
|
if (list.length === 0) {
|
2016-05-22 11:23:43 +00:00
|
|
|
tbody = null;
|
|
|
|
return;
|
2015-04-02 17:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!tbody) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var h2 = document.createElement('h2');
|
2016-05-22 11:23:43 +00:00
|
|
|
h2.textContent = title;
|
|
|
|
el.appendChild(h2);
|
2015-04-02 17:59:07 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var table = document.createElement('table');
|
|
|
|
table.classList.add('node-list');
|
2016-05-22 11:23:43 +00:00
|
|
|
el.appendChild(table);
|
2015-04-02 17:59:07 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
tbody = document.createElement('tbody');
|
|
|
|
tbody.last = V.h('tbody');
|
2016-05-22 11:23:43 +00:00
|
|
|
table.appendChild(tbody);
|
2015-04-02 17:59:07 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
var items = list.map(function (d) {
|
2017-10-29 19:52:17 +00:00
|
|
|
var td0Content = '';
|
|
|
|
if (helper.hasLocation(d)) {
|
2018-01-04 23:19:23 +00:00
|
|
|
td0Content = V.h('span', { props: { className: 'icon ion-location', title: _.t('location.location') } });
|
2017-10-29 19:52:17 +00:00
|
|
|
}
|
2015-04-02 17:59:07 +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-25 15:28:36 +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', moment(d[field]).from(data.now))
|
|
|
|
]);
|
2016-05-22 11:23:43 +00:00
|
|
|
});
|
2015-03-25 15:28:36 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var tbodyNew = V.h('tbody', items);
|
2017-02-18 22:13:29 +00:00
|
|
|
tbody = V.patch(tbody, tbodyNew);
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-03-25 15:28:36 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return self;
|
|
|
|
};
|
|
|
|
});
|