simplenodelist.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. define(["moment"], function (moment) {
  2. return function(config, nodes, field, router, title) {
  3. var self = this
  4. var el
  5. self.render = function (d) {
  6. el = document.createElement("div")
  7. d.appendChild(el)
  8. }
  9. self.setData = function (data) {
  10. var list = data.nodes[nodes]
  11. if (list.length === 0)
  12. return
  13. var h2 = document.createElement("h2")
  14. h2.textContent = title
  15. el.appendChild(h2)
  16. var table = document.createElement("table")
  17. el.appendChild(table)
  18. var tbody = document.createElement("tbody")
  19. list.forEach( function (d) {
  20. var time = moment(d[field]).fromNow()
  21. var row = document.createElement("tr")
  22. var td1 = document.createElement("td")
  23. var a = document.createElement("a")
  24. a.classList.add("hostname")
  25. a.classList.add(d.flags.online ? "online" : "offline")
  26. a.textContent = d.nodeinfo.hostname
  27. a.href = "#"
  28. a.onclick = router.node(d)
  29. td1.appendChild(a)
  30. if (has_location(d)) {
  31. var span = document.createElement("span")
  32. span.classList.add("icon")
  33. span.classList.add("ion-location")
  34. td1.appendChild(span)
  35. }
  36. if ("owner" in d.nodeinfo && config.showContact) {
  37. var contact = d.nodeinfo.owner.contact
  38. td1.appendChild(document.createTextNode(" – " + contact + ""))
  39. }
  40. var td2 = document.createElement("td")
  41. td2.textContent = time
  42. row.appendChild(td1)
  43. row.appendChild(td2)
  44. tbody.appendChild(row)
  45. })
  46. table.appendChild(tbody)
  47. el.appendChild(table)
  48. }
  49. return self
  50. }
  51. })