simplenodelist.js 1.6 KB

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