station.eta 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <% layout("/en/layout", { title: it.meteostanica.name }) %>
  2. <%~ include("/en/panel/partials/navbar") %>
  3. <% const backIcon = `
  4. <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  5. <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m12 19l-7-7l7-7m7 7H5" />
  6. </svg>
  7. ` %>
  8. <% const tickIcon = `
  9. <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  10. <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
  11. <circle cx="12" cy="12" r="10" />
  12. <path d="m9 12l2 2l4-4" />
  13. </g>
  14. </svg>
  15. ` %>
  16. <% const xIcon = `
  17. <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  18. <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
  19. <circle cx="12" cy="12" r="10" />
  20. <path d="m15 9l-6 6m0-6l6 6" />
  21. </g>
  22. </svg>
  23. ` %>
  24. <% const tempIcon = `
  25. <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  26. <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 4v10.54a4 4 0 1 1-4 0V4a2 2 0 0 1 4 0" />
  27. </svg>
  28. ` %>
  29. <% const pressureIcon = `
  30. <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  31. <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m12 14l4-4M3.34 19a10 10 0 1 1 17.32 0" />
  32. </svg>
  33. ` %>
  34. <% const humidityIcon = `
  35. <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  36. <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 22a7 7 0 0 0 7-7c0-2-1-3.9-3-5.5s-3.5-4-4-6.5c-.5 2.5-2 4.9-4 6.5S5 13 5 15a7 7 0 0 0 7 7" />
  37. </svg>
  38. ` %>
  39. <% const resetIcon = `
  40. <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  41. <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
  42. <path d="M3 12a9 9 0 1 0 9-9a9.75 9.75 0 0 0-6.74 2.74L3 8" />
  43. <path d="M3 3v5h5" />
  44. </g>
  45. </svg>
  46. ` %>
  47. <% const historyIcon = `
  48. <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  49. <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
  50. <path d="M3 12a9 9 0 1 0 9-9a9.75 9.75 0 0 0-6.74 2.74L3 8" />
  51. <path d="M3 3v5h5m4-1v5l4 2" />
  52. </g>
  53. </svg>
  54. ` %>
  55. <% const editIcon = `
  56. <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  57. <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
  58. <path d="M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" />
  59. <path d="M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z" />
  60. </g>
  61. </svg>
  62. ` %>
  63. <% const deleteIcon = `
  64. <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  65. <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 11v6m4-6v6m5-11v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
  66. </svg>
  67. ` %>
  68. <div class="container-row">
  69. <a role="button" href="/en/panel/stations"><%~ backIcon %></a>
  70. <h2><%= it.meteostanica.name %></h2>
  71. </div>
  72. <% if (it.meteostanica.description) { %>
  73. <p><strong>description:</strong> <%= it.meteostanica.description %></p>
  74. <% } %>
  75. <% if (it.data?.[0]) { %>
  76. <div id="mainStats">
  77. <% /* <div class="message error">
  78. <p>High temperature was detcted!</p>
  79. <p>High pressure was detcted!</p>
  80. <p>High humidity was detcted!</p>
  81. </div> */ %>
  82. <p><em>last updated: <%= it.data?.[0]?.timestamp %></em></p>
  83. <div class="stats">
  84. <div class="wrapper">
  85. <h2>indoor</h2>
  86. <div class="values indoor">
  87. <p><a role="button" href="/en/panel/stations/<%= it.meteostanica.id %>/history/indoorTemp"><%~ tempIcon %></a> <span id="indoorTemp"><%= it.data?.[0]?.indoorTemp / 100 %></span> °C</p>
  88. <p><a role="button" href="/en/panel/stations/<%= it.meteostanica.id %>/history/indoorPressure"><%~ pressureIcon %></a> <span id="indoorPressure"><%= it.data?.[0]?.indoorPressure / 100 %></span> hPa</p>
  89. <p><a role="button" href="/en/panel/stations/<%= it.meteostanica.id %>/history/indoorHumidity"><%~ humidityIcon %></a> <span id="indoorHumidity"><%= it.data?.[0]?.indoorHumidity / 100 %></span> %</p>
  90. </div>
  91. </div>
  92. <div class="wrapper">
  93. <h2>outdoor</h2>
  94. <div class="values outdoor">
  95. <p><a role="button" href="/en/panel/stations/<%= it.meteostanica.id %>/history/outdoorConnected" id="outdoorConnectedIcon"><%~ it.data?.[0]?.outdoorConnected ? tickIcon : xIcon %></a> <span id="outdoorConnectedText"><%= it.data?.[0]?.outdoorConnected ? `connected` : `disconnected` %></span></p>
  96. <p><a role="button" href="/en/panel/stations/<%= it.meteostanica.id %>/history/outdoorTemp"><%~ tempIcon %></a> <span id="outdoorTemp"><%= it.data?.[0]?.outdoorTemp / 100 %></span> °C</p>
  97. <p><a role="button" href="/en/panel/stations/<%= it.meteostanica.id %>/history/outdoorPressure"><%~ pressureIcon %></a> <span id="outdoorPressure"><%= it.data?.[0]?.outdoorPressure / 100 %></span> hPa</p>
  98. <p><a role="button" href="/en/panel/stations/<%= it.meteostanica.id %>/history/outdoorHumidity"><%~ humidityIcon %></a> <span id="outdoorHumidity"><%= it.data?.[0]?.outdoorHumidity / 100 %></span> %</p>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. <script defer>
  104. setInterval(async () => {
  105. const response = await fetch('/en/panel/stations/<%= it.meteostanica.id %>/currentData')
  106. const data = await response.json()
  107. const indoorTemp = document.querySelector(`#indoorTemp`)
  108. const indoorPressure = document.querySelector(`#indoorPressure`)
  109. const indoorHumidity = document.querySelector(`#indoorHumidity`)
  110. const indoorAltitude = document.querySelector(`#indoorAltitude`)
  111. const outdoorConnectedIcon = document.querySelector(`#outdoorConnectedIcon`)
  112. const outdoorConnectedText = document.querySelector(`#outdoorConnectedText`)
  113. const outdoorTemp = document.querySelector(`#outdoorTemp`)
  114. const outdoorPressure = document.querySelector(`#outdoorPressure`)
  115. const outdoorHumidity = document.querySelector(`#outdoorHumidity`)
  116. const outdoorAltitude = document.querySelector(`#outdoorAltitude`)
  117. indoorTemp.textContent = data?.indoorTemp / 100
  118. indoorPressure.textContent = data?.indoorPressure / 100
  119. indoorHumidity.textContent = data?.indoorHumidity / 100
  120. indoorAltitude.textContent = data?.indoorAltitude / 100
  121. const tickIcon = `<%~ tickIcon %>`
  122. const xIcon = `<%~ xIcon %>`
  123. outdoorConnectedIcon.innerHTML = data?.outdoorConnected ? tickIcon : xIcon
  124. outdoorConnectedText.textContent = data?.outdoorConnected ? `connected` : `disconnected`
  125. outdoorTemp.textContent = data?.outdoorTemp / 100
  126. outdoorPressure.textContent = data?.outdoorPressure / 100
  127. outdoorHumidity.textContent = data?.outdoorHumidity / 100
  128. outdoorAltitude.textContent = data?.outdoorAltitude / 100
  129. }, 10000)
  130. </script>
  131. <% } %>
  132. <p><strong>created:</strong> <%= it.meteostanica.timestamp %></p>
  133. <div class="container-row">
  134. <p><strong>websocket key:</strong> <%= it.meteostanica.websocketKey %></p>
  135. <a role="button" href="/en/panel/stations/<%= it.meteostanica.id %>/resetWebsocketKey"><%~ resetIcon %> reset</a>
  136. </div>
  137. <hr>
  138. <div class="container-row">
  139. <a role="button" href="/en/panel/stations/<%= it.meteostanica.id %>/history"><%~ historyIcon %> history</a>
  140. <a role="button" class="primary" href="/en/panel/stations/<%= it.meteostanica.id %>/edit"><%~ editIcon %> edit</a>
  141. <a role="button" class="danger" href="/en/panel/stations/<%= it.meteostanica.id %>/delete"><%~ deleteIcon %> delete</a>
  142. </div>