diff --git a/backend/app/models/schedule.py b/backend/app/models/schedule.py index 8296714..ccd97ba 100644 --- a/backend/app/models/schedule.py +++ b/backend/app/models/schedule.py @@ -20,7 +20,7 @@ class ScheduleTemplate(TimestampMixin, Base): user: Mapped["User"] = relationship("User", back_populates="schedule_templates") # noqa: F821 child: Mapped["Child | None"] = relationship("Child") # noqa: F821 blocks: Mapped[list["ScheduleBlock"]] = relationship( - "ScheduleBlock", back_populates="template", cascade="all, delete-orphan", order_by="ScheduleBlock.order_index" + "ScheduleBlock", back_populates="template", cascade="all, delete-orphan", order_by="ScheduleBlock.time_start" ) daily_sessions: Mapped[list["DailySession"]] = relationship( # noqa: F821 "DailySession", back_populates="template" diff --git a/backend/app/routers/dashboard.py b/backend/app/routers/dashboard.py index 9201ca8..7fc3b76 100644 --- a/backend/app/routers/dashboard.py +++ b/backend/app/routers/dashboard.py @@ -50,7 +50,7 @@ async def get_dashboard(child_id: int, db: AsyncSession = Depends(get_db)): select(ScheduleBlock) .where(ScheduleBlock.template_id == session.template_id) .options(selectinload(ScheduleBlock.subject).selectinload(Subject.options)) - .order_by(ScheduleBlock.order_index) + .order_by(ScheduleBlock.time_start) ) blocks = blocks_result.scalars().all() diff --git a/backend/app/routers/sessions.py b/backend/app/routers/sessions.py index 90d212e..a823102 100644 --- a/backend/app/routers/sessions.py +++ b/backend/app/routers/sessions.py @@ -28,7 +28,7 @@ async def _broadcast_session(db: AsyncSession, session: DailySession) -> None: select(ScheduleBlock) .where(ScheduleBlock.template_id == session.template_id) .options(selectinload(ScheduleBlock.subject).selectinload(Subject.options)) - .order_by(ScheduleBlock.order_index) + .order_by(ScheduleBlock.time_start) ) blocks = [ { diff --git a/frontend/src/stores/schedule.js b/frontend/src/stores/schedule.js index e7d22b1..2fcef44 100644 --- a/frontend/src/stores/schedule.js +++ b/frontend/src/stores/schedule.js @@ -24,9 +24,16 @@ export const useScheduleStore = defineStore('schedule', () => { return Math.round((completedBlockIds.value.length / blocks.value.length) * 100) }) + function sortBlocksByTime(arr) { + return (arr || []).slice().sort((a, b) => { + const toMin = (t) => { if (!t) return 0; const [h, m] = t.split(':').map(Number); return h * 60 + m } + return toMin(a.time_start) - toMin(b.time_start) + }) + } + function applySnapshot(snapshot) { session.value = snapshot.session - blocks.value = snapshot.blocks || [] + blocks.value = sortBlocksByTime(snapshot.blocks) completedBlockIds.value = snapshot.completed_block_ids || [] isPaused.value = false if (snapshot.child) child.value = snapshot.child diff --git a/frontend/src/views/AdminView.vue b/frontend/src/views/AdminView.vue index b69ec69..99eff44 100644 --- a/frontend/src/views/AdminView.vue +++ b/frontend/src/views/AdminView.vue @@ -186,7 +186,7 @@