diff --git a/README.md b/README.md index 30289f2..3105177 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # 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 | | --- | --- | -| `web/` | React/Vite-Frontend fuer Login, Dashboard, Trends, Admin-Bereich, Quellen, Rollen und Benutzer | -| `api/` | Express-API fuer Auth, Rollen, Aliase, Trendabfragen, Dashboard, SQL-Import und Benutzerverwaltung | -| `collector/` | HTTP-Service fuer Protokollquellen, Datenpunkte, Scans, Imports und zyklisches Logging | +| `web/` | React/Vite-Frontend für Login, Dashboard, Trends, Admin-Bereich, Quellen, Rollen und Benutzer | +| `api/` | Express-API für Auth, Rollen, Aliase, Trendabfragen, Dashboard, SQL-Import und Benutzerverwaltung | +| `collector/` | HTTP-Service für Protokollquellen, Datenpunkte, Scans, Imports und zyklisches Logging | | `mariadb` | Persistente Trenddaten und Benutzer-Tabelle | | `redis` | Metadaten, Aliase, Rollen, Einheiten, Dashboards, Auswahlen und User-Praeferenzen | | `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 Du solltest WSL installiert haben. -Falls du das nicht hast: +Falls du das nicht hast (im Windowsterminal als Administrator): ```powershell wsl --install Ubuntu ``` @@ -138,20 +138,34 @@ Die Installation einfach durchklicken und wenn du gefragt wirst ob du Hyper-V od ### 1. Repository vorbereiten - -Wenn du git auf deinem rechner installiert hast, dann öffne eine Powershell in dem Ordner, in dem du das LTD-System haben willst. +Du solltest GIT (https://git-scm.com/install/windows)auf deinem Rechner installiert haben. +Dann öffne eine Powershell in dem Ordner, in dem du das LTD-System haben willst. (rechtsklick im Windowsexplorer ins leere --> "In Terminal öffnen") ```powershell git clone https://git.portal.se-cloud.de/Hannes/SE-LTD -cd ./SeLTD +cd ./SE-LTD ``` 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: -(rechtsklick im Windowsexplorer ins leere --> "In Terminal öffnen") +(rechtsklick im Windowsexplorer ins leere in dem gerade erstellten Ordner --> "In Terminal öffnen") ```powershell docker compose build --no-cache web api collector @@ -166,7 +180,7 @@ docker ps -a ``` ...überprüfen -### 3. Aufrufen +### 4. Aufrufen Nun stehen dir mehrere Tools zur Verfügung: | Frontend | `http://localhost:81` | --> 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. 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. -### 4. Standard-Login +### 5. Standard-Login ```text Username: admin @@ -201,17 +215,17 @@ Die wichtigsten Variablen liegen in `.env`. | 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_EMAIL` | `admin@example.com` | Initiale Admin-E-Mail | | `ADMIN_PASSWORD` | `ChangeMe123!` | Initiales Admin-Passwort | | `ADMIN_NAME` | `System Admin` | Anzeigename des Admins | | `MARIADB_ROOT_PASSWORD` | `SE3112` | MariaDB-Root-Passwort | -| `DB_PASSWORD_FALLBACK` | `root` | Fallback fuer alte Entwicklungsvolumes | -| `CORS_ORIGIN` | `*` | Erlaubter Browser-Ursprung fuer 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. | +| `DB_PASSWORD_FALLBACK` | `root` | Fallback für alte Entwicklungsvolumes | +| `CORS_ORIGIN` | `*` | Erlaubter Browser-Ursprung für API-Aufrufe | +| `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 | -| `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 - 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 - Eigener Start-/Endzeitraum moeglich - Aktuelle Werte werden separat angezeigt -- Fokusmodus fuer den Graphen +- Fokusmodus für den Graphen ### Trend-Export @@ -425,7 +439,7 @@ MariaDB speichert: - `app_users` - bestehende `isp...` 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. @@ -460,7 +474,7 @@ type .\seltd-mariadb-backup.sql | docker exec -i seltd-mariadb mariadb -uroot -p ### Redis Backup -Redis nutzt ein Docker-Volume. Fuer ein einfaches Dateibackup: +Redis nutzt ein Docker-Volume. für ein einfaches Dateibackup: ```powershell 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 - [ ] Redis-Port `6379` nicht ungeschuetzt ins Internet veroeffentlichen - [ ] 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 --- @@ -648,7 +662,7 @@ Vor produktiver Nutzung: - Bestehende breite `isp...` Tabellen bleiben kompatibel. - Neue lokale Tabellen koennen als `trend_...` Tabellen angelegt werden. - 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. --- diff --git a/api/src/index.js b/api/src/index.js index b8b9215..6c360db 100644 --- a/api/src/index.js +++ b/api/src/index.js @@ -26,6 +26,7 @@ import { import { deleteSelection, getDashboard, + getGlobalSidebarLinks, getPreferences, getRoleMap, getSelection, @@ -33,6 +34,7 @@ import { listSelections, listUnits, saveDashboard, + saveGlobalSidebarLinks, savePreferences, saveRole, saveSelection, @@ -969,6 +971,14 @@ app.put("/api/preferences", authenticateToken, wrap(async (req, res) => { 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) => { console.error(error); res.status(400).json({ error: error.message || "Unexpected error." }); diff --git a/api/src/lib/store.js b/api/src/lib/store.js index 440c825..a96c15e 100644 --- a/api/src/lib/store.js +++ b/api/src/lib/store.js @@ -1,10 +1,12 @@ const SELECTION_SET_KEY = "selection:ids"; 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 { normalizeSidebarLink } from "../../../shared/sidebar-links.mjs"; const SELECTION_SEQ_KEY = "selection:seq"; const ROLE_SET_KEY = "role:names"; const UNIT_SET_KEY = "unit:symbols"; +const GLOBAL_SIDEBAR_LINKS_KEY = "settings:sidebar-links"; export const DEFAULT_ROLE_DEFINITIONS = [ { @@ -248,6 +250,35 @@ export async function saveDashboard(redis, userId, dashboard) { 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) { const stored = userId == null ? null : safeParse(await redis.get(`preferences:${userId}`)); return { @@ -257,10 +288,12 @@ export async function getPreferences(redis, userId) { trendLineWidth: 1.8, ...stored, maxTrendSeries: normalizeMaxTrendSeries(stored?.maxTrendSeries, DEFAULT_MAX_TREND_SERIES), + sidebarLinks: readSidebarLinks(stored?.sidebarLinks), }; } export async function savePreferences(redis, userId, preferences) { + const sidebarLinks = preferences.sidebarLinks === undefined ? undefined : validateSidebarLinks(preferences.sidebarLinks); const current = await getPreferences(redis, userId); const payload = { ...current, @@ -270,6 +303,7 @@ export async function savePreferences(redis, userId, preferences) { sidebarPinned: typeof preferences.sidebarPinned === "boolean" ? preferences.sidebarPinned : current.sidebarPinned, trendLineWidth: Number.isFinite(Number(preferences.trendLineWidth)) ? Number(preferences.trendLineWidth) : Number(current.trendLineWidth || 1.8), maxTrendSeries: normalizeMaxTrendSeries(preferences.maxTrendSeries, current.maxTrendSeries), + sidebarLinks: sidebarLinks ?? current.sidebarLinks, updatedAt: new Date().toISOString(), }; await redis.set(`preferences:${userId}`, JSON.stringify(payload)); diff --git a/shared/sidebar-links.mjs b/shared/sidebar-links.mjs new file mode 100644 index 0000000..2bbccf0 --- /dev/null +++ b/shared/sidebar-links.mjs @@ -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 }; +} diff --git a/web/src/App.jsx b/web/src/App.jsx index 8818afb..b1c134c 100644 --- a/web/src/App.jsx +++ b/web/src/App.jsx @@ -4,6 +4,7 @@ import { api } from "./api.js"; import Gauge from "./components/Gauge.jsx"; import TrendChart from "./components/TrendChart.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 { DEFAULT_CHART_SETTINGS, normalizeTrendChartSettings } from "../../shared/trend-chart-settings.mjs"; import { @@ -22,6 +23,7 @@ const views = [ ]; const CHART_DRAFT_KEY = "seltd:trend-chart"; +const TREND_TOUCH_KEY = "seltd:trend-touch"; function loadChartDraft() { try { @@ -602,12 +604,12 @@ function PointLibrary({ isp, metadata, metadataCache, selectedPoints, filterText {filteredPoints.map((point) => { const key = `${point.isp}:${point.pointIndex}`; const selected = selectedKeys.has(key); - const alias = normalizeDisplayText(point.alias, `Wert ${point.pointIndex}`); + const alias = normalizeDisplayText(point.alias, "Datenpunkt"); return ( @@ -673,8 +675,18 @@ export default function App() { const [themeMode, setThemeMode] = useState("system"); const [csvDelimiter, setCsvDelimiter] = useState(";"); 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 [trendFocus, setTrendFocus] = useState(false); + const [trendTouch, setTrendTouch] = useState(() => { + try { + return localStorage.getItem(TREND_TOUCH_KEY) === "1"; + } catch { + return false; + } + }); const [adminIsp, setAdminIsp] = useState(""); const [aliasEditor, setAliasEditor] = useState(null); 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 firstAdminSection = canEditAliases ? "aliases" : canManageSources ? "sources" : canManageAlarms ? "alarms" : canManageUsers ? "users" : canManageRoles ? "roles" : canManageIntegrations ? "integrations" : canManageRunner ? "runner" : canViewDebug ? "debug" : "aliases"; const sidebarCollapsed = !sidebarPinned; + const sidebarLinks = sidebarLinkPreferences?.token === token ? sidebarLinkPreferences.links : []; const selectedSelection = selections.find((selection) => selection.id === selectedSelectionId); const canEditSelectedSelection = Boolean(selectedSelection && ( selectedSelection.ownerId === user?.id || user?.role === "admin" @@ -935,6 +948,7 @@ export default function App() { setThemeMode(pref.theme || "system"); setCsvDelimiter(pref.csvDelimiter || ";"); setSidebarPinned(typeof pref.sidebarPinned === "boolean" ? pref.sidebarPinned : true); + setSidebarLinkPreferences({ token, links: pref.sidebarLinks || [] }); setTrendLineWidth(String(pref.trendLineWidth || 1.8)); setMaxTrendSeries(normalizeMaxTrendSeries(pref.maxTrendSeries)); setIsps(ispResult.isps || []); @@ -1024,6 +1038,26 @@ export default function App() { .catch(() => undefined); }, [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(() => { if (!selectedIsp || metadataCache[selectedIsp]) { return; @@ -1317,6 +1351,7 @@ export default function App() { setTrendLoading(false); setToken(""); setUser(null); + setSidebarLinkPreferences(null); setIsps([]); setSelections([]); setDashboard({ widgets: [] }); @@ -1463,6 +1498,16 @@ export default function App() { 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 widget = { id: createWidgetId(), @@ -2305,6 +2350,7 @@ export default function App() {
setSidebarPinned((current) => !current)} views={views.filter((view) => ({ dashboard: canViewDashboard, @@ -2319,16 +2365,28 @@ export default function App() { onLogout={handleLogout} /> -
+
Ansicht
{currentView.label}
- {activeView === "trends" && !trendFocus ? ( + {activeView === "trends" ? (
- ISPs mit Daten: {trendIsps.length} - Aktuelle Auswahl: {workingPoints.length} + {!trendFocus ? ( + <> + ISPs mit Daten: {trendIsps.length} + Aktuelle Auswahl: {workingPoints.length} + + ) : null} +
) : null}
@@ -2495,6 +2553,7 @@ export default function App() { allowExports allowFocusMode lineWidth={Number(trendLineWidth)} + touchMode={trendTouch} {...trendChartSettingsProps} /> ) : ( @@ -2640,6 +2699,7 @@ export default function App() { allowExports allowFocusMode lineWidth={Number(trendLineWidth)} + touchMode={trendTouch} {...trendChartSettingsProps} /> ) : ( @@ -3774,6 +3834,22 @@ export default function App() {
+ + {user?.role === "admin" ? ( + globalSidebarLinks ? ( + + ) : ( +
+

Globale Seitenleisten-Links

+

{globalSidebarLinksError || "Globale Links werden geladen ..."}

+
+ ) + ) : null} ) ) : null} diff --git a/web/src/api.js b/web/src/api.js index 312e064..b8c5a05 100644 --- a/web/src/api.js +++ b/web/src/api.js @@ -80,6 +80,8 @@ export const api = { loadDashboardData: (token, body) => apiRequest("/dashboard/data", { method: "POST", token, body }), getPreferences: (token) => apiRequest("/preferences", { token }), 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"), saveTrendDefaults: (token, body) => apiRequest("/settings/trend", { method: "PUT", token, body }), getIntegrations: (token) => apiRequest("/integrations", { token }), diff --git a/web/src/components/Sidebar.jsx b/web/src/components/Sidebar.jsx index 3c5e125..4a04da3 100644 --- a/web/src/components/Sidebar.jsx +++ b/web/src/components/Sidebar.jsx @@ -7,8 +7,16 @@ const icons = { collapse: "M3 5h18v14H3z M9 5v14 M16 9l-3 3 3 3", login: "M14 4h6v16h-6 M4 12h12 M12 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 }) { return (
by J.H. | SE Inno GmbH
; } -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 accountLabel = user ? "Abmelden" : "Anmelden"; @@ -58,6 +66,20 @@ export default function Sidebar({ collapsed, onToggle, views, activeView, onNavi ))} + {links.length ? ( + + ) : null}
{user && !collapsed ? ( diff --git a/web/src/components/SidebarLinkSettings.jsx b/web/src/components/SidebarLinkSettings.jsx new file mode 100644 index 0000000..26b4e05 --- /dev/null +++ b/web/src/components/SidebarLinkSettings.jsx @@ -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 ( +
+
+
+

{title}

+ {description ?

{description}

: null} +
+
+
+ + +
+ + {editingIndex === null ? null : ( + + )} +
+
+ {error ?
{error}
: null} + {notice ? {notice} : null} + {links.length ? ( +
    + {links.map((link, index) => ( +
  • +
    {link.label}{link.url}
    +
    + + +
    +
  • + ))} +
+ ) : null} +
+ ); +} diff --git a/web/src/components/TrendChart.jsx b/web/src/components/TrendChart.jsx index d423475..b205a9e 100644 --- a/web/src/components/TrendChart.jsx +++ b/web/src/components/TrendChart.jsx @@ -34,7 +34,7 @@ function formatTrendNumber(value) { return Number.isFinite(numeric) ? numeric.toFixed(2) : "--"; } -function TimeZoomOverlay({ offset, onZoom }) { +function TimeZoomOverlay({ offset, onZoom, touchMode }) { const activeDrag = useRef(null); const [drag, setDrag] = useState(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} fill="transparent" onPointerDown={(event) => { - if (!event.isPrimary || event.button !== 0) return; + if (!event.isPrimary || event.button !== 0 || (touchMode && event.pointerType === "touch")) return; const start = position(event); event.currentTarget.setPointerCapture(event.pointerId); activeDrag.current = { start, end: start, pointerId: event.pointerId }; @@ -101,6 +101,7 @@ export default function TrendChart({ allowExports = true, allowFocusMode = true, compact = false, + touchMode = false, lineWidth = 1.8, settings = DEFAULT_CHART_SETTINGS, onSettingsChange, @@ -144,6 +145,15 @@ export default function TrendChart({ 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 = () => { setSelectedKeys([]); }; @@ -298,7 +308,7 @@ export default function TrendChart({

{title}

- {rows.length > 1 && !compact ?

Zum Zeitzoom einen Bereich im Diagramm aufziehen.

: null} + {rows.length > 1 && !compact ?

{touchMode ? "Zeitzoom mit + und − einstellen." : "Zum Zeitzoom einen Bereich im Diagramm aufziehen."}

: null} {seriesLimited ?

Diagrammlimit: {result.maxSeries} von {result.requestedSeriesCount} Datenpunkten.

: null}
@@ -339,6 +349,7 @@ export default function TrendChart({ /> ) : null} {!compact && rows.length > 1 ? : null} + {touchMode && rows.length > 1 ? : null} {activeZoom ? : null} {allowFocusMode ? : null}
@@ -418,7 +429,7 @@ export default function TrendChart({ /> ); })} - {rows.length > 1 ? : null} + {rows.length > 1 ? : null}
diff --git a/web/src/styles.css b/web/src/styles.css index daa6e0c..085bdc5 100644 --- a/web/src/styles.css +++ b/web/src/styles.css @@ -355,6 +355,63 @@ span { 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 { min-height: 34px; padding: 0.38rem 0.58rem; @@ -820,27 +877,89 @@ span { 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) { - .content.trend-content { + .content.trend-content:not(.trend-touch) { display: flex; flex-direction: column; height: 100dvh; } - .trend-content .trend-layout { + .trend-content:not(.trend-touch) .trend-layout { flex: 1; min-height: 0; grid-template-rows: minmax(0, 1fr); } - .trend-content .trend-side { + .trend-content:not(.trend-touch) .trend-side { align-self: stretch; align-content: stretch; min-height: 0; 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; } } @@ -1178,6 +1297,13 @@ span { 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-footer { padding: 0;