2016-12-26 02:44:59 +00:00
|
|
|
define(["moment/moment", "virtual-dom", "helper", "moment/locale/de"], function (moment, V, helper) {
|
2016-05-27 21:59:01 +00:00
|
|
|
"use strict";
|
|
|
|
|
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;
|
|
|
|
var el, tbody;
|
2015-03-25 15:28:36 +00:00
|
|
|
|
2015-03-29 14:14:10 +00:00
|
|
|
self.render = function (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
|
|
|
|
2015-03-29 15:48:25 +00:00
|
|
|
self.setData = function (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) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var h2 = document.createElement("h2");
|
|
|
|
h2.textContent = title;
|
|
|
|
el.appendChild(h2);
|
2015-04-02 17:59:07 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var table = document.createElement("table");
|
2016-05-26 23:34:42 +00:00
|
|
|
table.classList.add("node-list");
|
2016-05-22 11:23:43 +00:00
|
|
|
el.appendChild(table);
|
2015-04-02 17:59:07 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
tbody = document.createElement("tbody");
|
|
|
|
tbody.last = V.h("tbody");
|
|
|
|
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
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var aClass = ["hostname", d.flags.online ? "online" : "offline"];
|
2015-04-02 17:59:07 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
td1Content.push(V.h("a", {
|
|
|
|
className: aClass.join(" "),
|
|
|
|
onclick: router.node(d),
|
|
|
|
href: "#"
|
|
|
|
}, d.nodeinfo.hostname));
|
2015-04-02 17:59:07 +00:00
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
if (helper.hasLocation(d)) {
|
2016-05-26 23:34:42 +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
|
|
|
|
2016-05-26 23:34:42 +00:00
|
|
|
var td0 = V.h("td", td0Content);
|
2016-05-22 11:23:43 +00:00
|
|
|
var td1 = V.h("td", td1Content);
|
|
|
|
var td2 = V.h("td", time);
|
2015-03-25 15:28:36 +00:00
|
|
|
|
2016-05-26 23:34:42 +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
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var tbodyNew = V.h("tbody", items);
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
});
|