@sailingrotevista/rotevista-dash 4.0.2 → 4.0.3

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 +43 -13
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -559,22 +559,52 @@ 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] }; }
568
+
569
+ // Proviamo i due percorsi standard di Signal K per i settings dei plugin
570
+ const urls = [
571
+ '/plugins/rotevista-dash/settings',
572
+ '/plugins/@sailingrotevista%2frotevista-dash/settings'
573
+ ];
574
+
575
+ for (let url of urls) {
576
+ try {
577
+ const response = await fetch(url);
578
+ if (response.ok) {
579
+ const data = await response.json();
580
+ // Signal K mette i dati reali dentro l'oggetto configuration o direttamente nel body
581
+ const actual = data.configuration || data;
582
+
583
+ if (actual) {
584
+ // FUNZIONE DI PULIZIA: Trasforma le stringhe "123" in numeri 123 reali
585
+ const parseObj = (obj) => {
586
+ for (let k in obj) {
587
+ if (typeof obj[k] === 'object') parseObj(obj[k]);
588
+ else if (!isNaN(obj[k]) && obj[k] !== "") obj[k] = parseFloat(obj[k]);
589
+ }
590
+ };
591
+ parseObj(actual);
592
+
593
+ // MAPPATURA INTELLIGENTE: Sovrascrive CONFIG solo con i dati ricevuti
594
+ if (actual.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...actual.alarms };
595
+ if (actual.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...actual.graphs };
596
+ if (actual.averaging) CONFIG.averages = { ...CONFIG.averages, ...actual.averaging };
597
+ if (actual.scales) {
598
+ for (let k in actual.scales) {
599
+ CONFIG.scales[k] = { ...CONFIG.scales[k], ...actual.scales[k] };
600
+ }
601
+ }
602
+ console.log("Configurazione caricata correttamente da:", url);
603
+ return; // Esci dal loop se il caricamento ha avuto successo
604
+ }
575
605
  }
576
- }
577
- } catch (e) { }
606
+ } catch (e) { console.warn(`Tentativo su ${url} fallito.`); }
607
+ }
578
608
  }
579
609
 
580
610
  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.3",
4
4
  "description": "Public Wind Dashboard with navigation and course aids",
5
5
  "main": "index.js",
6
6
  "publishConfig": {