-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_template.html
93 lines (89 loc) · 2.08 KB
/
view_template.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="pl">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<title>[{{.Printer}}] Podgląd i Status</title>
<style>
/* Twoje style CSS */
body {
margin: 0;
font-family: Arial, sans-serif;
}
.container {
display: flex;
flex-direction: column;
height: 100vh;
}
.preview {
flex: 1;
background: #000;
height: 50vh;
}
.status {
flex: 1;
background: #f0f0f0;
padding: 10px;
box-sizing: border-box;
height: 50vh;
}
.status p {
margin: 0;
}
img {
width: 100%;
height: 100%;
object-fit: contain;
}
@media (min-aspect-ratio: 1/1) {
.container {
flex-direction: row;
}
.preview,
.status {
height: 100%;
width: 50vw;
}
}
</style>
</head>
<body>
<div class="container">
<div class="preview">
<img src="/{{.Printer}}/cam/" width="100%" height="100%" alt="Podgląd" />
</div>
<div class="status">
<p id="status">Status ładowania...</p>
<input type="checkbox" onclick="triggerLights()">Włącz/Wyłącz światła</input>
<input type="button" value="Zatrzymaj drukowanie"
onclick="fetch('/{{.Printer}}/cancel/', { method: 'POST' }).catch(console.error)"
>
</div>
</div>
<script>
function fetchStatus() {
fetch('/{{.Printer}}/status/')
.then(response => response.json())
.then(data => {
const completion = data['progress']['completion'];
document.getElementById('status').innerHTML = `
<p>Postęp drukowania: ${(completion).toFixed(2)}%</p>
`;
})
.catch(error => {
document.getElementById('status').innerHTML = '<p>Błąd podczas pobierania statusu.</p>';
});
}
function triggerLights() {
const lightsOn = document.querySelector('input[type="checkbox"]').checked;
if (lightsOn) {
fetch('/lights/on/', { method: 'POST' }).catch(console.error);
} else {
fetch('/lights/off/', { method: 'POST' }).catch(console.error);
}
}
fetchStatus();
setInterval(fetchStatus, 5000);
</script>
</body>
</html>