feat(A1): Übungen als AP mit Wochentagsplan
Deploy Development / deploy (push) Successful in 46s
Test Suite / pytest-backend (push) Successful in 5m3s
Test Suite / lint-backend (push) Successful in 3s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 19s
Test Suite / playwright-smoke (push) Successful in 13s

Gate- und Kit-Übungen legen ein Arbeitspaket plus Schedule an; Today zeigt nur fällige Wochentage, nicht die ganze Gate-Liste.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-08-17 18:06:41 +02:00
1 parent ea0aa18b8d
commit a05bd34af3
16 files changed
+396 -57

No files matched your search

@@ -117,7 +117,8 @@ export function GateActivitySetSection({
<div>
<h3>{routineLabel}</h3>
<p className="section-lead muted">
Übungen gehören zu diesem Zielzustand — sie erscheinen in Today, wenn das Gate{' '}
Übungen sind Arbeitspakete mit Wochentagsplan an diesem Zielzustand.
Sie erscheinen in Today nur an den gewählten Tagen, solange das Gate{' '}
<strong>aktiv</strong> ist.
</p>
</div>
@@ -147,7 +148,7 @@ export function GateActivitySetSection({
<Link to={scopedPath('/work/today', { initiativeId })} className="link-inline">
Ausführen → Today
</Link>{' '}
— fällige Übungen dieser Routine abhaken.
— fällige Übungen dieser Stufe abhaken.
</p>
)}
@@ -182,13 +183,23 @@ export function GateActivitySetSection({
{loading ? (
<p className="muted">Übungen werden geladen…</p>
) : practices.length === 0 ? (
<EmptyState message="Noch keine Übungen — mindestens eine Übung für diese Routine anlegen." />
<EmptyState message="Noch keine Übungen — mindestens ein Arbeitspaket mit Wochentagen anlegen." />
) : (
<ul className="item-list gate-activity-set__list">
{practices.map((practice) => (
<li key={practice.id} className="list-item card-list-item">
<div className="list-item-main">
<strong>{practice.title}</strong>
{practice.action_id && initiativeId && (
<p className="muted list-item-sub">
<Link
to={scopedPath(`/actions/${practice.action_id}`, { initiativeId })}
className="link-inline"
>
Arbeitspaket öffnen
</Link>
</p>
)}
{practice.description && (
<p className="muted list-item-sub">{practice.description}</p>
)}
+11 -9
View File
@@ -6,6 +6,7 @@ import {
detectIntervalPreset,
scheduleFromApi,
toggleWeekdayMask,
weekdayBitForDate,
} from '../utils/scheduleUtils.js'
export function ScheduleEditor({
@@ -28,7 +29,7 @@ export function ScheduleEditor({
onChange({
...current,
schedule_kind: 'weekdays',
weekday_mask: current.weekday_mask || WEEKDAY_OPTIONS[0].bit,
weekday_mask: current.weekday_mask || weekdayBitForDate(),
})
setPreset('weekdays')
return
@@ -52,6 +53,13 @@ export function ScheduleEditor({
<legend className="schedule-editor__legend">Rhythmus</legend>
<div className="schedule-editor__modes" role="group" aria-label="Rhythmus-Art">
<button
type="button"
className={`btn btn-sm ${preset === 'weekdays' ? 'btn-primary' : 'btn-secondary'}`}
onClick={() => setKind('weekdays')}
>
Wochentage
</button>
{INTERVAL_PRESETS.filter((p) => p.id !== 'custom').map((p) => (
<button
key={p.id}
@@ -62,13 +70,6 @@ export function ScheduleEditor({
{p.label}
</button>
))}
<button
type="button"
className={`btn btn-sm ${preset === 'weekdays' ? 'btn-primary' : 'btn-secondary'}`}
onClick={() => setKind('weekdays')}
>
Wochentage
</button>
<button
type="button"
className={`btn btn-sm ${preset === 'custom' ? 'btn-primary' : 'btn-secondary'}`}
@@ -95,7 +96,8 @@ export function ScheduleEditor({
{current.schedule_kind === 'weekdays' && (
<div className="schedule-editor__weekdays">
<p className="muted schedule-editor__hint">
An welchen Tagen? {weekdaySummary ? `(${weekdaySummary})` : ''}
Immer an diesen Tagen — nach Erledigen bleibt der Wochentag.
{weekdaySummary ? ` (${weekdaySummary})` : ''}
</p>
<div className="schedule-editor__weekday-row">
{WEEKDAY_OPTIONS.map((day) => {
@@ -3,6 +3,7 @@ import { Link } from 'react-router-dom'
import { completeRecurringPractice } from '../api/recurring.js'
import { EmptyState } from './EmptyState.jsx'
import { scopedPath } from '../utils/routes.js'
import { isPracticeDueToday } from '../utils/scheduleUtils.js'
function formatDue(iso) {
if (!iso) return null
@@ -21,7 +22,10 @@ function activeWorkGates(roadmapItems = []) {
function exercisesForGate(recurringItems = [], gateId) {
return (recurringItems || []).filter(
(item) => item.status === 'active' && item.roadmap_item_id === gateId,
(item) =>
item.status === 'active' &&
item.roadmap_item_id === gateId &&
isPracticeDueToday(item),
)
}
@@ -123,19 +127,23 @@ export function WorkTodayPracticePanel({
<h2>Heutige Übungen</h2>
<p className="section-lead muted">
{gates.length > 0
? `${gates.length} aktive Gate(s) — pro Übung erledigen, optional Messwert notieren.`
? `${gates.length} aktive Gate(s) — nur heute fällige Übungen, optional Messwert.`
: 'Tages-Tracking für aktive Work-Gates.'}
</p>
</div>
</div>
{todayExercises.length === 0 ? (
<EmptyState message="Keine Übungen auf aktiven Gates — Starter-Kit oder Join-Fortschritt prüfen." />
<EmptyState message={
gates.length === 0
? 'Keine Übungen auf aktiven Gates — Starter-Kit oder Join-Fortschritt prüfen.'
: 'Heute keine fälligen Übungen.'
} />
) : (
<>
{allDone && (
<p className="work-today-practice__all-done muted">
Alle Übungen für heute erledigt — nächste Fälligkeit morgen.
Alle Übungen für heute erledigt — nächste Fälligkeit laut Rhythmus.
</p>
)}
{grouped.map(({ gate, exercises }) =>
+61 -5
View File
@@ -11,15 +11,20 @@ export const WEEKDAY_OPTIONS = [
export const INTERVAL_PRESETS = [
{ id: 'daily', label: 'Täglich', intervalDays: 1 },
{ id: 'every2', label: 'Alle 2 Tage', intervalDays: 2 },
{ id: 'weekly', label: 'Wöchentlich', intervalDays: 7 },
{ id: 'custom', label: 'Individuell…', intervalDays: null },
]
export function defaultScheduleValue() {
/** Monday=0 … Sunday=6, matching backend weekday_bit. */
export function weekdayBitForDate(date = new Date()) {
const mondayFirst = (date.getDay() + 6) % 7
return 1 << mondayFirst
}
export function defaultScheduleValue(date = new Date()) {
return {
schedule_kind: 'interval',
schedule_kind: 'weekdays',
interval_days: 1,
weekday_mask: 0,
weekday_mask: weekdayBitForDate(date),
pause_until: '',
}
}
@@ -45,7 +50,7 @@ export function formatScheduleLabel(schedule) {
return schedule.pause_until ? `${base} (Pause bis ${schedule.pause_until.slice(0, 10)})` : base
}
const days = schedule.interval_days || 1
let base = days === 1 ? 'Täglich' : days === 7 ? 'Wöchentlich' : `Alle ${days} Tage`
let base = days === 1 ? 'Täglich' : `Alle ${days} Tage`
if (schedule.pause_until) {
base = `${base} (Pause bis ${schedule.pause_until.slice(0, 10)})`
}
@@ -79,3 +84,54 @@ export function detectIntervalPreset(intervalDays) {
)
return match ? match.id : 'custom'
}
function startOfLocalDay(date) {
const copy = new Date(date)
copy.setHours(0, 0, 0, 0)
return copy
}
function parseDueDate(value) {
if (!value) return null
const parsed = new Date(value)
return Number.isNaN(parsed.getTime()) ? null : parsed
}
/**
* Same-routine weekday stickiness: due today if next_due ≤ today
* (includes overdue). Future weekdays stay hidden.
*/
export function isDueOnDate({ schedule, nextDueAt, onDate = new Date() } = {}) {
const day = startOfLocalDay(onDate)
const pauseUntil = schedule?.pause_until
if (pauseUntil) {
const pause = startOfLocalDay(new Date(pauseUntil))
if (!Number.isNaN(pause.getTime()) && day.getTime() <= pause.getTime()) {
return false
}
}
const due = parseDueDate(nextDueAt)
if (due && startOfLocalDay(due).getTime() > day.getTime()) {
return false
}
if ((schedule?.schedule_kind || 'interval') === 'weekdays') {
const mask = Number(schedule?.weekday_mask) || 0
if (due) return true
return Boolean(mask & weekdayBitForDate(day))
}
return true
}
export function isPracticeDueToday(practice, now = new Date()) {
if (!practice || practice.status !== 'active') return false
if (practice.today_completed) return true
const nextDueAt = practice.next_due_at || practice.open_cadence_instance?.due_at
return isDueOnDate({
schedule: practice.schedule,
nextDueAt,
onDate: now,
})
}
+75
View File
@@ -0,0 +1,75 @@
import { describe, expect, it } from 'vitest'
import {
defaultScheduleValue,
formatScheduleLabel,
isDueOnDate,
isPracticeDueToday,
weekdayBitForDate,
} from './scheduleUtils.js'
describe('scheduleUtils weekday foundation', () => {
it('defaults to weekdays on today', () => {
const monday = new Date('2026-08-17T12:00:00')
const value = defaultScheduleValue(monday)
expect(value.schedule_kind).toBe('weekdays')
expect(value.weekday_mask).toBe(weekdayBitForDate(monday))
})
it('does not call interval 7 weekly', () => {
expect(formatScheduleLabel({ schedule_kind: 'interval', interval_days: 7 })).toBe('Alle 7 Tage')
})
it('labels weekday masks as days, not weekly', () => {
expect(
formatScheduleLabel({ schedule_kind: 'weekdays', weekday_mask: 1 | 4 | 64 }),
).toBe('Mo, Mi, So')
})
it('hides future weekday occurrences', () => {
const monday = new Date('2026-08-17T12:00:00')
const tuesdayDue = '2026-08-18T12:00:00'
const due = isDueOnDate({
schedule: { schedule_kind: 'weekdays', weekday_mask: 1 | 4 | 64 },
nextDueAt: tuesdayDue,
onDate: monday,
})
expect(due).toBe(false)
})
it('shows overdue weekday series on a later day', () => {
const tuesday = new Date('2026-08-18T12:00:00')
const mondayDue = '2026-08-17T12:00:00'
expect(
isDueOnDate({
schedule: { schedule_kind: 'weekdays', weekday_mask: 1 },
nextDueAt: mondayDue,
onDate: tuesday,
}),
).toBe(true)
})
it('filters Today to due or completed practices', () => {
const monday = new Date('2026-08-17T12:00:00')
const due = {
status: 'active',
today_completed: false,
next_due_at: '2026-08-17T12:00:00',
schedule: { schedule_kind: 'weekdays', weekday_mask: 1 },
}
const later = {
status: 'active',
today_completed: false,
next_due_at: '2026-08-18T12:00:00',
schedule: { schedule_kind: 'weekdays', weekday_mask: 2 },
}
const done = {
status: 'active',
today_completed: true,
next_due_at: '2026-08-18T12:00:00',
schedule: { schedule_kind: 'weekdays', weekday_mask: 2 },
}
expect(isPracticeDueToday(due, monday)).toBe(true)
expect(isPracticeDueToday(later, monday)).toBe(false)
expect(isPracticeDueToday(done, monday)).toBe(true)
})
})