new css and functions

This commit is contained in:
Mateusz Gruszczyński
2025-02-27 00:29:52 +01:00
parent f9215590ea
commit a17423aaa1
3 changed files with 242 additions and 30 deletions

View File

@ -9,8 +9,13 @@
</button>
</div>
</div>
<form method="POST" action="{{ url_for('update_selected_devices') }}">
<button type="submit" class="btn btn-primary mb-3">Odśwież wybrane</button>
<!-- Formularz z przyciskami masowych operacji -->
<form id="mass-update-form">
<div class="mb-3">
<button type="button" id="mass-system-update-btn" class="btn btn-warning">Aktualizuj system (masowo)</button>
<button type="button" id="mass-firmware-update-btn" class="btn btn-danger">Aktualizuj firmware (masowo)</button>
<button type="submit" class="btn btn-primary">Odśwież wybrane</button>
</div>
<table class="table table-bordered table-hover">
<thead class="table-dark">
<tr>
@ -39,16 +44,16 @@
<td>{{ device.last_check.strftime('%Y-%m-%d %H:%M:%S') if device.last_check else 'Brak' }}</td>
<td>
{% if device.update_required or (device.current_firmware and device.upgrade_firmware and device.current_firmware != device.upgrade_firmware) %}
{% if device.update_required and (device.current_firmware and device.upgrade_firmware and device.current_firmware != device.upgrade_firmware) %}
<span class="badge bg-danger">Wymaga aktualizacji <small>(system i firmware)</small></span>
{% elif device.update_required %}
<span class="badge bg-danger">Wymaga aktualizacji <small>(system)</small></span>
{% if device.update_required and (device.current_firmware and device.upgrade_firmware and device.current_firmware != device.upgrade_firmware) %}
<span class="badge bg-danger">Wymaga aktualizacji <small>(system i firmware)</small></span>
{% elif device.update_required %}
<span class="badge bg-danger">Wymaga aktualizacji <small>(system)</small></span>
{% else %}
<span class="badge bg-danger">Wymaga aktualizacji <small>(firmware)</small></span>
{% endif %}
{% else %}
<span class="badge bg-danger">Wymaga aktualizacji <small>(firmware)</small></span>
<span class="badge bg-success">Aktualny</span>
{% endif %}
{% else %}
<span class="badge bg-success">Aktualny</span>
{% endif %}
</td>
<td>
<small>
@ -71,6 +76,25 @@
</tbody>
</table>
</form>
<!-- Overlay dla masowej aktualizacji systemu (5 minut) -->
<div id="mass-system-update-overlay" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.7); z-index:1000; color:white; text-align:center; padding-top:200px;">
<h3>Masowa aktualizacja systemu rozpoczęta...</h3>
<div style="width:50%; margin: 20px auto; background:#444; border-radius:5px;">
<div id="mass-system-progress" style="width:0%; height:30px; background:#4caf50; border-radius:5px;"></div>
</div>
<p id="mass-system-timer">300 sekund</p>
</div>
<!-- Overlay dla masowej aktualizacji firmware (2 minuty) -->
<div id="mass-firmware-update-overlay" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.7); z-index:1000; color:white; text-align:center; padding-top:200px;">
<h3>Masowa aktualizacja firmware (reboot) rozpoczęta...</h3>
<div style="width:50%; margin: 20px auto; background:#444; border-radius:5px;">
<div id="mass-firmware-progress" style="width:0%; height:30px; background:#4caf50; border-radius:5px;"></div>
</div>
<p id="mass-firmware-timer">120 sekund</p>
</div>
<script>
// Funkcja "Select all" zaznacza lub odznacza wszystkie checkboxy
document.getElementById('select-all').addEventListener('change', function() {
@ -79,5 +103,108 @@
checkbox.checked = this.checked;
}
});
// Pobierz zaznaczone urządzenia
function getSelectedDeviceIds() {
var selected = [];
var checkboxes = document.querySelectorAll('input[name="selected_devices"]:checked');
checkboxes.forEach(function(cb) {
selected.push(cb.value);
});
return selected;
}
// Funkcja masowej aktualizacji systemu
document.getElementById('mass-system-update-btn').addEventListener('click', function() {
var selectedDevices = getSelectedDeviceIds();
if(selectedDevices.length === 0) {
alert("Wybierz przynajmniej jedno urządzenie.");
return;
}
// Dla każdego urządzenia wykonaj update systemu asynchronicznie
selectedDevices.forEach(function(id) {
fetch("{{ url_for('update_device', device_id=0) }}".replace("0", id), { method: 'POST' })
.catch(function(error){ console.error('Błąd aktualizacji systemu dla urządzenia ' + id, error); });
});
// Pokaż overlay z paskiem postępu (5 minut)
var overlay = document.getElementById('mass-system-update-overlay');
overlay.style.display = 'block';
var timeLeft = 300; // 300 sekund
var progressBar = document.getElementById('mass-system-progress');
var timerDisplay = document.getElementById('mass-system-timer');
var interval = setInterval(function(){
timeLeft--;
var percent = ((300 - timeLeft) / 300) * 100;
progressBar.style.width = percent + '%';
timerDisplay.textContent = timeLeft + ' sekund';
if(timeLeft <= 0){
clearInterval(interval);
// Po zakończeniu odliczania wykonaj force_check dla każdego wybranego urządzenia
selectedDevices.forEach(function(id) {
fetch("{{ url_for('force_check', device_id=0) }}".replace("0", id), { method: 'GET' })
.catch(function(error){ console.error('Błąd force check dla urządzenia ' + id, error); });
});
location.reload();
}
}, 1000);
});
// Funkcja masowej aktualizacji firmware
document.getElementById('mass-firmware-update-btn').addEventListener('click', function() {
var selectedDevices = getSelectedDeviceIds();
if(selectedDevices.length === 0) {
alert("Wybierz przynajmniej jedno urządzenie.");
return;
}
// Dla każdego urządzenia wykonaj update firmware asynchronicznie
selectedDevices.forEach(function(id) {
fetch("{{ url_for('update_firmware', device_id=0) }}".replace("0", id), { method: 'POST' })
.catch(function(error){ console.error('Błąd aktualizacji firmware dla urządzenia ' + id, error); });
});
// Zapytaj użytkownika, czy chce zrestartować urządzenia
if(confirm("Firmware update zakończony. Czy chcesz teraz zrestartować wszystkie wybrane urządzenia?")) {
// Pokaż overlay z paskiem postępu dla reboot (2 minuty)
var overlay = document.getElementById('mass-firmware-update-overlay');
overlay.style.display = 'block';
var timeLeft = 120; // 120 sekund
var progressBar = document.getElementById('mass-firmware-progress');
var timerDisplay = document.getElementById('mass-firmware-timer');
var interval = setInterval(function(){
timeLeft--;
var percent = ((120 - timeLeft) / 120) * 100;
progressBar.style.width = percent + '%';
timerDisplay.textContent = timeLeft + ' sekund';
if(timeLeft <= 0){
clearInterval(interval);
// Po zakończeniu 2 minut wykonaj force_check dla każdego wybranego urządzenia
selectedDevices.forEach(function(id) {
fetch("{{ url_for('force_check', device_id=0) }}".replace("0", id), { method: 'GET' })
.catch(function(error){ console.error('Błąd force check dla urządzenia ' + id, error); });
});
location.reload();
}
}, 1000);
} else {
alert("Restart został anulowany. Pamiętaj, że firmware update wymaga rebootu.");
}
});
// Obsługa standardowego przycisku "Odśwież wybrane"
document.getElementById('mass-update-form').addEventListener('submit', function(e) {
e.preventDefault();
var selectedDevices = getSelectedDeviceIds();
if(selectedDevices.length === 0) {
alert("Wybierz przynajmniej jedno urządzenie.");
return;
}
// Dla każdego wybranego urządzenia wykonaj force_check
selectedDevices.forEach(function(id) {
fetch("{{ url_for('force_check', device_id=0) }}".replace("0", id), { method: 'GET' })
.catch(function(error){ console.error('Błąd force check dla urządzenia ' + id, error); });
});
// Po krótkiej chwili przeładuj stronę
setTimeout(function(){ location.reload(); }, 2000);
});
</script>
{% endblock %}