Files
PacketStation/server/packetstation/api/events.py
T
spencermandClaude Fable 5.1 5a4174e0c2
ci / frontend (push) Successful in 34s
ci / server (push) Successful in 7m15s
ci / image (push) Successful in 39s
ci / e2e (push) Successful in 2m4s
Phase 5: Supervisor and Stall screens, weld map, heat table, clock and CO verification
The shop at parity with the old build. Supervisor screen (department chips, CO headline, numbers, Change orders
on hold, station grid with clocks and CO tags, boards) and Stall screen (station picker, hero, My packets,
Submitted). Shop steps on the packet page: assign with station, welder picker and stamp; pull back; Start, Pause,
Resume; Submit with a PIN signature and the missing steps as links; review with Send to Q.C., Return to station
and Skip Q.C. route; a lead's read-only review. Weld map (pdf.js viewer with pan, pinch, zoom, full screen; marks
with leader lines; weld sheet; weld record with field CAS; carried marks). Heat map (heat table placed, dragged,
sized, removed; legacy amber tags; borrowed heat map read-only). Checklist tab with templates from settings.
VOID stamps on voided pages. Change orders: CO-n labels, supervisor verify with signature, approval copies the
heat table to the new sheet and the BOM merge keeps the shop's values. Server clock of record with VISUAL ticket
hours beside it. Presence per packet over SSE. Migration 0006 (bfx, bfy, carried_from, checklist_templates).
New endpoints /api/shop/board, /api/shop/stations, /api/shop/stall, /api/departments/{code}/people.

Tests: policy oracle for every shop action, role and status; clock arithmetic; concurrent inserts; CO apply;
frontend geometry, heat table, clock, checklist, weld sheet, screens; seven Playwright scenarios. Docs updated.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-10-16 22:46:56 -06:00

42 lines
1.7 KiB
Python

"""`GET /api/events`: the server-sent event stream (session required; locked sessions allowed)."""
from __future__ import annotations
from fastapi import APIRouter, Query, Request
from fastapi.responses import StreamingResponse
from starlette.concurrency import run_in_threadpool
from ..auth.groups import SCREENS
from ..events import EventHub, stream
from .deps import resolve_standalone, settings_of
router = APIRouter(prefix="/api", tags=["events"])
SSE_HEADERS = {"Cache-Control": "no-cache", "X-Accel-Buffering": "no", "Connection": "keep-alive"}
@router.get("/events")
async def events(
request: Request,
screen: str | None = Query(None, max_length=32),
packet_id: int | None = Query(None, ge=1, le=2**62),
) -> StreamingResponse:
"""The event stream. `packet_id` is the packet the page has open; presence carries it, so the packet page can
show who else is looking at the same packet. The client reopens the stream when the open packet changes."""
# The session check runs on its own pooled connection, returned before the stream starts
p = await run_in_threadpool(resolve_standalone, request)
hub: EventHub = request.app.state.events
sub = hub.subscribe(
session_id=p.session_id,
user_id=p.user_id,
display_name=p.user["display_name"],
screen=screen if screen in SCREENS and screen in p.screens else None,
packet_id=packet_id,
)
hello = {"session_id": str(p.session_id), "build": settings_of(request).ps_build}
return StreamingResponse(
stream(hub, sub, hello=hello, is_disconnected=request.is_disconnected),
media_type="text/event-stream",
headers=SSE_HEADERS,
)