feat: enhance sidebar functionality and styling

- Updated sidebar component to support dynamic width based on collapsed state.
- Improved sidebar icon rendering and added user account management features.
- Introduced new trend chart settings component for better user interaction.
- Added utility functions for engineering units and trend chart settings.
- Implemented color assignment logic for trend series to enhance visual representation.
- Enhanced CSS styles for better responsiveness and usability across different screen sizes.
- Introduced new configuration for Vite server to allow shared directory access.
- Added .dockerignore file to optimize Docker build context.
This commit is contained in:
jhartworks committed 2026-11-19 13:51:04 +01:00
1 parent 2f5f86452f
commit 3203577a9d
28 files changed
+1508 -758

No files matched your search

+68 -44
View File
@@ -1,4 +1,7 @@
const META_PREFIX = "meta:isp:";
import { AUTO_UNIT, DEFAULT_ANALOG_UNIT, resolveEngineeringUnit } from "../../../shared/engineering-units.mjs";
import { LEGACY_DATUM_UTC, LEGACY_TREND_TIME_ZONE } from "../../../shared/trend-time.mjs";
const META_PREFIX = "meta:isp:";
export const LEGACY_POINT_LIMIT = 200;
export const LOCAL_POINT_LIMIT = 2000;
@@ -106,40 +109,18 @@ function parseHslColor(value) {
};
}
function createRandomPointColor(seed) {
const hue = Math.round((seed * 47 + 17 + Math.random() * 28) % 360);
const saturation = 72 + (seed % 4) * 4;
const lightness = 45 + (seed % 3) * 4;
return hslToHex(hue, saturation, lightness);
}
export function normalizeEngineeringUnit(value, kind = "analog") {
const normalizedKind = kind === "digital" ? "digital" : "analog";
const raw = String(value ?? "").trim();
if (!raw) {
return normalizedKind === "digital" ? "bool" : "\u00B0C";
}
if (normalizedKind === "digital" && /^(?:bool|boolean)$/i.test(raw)) {
return "bool";
}
if (/^\?C$/i.test(raw) || /^\u00B0\s*C$/i.test(raw) || (/[^\x00-\x7F]/.test(raw) && /C/i.test(raw))) {
return normalizedKind === "digital" ? "bool" : "\u00B0C";
}
return raw;
}
export const normalizeEngineeringUnit = resolveEngineeringUnit;
function createDefaultPoint(index) {
return {
alias: `Wert${index}`,
unit: "\u00B0C",
unit: DEFAULT_ANALOG_UNIT,
unitAuto: true,
factor: 1,
kind: "analog",
min: 0,
max: 100,
color: createRandomPointColor(index),
color: "#000000",
};
}
@@ -174,7 +155,7 @@ export async function createLegacyWideTrendTable(pool, tableName) {
CREATE TABLE IF NOT EXISTS \`${safeTable}\` (
\`id\` INT(11) NOT NULL AUTO_INCREMENT,
\`datum\` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
\`userlevel\` INT(1) NOT NULL,
\`userlevel\` INT(1) NULL DEFAULT NULL,
${buildValueColumns()},
PRIMARY KEY (\`id\`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
@@ -205,6 +186,40 @@ export async function createTrendTable(pool, tableName) {
return safeTable;
}
export async function migrateLegacyUserLevels(pool) {
const [columns] = await pool.query(`
SELECT c.TABLE_NAME AS tableName, c.COLUMN_TYPE AS columnType,
c.COLUMN_DEFAULT AS defaultValue, c.COLUMN_COMMENT AS comment
FROM information_schema.COLUMNS c
JOIN information_schema.TABLES t
ON t.TABLE_SCHEMA = c.TABLE_SCHEMA AND t.TABLE_NAME = c.TABLE_NAME
WHERE c.TABLE_SCHEMA = DATABASE()
AND c.TABLE_NAME REGEXP '^(isp[a-z0-9_]*|trend_[a-z0-9_]+)$'
AND t.TABLE_TYPE = 'BASE TABLE'
AND c.COLUMN_NAME = 'userlevel' AND c.IS_NULLABLE = 'NO'
AND EXISTS (
SELECT 1 FROM information_schema.COLUMNS v
WHERE v.TABLE_SCHEMA = c.TABLE_SCHEMA AND v.TABLE_NAME = c.TABLE_NAME
AND v.COLUMN_NAME REGEXP '^Wert[0-9]+$'
)
`);
for (const { tableName, columnType, defaultValue, comment } of columns) {
const table = sanitizeIspName(tableName);
if (!/^(?:tinyint|smallint|mediumint|int|bigint)(?:\(\d+\))?(?: unsigned)?(?: zerofill)?$/i.test(columnType)) {
throw new Error(`Unexpected userlevel column type in ${table}.`);
}
const defaultSql = /^-?\d+$/.test(String(defaultValue)) ? String(defaultValue) : "NULL";
await pool.query(`ALTER TABLE \`${table}\` MODIFY COLUMN \`userlevel\` ${columnType} NULL DEFAULT ${defaultSql} COMMENT ?`, [comment]);
}
}
export async function verifyLegacyTrendTimeZone(pool) {
const [[row]] = await pool.query("SELECT CONVERT_TZ('2026-01-01 12:00:00', ?, '+00:00') AS converted", [LEGACY_TREND_TIME_ZONE]);
if (!row.converted) {
throw new Error(`MariaDB cannot resolve LEGACY_TREND_TIME_ZONE=${LEGACY_TREND_TIME_ZONE}. Check its time zone tables.`);
}
}
async function loadSourcePointSeeds(pool, tableName) {
const safeTable = sanitizeIspName(tableName);
@@ -275,7 +290,10 @@ async function describeTrendTable(pool, dbName, tableName) {
const widePointCount = columnNames.filter((name) => /^Wert\d+$/i.test(name)).length;
if (widePointCount > 0) {
const [rows] = await pool.query(`SELECT COUNT(*) AS rowCount, MAX(datum) AS latestTimestamp FROM \`${safeTable}\``);
const [rows] = await pool.query(
`SELECT COUNT(*) AS rowCount, CONVERT_TZ(MAX(datum), ?, '+00:00') AS latestTimestamp FROM \`${safeTable}\``,
[LEGACY_TREND_TIME_ZONE]
);
return {
tableName: safeTable,
storage: "wide",
@@ -393,7 +411,8 @@ export async function ensureIspMetadata(pool, redis, isp, pointCount = LEGACY_PO
parsed.points[pointKey] = {
...defaultPoint,
alias: initialAlias,
unit: normalizeEngineeringUnit(sourceSeed?.unit || defaultPoint.unit, sourceSeed?.kind || defaultPoint.kind),
unit: normalizeEngineeringUnit(sourceSeed?.unit, sourceSeed?.kind || defaultPoint.kind, initialAlias),
unitAuto: !sourceSeed?.unit,
kind: sourceSeed?.kind || defaultPoint.kind,
};
changed = true;
@@ -412,18 +431,16 @@ export async function ensureIspMetadata(pool, redis, isp, pointCount = LEGACY_PO
point.kind = sourceSeed.kind;
changed = true;
}
const normalizedUnit = normalizeEngineeringUnit(point.unit, point.kind || sourceSeed?.kind || defaultPoint.kind);
const kind = point.kind || sourceSeed?.kind || defaultPoint.kind;
const normalizedUnit = normalizeEngineeringUnit(
point.unitAuto === true ? AUTO_UNIT : (point.unit || sourceSeed?.unit),
kind,
point.alias
);
if (normalizedUnit !== point.unit) {
point.unit = normalizedUnit;
changed = true;
}
if ((!point.unit || point.unit === normalizeEngineeringUnit(defaultPoint.unit, defaultPoint.kind)) && sourceSeed?.unit) {
const seededUnit = normalizeEngineeringUnit(sourceSeed.unit, sourceSeed.kind || point.kind || defaultPoint.kind);
if (point.unit !== seededUnit) {
point.unit = seededUnit;
changed = true;
}
}
if (!point.kind) {
point.kind = sourceSeed?.kind || defaultPoint.kind;
changed = true;
@@ -468,7 +485,8 @@ export async function ensureIspMetadata(pool, redis, isp, pointCount = LEGACY_PO
metadata.points[pointKey] = {
...metadata.points[pointKey],
alias: sourceSeed.alias || sourceSeed.name || metadata.points[pointKey].alias,
unit: normalizeEngineeringUnit(sourceSeed.unit || metadata.points[pointKey].unit, sourceSeed.kind || metadata.points[pointKey].kind),
unit: normalizeEngineeringUnit(sourceSeed.unit, sourceSeed.kind, sourceSeed.alias || sourceSeed.name),
unitAuto: !sourceSeed.unit,
kind: sourceSeed.kind || metadata.points[pointKey].kind,
};
});
@@ -581,8 +599,11 @@ export async function fetchTrendSeries(pool, redis, points, range) {
const limit = range.maxRows || 4000;
const [rows] = await pool.query(
`SELECT datum, ${columns} FROM \`${isp}\` WHERE datum BETWEEN ? AND ? ORDER BY datum DESC LIMIT ?`,
[range.from, range.to, limit]
`SELECT ${LEGACY_DATUM_UTC} AS datum, ${columns} FROM \`${isp}\`
WHERE datum BETWEEN DATE_SUB(?, INTERVAL 1 DAY) AND DATE_ADD(?, INTERVAL 1 DAY)
AND ${LEGACY_DATUM_UTC} BETWEEN ? AND ?
ORDER BY \`${isp}\`.datum DESC LIMIT ?`,
[LEGACY_TREND_TIME_ZONE, range.from, range.to, LEGACY_TREND_TIME_ZONE, range.from, range.to, limit]
);
rows.reverse().forEach((row) => {
@@ -673,7 +694,10 @@ export async function fetchLatestValues(pool, redis, points) {
.map((descriptor) => `\`Wert${descriptor.pointIndex}\``)
.join(", ");
const [rows] = await pool.query(`SELECT datum, ${columns} FROM \`${isp}\` ORDER BY datum DESC LIMIT 1`);
const [rows] = await pool.query(
`SELECT ${LEGACY_DATUM_UTC} AS datum, ${columns} FROM \`${isp}\` ORDER BY \`${isp}\`.datum DESC LIMIT 1`,
[LEGACY_TREND_TIME_ZONE]
);
const row = rows[0];
pointDescriptors.forEach((descriptor) => {
@@ -690,8 +714,8 @@ export async function fetchLatestValues(pool, redis, points) {
return values;
}
export function normalizeRange(input = {}) {
const presetDays = Number(input.presetDays || 1);
export function normalizeRange(input = {}, defaultPresetDays = 1) {
const presetDays = Number(input.presetDays || defaultPresetDays);
const maxRows = Number(input.maxRows || 4000);
const now = new Date();
const to = input.to ? new Date(input.to) : now;
+17 -28
View File
@@ -1,4 +1,7 @@
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";
const SELECTION_SEQ_KEY = "selection:seq";
const ROLE_SET_KEY = "role:names";
const UNIT_SET_KEY = "unit:symbols";
@@ -24,33 +27,12 @@ export const DEFAULT_ROLE_DEFINITIONS = [
},
];
export const DEFAULT_UNIT_DEFINITIONS = [
{ symbol: "\u00B0C", label: "Grad Celsius", isSystem: true },
{ symbol: "%", label: "Prozent", isSystem: true },
{ symbol: "K", label: "Kelvin", isSystem: true },
{ symbol: "V", label: "Volt", isSystem: true },
{ symbol: "A", label: "Ampere", isSystem: true },
{ symbol: "Pa", label: "Pascal", isSystem: true },
{ symbol: "bool", label: "Digital / Bool", isSystem: true },
];
function safeParse(jsonValue) {
return jsonValue ? JSON.parse(jsonValue) : null;
}
function normalizeUnitSymbol(value, fallback = "") {
const raw = String(value ?? "").trim();
const collapsed = raw.replace(/\s+/g, "");
if (!collapsed) {
return fallback;
}
if (/^\?C$/i.test(collapsed) || /^Â?\u00B0C$/i.test(collapsed)) {
return "\u00B0C";
}
return raw;
return canonicalUnitSymbol(value) || fallback;
}
function unitStorageKey(symbol) {
@@ -179,11 +161,14 @@ export async function listUnits(redis) {
const symbols = await redis.smembers(UNIT_SET_KEY);
const items = await Promise.all(symbols.map((symbol) => redis.get(unitStorageKey(symbol))));
return items
.map((item) => safeParse(item))
.filter(Boolean)
.map((unit) => normalizeUnitRecord(unit))
.sort((left, right) => left.symbol.localeCompare(right.symbol, "de-DE"));
const units = new Map();
for (const item of items) {
const record = safeParse(item);
if (!record) continue;
const unit = normalizeUnitRecord(record);
if (!units.has(unit.symbol) || record.symbol === unit.symbol) units.set(unit.symbol, unit);
}
return [...units.values()].sort((left, right) => left.symbol.localeCompare(right.symbol, "de-DE"));
}
export async function saveUnit(redis, unit, previousSymbol = "") {
@@ -264,11 +249,14 @@ export async function saveDashboard(redis, userId, dashboard) {
}
export async function getPreferences(redis, userId) {
return safeParse(await redis.get(`preferences:${userId}`)) || {
const stored = userId == null ? null : safeParse(await redis.get(`preferences:${userId}`));
return {
theme: "system",
csvDelimiter: ";",
sidebarPinned: true,
trendLineWidth: 1.8,
...stored,
maxTrendSeries: normalizeMaxTrendSeries(stored?.maxTrendSeries, DEFAULT_MAX_TREND_SERIES),
};
}
@@ -281,6 +269,7 @@ export async function savePreferences(redis, userId, preferences) {
csvDelimiter: preferences.csvDelimiter || current.csvDelimiter || ";",
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),
updatedAt: new Date().toISOString(),
};
await redis.set(`preferences:${userId}`, JSON.stringify(payload));