feat: add global sidebar links management and settings UI
This commit is contained in:
1 parent
3203577a9d
commit
f6f3c402cc
10 files changed
+461
-38
No files matched your search
@@ -1,8 +1,8 @@
|
|||||||
# SE Local Trenddata
|
# SE Local Trenddata
|
||||||
|
|
||||||
SE Local Trenddata ist eine webbasierte Trend-, Dashboard- und Quellenverwaltung fuer lokale Anlagen- und WAGO-Daten. Das Projekt besteht aus einem React-Frontend, einer Node.js/Express-API, MariaDB, Redis und einem Collector-Service fuer Protokollquellen wie Modbus TCP, OPC UA, BACnet IP und KNX IP.
|
SE Local Trenddata ist eine webbasierte Trend-, Dashboard- und Quellenverwaltung für lokale Anlagen und Ersatz für das alte Trenddatensystem, welches auf 199 Werte pro ISP begrenzt ist. Das Projekt besteht aus einem React-Frontend, einer Node.js/Express-API, MariaDB, Redis und einem Collector-Service für Protokollquellen wie Modbus TCP, OPC UA, BACnet IP und KNX IP.
|
||||||
|
|
||||||
Das Ziel ist, bestehende breite Trendtabellen wie `isp01`, `isp02` usw. weiter nutzen zu koennen und zusaetzlich neue Quellen sauber ueber eine Weboberflaeche anzulegen, zu scannen, zu loggen und im Dashboard oder in der Trendansicht auszuwerten.
|
Das Ziel ist, bestehende breite Trendtabellen wie `isp01`, `isp02` usw. weiter nutzen zu können und zusätzlich neue Quellen sauber ueber eine Weboberflaeche anzulegen, zu scannen, zu loggen und im Dashboard oder in der Trendansicht auszuwerten.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -74,13 +74,13 @@ SeLTD/
|
|||||||
|
|
||||||
| Bereich | Aufgabe |
|
| Bereich | Aufgabe |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `web/` | React/Vite-Frontend fuer Login, Dashboard, Trends, Admin-Bereich, Quellen, Rollen und Benutzer |
|
| `web/` | React/Vite-Frontend für Login, Dashboard, Trends, Admin-Bereich, Quellen, Rollen und Benutzer |
|
||||||
| `api/` | Express-API fuer Auth, Rollen, Aliase, Trendabfragen, Dashboard, SQL-Import und Benutzerverwaltung |
|
| `api/` | Express-API für Auth, Rollen, Aliase, Trendabfragen, Dashboard, SQL-Import und Benutzerverwaltung |
|
||||||
| `collector/` | HTTP-Service fuer Protokollquellen, Datenpunkte, Scans, Imports und zyklisches Logging |
|
| `collector/` | HTTP-Service für Protokollquellen, Datenpunkte, Scans, Imports und zyklisches Logging |
|
||||||
| `mariadb` | Persistente Trenddaten und Benutzer-Tabelle |
|
| `mariadb` | Persistente Trenddaten und Benutzer-Tabelle |
|
||||||
| `redis` | Metadaten, Aliase, Rollen, Einheiten, Dashboards, Auswahlen und User-Praeferenzen |
|
| `redis` | Metadaten, Aliase, Rollen, Einheiten, Dashboards, Auswahlen und User-Praeferenzen |
|
||||||
| `dockhand` | Docker-Verwaltung ueber Weboberflaeche |
|
| `dockhand` | Docker-Verwaltung ueber Weboberflaeche |
|
||||||
| `cadvisor` | Container-Metriken fuer Monitoring |
|
| `cadvisor` | Container-Metriken für Monitoring |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ Wichtig: Die API laeuft im Container intern auf Port `8080`, wird aber nach auss
|
|||||||
## Schnellstart mit Docker Compose
|
## Schnellstart mit Docker Compose
|
||||||
|
|
||||||
Du solltest WSL installiert haben.
|
Du solltest WSL installiert haben.
|
||||||
Falls du das nicht hast:
|
Falls du das nicht hast (im Windowsterminal als Administrator):
|
||||||
```powershell
|
```powershell
|
||||||
wsl --install Ubuntu
|
wsl --install Ubuntu
|
||||||
```
|
```
|
||||||
@@ -138,20 +138,34 @@ Die Installation einfach durchklicken und wenn du gefragt wirst ob du Hyper-V od
|
|||||||
|
|
||||||
|
|
||||||
### 1. Repository vorbereiten
|
### 1. Repository vorbereiten
|
||||||
|
Du solltest GIT (https://git-scm.com/install/windows)auf deinem Rechner installiert haben.
|
||||||
Wenn du git auf deinem rechner installiert hast, dann öffne eine Powershell in dem Ordner, in dem du das LTD-System haben willst.
|
Dann öffne eine Powershell in dem Ordner, in dem du das LTD-System haben willst.
|
||||||
(rechtsklick im Windowsexplorer ins leere --> "In Terminal öffnen")
|
(rechtsklick im Windowsexplorer ins leere --> "In Terminal öffnen")
|
||||||
```powershell
|
```powershell
|
||||||
git clone https://git.portal.se-cloud.de/Hannes/SE-LTD
|
git clone https://git.portal.se-cloud.de/Hannes/SE-LTD
|
||||||
cd ./SeLTD
|
cd ./SE-LTD
|
||||||
```
|
```
|
||||||
Powershell nicht schließen, brauchst du gleich noch.
|
Powershell nicht schließen, brauchst du gleich noch.
|
||||||
|
|
||||||
|
### 2. Anpassungen vornehmen
|
||||||
|
Kopiere die .env.example nach .env.
|
||||||
|
Öffne die kopierte Datei (.env) mit Visual Code.
|
||||||
|
Falls du das nicht hast --> https://code.visualstudio.com/docs/setup/windows
|
||||||
|
Beim Setup ist es zu empfehlen, die zwei Optionen "Code im Datei und Explorer Context Menü anzeigen" an zu haken.
|
||||||
|
|
||||||
### 2. Stack bauen und starten
|
In der .env sollten unbedingt folgende Variablen angepasst werden:
|
||||||
|
JWT_SECRET --> sicher erzeugtes Passwort mit 32 Stellen
|
||||||
|
ADMIN_PASSWORD --> sicher erzeugtes Passwort mit 32 Stellen
|
||||||
|
MARIADB_ROOT_PASSWORD --> sicher erzeugtes Passwort mit 32 Stellen
|
||||||
|
Nur bei NICHT-Bestandsanlagen ändern. Sonst muss eine Anpassung im Programm stattfinden.
|
||||||
|
CORS_ORIGIN sollte auf * wenn ausserhalb von localhost zugegriffen werden soll
|
||||||
|
REDIS_PASSWORD --> sicher erzeugtes Passwort mit 32 Stellen
|
||||||
|
|
||||||
|
|
||||||
|
### 3. Stack bauen und starten
|
||||||
|
|
||||||
Falls du Powershell geschlossen hast:
|
Falls du Powershell geschlossen hast:
|
||||||
(rechtsklick im Windowsexplorer ins leere --> "In Terminal öffnen")
|
(rechtsklick im Windowsexplorer ins leere in dem gerade erstellten Ordner --> "In Terminal öffnen")
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
docker compose build --no-cache web api collector
|
docker compose build --no-cache web api collector
|
||||||
@@ -166,7 +180,7 @@ docker ps -a
|
|||||||
```
|
```
|
||||||
...überprüfen
|
...überprüfen
|
||||||
|
|
||||||
### 3. Aufrufen
|
### 4. Aufrufen
|
||||||
Nun stehen dir mehrere Tools zur Verfügung:
|
Nun stehen dir mehrere Tools zur Verfügung:
|
||||||
| Frontend | `http://localhost:81` |
|
| Frontend | `http://localhost:81` |
|
||||||
--> Das ist die normale Weboberfläche zum anschauen, editieren und anpassen von Trends.
|
--> Das ist die normale Weboberfläche zum anschauen, editieren und anpassen von Trends.
|
||||||
@@ -185,7 +199,7 @@ Nun stehen dir mehrere Tools zur Verfügung:
|
|||||||
--> Cadvisor stellt alle Containerdaten für Monitoring und Analyticprogramme bereit.
|
--> Cadvisor stellt alle Containerdaten für Monitoring und Analyticprogramme bereit.
|
||||||
So kann bei einer größeren Anlage, das Dockersystem mitr Prometheus oder ähnlichem überwacht werden.
|
So kann bei einer größeren Anlage, das Dockersystem mitr Prometheus oder ähnlichem überwacht werden.
|
||||||
Cadvisor stellt di Daten per html bereit, kannst du dir gern anschauen, ist aber ziemlich unübersichtlich.
|
Cadvisor stellt di Daten per html bereit, kannst du dir gern anschauen, ist aber ziemlich unübersichtlich.
|
||||||
### 4. Standard-Login
|
### 5. Standard-Login
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Username: admin
|
Username: admin
|
||||||
@@ -201,17 +215,17 @@ Die wichtigsten Variablen liegen in `.env`.
|
|||||||
|
|
||||||
| Variable | Beispiel | Beschreibung |
|
| Variable | Beispiel | Beschreibung |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `JWT_SECRET` | `change-me` | Signatur fuer Login-Tokens. In Produktion unbedingt aendern. |
|
| `JWT_SECRET` | `change-me` | Signatur für Login-Tokens. In Produktion unbedingt aendern. |
|
||||||
| `ADMIN_USERNAME` | `admin` | Initialer Admin-Username |
|
| `ADMIN_USERNAME` | `admin` | Initialer Admin-Username |
|
||||||
| `ADMIN_EMAIL` | `admin@example.com` | Initiale Admin-E-Mail |
|
| `ADMIN_EMAIL` | `admin@example.com` | Initiale Admin-E-Mail |
|
||||||
| `ADMIN_PASSWORD` | `ChangeMe123!` | Initiales Admin-Passwort |
|
| `ADMIN_PASSWORD` | `ChangeMe123!` | Initiales Admin-Passwort |
|
||||||
| `ADMIN_NAME` | `System Admin` | Anzeigename des Admins |
|
| `ADMIN_NAME` | `System Admin` | Anzeigename des Admins |
|
||||||
| `MARIADB_ROOT_PASSWORD` | `SE3112` | MariaDB-Root-Passwort |
|
| `MARIADB_ROOT_PASSWORD` | `SE3112` | MariaDB-Root-Passwort |
|
||||||
| `DB_PASSWORD_FALLBACK` | `root` | Fallback fuer alte Entwicklungsvolumes |
|
| `DB_PASSWORD_FALLBACK` | `root` | Fallback für alte Entwicklungsvolumes |
|
||||||
| `CORS_ORIGIN` | `*` | Erlaubter Browser-Ursprung fuer API-Aufrufe |
|
| `CORS_ORIGIN` | `*` | Erlaubter Browser-Ursprung für API-Aufrufe |
|
||||||
| `LEGACY_TREND_TIME_ZONE` | `Europe/Berlin` | Zeitzone der gespeicherten Controllerzeit in Bestandstabellen mit `Wert1` usw. Fuer bereits in UTC gespeicherte Bestandsdaten `+00:00` setzen. |
|
| `LEGACY_TREND_TIME_ZONE` | `Europe/Berlin` | Zeitzone der gespeicherten Controllerzeit in Bestandstabellen mit `Wert1` usw. für bereits in UTC gespeicherte Bestandsdaten `+00:00` setzen. |
|
||||||
| `VITE_API_PORT` | `18080` | API-Port, den das Frontend im Browser nutzt |
|
| `VITE_API_PORT` | `18080` | API-Port, den das Frontend im Browser nutzt |
|
||||||
| `POLL_TICK_MS` | `1000` | Collector-Tick fuer Polling-Pruefung |
|
| `POLL_TICK_MS` | `1000` | Collector-Tick für Polling-Pruefung |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -265,11 +279,11 @@ Benutzer, Rollen und Passwoerter werden ueber den Admin-Bereich verwaltet.
|
|||||||
### Trendansicht
|
### Trendansicht
|
||||||
|
|
||||||
- Datenpunkte aus mehreren Trendtabellen kombinierbar
|
- Datenpunkte aus mehreren Trendtabellen kombinierbar
|
||||||
- Auswahl speicherbar und optional fuer andere Benutzer freigebbar
|
- Auswahl speicherbar und optional für andere Benutzer freigebbar
|
||||||
- Zeitraeume als Presets von 5 Minuten bis 30 Tage
|
- Zeitraeume als Presets von 5 Minuten bis 30 Tage
|
||||||
- Eigener Start-/Endzeitraum moeglich
|
- Eigener Start-/Endzeitraum moeglich
|
||||||
- Aktuelle Werte werden separat angezeigt
|
- Aktuelle Werte werden separat angezeigt
|
||||||
- Fokusmodus fuer den Graphen
|
- Fokusmodus für den Graphen
|
||||||
|
|
||||||
### Trend-Export
|
### Trend-Export
|
||||||
|
|
||||||
@@ -425,7 +439,7 @@ MariaDB speichert:
|
|||||||
- `app_users`
|
- `app_users`
|
||||||
- bestehende `isp...` Tabellen
|
- bestehende `isp...` Tabellen
|
||||||
- neue `trend_...` Tabellen
|
- neue `trend_...` Tabellen
|
||||||
- Registry-Tabellen fuer Quellen und Datenpunkte, falls vom Collector/API genutzt
|
- Registry-Tabellen für Quellen und Datenpunkte, falls vom Collector/API genutzt
|
||||||
|
|
||||||
Die API kann bestehende breite Tabellen mit `Wert1`, `Wert2`, ... lesen. Neue lokale Trendtabellen koennen bis zu 2000 Werte unterstuetzen.
|
Die API kann bestehende breite Tabellen mit `Wert1`, `Wert2`, ... lesen. Neue lokale Trendtabellen koennen bis zu 2000 Werte unterstuetzen.
|
||||||
|
|
||||||
@@ -460,7 +474,7 @@ type .\seltd-mariadb-backup.sql | docker exec -i seltd-mariadb mariadb -uroot -p
|
|||||||
|
|
||||||
### Redis Backup
|
### Redis Backup
|
||||||
|
|
||||||
Redis nutzt ein Docker-Volume. Fuer ein einfaches Dateibackup:
|
Redis nutzt ein Docker-Volume. für ein einfaches Dateibackup:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
docker run --rm -v seltd_redis_data:/data -v ${PWD}:/backup alpine tar czf /backup/seltd-redis-backup.tar.gz -C /data .
|
docker run --rm -v seltd_redis_data:/data -v ${PWD}:/backup alpine tar czf /backup/seltd-redis-backup.tar.gz -C /data .
|
||||||
@@ -637,7 +651,7 @@ Vor produktiver Nutzung:
|
|||||||
- [ ] MariaDB-Port `3306` nicht ungeschuetzt ins Internet veroeffentlichen
|
- [ ] MariaDB-Port `3306` nicht ungeschuetzt ins Internet veroeffentlichen
|
||||||
- [ ] Redis-Port `6379` nicht ungeschuetzt ins Internet veroeffentlichen
|
- [ ] Redis-Port `6379` nicht ungeschuetzt ins Internet veroeffentlichen
|
||||||
- [ ] Dockhand absichern oder nur intern bereitstellen
|
- [ ] Dockhand absichern oder nur intern bereitstellen
|
||||||
- [ ] Backups fuer MariaDB, Redis und Collector-Daten einrichten
|
- [ ] Backups für MariaDB, Redis und Collector-Daten einrichten
|
||||||
- [ ] Reverse Proxy mit HTTPS verwenden
|
- [ ] Reverse Proxy mit HTTPS verwenden
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -648,7 +662,7 @@ Vor produktiver Nutzung:
|
|||||||
- Bestehende breite `isp...` Tabellen bleiben kompatibel.
|
- Bestehende breite `isp...` Tabellen bleiben kompatibel.
|
||||||
- Neue lokale Tabellen koennen als `trend_...` Tabellen angelegt werden.
|
- Neue lokale Tabellen koennen als `trend_...` Tabellen angelegt werden.
|
||||||
- Der Collector speichert seine Quellen/Datenpunkte aktuell dateibasiert in `sources.json`.
|
- Der Collector speichert seine Quellen/Datenpunkte aktuell dateibasiert in `sources.json`.
|
||||||
- Fuer vollstaendige Protokollintegration muessen je nach Feldbus noch Details wie Adressierung, Datentyp, Byteorder und Authentifizierung sauber projektspezifisch gepflegt werden.
|
- für vollstaendige Protokollintegration muessen je nach Feldbus noch Details wie Adressierung, Datentyp, Byteorder und Authentifizierung sauber projektspezifisch gepflegt werden.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
deleteSelection,
|
deleteSelection,
|
||||||
getDashboard,
|
getDashboard,
|
||||||
|
getGlobalSidebarLinks,
|
||||||
getPreferences,
|
getPreferences,
|
||||||
getRoleMap,
|
getRoleMap,
|
||||||
getSelection,
|
getSelection,
|
||||||
@@ -33,6 +34,7 @@ import {
|
|||||||
listSelections,
|
listSelections,
|
||||||
listUnits,
|
listUnits,
|
||||||
saveDashboard,
|
saveDashboard,
|
||||||
|
saveGlobalSidebarLinks,
|
||||||
savePreferences,
|
savePreferences,
|
||||||
saveRole,
|
saveRole,
|
||||||
saveSelection,
|
saveSelection,
|
||||||
@@ -969,6 +971,14 @@ app.put("/api/preferences", authenticateToken, wrap(async (req, res) => {
|
|||||||
res.json(preferences);
|
res.json(preferences);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
app.get("/api/settings/sidebar-links", wrap(async (_req, res) => {
|
||||||
|
res.json({ links: await getGlobalSidebarLinks(redis) });
|
||||||
|
}));
|
||||||
|
|
||||||
|
app.put("/api/settings/sidebar-links", authenticateToken, requireRoles("admin"), wrap(async (req, res) => {
|
||||||
|
res.json({ links: await saveGlobalSidebarLinks(redis, req.body?.links) });
|
||||||
|
}));
|
||||||
|
|
||||||
app.use((error, _req, res, _next) => {
|
app.use((error, _req, res, _next) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
res.status(400).json({ error: error.message || "Unexpected error." });
|
res.status(400).json({ error: error.message || "Unexpected error." });
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
const SELECTION_SET_KEY = "selection:ids";
|
const SELECTION_SET_KEY = "selection:ids";
|
||||||
import { DEFAULT_UNITS as DEFAULT_UNIT_DEFINITIONS, normalizeUnitSymbol as canonicalUnitSymbol } from "../../../shared/engineering-units.mjs";
|
import { DEFAULT_UNITS as DEFAULT_UNIT_DEFINITIONS, normalizeUnitSymbol as canonicalUnitSymbol } from "../../../shared/engineering-units.mjs";
|
||||||
import { DEFAULT_MAX_TREND_SERIES, normalizeMaxTrendSeries } from "../../../shared/trend-preferences.mjs";
|
import { DEFAULT_MAX_TREND_SERIES, normalizeMaxTrendSeries } from "../../../shared/trend-preferences.mjs";
|
||||||
|
import { normalizeSidebarLink } from "../../../shared/sidebar-links.mjs";
|
||||||
|
|
||||||
const SELECTION_SEQ_KEY = "selection:seq";
|
const SELECTION_SEQ_KEY = "selection:seq";
|
||||||
const ROLE_SET_KEY = "role:names";
|
const ROLE_SET_KEY = "role:names";
|
||||||
const UNIT_SET_KEY = "unit:symbols";
|
const UNIT_SET_KEY = "unit:symbols";
|
||||||
|
const GLOBAL_SIDEBAR_LINKS_KEY = "settings:sidebar-links";
|
||||||
|
|
||||||
export const DEFAULT_ROLE_DEFINITIONS = [
|
export const DEFAULT_ROLE_DEFINITIONS = [
|
||||||
{
|
{
|
||||||
@@ -248,6 +250,35 @@ export async function saveDashboard(redis, userId, dashboard) {
|
|||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readSidebarLinks(raw) {
|
||||||
|
const links = [];
|
||||||
|
for (const link of Array.isArray(raw) ? raw : []) {
|
||||||
|
try {
|
||||||
|
links.push(normalizeSidebarLink(link));
|
||||||
|
} catch {
|
||||||
|
// Ignore invalid links saved by older versions.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateSidebarLinks(links) {
|
||||||
|
if (!Array.isArray(links)) {
|
||||||
|
throw new Error("Seitenleisten-Links müssen als Liste übergeben werden.");
|
||||||
|
}
|
||||||
|
return links.map(normalizeSidebarLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getGlobalSidebarLinks(redis) {
|
||||||
|
return readSidebarLinks(safeParse(await redis.get(GLOBAL_SIDEBAR_LINKS_KEY)));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveGlobalSidebarLinks(redis, input) {
|
||||||
|
const links = validateSidebarLinks(input);
|
||||||
|
await redis.set(GLOBAL_SIDEBAR_LINKS_KEY, JSON.stringify(links));
|
||||||
|
return links;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getPreferences(redis, userId) {
|
export async function getPreferences(redis, userId) {
|
||||||
const stored = userId == null ? null : safeParse(await redis.get(`preferences:${userId}`));
|
const stored = userId == null ? null : safeParse(await redis.get(`preferences:${userId}`));
|
||||||
return {
|
return {
|
||||||
@@ -257,10 +288,12 @@ export async function getPreferences(redis, userId) {
|
|||||||
trendLineWidth: 1.8,
|
trendLineWidth: 1.8,
|
||||||
...stored,
|
...stored,
|
||||||
maxTrendSeries: normalizeMaxTrendSeries(stored?.maxTrendSeries, DEFAULT_MAX_TREND_SERIES),
|
maxTrendSeries: normalizeMaxTrendSeries(stored?.maxTrendSeries, DEFAULT_MAX_TREND_SERIES),
|
||||||
|
sidebarLinks: readSidebarLinks(stored?.sidebarLinks),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function savePreferences(redis, userId, preferences) {
|
export async function savePreferences(redis, userId, preferences) {
|
||||||
|
const sidebarLinks = preferences.sidebarLinks === undefined ? undefined : validateSidebarLinks(preferences.sidebarLinks);
|
||||||
const current = await getPreferences(redis, userId);
|
const current = await getPreferences(redis, userId);
|
||||||
const payload = {
|
const payload = {
|
||||||
...current,
|
...current,
|
||||||
@@ -270,6 +303,7 @@ export async function savePreferences(redis, userId, preferences) {
|
|||||||
sidebarPinned: typeof preferences.sidebarPinned === "boolean" ? preferences.sidebarPinned : current.sidebarPinned,
|
sidebarPinned: typeof preferences.sidebarPinned === "boolean" ? preferences.sidebarPinned : current.sidebarPinned,
|
||||||
trendLineWidth: Number.isFinite(Number(preferences.trendLineWidth)) ? Number(preferences.trendLineWidth) : Number(current.trendLineWidth || 1.8),
|
trendLineWidth: Number.isFinite(Number(preferences.trendLineWidth)) ? Number(preferences.trendLineWidth) : Number(current.trendLineWidth || 1.8),
|
||||||
maxTrendSeries: normalizeMaxTrendSeries(preferences.maxTrendSeries, current.maxTrendSeries),
|
maxTrendSeries: normalizeMaxTrendSeries(preferences.maxTrendSeries, current.maxTrendSeries),
|
||||||
|
sidebarLinks: sidebarLinks ?? current.sidebarLinks,
|
||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
await redis.set(`preferences:${userId}`, JSON.stringify(payload));
|
await redis.set(`preferences:${userId}`, JSON.stringify(payload));
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
export function normalizeSidebarLink(link) {
|
||||||
|
const label = typeof link?.label === "string" ? link.label.trim() : "";
|
||||||
|
if (!label) throw new Error("Bitte einen Namen für den Link eingeben.");
|
||||||
|
|
||||||
|
const address = typeof link.url === "string" ? link.url.trim() : "";
|
||||||
|
let url;
|
||||||
|
if (/^https?:\/\//i.test(address)) {
|
||||||
|
try {
|
||||||
|
url = new URL(address);
|
||||||
|
} catch {
|
||||||
|
// Report malformed addresses with the same message as unsupported schemes.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!url || url.username || url.password) {
|
||||||
|
throw new Error("Bitte eine vollständige HTTP- oder HTTPS-Adresse ohne Zugangsdaten eingeben.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return { label, url: url.href };
|
||||||
|
}
|
||||||
+80
-4
@@ -4,6 +4,7 @@ import { api } from "./api.js";
|
|||||||
import Gauge from "./components/Gauge.jsx";
|
import Gauge from "./components/Gauge.jsx";
|
||||||
import TrendChart from "./components/TrendChart.jsx";
|
import TrendChart from "./components/TrendChart.jsx";
|
||||||
import Sidebar, { SmallFootnote } from "./components/Sidebar.jsx";
|
import Sidebar, { SmallFootnote } from "./components/Sidebar.jsx";
|
||||||
|
import SidebarLinkSettings from "./components/SidebarLinkSettings.jsx";
|
||||||
import { AUTO_UNIT, DEFAULT_UNITS as DEFAULT_UNIT_OPTIONS, DIGITAL_UNIT, normalizeUnitSymbol, resolveEngineeringUnit } from "../../shared/engineering-units.mjs";
|
import { AUTO_UNIT, DEFAULT_UNITS as DEFAULT_UNIT_OPTIONS, DIGITAL_UNIT, normalizeUnitSymbol, resolveEngineeringUnit } from "../../shared/engineering-units.mjs";
|
||||||
import { DEFAULT_CHART_SETTINGS, normalizeTrendChartSettings } from "../../shared/trend-chart-settings.mjs";
|
import { DEFAULT_CHART_SETTINGS, normalizeTrendChartSettings } from "../../shared/trend-chart-settings.mjs";
|
||||||
import {
|
import {
|
||||||
@@ -22,6 +23,7 @@ const views = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const CHART_DRAFT_KEY = "seltd:trend-chart";
|
const CHART_DRAFT_KEY = "seltd:trend-chart";
|
||||||
|
const TREND_TOUCH_KEY = "seltd:trend-touch";
|
||||||
|
|
||||||
function loadChartDraft() {
|
function loadChartDraft() {
|
||||||
try {
|
try {
|
||||||
@@ -602,12 +604,12 @@ function PointLibrary({ isp, metadata, metadataCache, selectedPoints, filterText
|
|||||||
{filteredPoints.map((point) => {
|
{filteredPoints.map((point) => {
|
||||||
const key = `${point.isp}:${point.pointIndex}`;
|
const key = `${point.isp}:${point.pointIndex}`;
|
||||||
const selected = selectedKeys.has(key);
|
const selected = selectedKeys.has(key);
|
||||||
const alias = normalizeDisplayText(point.alias, `Wert ${point.pointIndex}`);
|
const alias = normalizeDisplayText(point.alias, "Datenpunkt");
|
||||||
return (
|
return (
|
||||||
<button key={key} type="button" className="point-item" aria-pressed={selected} title={alias} onClick={() => onTogglePoint(point)}>
|
<button key={key} type="button" className="point-item" aria-pressed={selected} title={alias} onClick={() => onTogglePoint(point)}>
|
||||||
<div className="point-copy">
|
<div className="point-copy">
|
||||||
<strong>{alias}</strong>
|
<strong>{alias}</strong>
|
||||||
<span>{selectedOnly ? `${normalizeDisplayText(metadataCache[point.isp]?.displayName, point.isp)} · ` : ""}{`Wert ${point.pointIndex}${point.unit ? ` · ${normalizeDisplayUnit(point.unit)}` : ""}`}</span>
|
{selectedOnly ? <span>{normalizeDisplayText(metadataCache[point.isp]?.displayName, point.isp)}</span> : null}
|
||||||
</div>
|
</div>
|
||||||
<span className="point-tag">{selected ? "\u2713" : point.kind}</span>
|
<span className="point-tag">{selected ? "\u2713" : point.kind}</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -673,8 +675,18 @@ export default function App() {
|
|||||||
const [themeMode, setThemeMode] = useState("system");
|
const [themeMode, setThemeMode] = useState("system");
|
||||||
const [csvDelimiter, setCsvDelimiter] = useState(";");
|
const [csvDelimiter, setCsvDelimiter] = useState(";");
|
||||||
const [sidebarPinned, setSidebarPinned] = useState(true);
|
const [sidebarPinned, setSidebarPinned] = useState(true);
|
||||||
|
const [sidebarLinkPreferences, setSidebarLinkPreferences] = useState(null);
|
||||||
|
const [globalSidebarLinks, setGlobalSidebarLinks] = useState(null);
|
||||||
|
const [globalSidebarLinksError, setGlobalSidebarLinksError] = useState("");
|
||||||
const [trendLineWidth, setTrendLineWidth] = useState("1.8");
|
const [trendLineWidth, setTrendLineWidth] = useState("1.8");
|
||||||
const [trendFocus, setTrendFocus] = useState(false);
|
const [trendFocus, setTrendFocus] = useState(false);
|
||||||
|
const [trendTouch, setTrendTouch] = useState(() => {
|
||||||
|
try {
|
||||||
|
return localStorage.getItem(TREND_TOUCH_KEY) === "1";
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
const [adminIsp, setAdminIsp] = useState("");
|
const [adminIsp, setAdminIsp] = useState("");
|
||||||
const [aliasEditor, setAliasEditor] = useState(null);
|
const [aliasEditor, setAliasEditor] = useState(null);
|
||||||
const [passwordDraft, setPasswordDraft] = useState({ currentPassword: "", nextPassword: "", repeatPassword: "" });
|
const [passwordDraft, setPasswordDraft] = useState({ currentPassword: "", nextPassword: "", repeatPassword: "" });
|
||||||
@@ -719,6 +731,7 @@ export default function App() {
|
|||||||
const canAccessAdmin = canEditAliases || canManageSources || canManageAlarms || canManageUsers || canManageRoles || canManageIntegrations || canManageRunner || canViewDebug;
|
const canAccessAdmin = canEditAliases || canManageSources || canManageAlarms || canManageUsers || canManageRoles || canManageIntegrations || canManageRunner || canViewDebug;
|
||||||
const firstAdminSection = canEditAliases ? "aliases" : canManageSources ? "sources" : canManageAlarms ? "alarms" : canManageUsers ? "users" : canManageRoles ? "roles" : canManageIntegrations ? "integrations" : canManageRunner ? "runner" : canViewDebug ? "debug" : "aliases";
|
const firstAdminSection = canEditAliases ? "aliases" : canManageSources ? "sources" : canManageAlarms ? "alarms" : canManageUsers ? "users" : canManageRoles ? "roles" : canManageIntegrations ? "integrations" : canManageRunner ? "runner" : canViewDebug ? "debug" : "aliases";
|
||||||
const sidebarCollapsed = !sidebarPinned;
|
const sidebarCollapsed = !sidebarPinned;
|
||||||
|
const sidebarLinks = sidebarLinkPreferences?.token === token ? sidebarLinkPreferences.links : [];
|
||||||
const selectedSelection = selections.find((selection) => selection.id === selectedSelectionId);
|
const selectedSelection = selections.find((selection) => selection.id === selectedSelectionId);
|
||||||
const canEditSelectedSelection = Boolean(selectedSelection && (
|
const canEditSelectedSelection = Boolean(selectedSelection && (
|
||||||
selectedSelection.ownerId === user?.id || user?.role === "admin"
|
selectedSelection.ownerId === user?.id || user?.role === "admin"
|
||||||
@@ -935,6 +948,7 @@ export default function App() {
|
|||||||
setThemeMode(pref.theme || "system");
|
setThemeMode(pref.theme || "system");
|
||||||
setCsvDelimiter(pref.csvDelimiter || ";");
|
setCsvDelimiter(pref.csvDelimiter || ";");
|
||||||
setSidebarPinned(typeof pref.sidebarPinned === "boolean" ? pref.sidebarPinned : true);
|
setSidebarPinned(typeof pref.sidebarPinned === "boolean" ? pref.sidebarPinned : true);
|
||||||
|
setSidebarLinkPreferences({ token, links: pref.sidebarLinks || [] });
|
||||||
setTrendLineWidth(String(pref.trendLineWidth || 1.8));
|
setTrendLineWidth(String(pref.trendLineWidth || 1.8));
|
||||||
setMaxTrendSeries(normalizeMaxTrendSeries(pref.maxTrendSeries));
|
setMaxTrendSeries(normalizeMaxTrendSeries(pref.maxTrendSeries));
|
||||||
setIsps(ispResult.isps || []);
|
setIsps(ispResult.isps || []);
|
||||||
@@ -1024,6 +1038,26 @@ export default function App() {
|
|||||||
.catch(() => undefined);
|
.catch(() => undefined);
|
||||||
}, [csvDelimiter, maxTrendSeries, preferencesReady, sidebarPinned, themeMode, token, trendLineWidth]);
|
}, [csvDelimiter, maxTrendSeries, preferencesReady, sidebarPinned, themeMode, token, trendLineWidth]);
|
||||||
|
|
||||||
|
const saveSidebarLinks = async (links) => {
|
||||||
|
const pending = preferenceWrite.current.then(() => api.savePreferences(token, { sidebarLinks: links }));
|
||||||
|
preferenceWrite.current = pending.catch(() => undefined);
|
||||||
|
const saved = await pending;
|
||||||
|
setSidebarLinkPreferences((current) => current?.token === token ? { token, links: saved.sidebarLinks } : current);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let ignore = false;
|
||||||
|
api.getGlobalSidebarLinks()
|
||||||
|
.then(({ links }) => { if (!ignore) setGlobalSidebarLinks(links); })
|
||||||
|
.catch(() => { if (!ignore) setGlobalSidebarLinksError("Globale Links konnten nicht geladen werden."); });
|
||||||
|
return () => { ignore = true; };
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const saveGlobalSidebarLinks = async (links) => {
|
||||||
|
const saved = await api.saveGlobalSidebarLinks(token, links);
|
||||||
|
setGlobalSidebarLinks(saved.links);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedIsp || metadataCache[selectedIsp]) {
|
if (!selectedIsp || metadataCache[selectedIsp]) {
|
||||||
return;
|
return;
|
||||||
@@ -1317,6 +1351,7 @@ export default function App() {
|
|||||||
setTrendLoading(false);
|
setTrendLoading(false);
|
||||||
setToken("");
|
setToken("");
|
||||||
setUser(null);
|
setUser(null);
|
||||||
|
setSidebarLinkPreferences(null);
|
||||||
setIsps([]);
|
setIsps([]);
|
||||||
setSelections([]);
|
setSelections([]);
|
||||||
setDashboard({ widgets: [] });
|
setDashboard({ widgets: [] });
|
||||||
@@ -1463,6 +1498,16 @@ export default function App() {
|
|||||||
savingSettings: savingSelection,
|
savingSettings: savingSelection,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleTrendTouch = () => {
|
||||||
|
const enabled = !trendTouch;
|
||||||
|
setTrendTouch(enabled);
|
||||||
|
try {
|
||||||
|
localStorage.setItem(TREND_TOUCH_KEY, enabled ? "1" : "0");
|
||||||
|
} catch {
|
||||||
|
// The mode remains available for the current page without browser storage.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const addWidget = () => {
|
const addWidget = () => {
|
||||||
const widget = {
|
const widget = {
|
||||||
id: createWidgetId(),
|
id: createWidgetId(),
|
||||||
@@ -2305,6 +2350,7 @@ export default function App() {
|
|||||||
<div className={sidebarCollapsed ? "app-shell sidebar-collapsed" : "app-shell"}>
|
<div className={sidebarCollapsed ? "app-shell sidebar-collapsed" : "app-shell"}>
|
||||||
<Sidebar
|
<Sidebar
|
||||||
collapsed={sidebarCollapsed}
|
collapsed={sidebarCollapsed}
|
||||||
|
links={[...(globalSidebarLinks || []), ...sidebarLinks]}
|
||||||
onToggle={() => setSidebarPinned((current) => !current)}
|
onToggle={() => setSidebarPinned((current) => !current)}
|
||||||
views={views.filter((view) => ({
|
views={views.filter((view) => ({
|
||||||
dashboard: canViewDashboard,
|
dashboard: canViewDashboard,
|
||||||
@@ -2319,16 +2365,28 @@ export default function App() {
|
|||||||
onLogout={handleLogout}
|
onLogout={handleLogout}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<main className={activeView === "trends" && !trendFocus ? "content trend-content" : "content"}>
|
<main className={[
|
||||||
|
"content",
|
||||||
|
activeView === "trends" && !trendFocus && "trend-content",
|
||||||
|
activeView === "trends" && trendTouch && "trend-touch",
|
||||||
|
].filter(Boolean).join(" ")}>
|
||||||
<div className="view-strip">
|
<div className="view-strip">
|
||||||
<div>
|
<div>
|
||||||
<div className="eyebrow">Ansicht</div>
|
<div className="eyebrow">Ansicht</div>
|
||||||
<strong>{currentView.label}</strong>
|
<strong>{currentView.label}</strong>
|
||||||
</div>
|
</div>
|
||||||
{activeView === "trends" && !trendFocus ? (
|
{activeView === "trends" ? (
|
||||||
<div className="view-meta">
|
<div className="view-meta">
|
||||||
|
{!trendFocus ? (
|
||||||
|
<>
|
||||||
<span className="small-badge">ISPs mit Daten: {trendIsps.length}</span>
|
<span className="small-badge">ISPs mit Daten: {trendIsps.length}</span>
|
||||||
<span className="small-badge">Aktuelle Auswahl: {workingPoints.length}</span>
|
<span className="small-badge">Aktuelle Auswahl: {workingPoints.length}</span>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
<button className="ghost-button compact-button trend-touch-toggle" type="button"
|
||||||
|
aria-pressed={trendTouch} onClick={toggleTrendTouch}>
|
||||||
|
Touch-Modus
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
@@ -2495,6 +2553,7 @@ export default function App() {
|
|||||||
allowExports
|
allowExports
|
||||||
allowFocusMode
|
allowFocusMode
|
||||||
lineWidth={Number(trendLineWidth)}
|
lineWidth={Number(trendLineWidth)}
|
||||||
|
touchMode={trendTouch}
|
||||||
{...trendChartSettingsProps}
|
{...trendChartSettingsProps}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -2640,6 +2699,7 @@ export default function App() {
|
|||||||
allowExports
|
allowExports
|
||||||
allowFocusMode
|
allowFocusMode
|
||||||
lineWidth={Number(trendLineWidth)}
|
lineWidth={Number(trendLineWidth)}
|
||||||
|
touchMode={trendTouch}
|
||||||
{...trendChartSettingsProps}
|
{...trendChartSettingsProps}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -3774,6 +3834,22 @@ export default function App() {
|
|||||||
</div>
|
</div>
|
||||||
<button className="primary-button compact-button" type="button" onClick={changePassword}>Passwort speichern</button>
|
<button className="primary-button compact-button" type="button" onClick={changePassword}>Passwort speichern</button>
|
||||||
</div>
|
</div>
|
||||||
|
<SidebarLinkSettings title="Persönliche Seitenleisten-Links" links={sidebarLinks} onSave={saveSidebarLinks} />
|
||||||
|
{user?.role === "admin" ? (
|
||||||
|
globalSidebarLinks ? (
|
||||||
|
<SidebarLinkSettings
|
||||||
|
title="Globale Seitenleisten-Links"
|
||||||
|
description="Sichtbar für alle, auch ohne Anmeldung."
|
||||||
|
links={globalSidebarLinks}
|
||||||
|
onSave={saveGlobalSidebarLinks}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="panel slim-panel span-two">
|
||||||
|
<h3>Globale Seitenleisten-Links</h3>
|
||||||
|
<p role="status">{globalSidebarLinksError || "Globale Links werden geladen ..."}</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
) : null}
|
||||||
</section>
|
</section>
|
||||||
)
|
)
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ export const api = {
|
|||||||
loadDashboardData: (token, body) => apiRequest("/dashboard/data", { method: "POST", token, body }),
|
loadDashboardData: (token, body) => apiRequest("/dashboard/data", { method: "POST", token, body }),
|
||||||
getPreferences: (token) => apiRequest("/preferences", { token }),
|
getPreferences: (token) => apiRequest("/preferences", { token }),
|
||||||
savePreferences: (token, body) => apiRequest("/preferences", { method: "PUT", token, body }),
|
savePreferences: (token, body) => apiRequest("/preferences", { method: "PUT", token, body }),
|
||||||
|
getGlobalSidebarLinks: () => apiRequest("/settings/sidebar-links"),
|
||||||
|
saveGlobalSidebarLinks: (token, links) => apiRequest("/settings/sidebar-links", { method: "PUT", token, body: { links } }),
|
||||||
getTrendDefaults: () => apiRequest("/settings/trend"),
|
getTrendDefaults: () => apiRequest("/settings/trend"),
|
||||||
saveTrendDefaults: (token, body) => apiRequest("/settings/trend", { method: "PUT", token, body }),
|
saveTrendDefaults: (token, body) => apiRequest("/settings/trend", { method: "PUT", token, body }),
|
||||||
getIntegrations: (token) => apiRequest("/integrations", { token }),
|
getIntegrations: (token) => apiRequest("/integrations", { token }),
|
||||||
|
|||||||
@@ -7,8 +7,16 @@ const icons = {
|
|||||||
collapse: "M3 5h18v14H3z M9 5v14 M16 9l-3 3 3 3",
|
collapse: "M3 5h18v14H3z M9 5v14 M16 9l-3 3 3 3",
|
||||||
login: "M14 4h6v16h-6 M4 12h12 M12 8l4 4-4 4",
|
login: "M14 4h6v16h-6 M4 12h12 M12 8l4 4-4 4",
|
||||||
logout: "M10 4H4v16h6 M8 12h12 M16 8l4 4-4 4",
|
logout: "M10 4H4v16h6 M8 12h12 M16 8l4 4-4 4",
|
||||||
|
external: "M13 4h7v7 M20 4l-9 9 M10 4H4v16h16v-6",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function linkMonogram(label) {
|
||||||
|
const words = label.split(/\s+/);
|
||||||
|
return words.length > 1
|
||||||
|
? words.slice(0, 2).map((word) => Array.from(word)[0]).join("")
|
||||||
|
: Array.from(label).slice(0, 2).join("");
|
||||||
|
}
|
||||||
|
|
||||||
function SidebarIcon({ name }) {
|
function SidebarIcon({ name }) {
|
||||||
return (
|
return (
|
||||||
<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
|
<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
|
||||||
@@ -21,7 +29,7 @@ export function SmallFootnote() {
|
|||||||
return <div className="tiny-note">by J.H. | SE Inno GmbH</div>;
|
return <div className="tiny-note">by J.H. | SE Inno GmbH</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Sidebar({ collapsed, onToggle, views, activeView, onNavigate, user, userLabel, onLogout }) {
|
export default function Sidebar({ collapsed, onToggle, views, activeView, onNavigate, links, user, userLabel, onLogout }) {
|
||||||
const toggleLabel = collapsed ? "Seitenleiste ausklappen" : "Seitenleiste einklappen";
|
const toggleLabel = collapsed ? "Seitenleiste ausklappen" : "Seitenleiste einklappen";
|
||||||
const accountLabel = user ? "Abmelden" : "Anmelden";
|
const accountLabel = user ? "Abmelden" : "Anmelden";
|
||||||
|
|
||||||
@@ -58,6 +66,20 @@ export default function Sidebar({ collapsed, onToggle, views, activeView, onNavi
|
|||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</nav>
|
</nav>
|
||||||
|
{links.length ? (
|
||||||
|
<nav className="nav-list sidebar-links" aria-label="Eigene Links">
|
||||||
|
{links.map((link, index) => (
|
||||||
|
<a key={index} className="sidebar-link nav-button" href={link.url} title={link.label} aria-label={link.label}>
|
||||||
|
{collapsed ? <span className="sidebar-link-monogram" aria-hidden="true">{linkMonogram(link.label)}</span> : (
|
||||||
|
<>
|
||||||
|
<SidebarIcon name="external" />
|
||||||
|
<span className="sidebar-link-label">{link.label}</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</a>
|
||||||
|
))}
|
||||||
|
</nav>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
<div className="sidebar-footer">
|
<div className="sidebar-footer">
|
||||||
{user && !collapsed ? (
|
{user && !collapsed ? (
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { normalizeSidebarLink } from "../../../shared/sidebar-links.mjs";
|
||||||
|
|
||||||
|
const emptyLink = { label: "", url: "" };
|
||||||
|
|
||||||
|
export default function SidebarLinkSettings({ title, description, links, onSave }) {
|
||||||
|
const [draft, setDraft] = useState(emptyLink);
|
||||||
|
const [editingIndex, setEditingIndex] = useState(null);
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
const [notice, setNotice] = useState("");
|
||||||
|
|
||||||
|
function resetDraft() {
|
||||||
|
setDraft(emptyLink);
|
||||||
|
setEditingIndex(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function persist(nextLinks) {
|
||||||
|
setSaving(true);
|
||||||
|
setError("");
|
||||||
|
setNotice("");
|
||||||
|
try {
|
||||||
|
await onSave(nextLinks);
|
||||||
|
setNotice("Seitenleisten-Links gespeichert.");
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
setError(error.message);
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
setSaving(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
setNotice("");
|
||||||
|
try {
|
||||||
|
const link = normalizeSidebarLink(draft);
|
||||||
|
const nextLinks = editingIndex === null
|
||||||
|
? [...links, link]
|
||||||
|
: links.map((existing, index) => index === editingIndex ? link : existing);
|
||||||
|
|
||||||
|
if (await persist(nextLinks)) resetDraft();
|
||||||
|
} catch (error) {
|
||||||
|
setError(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeLink(index) {
|
||||||
|
if (!window.confirm(`Link „${links[index].label}“ aus der Seitenleiste entfernen?`)) return;
|
||||||
|
if (await persist(links.filter((_, linkIndex) => linkIndex !== index))) {
|
||||||
|
if (editingIndex === index) resetDraft();
|
||||||
|
else if (editingIndex !== null && index < editingIndex) setEditingIndex(editingIndex - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="panel slim-panel span-two sidebar-link-settings">
|
||||||
|
<div className="panel-header compact-header">
|
||||||
|
<div>
|
||||||
|
<h3>{title}</h3>
|
||||||
|
{description ? <p>{description}</p> : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form className="form-grid" onSubmit={submit}>
|
||||||
|
<label>
|
||||||
|
<span>Name</span>
|
||||||
|
<input required value={draft.label} placeholder="Leitstelle" disabled={saving}
|
||||||
|
onChange={(event) => setDraft({ ...draft, label: event.target.value })} />
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>Adresse</span>
|
||||||
|
<input required type="url" placeholder="https://leitstelle.example" value={draft.url} disabled={saving}
|
||||||
|
onChange={(event) => setDraft({ ...draft, url: event.target.value })} />
|
||||||
|
</label>
|
||||||
|
<div className="button-row span-two">
|
||||||
|
<button className="primary-button compact-button" disabled={saving}>
|
||||||
|
{editingIndex === null ? "Link hinzufügen" : "Änderung speichern"}
|
||||||
|
</button>
|
||||||
|
{editingIndex === null ? null : (
|
||||||
|
<button className="ghost-button compact-button" type="button" disabled={saving} onClick={resetDraft}>Abbrechen</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{error ? <div className="error-box" role="alert">{error}</div> : null}
|
||||||
|
{notice ? <small className="muted" role="status">{notice}</small> : null}
|
||||||
|
{links.length ? (
|
||||||
|
<ul className="sidebar-link-list">
|
||||||
|
{links.map((link, index) => (
|
||||||
|
<li key={index} className="sidebar-link-setting">
|
||||||
|
<div className="sidebar-link-copy"><strong>{link.label}</strong><small className="muted">{link.url}</small></div>
|
||||||
|
<div className="button-row">
|
||||||
|
<button className="ghost-button compact-button" type="button" disabled={saving}
|
||||||
|
aria-label={`${link.label} bearbeiten`}
|
||||||
|
onClick={() => { setEditingIndex(index); setDraft(link); setError(""); setNotice(""); }}>
|
||||||
|
Bearbeiten
|
||||||
|
</button>
|
||||||
|
<button className="ghost-button compact-button danger" type="button" disabled={saving}
|
||||||
|
aria-label={`${link.label} entfernen`} onClick={() => removeLink(index)}>
|
||||||
|
Entfernen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -34,7 +34,7 @@ function formatTrendNumber(value) {
|
|||||||
return Number.isFinite(numeric) ? numeric.toFixed(2) : "--";
|
return Number.isFinite(numeric) ? numeric.toFixed(2) : "--";
|
||||||
}
|
}
|
||||||
|
|
||||||
function TimeZoomOverlay({ offset, onZoom }) {
|
function TimeZoomOverlay({ offset, onZoom, touchMode }) {
|
||||||
const activeDrag = useRef(null);
|
const activeDrag = useRef(null);
|
||||||
const [drag, setDrag] = useState(null);
|
const [drag, setDrag] = useState(null);
|
||||||
if (!offset?.width || !offset.height) return null;
|
if (!offset?.width || !offset.height) return null;
|
||||||
@@ -67,7 +67,7 @@ function TimeZoomOverlay({ offset, onZoom }) {
|
|||||||
x={offset.left} y={offset.top} width={offset.width} height={offset.height}
|
x={offset.left} y={offset.top} width={offset.width} height={offset.height}
|
||||||
fill="transparent"
|
fill="transparent"
|
||||||
onPointerDown={(event) => {
|
onPointerDown={(event) => {
|
||||||
if (!event.isPrimary || event.button !== 0) return;
|
if (!event.isPrimary || event.button !== 0 || (touchMode && event.pointerType === "touch")) return;
|
||||||
const start = position(event);
|
const start = position(event);
|
||||||
event.currentTarget.setPointerCapture(event.pointerId);
|
event.currentTarget.setPointerCapture(event.pointerId);
|
||||||
activeDrag.current = { start, end: start, pointerId: event.pointerId };
|
activeDrag.current = { start, end: start, pointerId: event.pointerId };
|
||||||
@@ -101,6 +101,7 @@ export default function TrendChart({
|
|||||||
allowExports = true,
|
allowExports = true,
|
||||||
allowFocusMode = true,
|
allowFocusMode = true,
|
||||||
compact = false,
|
compact = false,
|
||||||
|
touchMode = false,
|
||||||
lineWidth = 1.8,
|
lineWidth = 1.8,
|
||||||
settings = DEFAULT_CHART_SETTINGS,
|
settings = DEFAULT_CHART_SETTINGS,
|
||||||
onSettingsChange,
|
onSettingsChange,
|
||||||
@@ -144,6 +145,15 @@ export default function TrendChart({
|
|||||||
if (domain) setZoomDomain({ result, domain });
|
if (domain) setZoomDomain({ result, domain });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function zoomOutTime() {
|
||||||
|
if (!activeZoom) return;
|
||||||
|
const [min, max] = activeZoom;
|
||||||
|
const padding = Math.round((max - min) / 2);
|
||||||
|
const from = Math.max(baseXDomain[0], min - padding);
|
||||||
|
const to = Math.min(baseXDomain[1], max + padding);
|
||||||
|
setZoomDomain(from === baseXDomain[0] && to === baseXDomain[1] ? null : { result, domain: [from, to] });
|
||||||
|
}
|
||||||
|
|
||||||
const clearFocus = () => {
|
const clearFocus = () => {
|
||||||
setSelectedKeys([]);
|
setSelectedKeys([]);
|
||||||
};
|
};
|
||||||
@@ -298,7 +308,7 @@ export default function TrendChart({
|
|||||||
<div className="panel-header compact-header chart-toolbar">
|
<div className="panel-header compact-header chart-toolbar">
|
||||||
<div>
|
<div>
|
||||||
<h3>{title}</h3>
|
<h3>{title}</h3>
|
||||||
{rows.length > 1 && !compact ? <p>Zum Zeitzoom einen Bereich im Diagramm aufziehen.</p> : null}
|
{rows.length > 1 && !compact ? <p>{touchMode ? "Zeitzoom mit + und − einstellen." : "Zum Zeitzoom einen Bereich im Diagramm aufziehen."}</p> : null}
|
||||||
{seriesLimited ? <p>Diagrammlimit: {result.maxSeries} von {result.requestedSeriesCount} Datenpunkten.</p> : null}
|
{seriesLimited ? <p>Diagrammlimit: {result.maxSeries} von {result.requestedSeriesCount} Datenpunkten.</p> : null}
|
||||||
</div>
|
</div>
|
||||||
<div className="chart-actions">
|
<div className="chart-actions">
|
||||||
@@ -339,6 +349,7 @@ export default function TrendChart({
|
|||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
{!compact && rows.length > 1 ? <button className="ghost-button" type="button" onClick={() => zoomTime(0.25, 0.75)}>Zeitzoom +</button> : null}
|
{!compact && rows.length > 1 ? <button className="ghost-button" type="button" onClick={() => zoomTime(0.25, 0.75)}>Zeitzoom +</button> : null}
|
||||||
|
{touchMode && rows.length > 1 ? <button className="ghost-button" type="button" disabled={!activeZoom} onClick={zoomOutTime}>Zeitzoom −</button> : null}
|
||||||
{activeZoom ? <button className="ghost-button" type="button" onClick={() => setZoomDomain(null)}>Zoom zurück</button> : null}
|
{activeZoom ? <button className="ghost-button" type="button" onClick={() => setZoomDomain(null)}>Zoom zurück</button> : null}
|
||||||
{allowFocusMode ? <button className="ghost-button" type="button" onClick={onToggleExpanded}>{expanded ? "Normalansicht" : "Vollbild"}</button> : null}
|
{allowFocusMode ? <button className="ghost-button" type="button" onClick={onToggleExpanded}>{expanded ? "Normalansicht" : "Vollbild"}</button> : null}
|
||||||
</div>
|
</div>
|
||||||
@@ -418,7 +429,7 @@ export default function TrendChart({
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
{rows.length > 1 ? <Customized component={TimeZoomOverlay} onZoom={zoomTime} /> : null}
|
{rows.length > 1 ? <Customized component={TimeZoomOverlay} onZoom={zoomTime} touchMode={touchMode} /> : null}
|
||||||
</LineChart>
|
</LineChart>
|
||||||
</ResponsiveContainer>
|
</ResponsiveContainer>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+130
-4
@@ -355,6 +355,63 @@ span {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sidebar-links {
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
min-width: 0;
|
||||||
|
padding-top: 0.55rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-link {
|
||||||
|
text-decoration: none;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-link:hover {
|
||||||
|
border-color: var(--border-strong);
|
||||||
|
background: var(--surface-strong);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-link-label {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-link-monogram {
|
||||||
|
font-weight: 600;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-link-settings {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-link-list {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
display: grid;
|
||||||
|
gap: 0.35rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-link-setting {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.45rem;
|
||||||
|
padding: 0.4rem 0.55rem;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-link-copy {
|
||||||
|
display: grid;
|
||||||
|
gap: 0.15rem;
|
||||||
|
min-width: 0;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
.nav-button {
|
.nav-button {
|
||||||
min-height: 34px;
|
min-height: 34px;
|
||||||
padding: 0.38rem 0.58rem;
|
padding: 0.38rem 0.58rem;
|
||||||
@@ -820,27 +877,89 @@ span {
|
|||||||
margin-top: 0.44rem;
|
margin-top: 0.44rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.trend-touch-toggle {
|
||||||
|
min-height: 44px;
|
||||||
|
padding-inline: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trend-touch-toggle[aria-pressed="true"] {
|
||||||
|
color: var(--brand-2);
|
||||||
|
border-color: var(--border-strong);
|
||||||
|
background: color-mix(in srgb, var(--brand-2) 9%, var(--surface-strong));
|
||||||
|
}
|
||||||
|
|
||||||
|
.trend-touch :is(.view-meta, .button-row, .chart-actions, .legend-grid) {
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.55rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trend-touch :is(button, input, select, summary, .checkbox-field, .chart-check) {
|
||||||
|
min-height: 44px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trend-touch :is(button, summary, .checkbox-field, .chart-check) {
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trend-touch :is(input:not([type="checkbox"]), select) {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trend-touch :is(.checkbox-field, .chart-check) input[type="checkbox"] {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
min-height: 0;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trend-touch :is(.point-item, .legend-item) {
|
||||||
|
align-items: center;
|
||||||
|
padding-inline: 0.7rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trend-touch .point-copy strong {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trend-touch .point-list {
|
||||||
|
gap: 0.5rem;
|
||||||
|
max-height: min(42dvh, 28rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.trend-touch .trend-options > summary {
|
||||||
|
line-height: 1.5;
|
||||||
|
align-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trend-touch .chart-toolbar {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trend-touch .chart-wrapper {
|
||||||
|
touch-action: auto;
|
||||||
|
}
|
||||||
|
|
||||||
@media (min-width: 981px) and (min-height: 560px) {
|
@media (min-width: 981px) and (min-height: 560px) {
|
||||||
.content.trend-content {
|
.content.trend-content:not(.trend-touch) {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
height: 100dvh;
|
height: 100dvh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.trend-content .trend-layout {
|
.trend-content:not(.trend-touch) .trend-layout {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
grid-template-rows: minmax(0, 1fr);
|
grid-template-rows: minmax(0, 1fr);
|
||||||
}
|
}
|
||||||
|
|
||||||
.trend-content .trend-side {
|
.trend-content:not(.trend-touch) .trend-side {
|
||||||
align-self: stretch;
|
align-self: stretch;
|
||||||
align-content: stretch;
|
align-content: stretch;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
grid-template-rows: minmax(0, 1fr) auto;
|
grid-template-rows: minmax(0, 1fr) auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.trend-content .trend-point-library .point-list {
|
.trend-content:not(.trend-touch) .trend-point-library .point-list {
|
||||||
max-height: none;
|
max-height: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1178,6 +1297,13 @@ span {
|
|||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sidebar.collapsed .sidebar-links {
|
||||||
|
flex: 1 0 100%;
|
||||||
|
max-height: 6rem;
|
||||||
|
overflow: auto;
|
||||||
|
align-content: start;
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar.collapsed .sidebar-brand-row,
|
.sidebar.collapsed .sidebar-brand-row,
|
||||||
.sidebar.collapsed .sidebar-footer {
|
.sidebar.collapsed .sidebar-footer {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|||||||
Reference in new issue
Block a user