@sailingrotevista/rotevista-dash 4.0.2 → 4.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.
Files changed (2) hide show
  1. package/app.js +85 -13
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -559,22 +559,94 @@ function startDisplayLoop() {
559
559
  // ==========================================================================
560
560
  // 8. CONFIGURAZIONE E GRAFICI UTILS
561
561
  // ==========================================================================
562
+ /**
563
+ * Recupera la configurazione dal server Signal K e sovrascrive i default.
564
+ * Include una funzione di parsing per garantire che i valori siano numeri.
565
+ */
562
566
  async function fetchServerConfig() {
563
567
  if (!window.location.protocol.includes("http")) return;
564
- try {
565
- const response = await fetch(`/plugins/rotevista-dash/config`);
566
- if (response.ok) {
567
- const data = await response.json();
568
- const actual = data.configuration || data;
569
- if (actual) {
570
- const pN = (obj) => { for (let k in obj) { if (typeof obj[k] === 'object') pN(obj[k]); else if (!isNaN(obj[k]) && obj[k] !== "") obj[k] = parseFloat(obj[k]); } };
571
- pN(actual);
572
- if (actual.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...actual.alarms };
573
- if (actual.averaging) CONFIG.averages = { ...CONFIG.averages, ...actual.averaging };
574
- if (actual.scales) { for (let k in actual.scales) CONFIG.scales[k] = { ...CONFIG.scales[k], ...actual.scales[k] }; }
575
- }
568
+
569
+ // Proviamo i due percorsi standard di Signal K per i settings dei plugin
570
+ /**
571
+ * Recupera la configurazione tramite le API ufficiali di Signal K.
572
+ */
573
+ async function fetchServerConfig() {
574
+ if (!window.location.protocol.includes("http")) return;
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) { }
576
613
  }
577
- } catch (e) { }
614
+ console.warn("Impossibile caricare la configurazione. Verificare 'Anonymous Read' nelle impostazioni di Signal K.");
615
+ }
616
+
617
+ for (let url of urls) {
618
+ try {
619
+ const response = await fetch(url);
620
+ if (response.ok) {
621
+ 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
+
625
+ if (actual) {
626
+ // FUNZIONE DI PULIZIA: Trasforma le stringhe "123" in numeri 123 reali
627
+ const parseObj = (obj) => {
628
+ for (let k in obj) {
629
+ if (typeof obj[k] === 'object') parseObj(obj[k]);
630
+ else if (!isNaN(obj[k]) && obj[k] !== "") obj[k] = parseFloat(obj[k]);
631
+ }
632
+ };
633
+ parseObj(actual);
634
+
635
+ // MAPPATURA INTELLIGENTE: Sovrascrive CONFIG solo con i dati ricevuti
636
+ if (actual.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...actual.alarms };
637
+ if (actual.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...actual.graphs };
638
+ if (actual.averaging) CONFIG.averages = { ...CONFIG.averages, ...actual.averaging };
639
+ if (actual.scales) {
640
+ for (let k in actual.scales) {
641
+ CONFIG.scales[k] = { ...CONFIG.scales[k], ...actual.scales[k] };
642
+ }
643
+ }
644
+ console.log("Configurazione caricata correttamente da:", url);
645
+ return; // Esci dal loop se il caricamento ha avuto successo
646
+ }
647
+ }
648
+ } catch (e) { console.warn(`Tentativo su ${url} fallito.`); }
649
+ }
578
650
  }
579
651
 
580
652
  function manageHistory(t, v) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailingrotevista/rotevista-dash",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "Public Wind Dashboard with navigation and course aids",
5
5
  "main": "index.js",
6
6
  "publishConfig": {