Dashboard detail, library filtering/pagination, simplified playlist times,
job descriptions Dashboard: format breakdown (FLAC/MP3/etc. counts), approximate library size (bitrate*length/8, same approximation `beet stats` itself uses -- verified to match its "100.5 GiB" output exactly against the real library), and a credential auth-state summary per scope (configured y/n plus, for Bandcamp, cookie expiry parsed locally from the stored cookie jar -- deliberately not a live network probe like pipeline-status.sh's Qobuz check, since this renders on every dashboard load). Library: was one unfiltered page dumping all 4072 tracks. Added search (artist/title/album), playlist and format filter dropdowns, and real SQL-level pagination (LIMIT/OFFSET, not fetch-everything-then-slice). beets_service gained count_items()/distinct_formats() to support this. Playlists: cron_expr is still the stored/scheduled representation, but the UI now shows and edits a plain daily time picker instead of raw cron syntax -- every playlist schedule today is a simple daily HH:MM anyway. playlist_service.cron_to_time()/time_to_cron() convert at the router boundary; verified round-trip against all real playlist cron values. Jobs: each maintenance job now shows a short one-line description of what it actually does (MAINTENANCE_JOB_DESCRIPTIONS), and "next run" is formatted consistently with playlists' time style (HH:MM, with a day qualifier for non-today runs -- maintenance jobs can be weekly/monthly, unlike playlists' plain daily schedule). Verified end-to-end against the real production data (4072 tracks, 100.5 GiB, real credentials): stats/format-breakdown/search/pagination all correct, all 7 credential scopes report configured with Bandcamp's real cookie expiry (325 days), and a full authenticated page-render sweep (dashboard, library with every filter combination, playlist detail, jobs) all returned 200 with no template errors.
This commit is contained in:
@@ -5,12 +5,21 @@ 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
|
||||
from app.services import beets_service, credential_service, playlist_service
|
||||
|
||||
router = APIRouter(tags=["dashboard"])
|
||||
templates = Jinja2Templates(directory="app/templates")
|
||||
|
||||
|
||||
def _human_bytes(n: int) -> str:
|
||||
size = float(n)
|
||||
for unit in ("B", "KB", "MB", "GB", "TB"):
|
||||
if size < 1024 or unit == "TB":
|
||||
return f"{size:.1f} {unit}"
|
||||
size /= 1024
|
||||
return f"{size:.1f} TB"
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def dashboard(request: Request, user: dict = Depends(require_auth), db=Depends(get_db)):
|
||||
stats = beets_service.stats()
|
||||
@@ -24,8 +33,10 @@ async def dashboard(request: Request, user: dict = Depends(require_auth), db=Dep
|
||||
{
|
||||
"user": user,
|
||||
"stats": stats,
|
||||
"total_size_human": _human_bytes(stats.get("total_bytes", 0)),
|
||||
"playlist_count": len(playlists),
|
||||
"active_playlist_count": len([p for p in playlists if p.active]),
|
||||
"recent_runs": recent_runs,
|
||||
"auth_states": credential_service.auth_states(db),
|
||||
},
|
||||
)
|
||||
|
||||
+16
-1
@@ -12,6 +12,19 @@ router = APIRouter(prefix="/jobs", tags=["jobs"])
|
||||
templates = Jinja2Templates(directory="app/templates")
|
||||
|
||||
|
||||
def _format_next_run(dt) -> str:
|
||||
"""Same HH:MM (24h, zero-padded) convention the playlists' simplified
|
||||
time field uses, with a short day qualifier when it's not today --
|
||||
maintenance jobs can be weekly/monthly, so the date can't just be
|
||||
dropped the way it is for playlists' plain daily time."""
|
||||
if dt is None:
|
||||
return "-"
|
||||
now = dt.__class__.now(dt.tzinfo)
|
||||
if dt.date() == now.date():
|
||||
return dt.strftime("%H:%M")
|
||||
return dt.strftime("%a %H:%M")
|
||||
|
||||
|
||||
def _job_list_context(db):
|
||||
scheduler = scheduler_service.get_scheduler()
|
||||
registered = {j.id: j for j in (scheduler.get_jobs() if scheduler else [])}
|
||||
@@ -21,10 +34,12 @@ def _job_list_context(db):
|
||||
maintenance_jobs = []
|
||||
for job_key in scheduler_service.MAINTENANCE_JOBS:
|
||||
job = registered.get(job_key)
|
||||
next_run = getattr(job, "next_run_time", None) if job else None
|
||||
maintenance_jobs.append(
|
||||
{
|
||||
"job_key": job_key,
|
||||
"next_run": getattr(job, "next_run_time", None) if job else None,
|
||||
"description": scheduler_service.MAINTENANCE_JOB_DESCRIPTIONS.get(job_key, ""),
|
||||
"next_run": _format_next_run(next_run),
|
||||
"enabled": enabled_by_key.get(job_key, True),
|
||||
}
|
||||
)
|
||||
|
||||
+31
-3
@@ -10,11 +10,39 @@ router = APIRouter(prefix="/library", tags=["library"])
|
||||
templates = Jinja2Templates(directory="app/templates")
|
||||
|
||||
|
||||
PAGE_SIZE = 50
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def library_index(request: Request, grouping: str | None = None, user: dict = Depends(require_auth)):
|
||||
items = beets_service.query_items(grouping=grouping)
|
||||
async def library_index(
|
||||
request: Request,
|
||||
grouping: str | None = None,
|
||||
format: str | None = None,
|
||||
q: str | None = None,
|
||||
page: int = 1,
|
||||
user: dict = Depends(require_auth),
|
||||
):
|
||||
page = max(1, page)
|
||||
offset = (page - 1) * PAGE_SIZE
|
||||
items = beets_service.query_items(grouping=grouping, search=q, format=format, limit=PAGE_SIZE, offset=offset)
|
||||
total = beets_service.count_items(grouping=grouping, search=q, format=format)
|
||||
total_pages = max(1, (total + PAGE_SIZE - 1) // PAGE_SIZE)
|
||||
stats = beets_service.stats()
|
||||
|
||||
return templates.TemplateResponse(
|
||||
request, "library/index.html", {"items": items, "grouping": grouping}
|
||||
request,
|
||||
"library/index.html",
|
||||
{
|
||||
"items": items,
|
||||
"grouping": grouping or "",
|
||||
"format": format or "",
|
||||
"q": q or "",
|
||||
"page": page,
|
||||
"total_pages": total_pages,
|
||||
"total": total,
|
||||
"all_formats": beets_service.distinct_formats(),
|
||||
"all_groupings": stats["groupings"],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -13,20 +13,27 @@ templates = Jinja2Templates(directory="app/templates")
|
||||
@router.get("")
|
||||
async def playlists_index(request: Request, user: dict = Depends(require_auth), db=Depends(get_db)):
|
||||
playlists = playlist_service.list_all(db)
|
||||
return templates.TemplateResponse(request, "playlists/index.html", {"playlists": playlists})
|
||||
sync_times = {p.id: playlist_service.cron_to_time(p.cron_expr) for p in playlists}
|
||||
return templates.TemplateResponse(
|
||||
request, "playlists/index.html", {"playlists": playlists, "sync_times": sync_times}
|
||||
)
|
||||
|
||||
|
||||
@router.post("")
|
||||
async def create_playlist(
|
||||
name: str = Form(...),
|
||||
spotify_url: str = Form(...),
|
||||
cron_expr: str = Form(""),
|
||||
sync_time: str = Form(""),
|
||||
no_m3u: bool = Form(False),
|
||||
user: dict = Depends(require_auth),
|
||||
db=Depends(get_db),
|
||||
):
|
||||
playlist_service.create(
|
||||
db, name=name, spotify_url=spotify_url, cron_expr=cron_expr or None, no_m3u=no_m3u
|
||||
db,
|
||||
name=name,
|
||||
spotify_url=spotify_url,
|
||||
cron_expr=playlist_service.time_to_cron(sync_time),
|
||||
no_m3u=no_m3u,
|
||||
)
|
||||
return RedirectResponse(url="/playlists", status_code=303)
|
||||
|
||||
@@ -49,7 +56,12 @@ async def playlist_detail(
|
||||
return templates.TemplateResponse(
|
||||
request,
|
||||
"playlists/detail.html",
|
||||
{"playlist": playlist, "status": status, "error": error},
|
||||
{
|
||||
"playlist": playlist,
|
||||
"sync_time": playlist_service.cron_to_time(playlist.cron_expr),
|
||||
"status": status,
|
||||
"error": error,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -57,7 +69,7 @@ async def playlist_detail(
|
||||
async def update_playlist(
|
||||
playlist_id: int,
|
||||
active: bool = Form(False),
|
||||
cron_expr: str = Form(""),
|
||||
sync_time: str = Form(""),
|
||||
no_m3u: bool = Form(False),
|
||||
notes: str = Form(""),
|
||||
user: dict = Depends(require_auth),
|
||||
@@ -67,7 +79,7 @@ async def update_playlist(
|
||||
db,
|
||||
playlist_id,
|
||||
active=active,
|
||||
cron_expr=cron_expr or None,
|
||||
cron_expr=playlist_service.time_to_cron(sync_time),
|
||||
no_m3u=no_m3u,
|
||||
notes=notes or None,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user