From f4464971966c5b6f7fa2551c05aa88a227cc3249 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Nov 2026 17:39:07 +0000 Subject: [PATCH 1/6] docs(spec): register maps and file recording The user's decisions (2026-11-06): an imported register map becomes a dashboard with a table panel; recording writes a dashboard's variables, scaled, as a wide CSV, one file per day. The spec records the inventory (our CSV parser, plugin-fs append, the dialog scopes: save grants one file, a folder pick grants the folder) and the measurement that the native GTK dialog can be driven under Xvfb with xdotool, so both features get a real E2E on Linux. The plan splits the work into six tasks. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Rdii6QU3MVeyCefPEk5AL --- .../plans/2026-11-06-register-maps-logging.md | 46 ++++++++++++ ...2026-11-06-register-maps-logging-design.md | 75 +++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 docs/superpowers/plans/2026-11-06-register-maps-logging.md create mode 100644 docs/superpowers/specs/2026-11-06-register-maps-logging-design.md diff --git a/docs/superpowers/plans/2026-11-06-register-maps-logging.md b/docs/superpowers/plans/2026-11-06-register-maps-logging.md new file mode 100644 index 0000000..2f4b90e --- /dev/null +++ b/docs/superpowers/plans/2026-11-06-register-maps-logging.md @@ -0,0 +1,46 @@ +# Piano — mappe registri e registrazione su file + +**Goal:** importare la mappa registri di un dispositivo in una dashboard (pannello tabella) e +registrarne le variabili su CSV giornalieri. + +**Architecture:** +- `src/lib/dashboards.ts`: nuovo pannello `table` (righe: variabile, unità, decimali). +- `src/lib/registerMap.ts`: lettura e scrittura del CSV della mappa (funzioni pure). +- `src/lib/recording.ts`: intestazione, righe, nomi dei file, cadenza (funzioni pure). +- `src/lib/recorder.svelte.ts`: stato della registrazione e scrittura in append con plugin-fs, + avanzata dalle letture. +- Componenti: `TableView` (corpo del pannello), voci in `DashboardView` (Importa mappa, + Registra/Ferma), esportazione dal menu del pannello tabella. + +**Tech Stack:** Svelte 5, `@tauri-apps/plugin-fs` 2.7.1, `@tauri-apps/plugin-dialog` 2.8.4, +fast-check, webdriverio + xdotool (dialoghi GTK nell'E2E). + +**Spec:** `docs/superpowers/specs/2026-11-06-register-maps-logging-design.md` + +**Global Constraints:** file ≤600 LOC; token Aura; testi in `messages/` (en, it); gate di +`CLAUDE.md`; coverage ≥85%; READ, THEN PROBE, THEN IMPLEMENT. + +**Review Focus:** una mappa non valida non entra a metà; nessuna scrittura fuori dalla cartella +scelta; le righe non dipendono da timer; i progetti esistenti si aprono ancora. + +**Decisions taken while writing this plan:** +- Unità e decimali stanno nella riga del pannello tabella, non in `Variable`: aggiungerli a + `Variable` cambierebbe tutti i pannelli e il formato del progetto per un solo uso. +- Il pannello tabella entra nel progetto come gli altri: nessun cambio di versione del file. +- La cadenza delle righe e il cambio di giorno sono funzioni pure con il tempo passato da fuori: + i test non aspettano la mezzanotte. + +## Task + +- [ ] **T1 Pannello tabella (modello):** tipo, `newPanel`, validazione e lettura dei progetti, test. +- [ ] **T2 CSV della mappa:** `parseRegisterMap` (errori con riga e campo), `registerMapCsv`; + test d'esempio e di proprietà (andata e ritorno). +- [ ] **T3 Mappa nell'app:** `TableView`, editor delle righe, Importa mappa (unit id, nuova + dashboard), Esporta dal pannello; i18n; E2E su Linux: import col dialogo GTK, valori scalati letti + da pymodbus, export uguale all'originale. +- [ ] **T4 Registrazione (logica):** intestazione, righe, nomi, cadenza e giorno; registratore con + fs simulato; test. +- [ ] **T5 Registrazione nell'app:** Registra/Ferma con scelta della cartella, indicatore, errori; + E2E su Linux: righe nel file confrontate con pymodbus; misure: finestra minimizzata, mappa di 200 + righe per un'ora. +- [ ] **T6 Documenti:** README, CHANGELOG, file di verifica. diff --git a/docs/superpowers/specs/2026-11-06-register-maps-logging-design.md b/docs/superpowers/specs/2026-11-06-register-maps-logging-design.md new file mode 100644 index 0000000..93f5943 --- /dev/null +++ b/docs/superpowers/specs/2026-11-06-register-maps-logging-design.md @@ -0,0 +1,75 @@ +# Mappe registri e registrazione su file + +Data: 2026-11-06. Stato: decisioni dell'utente (sotto), misure preliminari fatte, da implementare. + +## Perché + +- **Mappa:** oggi ogni registro di un dispositivo si configura a mano. Il manuale di un inverter o + di un PLC fornisce già la tabella dei registri (indirizzo, nome, tipo, unità, scala): importarla + toglie il lavoro più lungo del commissioning. +- **Registrazione:** lo storico del trend dura 10 minuti e solo in memoria. Una prova notturna o un + guasto intermittente richiedono valori su file, per ore. + +## Decisioni dell'utente (2026-11-06) + +1. Una mappa importata diventa una **dashboard**: una variabile per riga, mostrate da un pannello + tabella. Non crea poll del master, che hanno un solo tipo per blocco e nessuna scalatura. +2. Si registrano le **variabili di una dashboard**, in unità ingegneristiche (scalate). +3. CSV **largo**: una riga per lettura, una colonna per variabile. +4. **Un file nuovo al giorno.** + +## Decisioni + +### Mappa (R) + +| # | Decisione | Fonte | +|---|---|---| +| R1 | Formato CSV con riga di intestazione; colonne riconosciute per nome, in qualsiasi ordine, maiuscole indifferenti: `name`, `table`, `address`, `type`, `byte_order`, `units`, `raw_min`, `raw_max`, `eng_min`, `eng_max`, `decimals`. Obbligatorie `name`, `table`, `address`, `type`; le colonne di scala vanno tutte e quattro insieme o nessuna | Un formato da una tabella di manuale si scrive a mano o con un foglio di calcolo | +| R2 | `table`: `coils`, `discrete inputs`, `holding registers`, `input registers` (anche `coil`, `discrete`, `holding`, `input`). `address`: indirizzo di protocollo 0…65535, non la notazione 40001 | I manuali usano entrambe le notazioni: indovinarla sbaglierebbe di 1 senza che nessuno se ne accorga. Lo dice il messaggio d'errore e il README | +| R3 | `type` come nei menu dell'app (`UInt16` … `Float64`, `Hex`, `Binary`, `ASCII`); `byte_order` `ABCD`/`CDAB`/`BADC`/`DCBA`, predefinito `ABCD` | Nomi Modbus in inglese (spec i18n) | +| R4 | Un file con una sola riga non valida viene rifiutato tutto, con il numero di riga e il campo: una mappa importata a metà sembra completa e non lo è | — | +| R5 | L'import chiede l'unit id (un dispositivo, un unit id) e crea una dashboard col nome del file e un **pannello tabella** con tutte le righe | Decisione 1 | +| R6 | Pannello tabella: per riga nome, valore scalato con i decimali della riga, unità; valore vuoto se la lettura è vecchia o in errore. Le letture usano il raggruppamento esistente (D21) | Riuso di `dashboardReads` | +| R7 | Il pannello tabella si esporta nello stesso CSV: andata e ritorno restituiscono la stessa mappa | Il formato si documenta da sé con un esempio prodotto dall'app | +| R8 | Il CSV si legge con il parser già nel progetto (`src/lib/csv.ts`) | Inventario: nessuna libreria nuova | + +### Registrazione (L) + +| # | Decisione | Fonte | +|---|---|---| +| L1 | Si registrano le variabili distinte della dashboard aperta (stessa identità di `variableKey`), con il valore scalato; una cella vuota se la lettura è vecchia o in errore | Decisione 2 | +| L2 | Intestazione `time` e poi una colonna per variabile, `nome [unità]`. Il tempo è locale, `AAAA-MM-GG hh:mm:ss.mmm`, che Excel e LibreOffice leggono come data | Decisione 3 | +| L3 | Una riga al più ogni periodo della dashboard, scritta all'arrivo di una lettura (nessun timer): senza letture, per esempio a master scollegato, non nascono righe e il buco si vede nella colonna del tempo | Un timer JS rallenta quando la finestra è nascosta; un evento dal backend no (da misurare, sotto) | +| L4 | L'utente sceglie una **cartella**; i file si chiamano `_AAAA-MM-GG.csv` e cambiano a mezzanotte locale. Se il file del giorno esiste già con la stessa intestazione si continua a scriverlo; con un'intestazione diversa si apre `_AAAA-MM-GG_2.csv` (e così via) | Decisione 4. Misura sotto: il dialogo di salvataggio dà il permesso su un solo file | +| L5 | Pulsante Registra/Ferma nella barra della dashboard, con indicatore e nome del file. Un errore di scrittura ferma la registrazione e lo dice | — | +| L6 | Il permesso sulla cartella vale per la sessione: dopo un riavvio dell'app la registrazione non riparte da sola | `tauri-plugin-dialog` 2.8.4: lo scope non è persistito | + +## Inventario (versioni installate) + +- `src/lib/csv.ts`: parser e scrittura CSV con virgolette, già usati per import/export dello slave e + per il traffico. +- `Variable` (`src/lib/dashboards.ts`) ha tabella, indirizzo, tipo, byte order, scalatura e colore: + manca solo il testo dell'unità e i decimali, che stanno nella riga del pannello tabella. +- `@tauri-apps/plugin-fs` 2.7.1: `writeTextFile(path, data, { append: true })`; permessi + `fs:allow-read-text-file` e `fs:allow-write-text-file` già concessi. +- `tauri-plugin-dialog` 2.8.4 (`src/commands.rs`): `save()` concede lo scope **solo sul file** + scelto (`allow_file`); `open({ directory: true })` concede la cartella (`allow_directory`). + +## Misure preliminari (2026-11-06, Linux, Xvfb, WebKitGTK 2.52.6) + +- **Dialoghi nativi nell'E2E:** il dialogo GTK "Open" aperto dall'app si pilota con `xdotool` + (`windowfocus`, Ctrl+L, percorso, Invio): l'app ha aperto il progetto scelto. `windowactivate` + non funziona senza window manager. Su Windows i dialoghi nativi non si pilotano: lì quei + controlli si dichiarano non eseguiti, come quelli seriali. + +## Da misurare durante l'implementazione + +- Scrittura in append su un file nuovo dentro la cartella scelta (scope della cartella). +- Il dialogo cartella di GTK guidato da `xdotool`. +- Righe scritte con la finestra minimizzata (L3). +- Prestazioni: una mappa di 200 righe letta a 1 s e registrata per un'ora (dimensione, CPU). + +## Cosa NON è dimostrato + +- Nessuna misura su Windows dei dialoghi nativi né della registrazione con la finestra nascosta. +- La notazione 40001 non è supportata (R2): una mappa scritta così va convertita. From 3e3a6d0eb0bd94fc780156b8b8cf1f309168e8f4 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Nov 2026 17:59:02 +0000 Subject: [PATCH 2/6] feat(dashboards): import a device's register map as a table A register map in CSV (name, table, address, type, and optionally byte order, units, decimals and two-point scaling) becomes a new dashboard with one table panel that reads every row through the existing grouped reads. The table exports the same CSV, and a file with one invalid row is refused whole, with its line and column: a map imported in part looks complete. Addresses are protocol addresses; the 40001 notation is refused with the reason, since guessing it would shift every register by one unnoticed. The parser reuses src/lib/csv.ts; number formatting moved to i18n.svelte.ts so the value panel and the table share it. Tests: example cases from a drive's table, every refused cell, and a fast-check round trip. The E2E imports a map through the native GTK dialog, driven with xdotool under Xvfb (keys sent before the dialog is ready are lost, measured, so the answer is repeated until the dialog closes), checks the values read from pymodbus, scaled and formatted, and compares the exported file. Windows cannot drive native dialogs: the run says those checks did not run. Local: 90/90. CI installs xdotool. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Rdii6QU3MVeyCefPEk5AL --- .github/workflows/ci.yml | 2 +- .../plans/2026-11-06-register-maps-logging.md | 9 +- ...2026-11-06-register-maps-logging-design.md | 2 +- e2e/helpers.mjs | 48 ++++++ e2e/registerMap.mjs | 85 +++++++++++ e2e/run.mjs | 7 +- knip.json | 3 +- messages/en.json | 18 ++- messages/it.json | 18 ++- src/lib/components/DashboardView.svelte | 24 +++ src/lib/components/PanelBody.svelte | 3 + src/lib/components/PanelForm.svelte | 32 ++++ src/lib/components/TableView.svelte | 72 +++++++++ src/lib/components/ValueView.svelte | 8 +- src/lib/csv.ts | 6 +- src/lib/dashboardActions.svelte.ts | 1 + src/lib/dashboardReads.svelte.ts | 2 + src/lib/dashboardReads.test.ts | 4 +- src/lib/dashboards.test.ts | 16 +- src/lib/dashboards.ts | 32 +++- src/lib/dashboardsFile.ts | 3 + src/lib/i18n.svelte.ts | 7 + src/lib/mapActions.svelte.ts | 56 +++++++ src/lib/mapActions.test.ts | 94 ++++++++++++ src/lib/registerMap.test.ts | 122 +++++++++++++++ src/lib/registerMap.ts | 140 ++++++++++++++++++ 26 files changed, 789 insertions(+), 25 deletions(-) create mode 100644 e2e/registerMap.mjs create mode 100644 src/lib/components/TableView.svelte create mode 100644 src/lib/mapActions.svelte.ts create mode 100644 src/lib/mapActions.test.ts create mode 100644 src/lib/registerMap.test.ts create mode 100644 src/lib/registerMap.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea0d76b..f388388 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -165,7 +165,7 @@ jobs: uses: ./.github/actions/linux-deps timeout-minutes: 30 with: - extra: webkit2gtk-driver xvfb socat + extra: webkit2gtk-driver xvfb socat xdotool - run: cargo install tauri-driver --locked --version 2.1.0 # tauri-driver drives Edge WebView2 through msedgedriver, whose version must match the # WebView2 on the runner (https://v2.tauri.app/develop/tests/webdriver/ci/). diff --git a/docs/superpowers/plans/2026-11-06-register-maps-logging.md b/docs/superpowers/plans/2026-11-06-register-maps-logging.md index 2f4b90e..31a9923 100644 --- a/docs/superpowers/plans/2026-11-06-register-maps-logging.md +++ b/docs/superpowers/plans/2026-11-06-register-maps-logging.md @@ -32,12 +32,15 @@ scelta; le righe non dipendono da timer; i progetti esistenti si aprono ancora. ## Task -- [ ] **T1 Pannello tabella (modello):** tipo, `newPanel`, validazione e lettura dei progetti, test. -- [ ] **T2 CSV della mappa:** `parseRegisterMap` (errori con riga e campo), `registerMapCsv`; +- [x] **T1 Pannello tabella (modello):** tipo, `newPanel`, validazione e lettura dei progetti, test. +- [x] **T2 CSV della mappa:** `parseRegisterMap` (errori con riga e campo), `registerMapCsv`; test d'esempio e di proprietà (andata e ritorno). -- [ ] **T3 Mappa nell'app:** `TableView`, editor delle righe, Importa mappa (unit id, nuova +- [x] **T3 Mappa nell'app:** `TableView`, editor delle righe, Importa mappa (unit id, nuova dashboard), Esporta dal pannello; i18n; E2E su Linux: import col dialogo GTK, valori scalati letti da pymodbus, export uguale all'originale. + T1–T3 in un solo commit: il pannello tabella senza interfaccia non si prova nell'E2E. + Misurato durante T3: i tasti inviati prima che il dialogo GTK sia pronto si perdono; l'E2E + ripete la risposta finché il dialogo non si chiude. - [ ] **T4 Registrazione (logica):** intestazione, righe, nomi, cadenza e giorno; registratore con fs simulato; test. - [ ] **T5 Registrazione nell'app:** Registra/Ferma con scelta della cartella, indicatore, errori; diff --git a/docs/superpowers/specs/2026-11-06-register-maps-logging-design.md b/docs/superpowers/specs/2026-11-06-register-maps-logging-design.md index 93f5943..031905a 100644 --- a/docs/superpowers/specs/2026-11-06-register-maps-logging-design.md +++ b/docs/superpowers/specs/2026-11-06-register-maps-logging-design.md @@ -24,7 +24,7 @@ Data: 2026-11-06. Stato: decisioni dell'utente (sotto), misure preliminari fatte | # | Decisione | Fonte | |---|---|---| -| R1 | Formato CSV con riga di intestazione; colonne riconosciute per nome, in qualsiasi ordine, maiuscole indifferenti: `name`, `table`, `address`, `type`, `byte_order`, `units`, `raw_min`, `raw_max`, `eng_min`, `eng_max`, `decimals`. Obbligatorie `name`, `table`, `address`, `type`; le colonne di scala vanno tutte e quattro insieme o nessuna | Un formato da una tabella di manuale si scrive a mano o con un foglio di calcolo | +| R1 | Formato CSV con riga di intestazione; colonne riconosciute per nome, in qualsiasi ordine, maiuscole indifferenti: `name`, `table`, `address`, `type`, `byte_order`, `units`, `raw_min`, `raw_max`, `eng_min`, `eng_max`, `decimals`. Obbligatorie `name`, `table`, `address`, e `type` per i registri (i bit non hanno tipo: per coil e discrete input il tipo si ignora); le quattro colonne di scala vanno insieme o nessuna, con `clamp` facoltativa (`true`/`false`, `yes`/`no`, `1`/`0`); `decimals` 0…10, predefinito 1 | Un formato da una tabella di manuale si scrive a mano o con un foglio di calcolo | | R2 | `table`: `coils`, `discrete inputs`, `holding registers`, `input registers` (anche `coil`, `discrete`, `holding`, `input`). `address`: indirizzo di protocollo 0…65535, non la notazione 40001 | I manuali usano entrambe le notazioni: indovinarla sbaglierebbe di 1 senza che nessuno se ne accorga. Lo dice il messaggio d'errore e il README | | R3 | `type` come nei menu dell'app (`UInt16` … `Float64`, `Hex`, `Binary`, `ASCII`); `byte_order` `ABCD`/`CDAB`/`BADC`/`DCBA`, predefinito `ABCD` | Nomi Modbus in inglese (spec i18n) | | R4 | Un file con una sola riga non valida viene rifiutato tutto, con il numero di riga e il campo: una mappa importata a metà sembra completa e non lo è | — | diff --git a/e2e/helpers.mjs b/e2e/helpers.mjs index af1475f..ba69d28 100644 --- a/e2e/helpers.mjs +++ b/e2e/helpers.mjs @@ -15,6 +15,12 @@ export const python = process.platform === "win32" ? "python" : "python3"; * the run says so, rather than counting them as passed. */ export const serial = process.platform !== "win32"; +/** + * Native file dialogs are answered on Linux by typing into the GTK chooser with xdotool. WebDriver + * cannot reach them, and Windows has no such tool here: there those checks are not run, and the + * run says so. + */ +export const nativeDialogs = process.platform === "linux"; /** Failure screenshots and the run's files; E2E_OUT names a folder CI uploads when a run fails. */ export const tmp = process.env.E2E_OUT ? (mkdirSync(process.env.E2E_OUT, { recursive: true }), process.env.E2E_OUT) @@ -134,3 +140,45 @@ export async function editCell(browser, index, value) { await input.addValue(String(value)); await browser.keys("Enter"); } + +/** The id of the visible window titled `title`; throws while there is none. */ +function windowTitled(title) { + return execFileSync("xdotool", ["search", "--onlyvisible", "--name", `^${title}$`], { encoding: "utf8" }) + .trim() + .split("\n") + .pop(); +} + +/** + * Answers the GTK file dialog titled `title` ("Open File", "Save File") with `path`. Xvfb has no + * window manager, so the dialog is focused, not activated. Keys typed before the dialog is ready + * are lost (measured), so the answer is typed again until the dialog has closed. The location + * takes the path after Ctrl+L in the open dialog, in the selected name field in the save dialog. + */ +export async function answerFileDialog(title, path) { + await eventually( + async () => { + const id = windowTitled(title); + execFileSync("xdotool", ["windowfocus", "--sync", id]); + execFileSync("xdotool", ["key", title.startsWith("Save") ? "ctrl+a" : "ctrl+l"]); + execFileSync("xdotool", ["key", "ctrl+a"]); + execFileSync("xdotool", ["type", "--delay", "20", path]); + execFileSync("xdotool", ["key", "Return"]); + await eventually( + () => { + let open = true; + try { + windowTitled(title); + } catch { + open = false; + } + if (open) throw new Error(`"${title}" still open`); + }, + `"${title}" closed`, + 2000, + ); + }, + `"${title}" answered`, + 20_000, + ); +} diff --git a/e2e/registerMap.mjs b/e2e/registerMap.mjs new file mode 100644 index 0000000..f0e055d --- /dev/null +++ b/e2e/registerMap.mjs @@ -0,0 +1,85 @@ +// Register maps against pymodbus (docs/superpowers/specs/2026-11-06-register-maps-logging-design.md): +// a map imported through the native file dialog becomes a dashboard table that reads the reference, +// and the table exports the same map. Reference input register n = 1000 + n, discrete inputs off +// (reference_servers.py); no scenario writes them. + +import { readFileSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { + answerFileDialog, + button, + check, + click, + dialog, + eventually, + expectEqual, + labelled, + setField, + tmp, +} from "./helpers.mjs"; + +// As a manual prints it: headers in its own words and case, mixed types, a scaled value, a bit. +const MAP = `Name,Table,Address,Type,Byte order,Units,Decimals,Raw min,Raw max,Eng min,Eng max +Inlet temperature,input registers,4,UInt16,,°C,0,,,, +Level,input registers,6,UInt16,,%,1,1000,1010,0,100 +Totaliser,input registers,2,UInt32,ABCD,m³,0,,,, +Alarm,discrete inputs,1,,,,0,,,, +`; + +// What the table exports: the app's own column names, every default written out. +const EXPORTED = `name,table,address,type,byte_order,units,decimals,raw_min,raw_max,eng_min,eng_max,clamp +Inlet temperature,input registers,4,UInt16,ABCD,°C,0,,,,, +Level,input registers,6,UInt16,ABCD,%,1,1000,1010,0,100,false +Totaliser,input registers,2,UInt32,ABCD,m³,0,,,,, +Alarm,discrete inputs,1,,,,0,,,,, +`; + +const rows = (browser) => + browser + .$$("//article//table//tbody/tr") + .map(async (tr) => (await tr.$$("td").map((td) => td.getProperty("textContent"))).map((t) => t.trim())); + +/** Runs with the master connected to the reference; leaves no dashboard behind. */ +export async function registerMapScenario(browser) { + console.log("Register map"); + const source = join(tmp, "drive.csv"); + const exported = join(tmp, "drive-exported.csv"); + writeFileSync(source, MAP); + await click(browser, "//nav//button[.//span[normalize-space()='Dashboard']]"); + + await check("Register map: an imported map reads every register, scaled, with its units", async () => { + await click(browser, button("", "Import register map")); + await setField(browser, dialog, "Device unit id", 1); + await click(browser, button(dialog, "Choose file")); + await answerFileDialog("Open File", source); + await eventually( + async () => + expectEqual( + await rows(browser), + [ + ["Inlet temperature", "1,004", "°C"], + ["Level", "60.0", "%"], + // Registers 2 and 3, high word first: 1002 * 65536 + 1003. + ["Totaliser", "65,668,075", "m³"], + ["Alarm", "0", ""], + ], + "table", + ), + "table", + ); + }); + + await check("Register map: a table exports the map it was imported from", async () => { + await click(browser, button("", "Edit")); + await click(browser, labelled("Edit drive")); + await click(browser, button(dialog, "Export register map")); + await answerFileDialog("Save File", exported); + await eventually(() => expectEqual(readFileSync(exported, "utf8"), EXPORTED, "exported map"), "export"); + await click(browser, button(dialog, "Cancel")); + await click(browser, button("", "Done")); + }); + + await click(browser, labelled("Delete dashboard")); + await click(browser, button(dialog, "Yes")); + await click(browser, "//nav//button[.//span[normalize-space()='Master']]"); +} diff --git a/e2e/run.mjs b/e2e/run.mjs index 42a44d3..6fe8daa 100644 --- a/e2e/run.mjs +++ b/e2e/run.mjs @@ -5,7 +5,8 @@ // npx tauri build --debug --no-bundle && node e2e/run.mjs [screenshot-dir] // // Needs: tauri-driver, the platform's WebDriver, python with pymodbus[serial]; on Linux also socat -// (the serial checks) and an X display. Windows runs every check but the serial ones. +// (the serial checks), xdotool (the native file dialogs) and an X display. Windows runs every check +// but the serial ones and those through a native file dialog. import { remote } from "webdriverio"; import { spawn } from "node:child_process"; @@ -23,6 +24,7 @@ import { expectEqual, gridValues, labelled, + nativeDialogs, panel, python, reference, @@ -35,6 +37,7 @@ import { track, } from "./helpers.mjs"; import { dashboardScenario } from "./dashboard.mjs"; +import { registerMapScenario } from "./registerMap.mjs"; import { typesMaster, typesSlave } from "./types.mjs"; const APP = process.platform === "win32" ? "modbus-tool.exe" : "modbus-tool"; @@ -193,6 +196,7 @@ async function masterScenario(browser, ports, serialRef) { await editPoll(browser, { Function: "FC03 · Holding registers" }); await typesMaster(browser, `127.0.0.1:${ports.tcp}`, 40); await dashboardScenario(browser, `127.0.0.1:${ports.tcp}`); + if (nativeDialogs) await registerMapScenario(browser); await editPoll(browser, { Function: "FC04 · Input registers", Address: 0, @@ -367,6 +371,7 @@ async function main() { } else { console.log("Not run on this platform (no socat): ASCII serial master, RTU serial slave\n"); } + if (!nativeDialogs) console.log("Not run on this platform (no xdotool): register map import and export\n"); background(python, [ join(root, "e2e/reference_servers.py"), ports.tcp, diff --git a/knip.json b/knip.json index 51fecf5..0e9e7d6 100644 --- a/knip.json +++ b/knip.json @@ -2,5 +2,6 @@ "$schema": "https://unpkg.com/knip@6/schema.json", "entry": ["site/site.js"], "ignoreExportsUsedInFile": true, - "ignoreDependencies": ["@inlang/plugin-message-format", "@inlang/plugin-m-function-matcher"] + "ignoreDependencies": ["@inlang/plugin-message-format", "@inlang/plugin-m-function-matcher"], + "ignoreBinaries": ["xdotool"] } diff --git a/messages/en.json b/messages/en.json index 96af790..c46f40b 100644 --- a/messages/en.json +++ b/messages/en.json @@ -53,6 +53,7 @@ "dashboard_delete_confirm": "Delete the dashboard {name} and its panels?", "panel_trend": "Trend", "panel_value": "Value", + "panel_table": "Table", "panel_bars": "Bars", "panel_lamp": "Lamp", "panel_button": "Button", @@ -249,5 +250,20 @@ "traffic_description": "Description", "traffic_bytes": "Bytes", "traffic_empty": "Frames sent and received by the master and the slave appear here.", - "traffic_exported": "Exported {count} frames" + "traffic_exported": "Exported {count} frames", + "map_import": "Import register map", + "map_import_help": "A CSV with the columns name, table, address and type, and optionally byte_order, units, decimals, raw_min, raw_max, eng_min, eng_max and clamp. Addresses are protocol addresses from 0. The map becomes a new dashboard with a table.", + "map_unit": "Device unit id", + "map_choose_file": "Choose file", + "map_export": "Export register map", + "map_file_type": "Register map", + "map_imported": "Imported {count} registers from {file}", + "map_exported": "Exported {count} registers to {file}", + "table_name": "Name", + "table_value": "Value", + "table_units": "Unit", + "map_empty": "The register map has no rows", + "map_missing_columns": "The register map needs the columns: {columns}", + "map_invalid_cell": "Register map, line {line}: invalid {column} \"{value}\"", + "map_invalid_address": "Register map, line {line}: address \"{value}\" is not 0 to 65535 (the protocol address, not the 40001 notation)" } diff --git a/messages/it.json b/messages/it.json index 05ea6d5..e80504c 100644 --- a/messages/it.json +++ b/messages/it.json @@ -53,6 +53,7 @@ "dashboard_delete_confirm": "Eliminare la dashboard {name} e i suoi pannelli?", "panel_trend": "Trend", "panel_value": "Valore", + "panel_table": "Tabella", "panel_bars": "Barre", "panel_lamp": "Lampada", "panel_button": "Pulsante", @@ -249,5 +250,20 @@ "traffic_description": "Descrizione", "traffic_bytes": "Byte", "traffic_empty": "Qui compaiono i frame inviati e ricevuti dal master e dallo slave.", - "traffic_exported": "Esportati {count} frame" + "traffic_exported": "Esportati {count} frame", + "map_import": "Importa mappa registri", + "map_import_help": "Un CSV con le colonne name, table, address e type, e facoltative byte_order, units, decimals, raw_min, raw_max, eng_min, eng_max e clamp. Gli indirizzi sono quelli di protocollo, da 0. La mappa diventa una nuova dashboard con una tabella.", + "map_unit": "Unit id del dispositivo", + "map_choose_file": "Scegli file", + "map_export": "Esporta mappa registri", + "map_file_type": "Mappa registri", + "map_imported": "Importati {count} registri da {file}", + "map_exported": "Esportati {count} registri in {file}", + "table_name": "Nome", + "table_value": "Valore", + "table_units": "Unità", + "map_empty": "La mappa registri non ha righe", + "map_missing_columns": "Alla mappa registri mancano le colonne: {columns}", + "map_invalid_cell": "Mappa registri, riga {line}: {column} non valido \"{value}\"", + "map_invalid_address": "Mappa registri, riga {line}: indirizzo \"{value}\" non compreso tra 0 e 65535 (l'indirizzo di protocollo, non la notazione 40001)" } diff --git a/src/lib/components/DashboardView.svelte b/src/lib/components/DashboardView.svelte index 7ec2223..f30aa9b 100644 --- a/src/lib/components/DashboardView.svelte +++ b/src/lib/components/DashboardView.svelte @@ -18,6 +18,7 @@ savePanel, } from "../dashboardActions.svelte"; import { PANEL_KINDS, type Panel, type PanelKind } from "../dashboards"; + import { importMap } from "../mapActions.svelte"; import { app } from "../state.svelte"; const dashboard = $derived(currentDashboard()); @@ -32,6 +33,8 @@ // The kind picker of "Add panel": a list of buttons, since WebKit fires no change event when a // + {#snippet actions()} + + + + {/snippet} + +{/if} + {#if naming} import { m } from "../../paraglide/messages.js"; import Modal from "./Modal.svelte"; + import TableView from "./TableView.svelte"; import TrendChart from "./TrendChart.svelte"; import ValueView from "./ValueView.svelte"; import { setpointRegisters, variableLabel, writeTarget } from "../dashboardActions.svelte"; @@ -90,6 +91,8 @@ /> {:else if panel.kind === "value"} +{:else if panel.kind === "table"} + {:else if panel.kind === "bars"}
{#each bars as bar, i (i)} diff --git a/src/lib/components/PanelForm.svelte b/src/lib/components/PanelForm.svelte index 14d0bd9..2891f8f 100644 --- a/src/lib/components/PanelForm.svelte +++ b/src/lib/components/PanelForm.svelte @@ -4,9 +4,11 @@ import ScalingFields from "./ScalingFields.svelte"; import VariableFields from "./VariableFields.svelte"; import { targetRegisters } from "../dashboardActions.svelte"; + import { exportMap } from "../mapActions.svelte"; import { INTERPOLATIONS, followTarget, + newTableRow, newVariable, targetVariable, type Interpolation, @@ -106,6 +108,36 @@ {:else if panel.kind === "bars"} {@render variableList(panel.variables)} +{:else if panel.kind === "table"} + {@const table = panel} + {#each table.rows as row, i (i)} + + {#snippet actions()} + + {/snippet} + +
+ + +
+ {/each} +
+ + +
{:else if panel.kind === "value"}
diff --git a/src/lib/components/TableView.svelte b/src/lib/components/TableView.svelte new file mode 100644 index 0000000..af948c0 --- /dev/null +++ b/src/lib/components/TableView.svelte @@ -0,0 +1,72 @@ + + +
+ + + + + + {#each panel.rows as row, i (i)} + {@const value = variableValue(row.variable)} + + + + + + {:else} + + {/each} + +
{m.table_name()}{m.table_value()}{m.table_units()}
{variableLabel(row.variable)}{value === null ? "—" : formatNumber(value, row.decimals)}{row.units}
{m.panel_no_variable()}
+
+ + diff --git a/src/lib/components/ValueView.svelte b/src/lib/components/ValueView.svelte index 6105cd7..1b96ca9 100644 --- a/src/lib/components/ValueView.svelte +++ b/src/lib/components/ValueView.svelte @@ -1,6 +1,6 @@