Files
spencermandClaude Fable 5.1 6b6db0230f
ci / frontend (push) Successful in 43s
ci / server (push) Successful in 11m6s
ci / image (push) Successful in 38s
ci / e2e (push) Successful in 3m55s
Phase 8: Project Management, find bar, presence and motion
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]>
2026-10-18 15:08:34 -06:00

47 lines
2.0 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 SCREEN_LABELS, SCREENS, role_label
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.
Presence names the person with the label of the screen they have open (a screen their roles allow), else their
primary role. A locked session is left out of presence until it unlocks."""
# 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
open_screen = screen if screen in SCREENS and screen in p.screens else None
sub = hub.subscribe(
session_id=p.session_id,
user_id=p.user_id,
display_name=p.user["display_name"],
screen=open_screen,
packet_id=packet_id,
role=SCREEN_LABELS[open_screen] if open_screen else role_label(p.roles),
locked=p.locked,
)
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,
)