containerCard.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. // export for app.js
  2. export const containerCard = (data) => {
  3. let { name, service, state, external_port, internal_port, ports, link } = data;
  4. let wrapped = name;
  5. let chart = name;
  6. if (name.length > 13) {
  7. wrapped = name.slice(0, 10) + '...';
  8. }
  9. //disable controls for a docker container depending on its name
  10. let actions = "";
  11. if (name.startsWith('dweebui')) {
  12. actions = 'disabled=""';
  13. }
  14. if ( external_port == undefined ) { external_port = 0; }
  15. if ( internal_port == undefined ) { internal_port = 0; }
  16. let state_indicator = 'green';
  17. if (state == 'exited') {
  18. state = 'stopped';
  19. state_indicator = 'red';
  20. } else if (state == 'paused') {
  21. state_indicator = 'orange';
  22. }
  23. let ports_data = [];
  24. if (ports) {
  25. ports_data = ports;
  26. } else {
  27. for (let i = 0; i < 12; i++) {
  28. let port_check = "checked";
  29. let external = i;
  30. let internal = i;
  31. let protocol = "tcp";
  32. ports_data.push({
  33. check: port_check,
  34. external: external,
  35. internal: internal,
  36. protocol: protocol
  37. });
  38. }
  39. }
  40. return `
  41. <div class="col-sm-6 col-lg-3 pt-1">
  42. <div class="card">
  43. <div class="card-body">
  44. <div class="card-stamp card-stamp-sm">
  45. <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>
  46. </div>
  47. <div class="d-flex align-items-center">
  48. <div class="subheader text-yellow">${external_port}:${internal_port}</div>
  49. <div class="ms-auto lh-1">
  50. <div class="card-actions btn-actions">
  51. <div class="card-actions btn-actions">
  52. <button class="btn-action" title="Start" data-hx-get="/click" data-hx-trigger="click" data-hx-swap="none" name="${name}" id="start" value="${state}" ${actions}><!-- player-play -->
  53. <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>
  54. </button>
  55. <button class="btn-action" title="Stop" data-hx-get="/click" data-hx-trigger="click" data-hx-swap="none" name="${name}" id="stop" value="${state}" ${actions}><!-- player-stop -->
  56. <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>
  57. </button>
  58. <button class="btn-action" title="Pause" data-hx-get="/click" data-hx-trigger="click" data-hx-swap="none" name="${name}" id="pause" value="${state}" ${actions}><!-- player-pause -->
  59. <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>
  60. </button>
  61. <button class="btn-action" title="Restart" data-hx-get="/click" data-hx-trigger="click" data-hx-swap="none" name="${name}" id="restart" value="${state}" ${actions}><!-- reload -->
  62. <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>
  63. </button>
  64. <div class="dropdown">
  65. <a href="#" class="btn-action dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  66. <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>
  67. </a>
  68. <div class="dropdown-menu dropdown-menu-end">
  69. <button class="dropdown-item text-secondary" onclick="clicked(this)" id="details" data-bs-toggle="modal" data-bs-target="#details_modal" href="#">Details</button>
  70. <button class="dropdown-item text-secondary" onclick="clicked(this)" name="${name}" id="logs" data-bs-toggle="modal" data-bs-target="#log_view" href="#">Logs</button>
  71. <button class="dropdown-item text-secondary" onclick="clicked(this)" name="${name}" id="edit" href="#">Edit</button>
  72. <button class="dropdown-item text-primary" onclick="clicked(this)" name="${name}" id="update" href="#">Update</button>
  73. <button class="dropdown-item text-danger" onclick="clicked(this)" name="${name}" id="remove" data-bs-toggle="modal" data-bs-target="#${name}_uninstall_modal" href="#">Remove</button>
  74. </div>
  75. </div>
  76. <div class="dropdown">
  77. <a href="#" class="btn-action dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  78. <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>
  79. </a>
  80. <div class="dropdown-menu dropdown-menu-end">
  81. <button class="dropdown-item text-secondary" data-hx-get="/click" data-hx-trigger="click" data-hx-swap="none" name="${name}" id="hide" value="hide">Hide</button>
  82. <button class="dropdown-item text-secondary" data-hx-get="/click" data-hx-trigger="click" data-hx-swap="none" name="${name}" id="reset" value="reset">Reset View</button>
  83. <button class="dropdown-item text-secondary" onclick="clicked(this)" name="${name}" id="permissions" value="permissions" data-bs-toggle="modal" data-bs-target="#${name}_permissions">Permissions</button>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. <div class="d-flex align-items-baseline">
  91. <div class="h1 me-2" title="${name}" style="margin-bottom: 0;">
  92. <a href="http://${link}:${external_port}" target="_blank">
  93. ${wrapped}
  94. </a>
  95. </div>
  96. <div class="ms-auto">
  97. <span class="text-${state_indicator} align-items-center lh-1">
  98. <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>
  99. ${state}
  100. </span>
  101. </div>
  102. </div>
  103. <div class="chart-sm" data-hx-get="/chart" data-hx-trigger="every 2s" name="${name}" data-hx-target="#${name}_chart" hx-swap="innerHTML">
  104. <div id="${name}_chart"></div>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. <div class="modal modal-blur fade" id="${name}_uninstall_modal" tabindex="-1" style="display: none;" aria-hidden="true">
  110. <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
  111. <div class="modal-content">
  112. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  113. <div class="modal-status bg-danger"></div>
  114. <div class="modal-body text-center py-3">
  115. <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>
  116. <h3>Remove ${name}?</h3>
  117. <form action="/uninstall" id="${name}_uninstall" method="POST">
  118. <input type="text" class="form-control" name="service_name" value="${name}" hidden/>
  119. <div class="mb-3"> </div>
  120. <div class="mb-2">
  121. <div class="divide-y">
  122. <div class="row">
  123. <div class="col-9">
  124. <label class="row text-start">
  125. <span class="col">Remove Volumes</span>
  126. </label>
  127. </div>
  128. <div class="col-3">
  129. <label class="form-check form-check-single form-switch text-end">
  130. <input class="form-check-input" type="checkbox" name="remove_volumes" disabled="">
  131. </label>
  132. </div>
  133. </div>
  134. <div class="row">
  135. <div class="col-9">
  136. <label class="row text-start">
  137. <span class="col">
  138. Remove Image
  139. </span>
  140. </label>
  141. </div>
  142. <div class="col-3">
  143. <label class="form-check form-check-single form-switch text-end">
  144. <input class="form-check-input" type="checkbox" name="remove_image" disabled="">
  145. </label>
  146. </div>
  147. </div>
  148. <div class="row">
  149. <div class="col-9">
  150. <label class="row text-start">
  151. <span class="col">
  152. Remove Backups
  153. </span>
  154. </label>
  155. </div>
  156. <div class="col-3">
  157. <label class="form-check form-check-single form-switch text-end">
  158. <input class="form-check-input" type="checkbox" name="remove_backups" disabled="">
  159. </label>
  160. </div>
  161. </div>
  162. </div>
  163. </div>
  164. <div class="mt-1"> </div>
  165. <div class="text-muted">Enter "Yes" below to remove the container.</div>
  166. <input type="text" class="form-control mb-2" name="confirm" autocomplete="off">
  167. </form>
  168. </div>
  169. <div class="modal-footer">
  170. <div class="w-100">
  171. <div class="row">
  172. <div class="col">
  173. <a href="#" class="btn w-100" data-bs-dismiss="modal">
  174. Cancel
  175. </a>
  176. </div>
  177. <div class="col">
  178. <input type="submit" form="${name}_uninstall" class="btn btn-danger w-100" value="Uninstall"/>
  179. </div>
  180. </div>
  181. </div>
  182. </div>
  183. </div>
  184. </div>
  185. </div>
  186. <div class="modal modal-blur fade" id="${name}_permissions" tabindex="-1" style="display: none;" aria-hidden="true">
  187. <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
  188. <div class="modal-content">
  189. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  190. <div class="modal-status bg-cyan"></div>
  191. <div class="modal-body text-center py-3">
  192. <h3>${name} permissions</h3>
  193. <form action="#" id="${name}_permissions" method="POST">
  194. <input type="text" class="form-control" name="service_name" value="${name}" hidden/>
  195. <div class="mb-2">
  196. <div class="divide-y">
  197. <div class="row">
  198. <div class="col-9">
  199. <label class="row text-start">
  200. <span class="col">Install</span>
  201. </label>
  202. </div>
  203. <div class="col-3">
  204. <label class="form-check form-check-single form-switch text-end">
  205. <input class="form-check-input" type="checkbox" name="remove_volumes">
  206. </label>
  207. </div>
  208. </div>
  209. <div class="row">
  210. <div class="col-9">
  211. <label class="row text-start">
  212. <span class="col">
  213. Uninstall
  214. </span>
  215. </label>
  216. </div>
  217. <div class="col-3">
  218. <label class="form-check form-check-single form-switch text-end">
  219. <input class="form-check-input" type="checkbox" name="remove_image">
  220. </label>
  221. </div>
  222. </div>
  223. <div class="row">
  224. <div class="col-9">
  225. <label class="row text-start">
  226. <span class="col">
  227. Edit
  228. </span>
  229. </label>
  230. </div>
  231. <div class="col-3">
  232. <label class="form-check form-check-single form-switch text-end">
  233. <input class="form-check-input" type="checkbox" name="remove_backups">
  234. </label>
  235. </div>
  236. </div>
  237. <div class="row">
  238. <div class="col-9">
  239. <label class="row text-start">
  240. <span class="col">
  241. Upgrade
  242. </span>
  243. </label>
  244. </div>
  245. <div class="col-3">
  246. <label class="form-check form-check-single form-switch text-end">
  247. <input class="form-check-input" type="checkbox" name="remove_backups">
  248. </label>
  249. </div>
  250. </div>
  251. </div>
  252. </div>
  253. <div class="mt-1"> </div>
  254. </form>
  255. </div>
  256. <div class="modal-footer">
  257. <div class="w-100">
  258. <div class="row">
  259. <div class="col">
  260. <a href="#" class="btn w-100" data-bs-dismiss="modal">
  261. Cancel
  262. </a>
  263. </div>
  264. <div class="col">
  265. <input type="submit" form="${name}_permissions" class="btn btn-primary w-100" value="Update"/>
  266. </div>
  267. </div>
  268. </div>
  269. </div>
  270. </div>
  271. </div>
  272. </div>`;
  273. }