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]>
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
A thread holds a sync psycopg connection (app role) doing LISTEN ps_events and pushes each NOTIFY payload
|
||||
to the event loop with call_soon_threadsafe. It reconnects with backoff when the database drops. Presence is
|
||||
kept in process (one uvicorn worker); phase 8 completes it.
|
||||
kept in process (one uvicorn worker): one entry per (user, screen, packet) with the display name and the role
|
||||
label. A locked session drops out of presence until it is unlocked; a revoked one drops out at once. A browser
|
||||
that goes away drops out when its stream ends (the stream's `finally`, at the latest on the next ping).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -15,6 +17,7 @@ import threading
|
||||
import uuid
|
||||
from collections.abc import AsyncIterator, Awaitable, Callable
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -44,9 +47,17 @@ class Subscriber:
|
||||
display_name: str
|
||||
screen: str | None = None
|
||||
packet_id: int | None = None # the packet the subscriber has open, for "Also here" on the packet page
|
||||
role: str = "" # the label shown beside the name: the screen open, else the person's primary role
|
||||
since: datetime = field(default_factory=lambda: datetime.now(UTC))
|
||||
locked: bool = False # the session is locked: left out of presence until it is unlocked
|
||||
revoked: bool = False # the session was revoked: left out of presence while the stream winds down
|
||||
id: str = field(default_factory=lambda: uuid.uuid4().hex)
|
||||
closed: bool = False
|
||||
|
||||
@property
|
||||
def present(self) -> bool:
|
||||
return not (self.closed or self.locked or self.revoked)
|
||||
|
||||
def put(self, item: Item) -> None:
|
||||
"""Called on the event loop."""
|
||||
try:
|
||||
@@ -74,6 +85,8 @@ class EventHub:
|
||||
display_name: str,
|
||||
screen: str | None = None,
|
||||
packet_id: int | None = None,
|
||||
role: str = "",
|
||||
locked: bool = False,
|
||||
) -> Subscriber:
|
||||
"""Register a subscriber on the running loop and broadcast presence."""
|
||||
sub = Subscriber(
|
||||
@@ -84,6 +97,8 @@ class EventHub:
|
||||
display_name=display_name,
|
||||
screen=screen,
|
||||
packet_id=packet_id,
|
||||
role=role,
|
||||
locked=locked,
|
||||
)
|
||||
with self._lock:
|
||||
self._subs[sub.id] = sub
|
||||
@@ -97,17 +112,37 @@ class EventHub:
|
||||
if removed is not None:
|
||||
self._broadcast_presence()
|
||||
|
||||
def presence(self) -> dict[str, Any]:
|
||||
def _users(self) -> list[dict[str, Any]]:
|
||||
"""One entry per (user, screen, packet) among the present subscribers, the earliest `since` kept."""
|
||||
with self._lock:
|
||||
subs = list(self._subs.values())
|
||||
subs = [s for s in self._subs.values() if s.present]
|
||||
seen: dict[tuple[str, str | None, int | None], dict[str, Any]] = {}
|
||||
for s in subs:
|
||||
for s in sorted(subs, key=lambda x: x.since):
|
||||
seen.setdefault(
|
||||
(s.user_id, s.screen, s.packet_id),
|
||||
{"user_id": s.user_id, "display_name": s.display_name, "screen": s.screen, "packet_id": s.packet_id},
|
||||
{
|
||||
"user_id": s.user_id,
|
||||
"display_name": s.display_name,
|
||||
"role": s.role,
|
||||
"screen": s.screen,
|
||||
"packet_id": s.packet_id,
|
||||
"since": s.since.isoformat(),
|
||||
},
|
||||
)
|
||||
users = sorted(seen.values(), key=lambda u: (u["display_name"].lower(), u["screen"] or "", u["packet_id"] or 0))
|
||||
return {"users": users}
|
||||
return sorted(seen.values(), key=lambda u: (u["display_name"].lower(), u["screen"] or "", u["packet_id"] or 0))
|
||||
|
||||
def presence(self) -> dict[str, Any]:
|
||||
"""{users: [{user_id, display_name, role, screen, packet_id, since}]}, locked and revoked sessions left
|
||||
out."""
|
||||
return {"users": self._users()}
|
||||
|
||||
def presence_by_screen(self) -> dict[str, list[dict[str, Any]]]:
|
||||
"""The same users grouped by the screen they have open ("none" for a stream without a screen), for the
|
||||
Admin "who's in" view."""
|
||||
out: dict[str, list[dict[str, Any]]] = {}
|
||||
for u in self._users():
|
||||
out.setdefault(u["screen"] or "none", []).append(u)
|
||||
return out
|
||||
|
||||
def _send(self, sub: Subscriber, item: Item) -> None:
|
||||
try:
|
||||
@@ -134,11 +169,30 @@ class EventHub:
|
||||
name = str(data.pop("event", "changed"))
|
||||
with self._lock:
|
||||
subs = list(self._subs.values())
|
||||
changed = False
|
||||
if name == "session":
|
||||
target = str(data.get("session_id"))
|
||||
subs = [s for s in subs if s.session_id == target]
|
||||
changed = self._mark(subs, str(data.get("action") or ""))
|
||||
for s in subs:
|
||||
self._send(s, (name, data))
|
||||
if changed:
|
||||
self._broadcast_presence()
|
||||
|
||||
def _mark(self, subs: list[Subscriber], action: str) -> bool:
|
||||
"""Apply a session event to that session's subscribers. True when presence changed."""
|
||||
changed = False
|
||||
with self._lock:
|
||||
for s in subs:
|
||||
before = s.present
|
||||
if action == "locked":
|
||||
s.locked = True
|
||||
elif action == "unlocked":
|
||||
s.locked = False
|
||||
elif action == "revoked":
|
||||
s.revoked = True
|
||||
changed = changed or before != s.present
|
||||
return changed
|
||||
|
||||
# ------------------------------------------------ listener thread
|
||||
|
||||
|
||||
Reference in New Issue
Block a user