@sailingrotevista/rotevista-dash 4.0.4 → 4.0.6
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 +33 -62
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -560,79 +560,47 @@ function startDisplayLoop() {
|
|
|
560
560
|
// 8. CONFIGURAZIONE E GRAFICI UTILS
|
|
561
561
|
// ==========================================================================
|
|
562
562
|
/**
|
|
563
|
-
* Recupera la configurazione
|
|
564
|
-
*
|
|
563
|
+
* Recupera la configurazione tramite le API ufficiali di Signal K.
|
|
564
|
+
* Sovrascrive i default locali con i parametri impostati nel server.
|
|
565
|
+
*/
|
|
566
|
+
/**
|
|
567
|
+
* Recupera la configurazione dal server Signal K provando diversi percorsi.
|
|
568
|
+
* Gestisce i permessi e converte i dati in formato numerico.
|
|
565
569
|
*/
|
|
566
570
|
async function fetchServerConfig() {
|
|
567
571
|
if (!window.location.protocol.includes("http")) return;
|
|
568
|
-
|
|
569
|
-
//
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
// Usiamo il percorso API ufficiale di Signal K per i plugin
|
|
577
|
-
const urls = [
|
|
578
|
-
'/signalk/v1/api/plugins/rotevista-dash',
|
|
579
|
-
'/signalk/v1/api/plugins/@sailingrotevista%2frotevista-dash'
|
|
580
|
-
];
|
|
581
|
-
|
|
582
|
-
for (let url of urls) {
|
|
583
|
-
try {
|
|
584
|
-
const response = await fetch(url);
|
|
585
|
-
if (response.ok) {
|
|
586
|
-
const data = await response.json();
|
|
587
|
-
|
|
588
|
-
// Nelle API ufficiali, i tuoi dati sono dentro 'data.settings' o 'data.configuration'
|
|
589
|
-
const actual = data.settings || data.configuration || data;
|
|
590
|
-
|
|
591
|
-
if (actual) {
|
|
592
|
-
const parseObj = (obj) => {
|
|
593
|
-
for (let k in obj) {
|
|
594
|
-
if (typeof obj[k] === 'object') parseObj(obj[k]);
|
|
595
|
-
else if (!isNaN(obj[k]) && obj[k] !== "") obj[k] = parseFloat(obj[k]);
|
|
596
|
-
}
|
|
597
|
-
};
|
|
598
|
-
parseObj(actual);
|
|
599
|
-
|
|
600
|
-
if (actual.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...actual.alarms };
|
|
601
|
-
if (actual.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...actual.graphs };
|
|
602
|
-
if (actual.averaging) CONFIG.averages = { ...CONFIG.averages, ...actual.averaging };
|
|
603
|
-
if (actual.scales) {
|
|
604
|
-
for (let k in actual.scales) {
|
|
605
|
-
CONFIG.scales[k] = { ...CONFIG.scales[k], ...actual.scales[k] };
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
console.log("Configurazione caricata con successo dall'API ufficiale.");
|
|
609
|
-
return;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
} catch (e) { }
|
|
613
|
-
}
|
|
614
|
-
console.warn("Impossibile caricare la configurazione. Verificare 'Anonymous Read' nelle impostazioni di Signal K.");
|
|
615
|
-
}
|
|
572
|
+
|
|
573
|
+
// Elenco percorsi dal più probabile (WebApp Data) al più tecnico (Plugin API)
|
|
574
|
+
const urls = [
|
|
575
|
+
'/signalk/v1/applicationData/user/rotevista-dash/1.0/settings',
|
|
576
|
+
'/signalk/v1/api/plugins/rotevista-dash',
|
|
577
|
+
'/plugins/rotevista-dash/config'
|
|
578
|
+
];
|
|
616
579
|
|
|
617
580
|
for (let url of urls) {
|
|
618
581
|
try {
|
|
582
|
+
console.log(`Tentativo di caricamento configurazione da: ${url}`);
|
|
619
583
|
const response = await fetch(url);
|
|
584
|
+
|
|
620
585
|
if (response.ok) {
|
|
621
586
|
const data = await response.json();
|
|
622
|
-
// Signal K mette i dati reali dentro l'oggetto configuration o direttamente nel body
|
|
623
|
-
const actual = data.configuration || data;
|
|
624
587
|
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
588
|
+
// Signal K può incapsulare i dati in 'settings', 'configuration' o 'value'
|
|
589
|
+
const actual = data.settings || data.configuration || data.value || data;
|
|
590
|
+
|
|
591
|
+
if (actual && (actual.alarms || actual.averaging || actual.graphs)) {
|
|
592
|
+
// FUNZIONE DI PARSING: Garantisce che i valori siano numeri reali
|
|
593
|
+
const parseNumbers = (obj) => {
|
|
628
594
|
for (let k in obj) {
|
|
629
|
-
if (typeof obj[k] === 'object')
|
|
630
|
-
else if (!isNaN(obj[k]) && obj[k] !== ""
|
|
595
|
+
if (typeof obj[k] === 'object') parseNumbers(obj[k]);
|
|
596
|
+
else if (!isNaN(obj[k]) && obj[k] !== "" && typeof obj[k] === 'string') {
|
|
597
|
+
obj[k] = parseFloat(obj[k]);
|
|
598
|
+
}
|
|
631
599
|
}
|
|
632
600
|
};
|
|
633
|
-
|
|
601
|
+
parseNumbers(actual);
|
|
634
602
|
|
|
635
|
-
//
|
|
603
|
+
// APPLICAZIONE DEI PARAMETRI (Inclusi i grafici che prima mancavano)
|
|
636
604
|
if (actual.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...actual.alarms };
|
|
637
605
|
if (actual.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...actual.graphs };
|
|
638
606
|
if (actual.averaging) CONFIG.averages = { ...CONFIG.averages, ...actual.averaging };
|
|
@@ -641,12 +609,15 @@ async function fetchServerConfig() {
|
|
|
641
609
|
CONFIG.scales[k] = { ...CONFIG.scales[k], ...actual.scales[k] };
|
|
642
610
|
}
|
|
643
611
|
}
|
|
644
|
-
console.log("Configurazione
|
|
645
|
-
return; //
|
|
612
|
+
console.log("✅ Configurazione applicata con successo da:", url);
|
|
613
|
+
return; // Uscita al primo successo
|
|
646
614
|
}
|
|
647
615
|
}
|
|
648
|
-
} catch (e) {
|
|
616
|
+
} catch (e) {
|
|
617
|
+
console.warn(`⚠️ Errore durante il fetch su ${url}:`, e.message);
|
|
618
|
+
}
|
|
649
619
|
}
|
|
620
|
+
console.warn("⚠️ Nessun percorso di configurazione valido trovato. Uso i default locali.");
|
|
650
621
|
}
|
|
651
622
|
|
|
652
623
|
function manageHistory(t, v) {
|