linklist.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. define(["tablesort", "tablesort.numeric"], function (Tablesort) {
  2. return function(linkScale, 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 (data) {
  10. if (data.graph.links.length === 0)
  11. return
  12. var h2 = document.createElement("h2")
  13. h2.textContent = "Verbindungen"
  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. tr.appendChild(th1)
  21. var th2 = document.createElement("th")
  22. th2.textContent = "TQ"
  23. tr.appendChild(th2)
  24. var th3 = document.createElement("th")
  25. th3.textContent = "Entfernung"
  26. th3.classList.add("sort-default")
  27. tr.appendChild(th3)
  28. thead.appendChild(tr)
  29. table.appendChild(thead)
  30. var tbody = document.createElement("tbody")
  31. data.graph.links.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.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname
  36. a.href = "#"
  37. a.onclick = router.link(d)
  38. td1.appendChild(a)
  39. row.appendChild(td1)
  40. if (d.vpn)
  41. td1.appendChild(document.createTextNode(" (VPN)"))
  42. var td2 = document.createElement("td")
  43. td2.textContent = showTq(d)
  44. td2.style.color = linkScale(d.tq)
  45. row.appendChild(td2)
  46. var td3 = document.createElement("td")
  47. td3.textContent = showDistance(d)
  48. td3.setAttribute("data-sort", d.distance !== undefined ? -d.distance : 1)
  49. row.appendChild(td3)
  50. tbody.appendChild(row)
  51. })
  52. table.appendChild(tbody)
  53. new Tablesort(table)
  54. el.appendChild(table)
  55. }
  56. }
  57. })