fix w masowej aktualizacji dirmware
This commit is contained in:
		| @@ -80,8 +80,8 @@ | |||||||
| <!-- Overlay dla masowej aktualizacji systemu (5 minut) --> | <!-- 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;"> | <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> |   <h3>Masowa aktualizacja systemu rozpoczęta...</h3> | ||||||
|   <div style="width:50%; margin: 20px auto; background:#444; border-radius:5px;"> |   <div class="progress-container"> | ||||||
|     <div id="mass-system-progress" style="width:0%; height:30px; background:#4caf50; border-radius:5px;"></div> |     <div id="mass-system-progress" class="progress-bar"></div> | ||||||
|   </div> |   </div> | ||||||
|   <p id="mass-system-timer">300 sekund</p> |   <p id="mass-system-timer">300 sekund</p> | ||||||
| </div> | </div> | ||||||
| @@ -89,8 +89,8 @@ | |||||||
| <!-- Overlay dla masowej aktualizacji firmware (2 minuty) --> | <!-- 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;"> | <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> |   <h3>Masowa aktualizacja firmware (reboot) rozpoczęta...</h3> | ||||||
|   <div style="width:50%; margin: 20px auto; background:#444; border-radius:5px;"> |   <div class="progress-container"> | ||||||
|     <div id="mass-firmware-progress" style="width:0%; height:30px; background:#4caf50; border-radius:5px;"></div> |     <div id="mass-firmware-progress" class="progress-bar"></div> | ||||||
|   </div> |   </div> | ||||||
|   <p id="mass-firmware-timer">120 sekund</p> |   <p id="mass-firmware-timer">120 sekund</p> | ||||||
| </div> | </div> | ||||||
| @@ -104,12 +104,20 @@ | |||||||
| </div> | </div> | ||||||
|  |  | ||||||
| <script> | <script> | ||||||
|   // Funkcja "Select all" – zaznacza lub odznacza wszystkie checkboxy |   // Dodajemy event listenery raz, aby uniknąć wielokrotnego przypisywania | ||||||
|   document.getElementById('select-all').addEventListener('change', function() { |   document.addEventListener('DOMContentLoaded', function() { | ||||||
|     var checkboxes = document.querySelectorAll('input[name="selected_devices"]'); |     document.getElementById('select-all').addEventListener('change', function() { | ||||||
|     for (var checkbox of checkboxes) { |       var checkboxes = document.querySelectorAll('input[name="selected_devices"]'); | ||||||
|       checkbox.checked = this.checked; |       for (var checkbox of checkboxes) { | ||||||
|     } |         checkbox.checked = this.checked; | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |      | ||||||
|  |     document.getElementById('mass-firmware-reboot-btn').addEventListener('click', onMassFirmwareReboot); | ||||||
|  |     document.getElementById('mass-firmware-cancel-btn').addEventListener('click', function() { | ||||||
|  |       alert("Restart został anulowany. Pamiętaj, że firmware update wymaga rebootu."); | ||||||
|  |       document.getElementById('mass-firmware-reboot-prompt').style.display = 'none'; | ||||||
|  |     }); | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|   // Pobierz zaznaczone urządzenia |   // Pobierz zaznaczone urządzenia | ||||||
| @@ -131,7 +139,7 @@ | |||||||
|     } |     } | ||||||
|     // Wysyłamy update systemu dla każdego urządzenia asynchronicznie |     // Wysyłamy update systemu dla każdego urządzenia asynchronicznie | ||||||
|     selectedDevices.forEach(function(id) { |     selectedDevices.forEach(function(id) { | ||||||
|       fetch("{{ url_for('update_device', device_id=0) }}".replace("0", id), { method: 'POST' }) |       fetch(`/device/${id}/update`, { method: 'POST' }) | ||||||
|         .catch(function(error){ console.error('Błąd aktualizacji systemu dla urządzenia ' + id, error); }); |         .catch(function(error){ console.error('Błąd aktualizacji systemu dla urządzenia ' + id, error); }); | ||||||
|     }); |     }); | ||||||
|     // Pokaż overlay z paskiem postępu (5 minut) |     // Pokaż overlay z paskiem postępu (5 minut) | ||||||
| @@ -149,7 +157,7 @@ | |||||||
|         clearInterval(interval); |         clearInterval(interval); | ||||||
|         // Po zakończeniu odliczania, dla każdego urządzenia wykonaj force_check |         // Po zakończeniu odliczania, dla każdego urządzenia wykonaj force_check | ||||||
|         selectedDevices.forEach(function(id) { |         selectedDevices.forEach(function(id) { | ||||||
|           fetch("{{ url_for('force_check', device_id=0) }}".replace("0", id), { method: 'GET' }) |           fetch(`/device/${id}/force_check`, { method: 'GET' }) | ||||||
|             .catch(function(error){ console.error('Błąd force check dla urządzenia ' + id, error); }); |             .catch(function(error){ console.error('Błąd force check dla urządzenia ' + id, error); }); | ||||||
|         }); |         }); | ||||||
|         location.reload(); |         location.reload(); | ||||||
| @@ -166,52 +174,59 @@ | |||||||
|     } |     } | ||||||
|     // Wysyłamy update firmware dla każdego urządzenia asynchronicznie |     // Wysyłamy update firmware dla każdego urządzenia asynchronicznie | ||||||
|     selectedDevices.forEach(function(id) { |     selectedDevices.forEach(function(id) { | ||||||
|       fetch("{{ url_for('update_firmware', device_id=0) }}".replace("0", id), { method: 'POST' }) |       fetch(`/device/${id}/update_firmware`, { method: 'POST' }) | ||||||
|         .catch(function(error){ console.error('Błąd aktualizacji firmware dla urządzenia ' + id, error); }); |         .catch(function(error){ console.error('Błąd aktualizacji firmware dla urządzenia ' + id, error); }); | ||||||
|     }); |     }); | ||||||
|     // Zamiast confirm() wyświetlamy dynamiczny prompt |     // Wyświetlamy dynamiczny prompt restartu | ||||||
|     var promptDiv = document.getElementById('mass-firmware-reboot-prompt'); |     document.getElementById('mass-firmware-reboot-prompt').style.display = 'block'; | ||||||
|     promptDiv.style.display = 'block'; |  | ||||||
|  |  | ||||||
|     // Obsługa przycisku restartu w prompt |  | ||||||
|     document.getElementById('mass-firmware-reboot-btn').addEventListener('click', function() { |  | ||||||
|       promptDiv.style.display = 'none'; |  | ||||||
|  |  | ||||||
|     // Wysyłamy reboot dla każdego wybranego urządzenia |  | ||||||
|       selectedDevices.forEach(function(id) { |  | ||||||
|         fetch("{{ url_for('restart_device', device_id=0) }}".replace("0", id), { method: 'POST' }) |  | ||||||
|           .catch(function(error){ console.error('Błąd wysyłania reboot dla urządzenia ' + id, error); }); |  | ||||||
|       }); |  | ||||||
|  |  | ||||||
|       // 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 odliczania, dla każdego 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); }); |  | ||||||
|           }); |  | ||||||
|           location.reload(); |  | ||||||
|         } |  | ||||||
|       }, 1000); |  | ||||||
|     }); |  | ||||||
|  |  | ||||||
|     // Obsługa przycisku anulowania restartu w prompt |  | ||||||
|     document.getElementById('mass-firmware-cancel-btn').addEventListener('click', function() { |  | ||||||
|       alert("Restart został anulowany. Pamiętaj, że firmware update wymaga rebootu."); |  | ||||||
|       promptDiv.style.display = 'none'; |  | ||||||
|     }); |  | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|  |   // Funkcja sekwencyjnego wysyłania reboot (z opóźnieniem) | ||||||
|  |   function sendRebootSequentially(devices, index = 0) { | ||||||
|  |     if (index >= devices.length) return Promise.resolve(); | ||||||
|  |     return fetch(`/device/${devices[index]}/restart`, { method: 'POST' }) | ||||||
|  |       .catch(function(error) { | ||||||
|  |         console.error('Błąd wysyłania reboot dla urządzenia ' + devices[index], error); | ||||||
|  |       }) | ||||||
|  |       .then(function() { | ||||||
|  |         // Opóźnienie 500 ms przed kolejnym rebootem | ||||||
|  |         return new Promise(resolve => setTimeout(resolve, 500)); | ||||||
|  |       }) | ||||||
|  |       .then(function() { | ||||||
|  |         return sendRebootSequentially(devices, index + 1); | ||||||
|  |       }); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // Obsługa przycisku restartu w prompt dla masowego firmware update | ||||||
|  |   function onMassFirmwareReboot() { | ||||||
|  |     document.getElementById('mass-firmware-reboot-prompt').style.display = 'none'; | ||||||
|  |     var selectedDevices = getSelectedDeviceIds(); | ||||||
|  |     // Wysyłamy rebooty sekwencyjnie | ||||||
|  |     sendRebootSequentially(selectedDevices) | ||||||
|  |       .then(function() { | ||||||
|  |         // Po wysłaniu reboot dla wszystkich urządzeń, pokazujemy overlay z 2-minutowym paskiem postępu | ||||||
|  |         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 odliczania, dla każdego urządzenia wykonaj force_check | ||||||
|  |             selectedDevices.forEach(function(id) { | ||||||
|  |               fetch(`/device/${id}/force_check`, { method: 'GET' }) | ||||||
|  |                 .catch(function(error){ console.error('Błąd force check dla urządzenia ' + id, error); }); | ||||||
|  |             }); | ||||||
|  |             location.reload(); | ||||||
|  |           } | ||||||
|  |         }, 1000); | ||||||
|  |       }); | ||||||
|  |   } | ||||||
|    |    | ||||||
|   // Obsługa standardowego przycisku "Odśwież wybrane" |   // Obsługa standardowego przycisku "Odśwież wybrane" | ||||||
|   document.getElementById('mass-update-form').addEventListener('submit', function(e) { |   document.getElementById('mass-update-form').addEventListener('submit', function(e) { | ||||||
| @@ -222,7 +237,7 @@ | |||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     selectedDevices.forEach(function(id) { |     selectedDevices.forEach(function(id) { | ||||||
|       fetch("{{ url_for('force_check', device_id=0) }}".replace("0", id), { method: 'GET' }) |       fetch(`/device/${id}/force_check`, { method: 'GET' }) | ||||||
|         .catch(function(error){ console.error('Błąd force check dla urządzenia ' + id, error); }); |         .catch(function(error){ console.error('Błąd force check dla urządzenia ' + id, error); }); | ||||||
|     }); |     }); | ||||||
|     setTimeout(function(){ location.reload(); }, 2000); |     setTimeout(function(){ location.reload(); }, 2000); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Mateusz Gruszczyński
					Mateusz Gruszczyński