Phase 8: Project Management, find bar, presence and motion
ci / frontend (push) Successful in 43s
ci / server (push) Successful in 11m6s
ci / image (push) Successful in 38s
ci / e2e (push) Successful in 3m55s

The Project Management screen (/pm, view only) with Overview, Projects & units, Bottlenecks & aging, Hours vs target,
Quality & issues and Find jobs, the period picker, health per unit and per project, drill down, Excel (CSV) per table
and for all, and the PESCO production status report PDF with the controlled-copy stamp; every export logged as
"report exported". The find bar on every home screen: the full search set, the dropdowns, quick flags with Mine, the
flag kinds, Board and List with sorts, filters saved per browser; every filter applied by the server on the list and
the boards, with facets. Presence in packets with role, lock and revoke drop; the motion switch with reduced motion
honoured, card glides, glow and count-up; Back restores the scroll spot; sheet placement and the iPad layout pass. The
data book compared page by page with the old build and six layout differences fixed. Tests for the PM aggregates,
search, filters, presence and exports; Playwright scenarios for the PM screen, the find bar and presence at desktop and
iPad viewports. Docs updated; PLAN.md questions 38 to 42.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
2026-10-18 15:08:34 -06:00
co-authored by Claude Fable 5.1
parent 904437153d
commit 6b6db0230f
90 changed files with 10450 additions and 563 deletions
+58 -13
View File
@@ -12,7 +12,7 @@ from typing import Any
from .. import policy
from ..api.errors import ApiError
from . import packets
from . import packets, search
LEAD, SUPERVISOR = 2, 3
LEVEL_NAMES = {1: "worker", 2: "lead", 3: "supervisor"}
@@ -110,6 +110,15 @@ WHERE p.id = ANY(%s)
"""
KPI_SQL = """
SELECT p.id, p.status::text AS status, s.clock_elapsed_ms, s.clock_running_since, s.clock_started_at,
(SELECT coalesce(sum(w.target_hrs), 0) FROM packet_work_orders w WHERE w.packet_id = p.id) AS target_hrs
FROM packets p
LEFT JOIN packet_stages s ON s.packet_id = p.id AND s.closed_at IS NULL
WHERE p.id = ANY(%s)
"""
def add_shop_fields(conn: Any, cards: list[dict[str, Any]]) -> list[dict[str, Any]]:
"""Add the shop fields to list_cards cards, in place: welder_stamp, clock {elapsed_ms, running}, target_hrs,
open_cos [{co_no, label, review}] and return_note."""
@@ -215,8 +224,12 @@ def board(
dept: str | None = None,
project_id: int | None = None,
unit_id: int | None = None,
filters: Mapping[str, Any] | None = None,
) -> dict[str, Any]:
"""GET /api/shop/board. 403 forbidden when the principal leads no department, or names one outside the scope."""
"""GET /api/shop/board. 403 forbidden when the principal leads no department, or names one outside the scope.
`filters` are the find bar's (search.parse_filters): they narrow the cards of every column and the station
grid. The KPIs follow the department, project and unit only."""
scope = board_scope(conn, pp)
if not scope:
raise ApiError(403, "forbidden", MSG_NO_LEAD)
@@ -233,7 +246,8 @@ def board(
{"depts": codes, "statuses": list(BOARD_STATUSES), "limit": BOARD_LIMIT, **fparams},
)
]
cards = _cards(conn, pp, ids)
narrow = search.narrowing(filters or {})
cards = _cards(conn, pp, ids, **search.board_filters(filters or {}))
columns: dict[str, list[dict[str, Any]]] = {k: [] for k in COLUMNS.values()}
at_station: list[dict[str, Any]] = []
@@ -290,14 +304,42 @@ def board(
}
)
kpis = {
"ready": len(columns["ready"]),
"at_stations": len(at_station),
"review": len(columns["review"]),
"elapsed_ms": sum(int(c["clock"]["elapsed_ms"]) for c in at_station),
"target_hrs": round(sum(float(c["target_hrs"]) for c in at_station), 3),
if narrow:
kpis = _board_kpis(conn, ids)
else:
kpis = {
"ready": len(columns["ready"]),
"at_stations": len(at_station),
"review": len(columns["review"]),
"elapsed_ms": sum(int(c["clock"]["elapsed_ms"]) for c in at_station),
"target_hrs": round(sum(float(c["target_hrs"]) for c in at_station), 3),
}
return {
"depts": depts,
"kpis": kpis,
"cos": cos,
"columns": columns,
"facets": search.facets(conn, ids=ids),
}
return {"depts": depts, "kpis": kpis, "cos": cos, "columns": columns}
def _board_kpis(conn: Any, ids: list[int]) -> dict[str, Any]:
"""The supervisor KPIs over the board's whole scope, when the find bar narrows the cards."""
counts = {"ready": 0, "review": 0, "at_stations": 0}
elapsed = 0
target = 0.0
if ids:
now = conn.execute("SELECT now()").fetchone()[0]
for r in packets.rows(conn, KPI_SQL, (ids,)):
st = r["status"]
if st in ("ready", "review"):
counts[st] += 1
elif st in policy.ACTIVE:
counts["at_stations"] += 1
if r.get("clock_elapsed_ms") is not None:
elapsed += int(packets.clock_of({**r, "closed_at": None}, now)["elapsed_ms"])
target += float(r.get("target_hrs") or 0)
return {**counts, "elapsed_ms": elapsed, "target_hrs": round(target, 3)}
def can_verify(pp: policy.Principal, dept: str) -> bool:
@@ -333,8 +375,9 @@ def stations_for(conn: Any, pp: policy.Principal) -> list[dict[str, Any]]:
return out
def stall(conn: Any, pp: policy.Principal, station_id: int) -> dict[str, Any]:
"""GET /api/shop/stall: the packets at one station. 403 when the station is not in the principal's list."""
def stall(conn: Any, pp: policy.Principal, station_id: int, filters: Mapping[str, Any] | None = None) -> dict[str, Any]:
"""GET /api/shop/stall: the packets at one station. 403 when the station is not in the principal's list.
`filters` (the find bar's) narrow the station's cards; Mine is the station's own work."""
mine_list = {int(s["id"]): s for s in stations_for(conn, pp)}
st = mine_list.get(int(station_id))
if st is None:
@@ -345,11 +388,13 @@ def stall(conn: Any, pp: policy.Principal, station_id: int) -> dict[str, Any]:
" AND status IN ('assigned', 'in_progress', 'review') ORDER BY updated_at, id LIMIT %s",
(int(station_id), BOARD_LIMIT),
)
cards = _cards(conn, pp, [int(r["id"]) for r in found])
ids = [int(r["id"]) for r in found]
cards = _cards(conn, pp, ids, **search.board_filters(filters or {}))
return {
"station": {"id": st["id"], "name": st["name"], "dept_code": st["dept_code"], "dept_name": st["dept_name"]},
"mine": [c for c in cards if c["status"] in policy.ACTIVE],
"submitted": [c for c in cards if c["status"] == "review"],
"facets": search.facets(conn, ids=ids),
}