2017-03-18 15:33:49 +01:00
|
|
|
define(["moment", "virtual-dom", "helper", "moment.de"], function (moment, V, helper) {
|
2017-03-17 03:14:57 +01:00
|
|
|
return function (nodes, field, router, title) {
|
|
|
|
var self = this;
|
|
|
|
var el, tbody;
|
2015-03-25 16:28:36 +01:00
|
|
|
|
2015-03-29 16:14:10 +02:00
|
|
|
self.render = function (d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
el = document.createElement("div");
|
|
|
|
d.appendChild(el);
|
|
|
|
};
|
2015-03-25 16:28:36 +01:00
|
|
|
|
2015-03-29 17:48:25 +02:00
|
|
|
self.setData = function (data) {
|
2017-03-17 03:14:57 +01:00
|
|
|
var list = data.nodes[nodes];
|
2015-03-29 17:48:25 +02:00
|
|
|
|
2015-04-02 19:59:07 +02:00
|
|
|
if (list.length === 0) {
|
2017-03-17 03:14:57 +01:00
|
|
|
while (el.firstChild) {
|
|
|
|
el.removeChild(el.firstChild);
|
|
|
|
}
|
2015-04-02 19:59:07 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
tbody = null;
|
2015-04-02 19:59:07 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
return;
|
2015-04-02 19:59:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!tbody) {
|
2017-03-17 03:14:57 +01:00
|
|
|
var h2 = document.createElement("h2");
|
|
|
|
h2.textContent = title;
|
|
|
|
el.appendChild(h2);
|
2015-04-02 19:59:07 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var table = document.createElement("table");
|
|
|
|
el.appendChild(table);
|
2015-04-02 19:59:07 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
tbody = document.createElement("tbody");
|
|
|
|
tbody.last = V.h("tbody");
|
|
|
|
table.appendChild(tbody);
|
2015-04-02 19:59:07 +02:00
|
|
|
}
|
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var items = list.map(function (d) {
|
|
|
|
var time = moment(d[field]).from(data.now);
|
|
|
|
var td1Content = [];
|
2015-04-02 19:59:07 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var aClass = ["hostname", d.flags.online ? "online" : "offline"];
|
2015-04-02 19:59:07 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
td1Content.push(V.h("a", {
|
|
|
|
className: aClass.join(" "),
|
|
|
|
onclick: router.node(d),
|
|
|
|
href: "#!n:" + d.nodeinfo.node_id
|
|
|
|
}, d.nodeinfo.hostname));
|
2015-04-02 19:59:07 +02:00
|
|
|
|
2017-03-18 15:33:49 +01:00
|
|
|
if (helper.hasLocation(d)) {
|
2017-03-17 03:14:57 +01:00
|
|
|
td1Content.push(V.h("span", {className: "icon ion-location"}));
|
|
|
|
}
|
2015-04-02 19:59:07 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var td1 = V.h("td", td1Content);
|
|
|
|
var td2 = V.h("td", time);
|
2015-03-25 16:28:36 +01:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
return V.h("tr", [td1, td2]);
|
|
|
|
});
|
2015-03-25 16:28:36 +01:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var tbodyNew = V.h("tbody", items);
|
|
|
|
tbody = V.patch(tbody, V.diff(tbody.last, tbodyNew));
|
|
|
|
tbody.last = tbodyNew;
|
|
|
|
};
|
2015-03-25 16:28:36 +01:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
return self;
|
|
|
|
};
|
|
|
|
});
|