feat: Extend widget configuration for activity overview and improve validation
- Added support for the "activity_overview" widget in the dashboard configuration, allowing for chart_days validation. - Refactored validation logic to streamline error handling for both "body_overview" and "activity_overview" widgets. - Updated the widget catalog description to reflect the new configuration options. - Enhanced the DashboardLabPage to manage chart_days input for both widgets, improving user experience. - Bumped app_dashboard version to 1.3.0 to reflect these enhancements.
This commit is contained in:
1 parent
4493b140bd
commit
b617212145
9 files changed
+164
-60
No files matched your search
@@ -11,7 +11,7 @@ from typing import Any
|
||||
|
||||
MAX_WIDGET_CONFIG_JSON_BYTES = 1024
|
||||
|
||||
WIDGETS_ALLOWING_CONFIG: frozenset[str] = frozenset({"body_overview"})
|
||||
WIDGETS_ALLOWING_CONFIG: frozenset[str] = frozenset({"body_overview", "activity_overview"})
|
||||
|
||||
|
||||
def _config_json_size_bytes(config: dict[str, Any]) -> int:
|
||||
@@ -32,33 +32,35 @@ def validate_widget_entry_config(widget_id: str, raw: Any) -> dict[str, Any]:
|
||||
raise ValueError(f"Widget {widget_id}: keine Konfiguration unterstützt")
|
||||
|
||||
if widget_id == "body_overview":
|
||||
return _validate_body_overview_config(raw)
|
||||
return _validate_chart_days_only(raw, label="body_overview")
|
||||
if widget_id == "activity_overview":
|
||||
return _validate_chart_days_only(raw, label="activity_overview")
|
||||
|
||||
raise ValueError(f"Widget {widget_id}: keine Konfiguration unterstützt")
|
||||
|
||||
|
||||
def _validate_body_overview_config(raw: dict[str, Any]) -> dict[str, Any]:
|
||||
def _parse_chart_days(v: Any, label: str) -> int:
|
||||
if isinstance(v, bool):
|
||||
raise ValueError(f"{label}: chart_days muss ganze Zahl sein")
|
||||
if isinstance(v, float):
|
||||
if not math.isfinite(v):
|
||||
raise ValueError(f"{label}: chart_days muss ganze Zahl sein")
|
||||
if abs(v - round(v)) > 1e-9:
|
||||
raise ValueError(f"{label}: chart_days muss ganze Zahl sein")
|
||||
return int(round(v))
|
||||
if isinstance(v, int):
|
||||
return v
|
||||
raise ValueError(f"{label}: chart_days muss ganze Zahl sein")
|
||||
|
||||
|
||||
def _validate_chart_days_only(raw: dict[str, Any], *, label: str) -> dict[str, Any]:
|
||||
allowed = frozenset({"chart_days"})
|
||||
unknown = set(raw) - allowed
|
||||
if unknown:
|
||||
raise ValueError(f"body_overview: unbekannte config-Felder: {sorted(unknown)}")
|
||||
out: dict[str, Any] = {}
|
||||
raise ValueError(f"{label}: unbekannte config-Felder: {sorted(unknown)}")
|
||||
if "chart_days" not in raw:
|
||||
return out
|
||||
v = raw["chart_days"]
|
||||
if isinstance(v, bool):
|
||||
raise ValueError("body_overview: chart_days muss ganze Zahl sein")
|
||||
if isinstance(v, float):
|
||||
if not math.isfinite(v):
|
||||
raise ValueError("body_overview: chart_days muss ganze Zahl sein")
|
||||
if abs(v - round(v)) > 1e-9:
|
||||
raise ValueError("body_overview: chart_days muss ganze Zahl sein")
|
||||
v = int(round(v))
|
||||
elif isinstance(v, int):
|
||||
pass
|
||||
else:
|
||||
raise ValueError("body_overview: chart_days muss ganze Zahl sein")
|
||||
return {}
|
||||
v = _parse_chart_days(raw["chart_days"], label)
|
||||
if v < 7 or v > 90:
|
||||
raise ValueError("body_overview: chart_days muss zwischen 7 und 90 liegen")
|
||||
out["chart_days"] = v
|
||||
return out
|
||||
raise ValueError(f"{label}: chart_days muss zwischen 7 und 90 liegen")
|
||||
return {"chart_days": v}
|
||||
Reference in new issue
Block a user