@sailingrotevista/rotevista-dash 4.0.8 โ†’ 4.0.9

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.
Files changed (2) hide show
  1. package/app.js +106 -34
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -566,52 +566,124 @@ function startDisplayLoop() {
566
566
  * Converte i testi in numeri per garantire la precisione dei calcoli.
567
567
  */
568
568
  async function fetchServerConfig() {
569
- if (!window.location.protocol.includes("http")) return;
570
-
569
+ if (!window.location.protocol.startsWith("http")) {
570
+ console.warn("Non in ambiente HTTP");
571
+ return;
572
+ }
573
+
571
574
  const urls = [
575
+ '/signalk/v1/api/plugins/rotevista-dash/config',
576
+ '/signalk/v1/api/plugins/@sailingrotevista%2frotevista-dash/config',
572
577
  '/signalk/v1/api/plugins/rotevista-dash',
573
- '/signalk/v1/api/plugins/@sailingrotevista%2frotevista-dash',
574
578
  '/plugins/rotevista-dash/settings'
575
579
  ];
576
580
 
577
- for (let url of urls) {
581
+ for (const url of urls) {
578
582
  try {
579
- const response = await fetch(url);
580
- if (response.ok) {
581
- const data = await response.json();
582
-
583
- // Signal K puรฒ incapsulare i dati in settings o configuration
584
- const actual = data.settings || data.configuration || data.options || data;
585
-
586
- if (actual && (actual.alarms || actual.averaging || actual.graphs)) {
587
- // FUNZIONE DI PARSING: Trasforma eventuali testi "12.5" in numeri 12.5 reali
588
- const parseNumbers = (obj) => {
589
- for (let k in obj) {
590
- if (typeof obj[k] === 'object') parseNumbers(obj[k]);
591
- else if (!isNaN(obj[k]) && obj[k] !== "" && typeof obj[k] === 'string') {
592
- obj[k] = parseFloat(obj[k]);
593
- }
594
- }
595
- };
596
- parseNumbers(actual);
597
-
598
- // MAPPATURA INTEGRALE NEL CONFIG LOCALE
599
- if (actual.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...actual.alarms };
600
- if (actual.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...actual.graphs };
601
- if (actual.averaging) CONFIG.averages = { ...CONFIG.averages, ...actual.averaging };
602
- if (actual.scales) {
603
- for (let k in actual.scales) {
604
- CONFIG.scales[k] = { ...CONFIG.scales[k], ...actual.scales[k] };
605
- }
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);
606
637
  }
607
- console.log("โœ… Configurazione caricata correttamente da:", url);
608
- return;
609
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
+ };
610
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
+ }
667
+
668
+ if (actual.scales) {
669
+ for (const k in actual.scales) {
670
+ CONFIG.scales[k] = {
671
+ ...CONFIG.scales[k],
672
+ ...actual.scales[k]
673
+ };
674
+ }
675
+ }
676
+
677
+ console.log(`โœ… Config caricata da ${url}`);
678
+
679
+ return actual;
680
+
611
681
  } catch (e) {
612
- console.warn(`โš ๏ธ Tentativo fallito su ${url}`);
682
+ console.error(`โŒ Errore su ${url}`, e);
613
683
  }
614
684
  }
685
+
686
+ console.error("โŒ Nessuna configurazione trovata");
615
687
  }
616
688
 
617
689
  function manageHistory(t, v) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailingrotevista/rotevista-dash",
3
- "version": "4.0.8",
3
+ "version": "4.0.9",
4
4
  "description": "Public Wind Dashboard with navigation and course aids",
5
5
  "main": "index.js",
6
6
  "publishConfig": {