nodelist.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. define(function () {
  2. return function(router) {
  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 (now, nodes) {
  10. if (nodes.length == 0)
  11. return
  12. var h2 = document.createElement("h2")
  13. h2.textContent = "Alle Knoten"
  14. el.appendChild(h2)
  15. var table = document.createElement("table")
  16. var thead = document.createElement("thead")
  17. var tr = document.createElement("tr")
  18. var th1 = document.createElement("th")
  19. th1.textContent = "Knoten"
  20. th1.classList.add("sort-default")
  21. tr.appendChild(th1)
  22. var th2 = document.createElement("th")
  23. th2.textContent = "Uptime"
  24. tr.appendChild(th2)
  25. var th3 = document.createElement("th")
  26. th3.textContent = "Clients"
  27. tr.appendChild(th3)
  28. thead.appendChild(tr)
  29. table.appendChild(thead)
  30. var tbody = document.createElement("tbody")
  31. nodes.forEach( function (d) {
  32. var row = document.createElement("tr")
  33. var td1 = document.createElement("td")
  34. var a = document.createElement("a")
  35. a.textContent = d.nodeinfo.hostname
  36. a.href = "#"
  37. a.onclick = router.node(d)
  38. a.classList.add("hostname")
  39. a.classList.add(d.flags.online ? "online" : "offline")
  40. td1.appendChild(a)
  41. row.appendChild(td1)
  42. if (has_location(d)) {
  43. var span = document.createElement("span")
  44. span.classList.add("icon")
  45. span.classList.add("ion-location")
  46. td1.appendChild(span)
  47. }
  48. var td2 = document.createElement("td")
  49. showUptime(td2, d)
  50. row.appendChild(td2)
  51. var td3 = document.createElement("td")
  52. td3.textContent = "clients" in d.statistics ? d.statistics.clients : ""
  53. row.appendChild(td3)
  54. tbody.appendChild(row)
  55. })
  56. table.appendChild(tbody)
  57. new Tablesort(table)
  58. el.appendChild(table)
  59. function showUptime(el, d) {
  60. var uptime
  61. if (d.flags.online && "uptime" in d.statistics)
  62. uptime = Math.round(d.statistics.uptime / 3600)
  63. else if (!d.flags.online && "lastseen" in d)
  64. uptime = Math.round(-(now - d.lastseen) / 3600000)
  65. var s = ""
  66. if (uptime !== undefined) {
  67. if (Math.abs(uptime) >= 24)
  68. s = Math.round(uptime/24) + "d"
  69. else
  70. s = uptime + "h"
  71. }
  72. el.textContent = s
  73. el.setAttribute("data-sort", uptime !== undefined ? -uptime : 0)
  74. }
  75. }
  76. }
  77. })