Add subject options and redesign TV dashboard layout

Subject options:
- New subject_options table (auto-created on startup)
- SubjectOut now includes options list; all eager-loading chains updated
- Admin: Options panel per subject with add, inline edit, and delete
- WS broadcast and dashboard API include options in block subject data

TV dashboard:
- Three equal columns: Timer | Activities | Schedule
- Activities column shows current subject's options in large readable text
- Activities area has subject-colored border and tinted background
- Subject name and label displayed correctly using embedded subject data

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 11:18:55 -08:00
parent c12f07daa3
commit c9441a9c9a
11 changed files with 375 additions and 51 deletions

View File

@@ -5,6 +5,7 @@ from sqlalchemy.orm import selectinload
from app.dependencies import get_db, get_current_user
from app.models.schedule import ScheduleTemplate, ScheduleBlock
from app.models.subject import Subject # noqa: F401 — for selectinload chain
from app.models.user import User
from app.schemas.schedule import (
ScheduleTemplateCreate,
@@ -26,7 +27,7 @@ async def list_templates(
result = await db.execute(
select(ScheduleTemplate)
.where(ScheduleTemplate.user_id == current_user.id)
.options(selectinload(ScheduleTemplate.blocks))
.options(selectinload(ScheduleTemplate.blocks).selectinload(ScheduleBlock.subject).selectinload(Subject.options))
.order_by(ScheduleTemplate.name)
)
return result.scalars().all()
@@ -60,7 +61,7 @@ async def create_template(
result = await db.execute(
select(ScheduleTemplate)
.where(ScheduleTemplate.id == template.id)
.options(selectinload(ScheduleTemplate.blocks))
.options(selectinload(ScheduleTemplate.blocks).selectinload(ScheduleBlock.subject).selectinload(Subject.options))
)
return result.scalar_one()
@@ -74,7 +75,7 @@ async def get_template(
result = await db.execute(
select(ScheduleTemplate)
.where(ScheduleTemplate.id == template_id, ScheduleTemplate.user_id == current_user.id)
.options(selectinload(ScheduleTemplate.blocks))
.options(selectinload(ScheduleTemplate.blocks).selectinload(ScheduleBlock.subject).selectinload(Subject.options))
)
template = result.scalar_one_or_none()
if not template:
@@ -92,7 +93,7 @@ async def update_template(
result = await db.execute(
select(ScheduleTemplate)
.where(ScheduleTemplate.id == template_id, ScheduleTemplate.user_id == current_user.id)
.options(selectinload(ScheduleTemplate.blocks))
.options(selectinload(ScheduleTemplate.blocks).selectinload(ScheduleBlock.subject).selectinload(Subject.options))
)
template = result.scalar_one_or_none()
if not template:
@@ -141,8 +142,12 @@ async def add_block(
block = ScheduleBlock(template_id=template_id, **body.model_dump())
db.add(block)
await db.commit()
await db.refresh(block)
return block
result = await db.execute(
select(ScheduleBlock)
.where(ScheduleBlock.id == block.id)
.options(selectinload(ScheduleBlock.subject).selectinload(Subject.options))
)
return result.scalar_one()
@router.patch("/{template_id}/blocks/{block_id}", response_model=ScheduleBlockOut)
@@ -169,8 +174,12 @@ async def update_block(
for field, value in body.model_dump(exclude_unset=True).items():
setattr(block, field, value)
await db.commit()
await db.refresh(block)
return block
result = await db.execute(
select(ScheduleBlock)
.where(ScheduleBlock.id == block.id)
.options(selectinload(ScheduleBlock.subject).selectinload(Subject.options))
)
return result.scalar_one()
@router.delete("/{template_id}/blocks/{block_id}", status_code=status.HTTP_204_NO_CONTENT)