@sailingrotevista/rotevista-dash 4.0.11 → 4.0.12

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 +27 -11
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -565,23 +565,39 @@ function startDisplayLoop() {
565
565
  * Prova i percorsi API ufficiali e quelli scoped (@sailingrotevista).
566
566
  * Converte i testi in numeri per garantire la precisione dei calcoli.
567
567
  */
568
+ /**
569
+ * Recupera la configurazione dal server Signal K.
570
+ * Utilizza un approccio semplificato e converte i dati in numeri reali.
571
+ */
568
572
  async function fetchServerConfig() {
569
573
  try {
570
- const response = await fetch(
571
- '/plugins/rotevista-dash/public-config'
572
- );
573
-
574
- if (!response.ok) throw new Error();
574
+ // Puntiamo al percorso config del plugin
575
+ const response = await fetch('/plugins/rotevista-dash/config');
576
+ if (!response.ok) throw new Error(`Status: ${response.status}`);
575
577
 
576
578
  const actual = await response.json();
577
579
 
578
- Object.assign(CONFIG.alarms, actual.alarms || {});
579
- Object.assign(CONFIG.graphs, actual.graphs || {});
580
- Object.assign(CONFIG.averages, actual.averaging || {});
580
+ // FUNZIONE DI PARSING: Trasforma eventuali "20" (stringhe) in 20 (numeri)
581
+ const parse = (obj) => {
582
+ for (let k in obj) {
583
+ if (typeof obj[k] === 'object') parse(obj[k]);
584
+ else if (!isNaN(obj[k]) && typeof obj[k] === 'string' && obj[k] !== "")
585
+ obj[k] = parseFloat(obj[k]);
586
+ }
587
+ return obj;
588
+ };
589
+
590
+ const data = parse(actual.configuration || actual);
591
+
592
+ // ASSEGNAZIONE DINAMICA: Aggiorna tutti i blocchi del CONFIG
593
+ if (data.alarms) Object.assign(CONFIG.alarms, data.alarms);
594
+ if (data.graphs) Object.assign(CONFIG.graphs, data.graphs);
595
+ if (data.averaging) Object.assign(CONFIG.averages, data.averaging);
596
+ if (data.scales) Object.assign(CONFIG.scales, data.scales);
581
597
 
582
- console.log("✅ Config caricata");
583
- } catch {
584
- console.warn("⚠️ Default locali");
598
+ console.log("✅ Configurazione server caricata e sincronizzata.");
599
+ } catch (err) {
600
+ console.warn("⚠️ Impossibile caricare config server, uso default locali.");
585
601
  }
586
602
  }
587
603
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailingrotevista/rotevista-dash",
3
- "version": "4.0.11",
3
+ "version": "4.0.12",
4
4
  "description": "Public Wind Dashboard with navigation and course aids",
5
5
  "main": "index.js",
6
6
  "publishConfig": {