Add duration_minutes field to schedule blocks
Separates "recommended time" (time_start/time_end) from actual timer duration. If duration_minutes is set, the timer counts down from that value; otherwise falls back to the time_start–time_end window. - ScheduleBlock model: add nullable duration_minutes INT column - Startup migration: idempotent ADD COLUMN for existing DBs - Schemas: duration_minutes in create, update, and out - TimerDisplay: prefer duration_minutes * 60 over time diff when set - Admin block forms: Duration (min) input on add and edit forms Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,7 @@ async def lifespan(app: FastAPI):
|
|||||||
# Idempotent column additions for schema migrations
|
# Idempotent column additions for schema migrations
|
||||||
await _add_column_if_missing(conn, "schedule_templates", "day_start_time", "TIME NULL")
|
await _add_column_if_missing(conn, "schedule_templates", "day_start_time", "TIME NULL")
|
||||||
await _add_column_if_missing(conn, "schedule_templates", "day_end_time", "TIME NULL")
|
await _add_column_if_missing(conn, "schedule_templates", "day_end_time", "TIME NULL")
|
||||||
|
await _add_column_if_missing(conn, "schedule_blocks", "duration_minutes", "INT NULL")
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class ScheduleBlock(Base):
|
|||||||
)
|
)
|
||||||
time_start: Mapped[time] = mapped_column(Time, nullable=False)
|
time_start: Mapped[time] = mapped_column(Time, nullable=False)
|
||||||
time_end: Mapped[time] = mapped_column(Time, nullable=False)
|
time_end: Mapped[time] = mapped_column(Time, nullable=False)
|
||||||
|
duration_minutes: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||||
label: Mapped[str | None] = mapped_column(String(100), nullable=True) # override subject name
|
label: Mapped[str | None] = mapped_column(String(100), nullable=True) # override subject name
|
||||||
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||||
order_index: Mapped[int] = mapped_column(Integer, default=0)
|
order_index: Mapped[int] = mapped_column(Integer, default=0)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class ScheduleBlockCreate(BaseModel):
|
|||||||
subject_id: int | None = None
|
subject_id: int | None = None
|
||||||
time_start: time
|
time_start: time
|
||||||
time_end: time
|
time_end: time
|
||||||
|
duration_minutes: int | None = None
|
||||||
label: str | None = None
|
label: str | None = None
|
||||||
notes: str | None = None
|
notes: str | None = None
|
||||||
order_index: int = 0
|
order_index: int = 0
|
||||||
@@ -15,6 +16,7 @@ class ScheduleBlockUpdate(BaseModel):
|
|||||||
subject_id: int | None = None
|
subject_id: int | None = None
|
||||||
time_start: time | None = None
|
time_start: time | None = None
|
||||||
time_end: time | None = None
|
time_end: time | None = None
|
||||||
|
duration_minutes: int | None = None
|
||||||
label: str | None = None
|
label: str | None = None
|
||||||
notes: str | None = None
|
notes: str | None = None
|
||||||
order_index: int | None = None
|
order_index: int | None = None
|
||||||
@@ -25,6 +27,7 @@ class ScheduleBlockOut(BaseModel):
|
|||||||
subject_id: int | None
|
subject_id: int | None
|
||||||
time_start: time
|
time_start: time
|
||||||
time_end: time
|
time_end: time
|
||||||
|
duration_minutes: int | None
|
||||||
label: str | None
|
label: str | None
|
||||||
notes: str | None
|
notes: str | None
|
||||||
order_index: int
|
order_index: int
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ function parseTime(str) {
|
|||||||
|
|
||||||
const blockDuration = computed(() => {
|
const blockDuration = computed(() => {
|
||||||
if (!props.block) return 0
|
if (!props.block) return 0
|
||||||
|
if (props.block.duration_minutes != null) return props.block.duration_minutes * 60
|
||||||
return parseTime(props.block.time_end) - parseTime(props.block.time_start)
|
return parseTime(props.block.time_end) - parseTime(props.block.time_start)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -168,6 +168,12 @@
|
|||||||
<input v-model="editingBlock.time_start" type="time" required />
|
<input v-model="editingBlock.time_start" type="time" required />
|
||||||
<span>to</span>
|
<span>to</span>
|
||||||
<input v-model="editingBlock.time_end" type="time" required />
|
<input v-model="editingBlock.time_end" type="time" required />
|
||||||
|
<input
|
||||||
|
v-model.number="editingBlock.duration_minutes"
|
||||||
|
type="number" min="1" max="480"
|
||||||
|
placeholder="Duration (min)"
|
||||||
|
style="width:130px"
|
||||||
|
/>
|
||||||
<input v-model="editingBlock.label" placeholder="Label (optional)" />
|
<input v-model="editingBlock.label" placeholder="Label (optional)" />
|
||||||
<button type="submit" class="btn-sm btn-primary">Save</button>
|
<button type="submit" class="btn-sm btn-primary">Save</button>
|
||||||
<button type="button" class="btn-sm" @click="editingBlock = null">Cancel</button>
|
<button type="button" class="btn-sm" @click="editingBlock = null">Cancel</button>
|
||||||
@@ -192,6 +198,12 @@
|
|||||||
<input v-model="newBlock.time_start" type="time" required />
|
<input v-model="newBlock.time_start" type="time" required />
|
||||||
<span>to</span>
|
<span>to</span>
|
||||||
<input v-model="newBlock.time_end" type="time" required />
|
<input v-model="newBlock.time_end" type="time" required />
|
||||||
|
<input
|
||||||
|
v-model.number="newBlock.duration_minutes"
|
||||||
|
type="number" min="1" max="480"
|
||||||
|
placeholder="Duration (min)"
|
||||||
|
style="width:130px"
|
||||||
|
/>
|
||||||
<input v-model="newBlock.label" placeholder="Label (optional)" />
|
<input v-model="newBlock.label" placeholder="Label (optional)" />
|
||||||
<button type="submit" class="btn-primary btn-sm">Add Block</button>
|
<button type="submit" class="btn-primary btn-sm">Add Block</button>
|
||||||
</form>
|
</form>
|
||||||
@@ -295,7 +307,7 @@ const templates = ref([])
|
|||||||
const showCreateForm = ref(false)
|
const showCreateForm = ref(false)
|
||||||
const editingTemplate = ref(null)
|
const editingTemplate = ref(null)
|
||||||
const newTemplate = ref({ name: '', child_id: null, is_default: false })
|
const newTemplate = ref({ name: '', child_id: null, is_default: false })
|
||||||
const newBlock = ref({ subject_id: null, time_start: '', time_end: '', label: '', order_index: 0 })
|
const newBlock = ref({ subject_id: null, time_start: '', time_end: '', duration_minutes: null, label: '', order_index: 0 })
|
||||||
const editingBlock = ref(null)
|
const editingBlock = ref(null)
|
||||||
|
|
||||||
function childName(id) {
|
function childName(id) {
|
||||||
@@ -331,7 +343,7 @@ async function addBlock(templateId) {
|
|||||||
order_index: templates.value.find((t) => t.id === templateId)?.blocks.length || 0,
|
order_index: templates.value.find((t) => t.id === templateId)?.blocks.length || 0,
|
||||||
}
|
}
|
||||||
await api.post(`/api/schedules/${templateId}/blocks`, payload)
|
await api.post(`/api/schedules/${templateId}/blocks`, payload)
|
||||||
newBlock.value = { subject_id: null, time_start: '', time_end: '', label: '', order_index: 0 }
|
newBlock.value = { subject_id: null, time_start: '', time_end: '', duration_minutes: null, label: '', order_index: 0 }
|
||||||
await loadTemplates()
|
await loadTemplates()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,6 +353,7 @@ function startEditBlock(block) {
|
|||||||
subject_id: block.subject_id,
|
subject_id: block.subject_id,
|
||||||
time_start: block.time_start ? block.time_start.slice(0, 5) : '',
|
time_start: block.time_start ? block.time_start.slice(0, 5) : '',
|
||||||
time_end: block.time_end ? block.time_end.slice(0, 5) : '',
|
time_end: block.time_end ? block.time_end.slice(0, 5) : '',
|
||||||
|
duration_minutes: block.duration_minutes ?? null,
|
||||||
label: block.label || '',
|
label: block.label || '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user