containerCard.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 deleteme">
  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 onclick="clicked(this)" name="${name}" value="${state}" id="start" class="btn-action" title="Start" ${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 onclick="clicked(this)" name="${name}" value="${state}" id="stop" class="btn-action" title="Stop" ${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 onclick="clicked(this)" name="${name}" value="${state}" id="pause" class="btn-action" title="Pause" ${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 onclick="clicked(this)" name="${name}" value="${state}" id="restart" class="btn-action" title="Restart" ${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" onclick="clicked(this)" name="${name}" id="hide" value="hide">Hide</button>
  82. <button class="dropdown-item text-secondary" onclick="clicked(this)" name="${name}" id="resetView" value="resetView">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 id="${chart}_chart" class="chart-sm"></div>
  104. </div>
  105. </div>
  106. </div>
  107. <div class="modal modal-blur fade" id="${name}_uninstall_modal" tabindex="-1" style="display: none;" aria-hidden="true">
  108. <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
  109. <div class="modal-content">
  110. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  111. <div class="modal-status bg-danger"></div>
  112. <div class="modal-body text-center py-3">
  113. <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>
  114. <h3>Remove ${name}?</h3>
  115. <form action="/uninstall" id="${name}_uninstall" method="POST">
  116. <input type="text" class="form-control" name="service_name" value="${name}" hidden/>
  117. <div class="mb-3"> </div>
  118. <div class="mb-2">
  119. <div class="divide-y">
  120. <div class="row">
  121. <div class="col-9">
  122. <label class="row text-start">
  123. <span class="col">Remove Volumes</span>
  124. </label>
  125. </div>
  126. <div class="col-3">
  127. <label class="form-check form-check-single form-switch text-end">
  128. <input class="form-check-input" type="checkbox" name="remove_volumes" disabled="">
  129. </label>
  130. </div>
  131. </div>
  132. <div class="row">
  133. <div class="col-9">
  134. <label class="row text-start">
  135. <span class="col">
  136. Remove Image
  137. </span>
  138. </label>
  139. </div>
  140. <div class="col-3">
  141. <label class="form-check form-check-single form-switch text-end">
  142. <input class="form-check-input" type="checkbox" name="remove_image" disabled="">
  143. </label>
  144. </div>
  145. </div>
  146. <div class="row">
  147. <div class="col-9">
  148. <label class="row text-start">
  149. <span class="col">
  150. Remove Backups
  151. </span>
  152. </label>
  153. </div>
  154. <div class="col-3">
  155. <label class="form-check form-check-single form-switch text-end">
  156. <input class="form-check-input" type="checkbox" name="remove_backups" disabled="">
  157. </label>
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. <div class="mt-1"> </div>
  163. <div class="text-muted">Enter "Yes" below to remove the container.</div>
  164. <input type="text" class="form-control mb-2" name="confirm" autocomplete="off">
  165. </form>
  166. </div>
  167. <div class="modal-footer">
  168. <div class="w-100">
  169. <div class="row">
  170. <div class="col">
  171. <a href="#" class="btn w-100" data-bs-dismiss="modal">
  172. Cancel
  173. </a>
  174. </div>
  175. <div class="col">
  176. <input type="submit" form="${name}_uninstall" class="btn btn-danger w-100" value="Uninstall"/>
  177. </div>
  178. </div>
  179. </div>
  180. </div>
  181. </div>
  182. </div>
  183. </div>
  184. <div class="modal modal-blur fade" id="${name}_permissions" tabindex="-1" style="display: none;" aria-hidden="true">
  185. <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
  186. <div class="modal-content">
  187. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  188. <div class="modal-status bg-cyan"></div>
  189. <div class="modal-body text-center py-3">
  190. <h3>${name} permissions</h3>
  191. <form action="#" id="${name}_permissions" method="POST">
  192. <input type="text" class="form-control" name="service_name" value="${name}" hidden/>
  193. <div class="mb-2">
  194. <div class="divide-y">
  195. <div class="row">
  196. <div class="col-9">
  197. <label class="row text-start">
  198. <span class="col">Install</span>
  199. </label>
  200. </div>
  201. <div class="col-3">
  202. <label class="form-check form-check-single form-switch text-end">
  203. <input class="form-check-input" type="checkbox" name="remove_volumes">
  204. </label>
  205. </div>
  206. </div>
  207. <div class="row">
  208. <div class="col-9">
  209. <label class="row text-start">
  210. <span class="col">
  211. Uninstall
  212. </span>
  213. </label>
  214. </div>
  215. <div class="col-3">
  216. <label class="form-check form-check-single form-switch text-end">
  217. <input class="form-check-input" type="checkbox" name="remove_image">
  218. </label>
  219. </div>
  220. </div>
  221. <div class="row">
  222. <div class="col-9">
  223. <label class="row text-start">
  224. <span class="col">
  225. Edit
  226. </span>
  227. </label>
  228. </div>
  229. <div class="col-3">
  230. <label class="form-check form-check-single form-switch text-end">
  231. <input class="form-check-input" type="checkbox" name="remove_backups">
  232. </label>
  233. </div>
  234. </div>
  235. <div class="row">
  236. <div class="col-9">
  237. <label class="row text-start">
  238. <span class="col">
  239. Upgrade
  240. </span>
  241. </label>
  242. </div>
  243. <div class="col-3">
  244. <label class="form-check form-check-single form-switch text-end">
  245. <input class="form-check-input" type="checkbox" name="remove_backups">
  246. </label>
  247. </div>
  248. </div>
  249. </div>
  250. </div>
  251. <div class="mt-1"> </div>
  252. </form>
  253. </div>
  254. <div class="modal-footer">
  255. <div class="w-100">
  256. <div class="row">
  257. <div class="col">
  258. <a href="#" class="btn w-100" data-bs-dismiss="modal">
  259. Cancel
  260. </a>
  261. </div>
  262. <div class="col">
  263. <input type="submit" form="${name}_permissions" class="btn btn-primary w-100" value="Update"/>
  264. </div>
  265. </div>
  266. </div>
  267. </div>
  268. </div>
  269. </div>
  270. </div>`;
  271. }