@sailingrotevista/rotevista-dash 5.0.3 → 5.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.js +65 -13
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -666,33 +666,84 @@ function startDisplayLoop() {
|
|
|
666
666
|
}
|
|
667
667
|
|
|
668
668
|
// ==========================================================================
|
|
669
|
-
// 8. CONFIGURAZIONE E GRAFICI UTILS
|
|
669
|
+
// 8. CONFIGURAZIONE, AGGIORNAMENTO LIVE E GRAFICI UTILS
|
|
670
670
|
// ==========================================================================
|
|
671
|
+
|
|
672
|
+
let currentConfigString = ""; // Memoria per rilevare cambiamenti nei settings
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Funzione Helper: Applica fisicamente i dati JSON all'oggetto CONFIG globale
|
|
676
|
+
*/
|
|
677
|
+
function applyConfigData(data) {
|
|
678
|
+
Object.assign(CONFIG.alarms, data.alarms || {});
|
|
679
|
+
Object.assign(CONFIG.graphs, data.graphs || {});
|
|
680
|
+
Object.assign(CONFIG.averaging, data.averaging || {});
|
|
681
|
+
|
|
682
|
+
// Migrazione Silenziosa: Rilevato vecchio parametro stabilità (<= 0.85).
|
|
683
|
+
// Aggiornato a 0.95 per ottimizzazione filtri.
|
|
684
|
+
if (CONFIG.averaging.stabilityThreshold <= 0.85) {
|
|
685
|
+
CONFIG.averaging.stabilityThreshold = 0.95;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
if (data.scales) {
|
|
689
|
+
for (let key in data.scales) {
|
|
690
|
+
if (CONFIG.scales[key]) Object.assign(CONFIG.scales[key], data.scales[key]);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Recupera la configurazione iniziale al caricamento della pagina
|
|
697
|
+
*/
|
|
671
698
|
async function fetchServerConfig() {
|
|
672
699
|
try {
|
|
673
700
|
const response = await fetch('/rotevista-config');
|
|
674
701
|
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
675
702
|
const data = await response.json();
|
|
676
703
|
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
704
|
+
// Salviamo l'impronta digitale della configurazione per i confronti futuri
|
|
705
|
+
currentConfigString = JSON.stringify(data);
|
|
706
|
+
|
|
707
|
+
applyConfigData(data);
|
|
708
|
+
console.log("✅ Configurazione iniziale applicata con successo.");
|
|
709
|
+
} catch (err) {
|
|
710
|
+
console.warn("⚠️ Impossibile raggiungere il server per le configurazioni. Utilizzo default locali. Motivo:", err.message);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* Watchdog: Controlla in background se le impostazioni sul server sono cambiate
|
|
716
|
+
*/
|
|
717
|
+
async function watchConfigChanges() {
|
|
718
|
+
try {
|
|
719
|
+
const response = await fetch('/rotevista-config');
|
|
720
|
+
if (!response.ok) return;
|
|
721
|
+
const data = await response.json();
|
|
680
722
|
|
|
681
|
-
|
|
682
|
-
CONFIG.averaging.stabilityThreshold = 0.95;
|
|
683
|
-
console.log("♻️ Migrazione Silenziosa: Rilevato vecchio parametro stabilità (<= 0.85). Aggiornato a 0.95 per ottimizzazione filtri.");
|
|
684
|
-
}
|
|
723
|
+
const newConfigString = JSON.stringify(data);
|
|
685
724
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
725
|
+
// Se l'impronta digitale è diversa, l'utente ha salvato nuovi settings!
|
|
726
|
+
if (newConfigString !== currentConfigString) {
|
|
727
|
+
console.log("🔄 Rilevato cambio impostazioni su Signal K! Aggiornamento in tempo reale...");
|
|
728
|
+
|
|
729
|
+
// Applichiamo i nuovi settings al volo
|
|
730
|
+
applyConfigData(data);
|
|
731
|
+
|
|
732
|
+
// Aggiorniamo l'impronta
|
|
733
|
+
currentConfigString = newConfigString;
|
|
734
|
+
|
|
735
|
+
// FEEDBACK VISIVO: Avvisiamo l'utente dell'aggiornamento
|
|
736
|
+
ui.status.innerText = "CONFIG UPDATED!";
|
|
737
|
+
ui.status.style.color = "#00C851"; // Verde Neon
|
|
738
|
+
setTimeout(() => { ui.status.style.color = ""; }, 4000);
|
|
690
739
|
}
|
|
691
740
|
} catch (err) {
|
|
692
|
-
console
|
|
741
|
+
// Ignoriamo gli errori di rete nel watchdog per non intasare la console in caso di disconnessione
|
|
693
742
|
}
|
|
694
743
|
}
|
|
695
744
|
|
|
745
|
+
// --------------------------------------------------------------------------
|
|
746
|
+
|
|
696
747
|
/**
|
|
697
748
|
* Rielaborazione Storica Time-Based (Rimuove accumulo e gestisce il Pruning dinamicamente)
|
|
698
749
|
*/
|
|
@@ -1018,6 +1069,7 @@ async function init() {
|
|
|
1018
1069
|
await fetchServerConfig();
|
|
1019
1070
|
startDisplayLoop();
|
|
1020
1071
|
connect();
|
|
1072
|
+
setInterval(watchConfigChanges, 10000);
|
|
1021
1073
|
}
|
|
1022
1074
|
|
|
1023
1075
|
window.addEventListener('load', init);
|