@sailingrotevista/rotevista-dash 4.0.9 โ 4.0.11
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 +12 -113
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -566,124 +566,23 @@ function startDisplayLoop() {
|
|
|
566
566
|
* Converte i testi in numeri per garantire la precisione dei calcoli.
|
|
567
567
|
*/
|
|
568
568
|
async function fetchServerConfig() {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
const urls = [
|
|
575
|
-
'/signalk/v1/api/plugins/rotevista-dash/config',
|
|
576
|
-
'/signalk/v1/api/plugins/@sailingrotevista%2frotevista-dash/config',
|
|
577
|
-
'/signalk/v1/api/plugins/rotevista-dash',
|
|
578
|
-
'/plugins/rotevista-dash/settings'
|
|
579
|
-
];
|
|
580
|
-
|
|
581
|
-
for (const url of urls) {
|
|
582
|
-
try {
|
|
583
|
-
console.log(`๐ Provo: ${url}`);
|
|
584
|
-
|
|
585
|
-
const response = await fetch(url, {
|
|
586
|
-
method: 'GET',
|
|
587
|
-
headers: {
|
|
588
|
-
'Accept': 'application/json'
|
|
589
|
-
}
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
console.log(`Status ${response.status}`);
|
|
593
|
-
|
|
594
|
-
if (!response.ok) continue;
|
|
595
|
-
|
|
596
|
-
const text = await response.text();
|
|
597
|
-
|
|
598
|
-
console.log("RAW RESPONSE:", text);
|
|
599
|
-
|
|
600
|
-
let data;
|
|
601
|
-
|
|
602
|
-
try {
|
|
603
|
-
data = JSON.parse(text);
|
|
604
|
-
} catch (e) {
|
|
605
|
-
console.warn("โ Non รจ JSON valido");
|
|
606
|
-
continue;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
console.log("JSON:", data);
|
|
610
|
-
|
|
611
|
-
const actual =
|
|
612
|
-
data.settings ||
|
|
613
|
-
data.configuration ||
|
|
614
|
-
data.options ||
|
|
615
|
-
data;
|
|
616
|
-
|
|
617
|
-
if (!actual || typeof actual !== 'object') {
|
|
618
|
-
console.warn("โ Config non valida");
|
|
619
|
-
continue;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
const parseNumbers = (obj) => {
|
|
623
|
-
if (!obj || typeof obj !== 'object') return;
|
|
624
|
-
|
|
625
|
-
for (const k in obj) {
|
|
626
|
-
const v = obj[k];
|
|
627
|
-
|
|
628
|
-
if (v && typeof v === 'object') {
|
|
629
|
-
parseNumbers(v);
|
|
630
|
-
}
|
|
631
|
-
else if (
|
|
632
|
-
typeof v === 'string' &&
|
|
633
|
-
v.trim() !== '' &&
|
|
634
|
-
!isNaN(v)
|
|
635
|
-
) {
|
|
636
|
-
obj[k] = parseFloat(v);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
parseNumbers(actual);
|
|
642
|
-
|
|
643
|
-
console.log("CONFIG PARSATA:", actual);
|
|
644
|
-
|
|
645
|
-
if (actual.alarms) {
|
|
646
|
-
CONFIG.alarms = {
|
|
647
|
-
...CONFIG.alarms,
|
|
648
|
-
...actual.alarms
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
if (actual.graphs) {
|
|
653
|
-
CONFIG.graphs = {
|
|
654
|
-
...CONFIG.graphs,
|
|
655
|
-
...actual.graphs
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
// ATTENZIONE:
|
|
660
|
-
// averaging -> averages
|
|
661
|
-
if (actual.averaging) {
|
|
662
|
-
CONFIG.averages = {
|
|
663
|
-
...CONFIG.averages,
|
|
664
|
-
...actual.averaging
|
|
665
|
-
};
|
|
666
|
-
}
|
|
569
|
+
try {
|
|
570
|
+
const response = await fetch(
|
|
571
|
+
'/plugins/rotevista-dash/public-config'
|
|
572
|
+
);
|
|
667
573
|
|
|
668
|
-
|
|
669
|
-
for (const k in actual.scales) {
|
|
670
|
-
CONFIG.scales[k] = {
|
|
671
|
-
...CONFIG.scales[k],
|
|
672
|
-
...actual.scales[k]
|
|
673
|
-
};
|
|
674
|
-
}
|
|
675
|
-
}
|
|
574
|
+
if (!response.ok) throw new Error();
|
|
676
575
|
|
|
677
|
-
|
|
576
|
+
const actual = await response.json();
|
|
678
577
|
|
|
679
|
-
|
|
578
|
+
Object.assign(CONFIG.alarms, actual.alarms || {});
|
|
579
|
+
Object.assign(CONFIG.graphs, actual.graphs || {});
|
|
580
|
+
Object.assign(CONFIG.averages, actual.averaging || {});
|
|
680
581
|
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
582
|
+
console.log("โ
Config caricata");
|
|
583
|
+
} catch {
|
|
584
|
+
console.warn("โ ๏ธ Default locali");
|
|
684
585
|
}
|
|
685
|
-
|
|
686
|
-
console.error("โ Nessuna configurazione trovata");
|
|
687
586
|
}
|
|
688
587
|
|
|
689
588
|
function manageHistory(t, v) {
|