containerCard.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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="#remove_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" onclick="clicked(this)" name="${name}" id="hide" value="hide">Hide</button>
  82. <button class="dropdown-item" onclick="clicked(this)" name="${name}" id="resetView" value="resetView">Reset View</button>
  83. <button class="dropdown-item" onclick="clicked(this)" name="${name}" id="permissions" value="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. }