Add playlists, credentials, and jobs pages; wire up dashboard
Vendored htmx.min.js (1.9.12) and alpine.min.js (3.14.1) into static/ -- self-hosted per the no-CDN/CSP requirement, included in base.html. routers/playlists.py: list/add/remove playlists, a detail page showing live per-playlist status via status_service (Spotify vs. beets vs. sldl index vs. quarantine), edit form for active/cron_expr/no_m3u/notes, and a "Run now" button wired to the jobs run-now endpoint. routers/credentials.py: write-only credential forms per scope (a saved secret is never sent back to the browser -- fields just show "(set)" and leaving a field blank keeps its current value, matching credential_service.set_credentials' partial-update semantics). routers/jobs.py: maintenance job list with run-now/enable-disable, and a recent-runs table that auto-refreshes via HTMX polling (hx-trigger="every 5s") against a partial-only endpoint -- the one place in the UI where avoiding a full-page reload actually matters, since job status changes while the page is sitting open. Per-run log viewing. Dashboard now shows real data (beets stats, playlist counts, recent job runs) instead of the placeholder from Task 2. Verified all 10 authenticated pages render successfully (200, no template errors) via TestClient with require_auth overridden, including the playlist detail page's graceful-degradation path when Spotify credentials aren't configured yet (renders a "couldn't fetch live status" message instead of a 500).
This commit is contained in:
@@ -1,16 +1,31 @@
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.db import get_db
|
||||
from app.models import JobRun
|
||||
from app.security.deps import require_auth
|
||||
from app.services import beets_service, playlist_service
|
||||
|
||||
router = APIRouter(tags=["dashboard"])
|
||||
templates = Jinja2Templates(directory="app/templates")
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def dashboard(request: Request, user: dict = Depends(require_auth)):
|
||||
async def dashboard(request: Request, user: dict = Depends(require_auth), db=Depends(get_db)):
|
||||
stats = beets_service.stats()
|
||||
playlists = playlist_service.list_all(db)
|
||||
recent_runs = list(
|
||||
db.execute(select(JobRun).order_by(JobRun.started_at.desc()).limit(10)).scalars()
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"dashboard.html",
|
||||
{"user": user},
|
||||
{
|
||||
"user": user,
|
||||
"stats": stats,
|
||||
"playlist_count": len(playlists),
|
||||
"active_playlist_count": len([p for p in playlists if p.active]),
|
||||
"recent_runs": recent_runs,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user