@sailingrotevista/rotevista-dash 1.0.14 → 1.0.16

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 (3) hide show
  1. package/app.js +26 -13
  2. package/index.js +14 -11
  3. package/package.json +1 -1
package/app.js CHANGED
@@ -74,28 +74,35 @@ const ui = {
74
74
  };
75
75
 
76
76
  // ==========================================================================
77
- // 3. CARICAMENTO CONFIGURAZIONE DA SIGNALK
77
+ // 3. CARICAMENTO CONFIGURAZIONE DAL SERVER
78
78
  // ==========================================================================
79
79
  async function fetchServerConfig() {
80
- if (window.location.protocol.includes("http")) {
80
+ // Cerchiamo di capire se siamo su un server reale o in locale
81
+ const isRemote = window.location.protocol.includes("http");
82
+
83
+ if (isRemote) {
81
84
  try {
82
- // SignalK espone le configurazioni dei plugin a questo indirizzo
83
- const response = await fetch('/plugins/rotevista-dash/settings');
85
+ console.log("Dashboard: Recupero impostazioni dal server...");
86
+ // L'URL ufficiale per leggere i settaggi del plugin
87
+ const response = await fetch('/signalk/v1/plugins/rotevista-dash/settings');
88
+
84
89
  if (response.ok) {
85
90
  const serverConfig = await response.json();
86
91
 
87
- // Sovrascrive CONFIG solo con i valori definiti dall'utente
92
+ // Se il server ha dei dati salvati, sovrascriviamo il CONFIG di default
88
93
  if (serverConfig && Object.keys(serverConfig).length > 0) {
89
- // Eseguiamo un merge profondo manuale o semplice
90
- if (serverConfig.alarms) Object.assign(CONFIG.alarms, serverConfig.alarms);
91
- if (serverConfig.graphs) Object.assign(CONFIG.graphs, serverConfig.graphs);
92
- if (serverConfig.averages) Object.assign(CONFIG.averages, serverConfig.averages);
94
+ // Merge dei blocchi (Alarms, Graphs, Averages)
95
+ if (serverConfig.alarms) CONFIG.alarms = { ...CONFIG.alarms, ...serverConfig.alarms };
96
+ if (serverConfig.graphs) CONFIG.graphs = { ...CONFIG.graphs, ...serverConfig.graphs };
97
+ if (serverConfig.averages) CONFIG.averages = { ...CONFIG.averages, ...serverConfig.averages };
93
98
 
94
- console.log("Configurazione Plugin caricata da SignalK:", CONFIG);
99
+ console.log("Dashboard: Configurazione caricata correttamente!", CONFIG);
95
100
  }
101
+ } else {
102
+ console.log("Dashboard: Il server non ha ancora impostazioni salvate. Uso i default.");
96
103
  }
97
104
  } catch (e) {
98
- console.log("Errore nel caricamento della configurazione plugin, uso i default.");
105
+ console.error("Dashboard: Errore critico nel fetch delle impostazioni:", e);
99
106
  }
100
107
  }
101
108
  }
@@ -331,13 +338,19 @@ if (ui.hotspot) {
331
338
  if (c) { for (let i = 0; i < 360; i += 10) { const l = document.createElementNS("http://www.w3.org/2000/svg", "line"); const m = i % 30 === 0; l.setAttribute("x1", "200"); l.setAttribute("y1", "40"); l.setAttribute("x2", "200"); l.setAttribute("y2", (m ? 60 : 50)); l.setAttribute("stroke", m ? "#fff" : "#666"); l.setAttribute("stroke-width", m ? "2" : "1"); l.setAttribute("transform", `rotate(${i}, 200, 200)`); c.appendChild(l); } }
332
339
  })();
333
340
 
334
- // Lancio Applicazione
341
+ // ==========================================================================
342
+ // 9. LANCIO APPLICAZIONE (Sincronizzato)
343
+ // ==========================================================================
335
344
  async function init() {
336
- await fetchServerConfig(); // Scarica prima i settaggi della barca
345
+ // 1. Prima scarichiamo la configurazione dal server
346
+ await fetchServerConfig();
347
+
348
+ // 2. Poi facciamo partire tutto il resto
337
349
  startDisplayLoop();
338
350
  connect();
339
351
  }
340
352
 
353
+ // Avvio al caricamento della pagina
341
354
  window.addEventListener('load', init);
342
355
 
343
356
  function checkDepthAlarm(m) { ui.depth.classList.remove('alarm-warning', 'alarm-danger'); if (m < CONFIG.alarms.depthDanger) { ui.depth.classList.add('alarm-danger'); playBingBing(); } else if (m < CONFIG.alarms.depthWarning) ui.depth.classList.add('alarm-warning'); }
package/index.js CHANGED
@@ -1,19 +1,22 @@
1
1
  module.exports = function (app) {
2
2
  const plugin = {};
3
- plugin.id = 'rotevista-dash'; // Questo ID determina l'URL delle impostazioni
4
- plugin.name = 'Rotevista Dash Configuration';
5
- plugin.description = 'Configura i parametri della barca per la Dashboard';
3
+
4
+ plugin.id = 'rotevista-dash'; // ID univoco per il plugin
5
+ plugin.name = 'Rotevista Dash Config';
6
+ plugin.description = 'Impostazioni centralizzate per la Dashboard Rotevista';
6
7
 
7
8
  plugin.start = function (options, restartServer) {
8
- app.debug('Rotevista Dash Plugin Started');
9
+ app.debug('Plugin Rotevista Dash avviato con opzioni:', options);
9
10
  };
10
11
 
11
12
  plugin.stop = function () {
12
- app.debug('Rotevista Dash Plugin Stopped');
13
+ app.debug('Plugin Rotevista Dash fermato');
13
14
  };
14
15
 
16
+ // Schema conforme alla doc di SignalK per generare la UI
15
17
  plugin.schema = {
16
18
  type: 'object',
19
+ title: 'Configurazione Barca',
17
20
  properties: {
18
21
  alarms: {
19
22
  type: 'object',
@@ -25,18 +28,18 @@ module.exports = function (app) {
25
28
  },
26
29
  graphs: {
27
30
  type: 'object',
28
- title: 'Soglie Terzaroli (Nodi TWS)',
31
+ title: 'Soglie Vento (Nodi TWS)',
29
32
  properties: {
30
- reef1: { type: 'number', title: '1° Mano (Arancio)', default: 15.0 },
31
- reef2: { type: 'number', title: '2° Mano (Rosso)', default: 20.0 }
33
+ reef1: { type: 'number', title: 'Soglia Arancio (1° Mano)', default: 15.0 },
34
+ reef2: { type: 'number', title: 'Soglia Rossa (2° Mano)', default: 20.0 }
32
35
  }
33
36
  },
34
37
  averages: {
35
38
  type: 'object',
36
- title: 'Medie e Stabilità',
39
+ title: 'Parametri Medie',
37
40
  properties: {
38
- longWindow: { type: 'number', title: 'Finestra Medie MEAN (millisecondi)', default: 60000 },
39
- minSpeed: { type: 'number', title: 'Velocità minima stabilità (nodi)', default: 0.5 }
41
+ longWindow: { type: 'number', title: 'Finestra Medie LUNGHE (ms)', default: 60000 },
42
+ minSpeed: { type: 'number', title: 'Velocità Minima Stabilità (kts)', default: 0.5 }
40
43
  }
41
44
  }
42
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailingrotevista/rotevista-dash",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "Public Wind Dashboard with navigation and course aids",
5
5
  "main": "index.js",
6
6
  "publishConfig": {