@sailingrotevista/rotevista-dash 4.0.11 → 4.0.12
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 +27 -11
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -565,23 +565,39 @@ function startDisplayLoop() {
|
|
|
565
565
|
* Prova i percorsi API ufficiali e quelli scoped (@sailingrotevista).
|
|
566
566
|
* Converte i testi in numeri per garantire la precisione dei calcoli.
|
|
567
567
|
*/
|
|
568
|
+
/**
|
|
569
|
+
* Recupera la configurazione dal server Signal K.
|
|
570
|
+
* Utilizza un approccio semplificato e converte i dati in numeri reali.
|
|
571
|
+
*/
|
|
568
572
|
async function fetchServerConfig() {
|
|
569
573
|
try {
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
);
|
|
573
|
-
|
|
574
|
-
if (!response.ok) throw new Error();
|
|
574
|
+
// Puntiamo al percorso config del plugin
|
|
575
|
+
const response = await fetch('/plugins/rotevista-dash/config');
|
|
576
|
+
if (!response.ok) throw new Error(`Status: ${response.status}`);
|
|
575
577
|
|
|
576
578
|
const actual = await response.json();
|
|
577
579
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
580
|
+
// FUNZIONE DI PARSING: Trasforma eventuali "20" (stringhe) in 20 (numeri)
|
|
581
|
+
const parse = (obj) => {
|
|
582
|
+
for (let k in obj) {
|
|
583
|
+
if (typeof obj[k] === 'object') parse(obj[k]);
|
|
584
|
+
else if (!isNaN(obj[k]) && typeof obj[k] === 'string' && obj[k] !== "")
|
|
585
|
+
obj[k] = parseFloat(obj[k]);
|
|
586
|
+
}
|
|
587
|
+
return obj;
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
const data = parse(actual.configuration || actual);
|
|
591
|
+
|
|
592
|
+
// ASSEGNAZIONE DINAMICA: Aggiorna tutti i blocchi del CONFIG
|
|
593
|
+
if (data.alarms) Object.assign(CONFIG.alarms, data.alarms);
|
|
594
|
+
if (data.graphs) Object.assign(CONFIG.graphs, data.graphs);
|
|
595
|
+
if (data.averaging) Object.assign(CONFIG.averages, data.averaging);
|
|
596
|
+
if (data.scales) Object.assign(CONFIG.scales, data.scales);
|
|
581
597
|
|
|
582
|
-
console.log("✅
|
|
583
|
-
} catch {
|
|
584
|
-
console.warn("⚠️
|
|
598
|
+
console.log("✅ Configurazione server caricata e sincronizzata.");
|
|
599
|
+
} catch (err) {
|
|
600
|
+
console.warn("⚠️ Impossibile caricare config server, uso default locali.");
|
|
585
601
|
}
|
|
586
602
|
}
|
|
587
603
|
|