2017-01-29 23:51:08 +00:00
|
|
|
define(['moment/moment', 'virtual-dom', 'helper', 'moment/locale/de'], function (moment, V, helper) {
|
|
|
|
'use strict';
|
2016-05-27 21:59:01 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (nodes, field, router, 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) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var time = moment(d[field]).from(data.now);
|
2016-05-26 23:34:42 +00:00
|
|
|
var td0Content = [];
|
2016-05-22 11:23:43 +00:00
|
|
|
var td1Content = [];
|
2015-04-02 17:59:07 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var aClass = ['hostname', d.flags.online ? 'online' : 'offline'];
|
2015-04-02 17:59:07 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
td1Content.push(V.h('a', {
|
|
|
|
className: aClass.join(' '),
|
2016-05-22 12:51:30 +00:00
|
|
|
onclick: router.node(d),
|
2017-01-29 23:51:08 +00:00
|
|
|
href: '#'
|
2016-05-22 12:51:30 +00:00
|
|
|
}, d.nodeinfo.hostname));
|
2015-04-02 17:59:07 +00:00
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
if (helper.hasLocation(d)) {
|
2017-01-29 23:51:08 +00:00
|
|
|
td0Content.push(V.h('span', { className: 'icon ion-location' }));
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-04-02 17:59:07 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var td0 = V.h('td', td0Content);
|
|
|
|
var td1 = V.h('td', td1Content);
|
|
|
|
var td2 = V.h('td', time);
|
2015-03-25 15:28:36 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
return V.h('tr', [td0, td1, td2]);
|
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);
|
2016-05-22 11:23:43 +00:00
|
|
|
tbody = V.patch(tbody, V.diff(tbody.last, tbodyNew));
|
|
|
|
tbody.last = tbodyNew;
|
|
|
|
};
|
2015-03-25 15:28:36 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return self;
|
|
|
|
};
|
|
|
|
});
|