containerCard.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. export const containerCard = (data) => {
  2. let { name, service, state, external_port, internal_port, ports, link } = data;
  3. let wrapped = name;
  4. let disable = "";
  5. let chartName = name.replace(/-/g, '');
  6. // shorten long names
  7. if (name.length > 13) { wrapped = name.slice(0, 10) + '...'; }
  8. // disable buttons for dweebui
  9. if (name.startsWith('dweebui')) { disable = 'disabled=""'; }
  10. if ( external_port == undefined ) { external_port = 0; }
  11. if ( internal_port == undefined ) { internal_port = 0; }
  12. let state_indicator = 'green';
  13. if (state == 'exited') {
  14. state = 'stopped';
  15. state_indicator = 'red';
  16. } else if (state == 'paused') {
  17. state_indicator = 'orange';
  18. }
  19. let ports_data = [];
  20. if (ports) {
  21. ports_data = ports;
  22. } else {
  23. for (let i = 0; i < 12; i++) {
  24. let port_check = "checked";
  25. let external = i;
  26. let internal = i;
  27. let protocol = "tcp";
  28. ports_data.push({
  29. check: port_check,
  30. external: external,
  31. internal: internal,
  32. protocol: protocol
  33. });
  34. }
  35. }
  36. return `
  37. <div class="col-sm-6 col-lg-3 pt-1">
  38. <div class="card">
  39. <div class="card-body">
  40. <div class="card-stamp card-stamp-sm">
  41. <img width="100px" src="https://raw.githubusercontent.com/lllllllillllllillll/DweebUI-Icons/main/${service}.png" onerror="this.onerror=null;this.src='https://raw.githubusercontent.com/lllllllillllllillll/DweebUI-Icons/main/docker.png';"></img>
  42. </div>
  43. <div class="d-flex align-items-center">
  44. <div class="subheader text-yellow">${external_port}:${internal_port}</div>
  45. <div class="ms-auto lh-1">
  46. <div class="card-actions btn-actions">
  47. <div class="card-actions btn-actions">
  48. <button class="btn-action" title="Start" data-hx-post="/start" data-hx-trigger="click" data-hx-swap="none" name="${name}" id="${state}" ${disable}><!-- player-play -->
  49. <svg xmlns="http://www.w3.org/2000/svg" class="icon-tabler icon-tabler-player-play" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M7 4v16l13 -8z"></path></svg>
  50. </button>
  51. <button class="btn-action" title="Stop" data-hx-post="/stop" data-hx-trigger="click" data-hx-swap="none" name="${name}" id="${state}" ${disable}><!-- player-stop -->
  52. <svg xmlns="http://www.w3.org/2000/svg" class="icon-tabler icon-tabler-player-stop" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 5m0 2a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2z"></path></svg>
  53. </button>
  54. <button class="btn-action" title="Pause" data-hx-post="/pause" data-hx-trigger="click" data-hx-swap="none" name="${name}" id="${state}" ${disable}><!-- player-pause -->
  55. <svg xmlns="http://www.w3.org/2000/svg" class="icon-tabler icon-tabler-player-pause" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M6 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"></path><path d="M14 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"></path></svg>
  56. </button>
  57. <button class="btn-action" title="Restart" data-hx-post="/restart" data-hx-trigger="click" data-hx-swap="none" name="${name}" id="${state}" ${disable}><!-- reload -->
  58. <svg xmlns="http://www.w3.org/2000/svg" class="icon-tabler icon-tabler-reload" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M19.933 13.041a8 8 0 1 1 -9.925 -8.788c3.899 -1 7.935 1.007 9.425 4.747"></path><path d="M20 4v5h-5"></path></svg>
  59. </button>
  60. <div class="dropdown">
  61. <a href="#" class="btn-action dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  62. <svg xmlns="http://www.w3.org/2000/svg" class="" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><circle cx="12" cy="12" r="1"></circle><circle cx="12" cy="19" r="1"></circle><circle cx="12" cy="5" r="1"></circle></svg>
  63. </a>
  64. <div class="dropdown-menu dropdown-menu-end">
  65. <button class="dropdown-item text-secondary" name="${name}" data-hx-get="/modal" data-hx-target="#modals-here" data-hx-trigger="click" data-bs-toggle="modal" data-bs-target="#modals-here">Details</button>
  66. <button class="dropdown-item text-secondary" name="${name}" id="logs" data-hx-get="/logs" data-hx-target="#logView" data-bs-toggle="modal" data-bs-target="#log_view">Logs</button>
  67. <button class="dropdown-item text-secondary" name="${name}" id="edit">Edit</button>
  68. <button class="dropdown-item text-primary" name="${name}" id="update" disabled="">Update</button>
  69. <button class="dropdown-item text-danger" name="${name}" id="remove" data-bs-toggle="modal" data-bs-target="#${name}_uninstall_modal" href="#">Remove</button>
  70. </div>
  71. </div>
  72. <div class="dropdown">
  73. <a href="#" class="btn-action dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  74. <svg xmlns="http://www.w3.org/2000/svg" class="icon-tabler icon-tabler-eye" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"/> <path d="M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" /> <path d="M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6" /> </svg>
  75. </a>
  76. <div class="dropdown-menu dropdown-menu-end">
  77. <button class="dropdown-item text-secondary" data-hx-post="/hide" data-hx-trigger="click" data-hx-swap="none" name="${name}" id="hide" value="hide">Hide</button>
  78. <button class="dropdown-item text-secondary" data-hx-post="/reset" data-hx-trigger="click" data-hx-swap="none" name="${name}" id="reset" value="reset">Reset View</button>
  79. <button class="dropdown-item text-secondary" name="${name}" id="permissions" data-hx-get="/modal" data-hx-target="#modals-here" data-hx-trigger="click" data-bs-toggle="modal" data-bs-target="#modals-here">Permissions</button>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. <div class="d-flex align-items-baseline">
  87. <div class="h1 me-2" title="${name}" style="margin-bottom: 0;">
  88. <a href="http://${link}:${external_port}" target="_blank">
  89. ${wrapped}
  90. </a>
  91. </div>
  92. <div class="ms-auto">
  93. <span class="text-${state_indicator} align-items-center lh-1">
  94. <svg xmlns="http://www.w3.org/2000/svg" class="icon-tabler icon-tabler-point-filled" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <path d="M12 7a5 5 0 1 1 -4.995 5.217l-.005 -.217l.005 -.217a5 5 0 0 1 4.995 -4.783z" stroke-width="0" fill="currentColor"></path></svg>
  95. ${state}
  96. </span>
  97. </div>
  98. </div>
  99. <script>
  100. var ${chartName}chart = new ApexCharts(document.querySelector("#${chartName}_chart"), options);
  101. </script>
  102. <div class="chart-sm">
  103. <div id="${chartName}_chart" data-hx-trigger="load, every 2s" data-hx-get="/chart" name="${chartName}">
  104. <script>
  105. ${chartName}chart.render();
  106. </script>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. <div class="modal modal-blur fade" id="${name}_uninstall_modal" tabindex="-1" style="display: none;" aria-hidden="true">
  113. <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
  114. <div class="modal-content">
  115. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  116. <div class="modal-status bg-danger"></div>
  117. <div class="modal-body text-center py-3">
  118. <svg xmlns="http://www.w3.org/2000/svg" class="icon mb-2 text-danger icon-lg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M12 9v2m0 4v.01"></path><path d="M5 19h14a2 2 0 0 0 1.84 -2.75l-7.1 -12.25a2 2 0 0 0 -3.5 0l-7.1 12.25a2 2 0 0 0 1.75 2.75"></path></svg>
  119. <h3>Remove ${name}?</h3>
  120. <form action="/uninstall" id="${name}_uninstall" method="POST">
  121. <input type="text" class="form-control" name="service_name" value="${name}" hidden/>
  122. <div class="mb-3"> </div>
  123. <div class="mb-2">
  124. <div class="divide-y">
  125. <div class="row">
  126. <div class="col-9">
  127. <label class="row text-start">
  128. <span class="col">Remove Volumes</span>
  129. </label>
  130. </div>
  131. <div class="col-3">
  132. <label class="form-check form-check-single form-switch text-end">
  133. <input class="form-check-input" type="checkbox" name="remove_volumes" disabled="">
  134. </label>
  135. </div>
  136. </div>
  137. <div class="row">
  138. <div class="col-9">
  139. <label class="row text-start">
  140. <span class="col">
  141. Remove Image
  142. </span>
  143. </label>
  144. </div>
  145. <div class="col-3">
  146. <label class="form-check form-check-single form-switch text-end">
  147. <input class="form-check-input" type="checkbox" name="remove_image" disabled="">
  148. </label>
  149. </div>
  150. </div>
  151. <div class="row">
  152. <div class="col-9">
  153. <label class="row text-start">
  154. <span class="col">
  155. Remove Backups
  156. </span>
  157. </label>
  158. </div>
  159. <div class="col-3">
  160. <label class="form-check form-check-single form-switch text-end">
  161. <input class="form-check-input" type="checkbox" name="remove_backups" disabled="">
  162. </label>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. <div class="mt-1"> </div>
  168. <div class="text-muted">Enter "Yes" below to remove the container.</div>
  169. <input type="text" class="form-control mb-2" name="confirm" autocomplete="off">
  170. </form>
  171. </div>
  172. <div class="modal-footer">
  173. <div class="w-100">
  174. <div class="row">
  175. <div class="col">
  176. <a href="#" class="btn w-100" data-bs-dismiss="modal">
  177. Cancel
  178. </a>
  179. </div>
  180. <div class="col">
  181. <input type="submit" form="${name}_uninstall" class="btn btn-danger w-100" value="Uninstall"/>
  182. </div>
  183. </div>
  184. </div>
  185. </div>
  186. </div>
  187. </div>
  188. </div>
  189. <div class="modal modal-blur fade" id="${name}_permissions" tabindex="-1" style="display: none;" aria-hidden="true">
  190. <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
  191. <div class="modal-content">
  192. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  193. <div class="modal-status bg-cyan"></div>
  194. <div class="modal-body text-center py-3">
  195. <h3>${name} permissions</h3>
  196. <form action="#" id="${name}_permissions" method="POST">
  197. <input type="text" class="form-control" name="service_name" value="${name}" hidden/>
  198. <div class="mb-2">
  199. <div class="divide-y">
  200. <div class="row">
  201. <div class="col-9">
  202. <div class="d-flex align-items-center">
  203. User:
  204. <select class="form-select ms-2">
  205. <option value="john_doe" selected hidden>John Doe</option>
  206. <option value="john_doe">John Doe</option>
  207. <option value="jane_doe">Jane Doe</option>
  208. </select>
  209. </div>
  210. </div>
  211. </div>
  212. <div class="row">
  213. <div class="col-9">
  214. <label class="row text-start">
  215. <span class="col">
  216. View
  217. </span>
  218. </label>
  219. </div>
  220. <div class="col-3">
  221. <label class="form-check form-check-single form-switch text-end">
  222. <input class="form-check-input" type="checkbox" name="remove_image">
  223. </label>
  224. </div>
  225. </div>
  226. <div class="row">
  227. <div class="col-9">
  228. <label class="row text-start">
  229. <span class="col">
  230. Uninstall
  231. </span>
  232. </label>
  233. </div>
  234. <div class="col-3">
  235. <label class="form-check form-check-single form-switch text-end">
  236. <input class="form-check-input" type="checkbox" name="remove_image">
  237. </label>
  238. </div>
  239. </div>
  240. <div class="row">
  241. <div class="col-9">
  242. <label class="row text-start">
  243. <span class="col">
  244. Edit
  245. </span>
  246. </label>
  247. </div>
  248. <div class="col-3">
  249. <label class="form-check form-check-single form-switch text-end">
  250. <input class="form-check-input" type="checkbox" name="remove_backups">
  251. </label>
  252. </div>
  253. </div>
  254. <div class="row">
  255. <div class="col-9">
  256. <label class="row text-start">
  257. <span class="col">
  258. Upgrade
  259. </span>
  260. </label>
  261. </div>
  262. <div class="col-3">
  263. <label class="form-check form-check-single form-switch text-end">
  264. <input class="form-check-input" type="checkbox" name="remove_backups">
  265. </label>
  266. </div>
  267. </div>
  268. </div>
  269. </div>
  270. <div class="mt-1"> </div>
  271. </form>
  272. </div>
  273. <div class="modal-footer">
  274. <div class="w-100">
  275. <div class="row">
  276. <div class="col">
  277. <a href="#" class="btn w-100" data-bs-dismiss="modal">
  278. Cancel
  279. </a>
  280. </div>
  281. <div class="col">
  282. <input type="submit" form="${name}_permissions" class="btn btn-primary w-100" value="Update"/>
  283. </div>
  284. </div>
  285. </div>
  286. </div>
  287. </div>
  288. </div>
  289. </div>`;
  290. }