Improve shift report mode navigation

This commit is contained in:
admin committed 2026-10-20 15:19:07 +02:00
1 parent dcde029bc7
commit 211fb45d52
5 files changed
+61 -3

No files matched your search

@@ -0,0 +1,29 @@
"""Shared, server-rendered navigation between the two web workflows."""
from typing import Literal
Mode = Literal["shift", "order"]
MODE_NAV_CSS = """
.mode-nav{display:inline-flex;gap:.25rem;padding:.25rem;margin-bottom:1rem;
background:#e8eef3;border:1px solid #aab9c5;border-radius:.55rem}
.mode-nav a{display:block;padding:.55rem .85rem;border:1px solid transparent;
border-radius:.35rem;color:#182c3b;font-weight:600;text-decoration:none}
.mode-nav a:hover{background:#d4e0e9}
.mode-nav a[aria-current="page"]{background:#294d67;border-color:#294d67;color:white}
.mode-nav a[aria-current="page"]:hover{background:#294d67}
.mode-nav a:focus-visible{outline:3px solid #bf6525;outline-offset:2px}
"""
def render_mode_navigation(active: Mode) -> str:
if active not in ("shift", "order"):
raise ValueError("Unknown web workflow")
links = (("shift", "/", "Schichtbericht"),
("order", "/orders", "Fertigungsauftrag"))
items = "".join(
f'<a href="{href}"' + (' aria-current="page"' if mode == active else "")
+ f">{label}</a>"
for mode, href, label in links
)
return f'<nav class="mode-nav" aria-label="Bereich wählen">{items}</nav>'
@@ -3,6 +3,10 @@
from html import escape
from urllib.parse import urlencode
from production_analytics.presentation.mode_navigation import (
MODE_NAV_CSS,
render_mode_navigation,
)
from production_analytics.service.production_order import (
ProductionOrderDetail,
ProductionOrderSearchResult,
@@ -23,8 +27,8 @@ table {{width:100%;border-collapse:collapse}} th,td {{text-align:left;padding:.7
border-bottom:1px solid #c9d1d8}} th {{background:#e8eef3}}
.table-scroll {{overflow-x:auto}} .metadata {{color:#526473;font-size:.9rem}}
.error {{padding:1rem;background:#ffe8e5;border-left:4px solid #a32920}}
</style></head><body><main><nav><a href="/">Schichtberichte</a> ·
<a href="/orders">Fertigungsauftrag suchen</a></nav>{body}</main></body></html>'''
{MODE_NAV_CSS}</style></head><body><main>{render_mode_navigation("order")}
{body}</main></body></html>'''
def _form(query: str) -> str:
@@ -3,6 +3,10 @@
from html import escape
from math import fsum
from production_analytics.presentation.mode_navigation import (
MODE_NAV_CSS,
render_mode_navigation,
)
from production_analytics.presentation.shift_report import (
MaterialPieBlock,
TableBlock,
@@ -117,7 +121,7 @@ width:220px; max-width:100%; margin:.75rem auto}}
.material-swatch {{width:.9rem; height:.9rem; flex-shrink:0; margin-top:.2rem}}
@media(max-width:850px) {{.material-layout {{grid-template-columns:minmax(0, 1fr)}}}}
.error {{padding:1rem; background:#ffe8e5; border-left:4px solid #a32920}}
</style></head><body><main><nav><a href="/orders">Fertigungsauftrag suchen</a></nav>
{MODE_NAV_CSS}</style></head><body><main>{render_mode_navigation("shift")}
<h1>Live-Schichtberichte</h1>
<form method="get" action="/">
<label>Datum (Schichtbeginn)<input type="date" name="date" required
+12
View File
@@ -15,6 +15,7 @@ from production_analytics.erp.gateway import (
OrderConfirmationGroup,
OrderConfirmationRow,
)
from production_analytics.presentation.production_order_html import render_detail, render_search
from production_analytics.service.production_order import ProductionOrderService
from production_analytics.service.shift_report_config import load_shift_report_machines
@@ -166,11 +167,22 @@ def test_search_and_detail_web_pages_and_encoded_report_link():
assert status == "200 OK" and ORDER in text and "/order?production_order=" in text
status, text = web_request(app, "/order", urlencode({"production_order": ORDER}))
assert status == "200 OK"
assert '<a href="/orders" aria-current="page">Fertigungsauftrag</a>' in text
assert "Article name" in text and "10.00 m²" in text
assert "Schichtbericht" in text
assert "/?date=2026-10-19&amp;shift=early&amp;machine=Gitter+3" in text
@pytest.mark.parametrize("html", [render_search(), render_detail(detail=None)],
ids=["search", "detail"])
def test_order_pages_mark_order_mode_active(html):
assert '<nav class="mode-nav" aria-label="Bereich wählen">' in html
assert '<a href="/">Schichtbericht</a>' in html
assert '<a href="/orders" aria-current="page">Fertigungsauftrag</a>' in html
assert html.split("</style>", 1)[1].count('aria-current="page"') == 1
assert ".mode-nav a:focus-visible" in html
def test_order_pages_escape_erp_text():
unsafe = "<script>alert(1)</script>"
gateway = FakeGateway(
+9
View File
@@ -25,6 +25,15 @@ def page(value):
)
def test_shift_report_mode_navigation():
html = page(material_report((10,)))
assert '<nav class="mode-nav" aria-label="Bereich wählen">' in html
assert '<a href="/" aria-current="page">Schichtbericht</a>' in html
assert '<a href="/orders">Fertigungsauftrag</a>' in html
assert html.split("</style>", 1)[1].count('aria-current="page"') == 1
assert ".mode-nav a:focus-visible" in html
def test_multiple_materials_chart_and_table():
html = page(material_report((10, 30)))
assert '<figure class="material-chart">' in html