PY_DOCKER_DASHBOARD/templates/index.html

117 lines
4.5 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{title}}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<style>
</style>
</head>
<body data-bs-theme="dark">
<div class="container-fluid">
<a href="/" class="d-flex text-decoration-none text-primary">
<i style="font-size: 3rem;" class="bi bi-stack me-2"></i>
<div class="mb-2">
<h2 class="mb-0">Containers</h2>
<small>{{subtitle}}</small>
</div>
</a>
<div class="row row-cols-auto g-2">
{% for container in containers %}
<div class="col-6 col-sm-4 col-md-4 col-lg-3 col-xxl-2">
<div class="border h-100 p-3">
<div class="square-content" onclick="openModalForContainer('{{container.id}}')">
<!-- Content for the square item -->
<div class="d-flex justify-content-between">
<img height="60" width="60"
src="https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/nginx.svg" alt="">
<div class="form-check form-switch form-check-reverse">
<input class="form-check-input" type="checkbox" id="flexSwitchCheckReverse"
onclick="toggleContainer('{{container.id}}', '{{container.status}}', this, event);" {% if
container.status=="running" %} checked {% endif %}>
<label class="form-check-label d-none d-md-block "
for="flexSwitchCheckReverse">{{container.status}}</label>
</div>
</div>
<h4 class="text-truncate">{{container.attrs['Config']['Labels']['com.docker.compose.project']}}</h4>
<h5 class="text-truncate">{{container.name}}</h5>
{% if container.status=="running" %}
{% for port in container.attrs['NetworkSettings']['Ports'] %}
<a href="//127.0.0.1:{{ port.split(" /")[0] }}" target="_blank">{{ port.split("/")[0] }}</a>
{%endfor%}
{%endif%}
</div>
</div>
</div>
{%endfor%}
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-fullscreen-sm-down">
<div class="modal-content">
<div class="modal-body">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm"
crossorigin="anonymous"></script>
<script>
async function toggleContainer(container_id, status, control, control_event) {
//control_event.preventDefault();
control_event.stopPropagation();
console.log(control);
control.disabled = true;
route = (status == 'running' ? 'stop' : 'start')
method = (status == 'running' ? 'DELETE' : 'POST')
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText)
control.checked = (this.responseText == 'running' ? true : false);
}
control.disabled = false;
};
xhttp.open(method, '/api/' + container_id + '/' + route, true);
xhttp.send();
await new Promise(r => setTimeout(() => r(), 1500));
//window.location.reload();
}
function openModalForContainer(container_id) {
document.getElementById('exampleModal').getElementsByClassName('modal-content')[0].innerHTML = "<div class=\"modal-body\"><div class=\"spinner-border\" role=\"status\"><span class=\"visually-hidden\">Loading...</span></div></div>"
const myModal = new bootstrap.Modal('#exampleModal')
myModal.show()
const xhttp = new XMLHttpRequest();
xhttp.onload = function () {
document.getElementById('exampleModal').getElementsByClassName('modal-content')[0].innerHTML = this.responseText;
}
xhttp.open("GET", "/parts/modal/container/" + container_id, true);
xhttp.send();
}
</script>
</body>
</html>