Commit Graph
92 Commits
Author SHA1 Message Date
aksdb d387854329 🐛 Merge entry edits after pending sync data has landed
update() read the record before save() waited for the sync to apply
server state, and the record finally written was that stale read plus
the patch with a fresh client_updated_at: an edit silently reverted
what another device had changed in between, and the server took it as
the newer version.

update() and remove() now patch the record after the wait, so every
field they do not touch keeps the value the pull just applied. The
test holds an update while a round applies a remote change to the same
record and fails on the old code with the reverted field.
2026-12-01 19:04:50 +01:00
aksdb d750b8c3c9 🐛 Recover the app when the session expires
A 401 mid-session made the PocketBase SDK drop the auth store, while
session.userId and the gate of the layout stayed set: the user remained
in the app, every round failed, /login was bounced back and a token-less
pull was even taken for a successful round.

The sync layer now ends the session through an onSessionExpired hook
when a round fails with 401 or finds the auth store cleared, and reports
no round as synced without a valid auth store. The session module tries
one token refresh before it clears the session, and the layout resolves
the gate again whenever the auth store is no longer valid, so the user
lands on the login page and the next sign-in brings the data back.
2026-12-01 19:04:06 +01:00
aksdb e630f9fd66 ♻️ Drop legacy browser storage on sign-in
Browsers of users of the Dexie based version still hold its token in
the auth_token key of localStorage and its database named wotra, next
to the per user databases of this version. resolveGate() now removes
both whenever it lets the user into the app, the first open included.
The removal resolves on success, error and block, like wipeLocal, and
never throws, so a browser that denies storage cannot keep the user
out.
2026-12-01 18:07:31 +01:00
aksdb 1c899b2743 🗑️ Remove the Dexie data layer and its dependencies
The API client and the two stores on Dexie have been dead since the
collections took over every read and write, and nothing imports them
any more. Dexie and workbox-window go with them; the service worker is
registered by hand and needs no client library.

The static adapter wipes build/ on every build, which dropped the
tracked placeholder that keeps the directory in the repository. A
postbuild step writes it back.
2026-12-01 18:06:39 +01:00
aksdb bddabbf93d 🐛 Surface changes rejected by the server
The server now answers an invalid change per item instead of failing
the whole batch, and the client dropped such a change silently: the
round went through and nothing told the user that the edit never
reached the server. A rejected change now sets the sync status to
"<collection>: <error>", cut to 200 characters, so the sync button
shows its warning state. The change is not retried, as before.

The message survives the collections that still succeed in the same
round, since each of them used to clear the error. The next round
without a rejection clears it.
2026-12-01 17:59:29 +01:00
aksdb 6ce66f81c7 🐛 Stop the sync from undoing writes made during a round
The sync manager learns of a local write only from the change record
it creates after the write finished, and it applies the pulled server
state without regard to newer local changes. A write made while a
round was pulling or pushing was therefore replaced by the older
server version, or removed as unknown to the snapshot, until the next
round pushed it again: a deleted adjustment came back, an edit
reverted, a new row vanished for a moment.

Each pull now waits for the writes in flight on the collection and on
the change records, keeps the server version of items whose change
record the round did not push, and local writes wait while the sync
applies server state to their collection; network requests stay
exempt. The stress test writes to four collections for 300 rounds,
with the sync idle and with a push held in flight, and asserts that
reactive and plain reads always show the last write. Without the fix
it fails in the first round.
2026-12-01 17:56:43 +01:00
aksdb bd2ec79a69 🐛 Silence SignalDB warnings for reads outside reactive scopes
Every read outside a reactive scope passed { reactive: false } and made
Cursor.depend() log a warning. Such reads now use a silent reactivity
adapter, and all, get, pendingCount and save release the cursor again
with cleanup(), so nothing is registered and nothing leaks. Reads inside
$derived or $effect stay reactive as before.

Vitest now resolves the browser export of Svelte. Without it
svelte/reactivity is the server stub, createSubscriber never starts and
no effect re-runs after a write in tests.
2026-12-01 17:02:53 +01:00
aksdb 73359d3f39 ♻️ Answer unknown API routes with JSON and fix stale comments
The SPA catch-all answered unknown /api paths with the index page and
status 200, so the client SDK failed to parse the body. A catch-all per
HTTP method answers them with a JSON 404 in the error shape of
PocketBase; the routes registered before keep precedence. The comment
on DataFields no longer claims the fields of the read-only collections
were client writable.
2026-12-01 16:59:19 +01:00
aksdb c3e2bd2555 ♻️ Align week recompute with week close
CloseWeek left closed days that are no workdays out of the total, but
recomputeWeek counted every closed day of the week. A closed Saturday
therefore changed the total of an already closed week as soon as another
day of that week was closed, reopened or marked. Both use the same rule
now, with the settings effective on the closed day.
2026-12-01 16:56:20 +01:00
aksdb 590758dfb6 🐛 Bound hours per week on settings
The field accepted any number from 0.01 up, so a typo or a bad client
could store more hours than a week has and break every expected value
derived from it. The initial migration limits hours_per_week to 168; no
database was ever deployed with the previous version of the migration.
2026-12-01 16:54:32 +01:00
aksdb b41f83342c 🐛 Return server errors as 500 when marking a day fails
Marking a day answered every error except an invalid day key with 422,
including database errors. Only an invalid kind is a 422 now. Server
errors are logged with their cause and answered with a generic message
instead of the error text, which can contain SQL, and the timezone
lookup logs at warn before it falls back to UTC.
2026-12-01 16:52:30 +01:00
aksdb 2bcf2d69a1 🐛 Stop stale entries without overwriting a concurrent stop
The auto-stop listed the running entries and later saved the whole stale
row, so a stop pushed by a client in between was overwritten and then
answered as stale. Each candidate is now loaded again inside its own
transaction and only saved while it is still running and not deleted.
The end of the day uses the timezone effective on the day of the entry,
and entries without a real day_key are skipped with a debug message
instead of an error every minute.
2026-12-01 16:49:15 +01:00
aksdb 0bfacb7059 🐛 Reject week keys that are not real ISO weeks
WeekDayKeys accepted W01 to W53 without checking that the year has that
week. Closing 2025-W53, a year with 52 weeks, closed the days of
2026-W01 under a second key and the balance counted them twice. The
computed Monday must now map back to the requested week key.
2026-12-01 16:43:40 +01:00
aksdb 9f0700fa1c 🐛 Reject invalid changes instead of failing the whole sync batch
Every whitelisted field was written, so a tombstone or a partial change
without the required fields failed the validation and rolled back the
whole batch with 400, which a client would retry forever. Only the keys
present in the change are set now, a change is validated on its own and
answered as invalid with the message, and a tombstone for an unknown
row is answered ok without writing anything.
2026-12-01 16:41:57 +01:00
aksdb 8898d976e6 🐛 Keep tombstones when replacing data in the legacy import
Clients only pull changed rows and never learn about hard deletes, so
a row they already pulled survived as a ghost: it kept winning against
imported rows with the same effective_from. Existing rows now become
tombstones. Closed days and weeks are overwritten in place when an
imported row has the same key, so their unique index holds.
2026-12-01 16:37:26 +01:00
aksdb 20df2918c9 ♻️ Move the settings page to PocketBase and SignalDB
The shared token form is gone. Working hours, workdays and timezone
are edited through the synced settings collection, and a new account
card shows the signed-in user, a password change and sign out.
2026-11-30 17:43:13 +00:00
aksdb cd39c7457e ♻️ Read history and balance from SignalDB
Closed weeks, closed days, the balance and the adjustments are derived
from the synced collections instead of being loaded once on mount, so
every change shows up without a reload.
2026-11-30 17:43:13 +00:00
aksdb f0cf796ef6 ♻️ Drive the day detail from SignalDB collections
The day detail panel no longer loads entries and the closed day on
demand and patches its lists after each mutation. Entries, the closed
day, the running entry and the total are derived from the synced
collections, so they update on local changes and on sync. The ticker
restarts whenever the running entry changes. Closing, marking and
reopening a day rely on the sync the domain functions trigger.
2026-11-30 17:43:13 +00:00
aksdb a47affa765 ♻️ Read the week view reactively from SignalDB
The week view no longer loads its data on demand and patches it after
each mutation. Entries, closed days, the closed week and the settings
are derived from the synced collections, so the view follows local
changes and sync results. Closing and reopening a week report errors
from the server in place.
2026-11-30 17:43:13 +00:00
aksdb f54e7238b4 ♻️ Gate the app behind PocketBase authentication
Only signed-in users reach the working pages. Everyone else lands on
the login page and returns to the page they asked for after signing in.
The manifest link moves into the page template and the service worker
is registered only in production builds.
2026-11-30 17:43:13 +00:00
aksdb 23cecdea80 ✨ Add login and sign-up page
The app no longer uses a shared bearer token. The page signs users in
or creates an account through PocketBase and offers the configured
OAuth2 providers.
2026-11-30 17:43:13 +00:00
aksdb 6a95b885b8 📝 Document the PocketBase and SignalDB stack
The README now describes the PocketBase binary, the per-user settings,
the admin UI, the sign-in page and the import-legacy command. PLAN.md
records the decisions of the migration and marks the sections that
describe the old backend as superseded.
2026-11-30 17:43:13 +00:00
aksdb 74ebd2b38f ♻️ Build on PocketBase defaults in container and tasks 2026-11-30 17:39:27 +00:00
aksdb bb5ba06110 🔧 Tidy Go modules after the legacy removal 2026-11-29 20:28:25 +00:00
aksdb cb2d090ffc 🗑️ Remove legacy SQLite store, services and handlers 2026-11-29 20:28:10 +00:00
aksdb 611a2d105a 🧪 Test day and week closing rules 2026-11-29 20:27:12 +00:00
aksdb 9489952842 ✨ Export entries, days and weeks as CSV 2026-11-29 20:24:54 +00:00
aksdb 1edaf75e4b ✨ Seed settings for new users and auto-stop stale entries 2026-11-29 20:24:48 +00:00
aksdb 31b404e27a ✨ Add day and week closing on PocketBase records 2026-11-29 20:24:40 +00:00
aksdb 39e0f69342 🧪 Test legacy import
The tests build a legacy SQLite fixture from the old migrations and
cover the field mapping, skipped invalid rows, the replace-on-rerun
behaviour, the dry run and the guarantee that the legacy file and its
directory stay untouched.
2026-11-29 20:24:32 +00:00
aksdb e190c5c919 ✨ Add import-legacy command for the SQLite database
The command copies the tables of the old wotra.db into the PocketBase
records of one user, so the tracked time survives the move to the new
backend. The legacy file is only ever read; a dry run shows what would
be imported without writing anything.
2026-11-29 20:24:29 +00:00
aksdb 1e5110f253 🧪 Test timezone helpers and local collections 2026-11-29 20:16:45 +00:00
aksdb 29f3cb9926 🐛 Push sync changes in batches of 200
The server rejects more than 500 changes per request, so one large
offline batch would otherwise stay pending forever.
2026-11-29 20:16:45 +00:00
aksdb 98f3e8048c 🔧 Stop caching API responses in the service worker 2026-11-29 20:16:45 +00:00
aksdb d9890db12f ✨ Add tracking domain functions on SignalDB 2026-11-29 20:16:41 +00:00
aksdb 6a6c2bb71d ✨ Add SignalDB collections synced with PocketBase 2026-11-29 17:21:41 +00:00
aksdb c00b393bec ✨ Add PocketBase client and session helpers 2026-11-29 17:21:36 +00:00
aksdb 58479668b6 ✨ Run PocketBase as the wotra binary
The root package is now the entry point: one binary that serves the
PocketBase API, applies the migrations and ships the SvelteKit build
from web/build as a single-page app. The legacy chi entry point is
gone.

Note that the image is embedded unconditionally, so a Go build needs
at least the tracked web/build/.gitkeep and a web build has to run
first to get a working UI.
2026-11-29 17:06:46 +00:00
aksdb 03c1a1f8d9 🗑️ Remove legacy asset embedding and command wiring
The repo root was the legacy "assets" package and cmd/wotra held the
old chi entry point. Go does not allow "package main" next to another
package in the same directory, so both have to go before the
PocketBase entry point can live at the root and embed web/build from
there.

The remaining legacy packages (internal/store, service, handler,
domain, config, clock) are untouched and keep building as a
reference.
2026-11-29 17:05:19 +00:00
aksdb fcb008dd57 🧪 Test sync push endpoint
Covers create, update, stale, forbidden and readonly answers, the
guard for the last settings row, request validation, the missing auth
token and that a failing change rolls back the whole batch. Also
checks that regular users cannot write synced collections over REST
and that superuser writes keep the owner and rev consistent.
2026-11-29 17:03:45 +00:00
aksdb f63fe1b549 ✨ Add batch push endpoint for synced collections
POST /api/sync/push applies up to 500 client changes of a signed-in
user in one transaction. Every change is answered with ok, stale,
forbidden or readonly, so the client can reconcile its local state
with the server state.

closed_days and closed_weeks are answered as readonly because only
the server computes them. The last remaining settings row of a user
cannot be deleted either; such a change is answered as stale, which
clients already treat as "server wins".
2026-11-29 17:03:42 +00:00
aksdb a2507d22d3 ✨ Scaffold PocketBase app with embedded UI
Add PocketBase v0.40.6 as a dependency together with the pieces the
new backend is built from: the list of synced collections with their
client-writable fields, the initial migration that creates the five
per-user collections (entries, closed_days, closed_weeks,
settings_history, balance_adjustments), and empty Register stubs for
the tracking and legacy import packages.

Clients only get read access to their own rows over REST; writes are
meant to go through the sync push endpoint. web/build is now ignored
except for a tracked placeholder so the built SPA can be embedded.

The entry point (main.go) and the UI embedding (ui.go) are not part
of this commit: the repo root is still the legacy "assets" package,
and Go does not allow "package main" in the same directory.
2026-11-29 16:58:41 +00:00
aksdb 3b024b6766 ⬆️ Add SignalDB and PocketBase client dependencies 2026-11-29 16:57:28 +00:00
aksdb ab5749107c ♻️ Bootstrap when syncmarker is zero 2026-08-20 15:53:39 +00:00
aksdb 29284a024d 🐛 Fix sync from zero 2026-08-20 17:35:43 +02:00
aksdb babc9a8096 🧪 Reproduce failing sync from zero 2026-08-20 16:42:08 +02:00
aksdb 4fa598e5ce ⬆️ Update dependencies 2026-08-20 16:34:55 +02:00
aksdb 8cd58fbd2c fix: closing the week early should count properly 2026-05-13 20:47:39 +00:00
aksdb c617012401 test: expect proper midweek handling 2026-05-13 20:44:14 +00:00
aksdb ca5f5f95e2 refactor: introduce clock to make tests reproducible 2026-05-13 20:24:56 +00:00
aksdb 7e6c47a50e refactor: default to today-view 2026-05-08 20:40:20 +00:00
aksdb d3faf79b57 fix: service worker registration 2026-05-08 19:27:07 +02:00
aksdb 68e16fa4ca build: force vite-plugin-pwa to use project vite instance 2026-05-01 22:37:42 +02:00
aksdb 905d668847 build: replace install task with mise deps for automatic dependency management 2026-05-01 22:34:46 +02:00
aksdb fe5603e206 build: add Containerfile for multi-stage container image
Three stages: node:24-alpine builds the Svelte SPA, golang:1.26-alpine
compiles the Go binary with embedded assets (-tags production), and
alpine:3.21 is the minimal runtime.

Runs as unprivileged user (uid 1000). DB_PATH defaults to /data/wotra.db
so a volume mount at /data provides persistent storage.

  podman run -e AUTH_TOKEN=secret -p 8080:8080 -v wotra-data:/data wotra
2026-05-01 22:05:29 +02:00
aksdb a372c17860 feat: sync status indicator in nav
Shows a sync button in the top-right corner of the nav bar with live
status: spinning while syncing, warning icon on error, grey when idle.
Tooltip shows last synced time or error message. An orange badge
appears when there are pending outbox items.

- sync.ts: add syncState store (status, lastSynced, pendingCount,
  error); guard against concurrent sync cycles with syncInFlight flag
- layout: sync button wired to triggerSync(); ticks every 15s so the
  'Xs ago' label stays current
2026-05-01 21:44:50 +02:00
aksdb 57697ec2aa feat: offline-first client
All reads now come directly from Dexie; all mutations write to Dexie +
outbox immediately without waiting for the server. The background sync
loop (every 30s) pushes the outbox and pulls server changes.

Day/week close and reopen remain server-only (require server-side
computation). triggerSync() is called after them to update Dexie
promptly. The optimistic closedDaysMap update in the week page is kept
separate from the Dexie reload to avoid a race that was causing the
reopen button and day actions to disappear until a page reload.

- client.ts: remove online-first fetch paths; all reads from Dexie
- sync.ts: add triggerSync() and waitForSync() exports
- DayDetail: pass ClosedDay | null to oninvalidate after close/reopen
- week/+page.svelte: update closedDaysMap optimistically on close/reopen;
  only reload from Dexie on entry mutations
- settings/+page.svelte: read history() directly (never throws 503);
  derive current locally
- layout: remove offline banner and online.ts (behaviour is now
  identical online and offline)
2026-05-01 16:35:02 +02:00
aksdb f4836a6fa2 feat: be more lenient on sync 2026-05-01 15:26:54 +02:00
aksdb f602e08b5a feat: responsive day chips via CSS container queries
Wrap each DayChip in a container-query context so the chip layout
responds to the actual space available rather than the viewport width.

Breakpoints (per-chip width):
- < 72px  (mobile, 7 chips in ~320px): compact — label + date + progress bar + badges only
- ≥ 72px  (tablet+): show worked duration text below the date number; slightly larger padding/font
- ≥ 100px (desktop, 7 chips in ~750px wide main): larger date number, bigger worked label

The .chip-slot div in week/+page.svelte is the flex child (flex: 1,
min-width: 2.8rem) that feeds width into the container; .chip-wrap
inside DayChip carries container-type: inline-size and fills the slot.
2026-05-01 13:29:07 +02:00
aksdb bf2c4a3301 build: exclude binaries from git 2026-05-01 12:11:54 +02:00
aksdb 725df56cc8 feat: offline read fallback + online status indicator
All GET calls in client.ts now fall back to Dexie when a network error
(TypeError) is caught, so pages render from cached data when the server
is unreachable:

- entries.list()       → db.entries filtered by day_key range
- days.list()          → db.closed_days filtered by day_key range
- weeks.list()         → db.closed_weeks filtered by week_key range
- weeks.balance()      → computed locally from closed_weeks + balance_adjustments
- balance.list()       → db.balance_adjustments ordered by effective_at DESC
- settings.current()   → db.settings_history, latest row with effective_from <= today
- settings.history()   → db.settings_history ordered by effective_from DESC

Day/week close and reopen remain online-only (they require server-side
computation).

Add isOnline store (navigator.onLine + window online/offline events) and
an amber 'Offline — showing cached data' banner in +layout.svelte shown
whenever the store is false.
2026-05-01 09:47:14 +02:00
aksdb 31535e944d fix: move embed to repo root; make build sequential
- Move embed_prod.go/embed_dev.go out of cmd/wotra/ into root-level
  assets_prod.go / assets_dev.go (package assets). go:embed paths
  must be relative to the source file; cmd/wotra/ cannot reach
  ../../web/build.
- Update cmd/wotra/main.go to import the root assets package.
- Change mise.toml build task from parallel depends to sequential
  shell commands (build:web then build:go) so the frontend is always
  compiled before the Go embed runs.
2026-05-01 09:39:52 +02:00
aksdb a8a4ea0d4f M9.1: wire sync logging into all mutation paths
- Add LogClosedDayDelete and LogClosedWeekDelete to SyncStore
- Inject syncStore into EntryService; log Start, Stop, StopByID,
  Update, CreateInterval, Delete, AutoStopStalledEntries
- Inject syncStore into DayService; log CloseDay, MarkDay, ReopenDay,
  and the recomputeWeek closed-week upsert
- Inject syncStore into SettingsService; log Upsert, UpdateSettings,
  DeleteSettings
- Add LogClosedWeek/LogClosedWeekDelete calls in WeekService.CloseWeek
  and ReopenWeek
- Update main.go and all service test helpers for new constructor signatures
- All Go tests and 19 Vitest tests pass
2026-04-30 22:57:02 +02:00
aksdb d8366f5c25 Add sync redesign with offline fallback (M9)
- Migration 003: adds logged_at to sync_log for TTL pruning; migrates
  settings_history to UUID TEXT PK with updated_at column
- SyncStore: Prune() deletes rows older than 30d and writes a '_pruned'
  marker at the boundary version; Pull() calls Prune lazily and returns
  ErrSyncStale (410) when the client's since_version is behind the marker
- sync_handler.go: GET /api/sync/pull?since=N; POST /api/sync/push with
  last-updated_at-wins conflict resolution for entries, balance_adjustments,
  settings_history; closed_days/closed_weeks skipped (server-only mutations)
- router.go: passes entryStore, adjustmentStore, settingsStore to SyncHandler
- settings_store.go: UUID PK, updated_at column, Upsert() for push path
- settings_service.go: generates UUID on create, sets updated_at on update
- settings_handler.go: ID params changed from int64 to string
- domain.go: Settings.ID string, Settings.UpdatedAt added
- client.ts: all mutation methods catch TypeError (offline) and fall back
  to Dexie write + outbox enqueue; crypto.randomUUID() for offline creates;
  Settings.id type changed to string
- db.ts: Dexie v3 — settings_history key path changed to string UUID;
  upgrade handler clears table for repopulation via pull
- sync.ts: real pushOutbox to POST /api/sync/push; pullChanges uses GET
  with ?since=N; 410 triggers coldStart() + retry; coldStart() wipes all
  tables and resets last_version
- 4 new Go store tests covering normal pull, stale client, empty prune,
  client-ahead-of-marker; all tests pass (store + service, 19 Vitest)
2026-04-30 22:50:33 +02:00
aksdb 3214f48a6f Add balance adjustments (M8)
- New balance_adjustments table with CRUD store, sync logging, and service methods
- SQL migrations restructured: embed fs.FS from internal/store/migrations/, apply in order via user_version
- WeekService.Balance combines closed-weeks delta + adjustments delta; BalanceSummary breakdown
- Four REST routes: GET/POST /api/balance/adjustments, PUT/DELETE /api/balance/adjustments/{id}
- Dexie schema v2 + sync apply cases for balance_adjustments
- API client: BalanceAdjustment type, balance namespace (list/create/update/delete)
- utils: composeDeltaMs / decomposeDeltaMs helpers + 8 new Vitest tests (19 total, all passing)
- History page: balance card breakdown line + full adjustments section with inline add/edit/delete
2026-04-30 21:50:57 +02:00
aksdb 8ca838fa6e feat: overall overtime balance on history page
Backend:
- ClosedWeekStore.SumDelta: single SQL aggregate returning total delta_ms and
  row count across all closed_weeks
- WeekService.Balance: thin passthrough returning BalanceResult{TotalDeltaMs, ClosedWeekCount}
- GET /api/weeks/balance handler; route registered alongside /weeks list/close/reopen
- Tests: store-level SumDelta (empty + populated), service-level Balance (empty + 2 weeks)

Frontend:
- weeks.balance() added to API client
- History page: balance card at top, fetched in parallel with existing data
- Loading state shows '—'; once loaded shows formatDelta value in green/red/gray
- Shows 'across N closed weeks' count alongside the value
2026-04-30 20:01:24 +02:00
aksdb 15bf3c3a18 feat: edit and delete settings history rows
Backend:
- SettingsStore: Add GetByID, Update, Delete, Count methods
- SettingsService: Add UpdateSettings (validates same rules as Upsert),
  DeleteSettings (guards against deleting the last row → 409)
- New sentinels: ErrSettingsNotFound, ErrLastSettingsRow
- Handler: PUT /api/settings/history/{id} → 200 updated row
           DELETE /api/settings/history/{id} → 204 / 404 / 409

Frontend:
- API client: settings.update(id, body) and settings.delete(id)
- Settings page: history table gains edit (pencil) and delete (×) buttons
- Inline edit form expands in place within the table row
- Delete button disabled and hint shown when only one row remains
- maskLabel() helper shows workday names instead of raw bitmask
- After save/delete: full reload to reflect changes in 'current' section
2026-04-30 19:50:27 +02:00
aksdb b25340644b refactor(nav): Today tab shortcut to week view; delete /today route
- Today nav link targets /week?week=<currentWeek>&day=<todayKey>
- Today tab active: route=/week AND ?day===todayKey() (not just pathname)
- Week tab active: route=/week AND today tab not active
- Root / redirect updated from /today to /week?week=…&day=…
- /today route hard-deleted (src/routes/today/ removed)
- +layout.svelte imports todayKey/currentWeekKey for link generation
2026-04-30 19:10:17 +02:00
aksdb bf0c728818 fix(entries): reject create/update of intervals in the future
- Add ErrFutureDay sentinel error
- CreateInterval: rejects if startDayKey > todayKey (400)
- Update: rejects if new start_time moves entry to a future day (400)
- Handler maps ErrFutureDay → 400 Bad Request for both endpoints
- Add TestCreateIntervalRejectsFutureDay
- Add TestUpdateRejectsMoveToFutureDay
- UI already gates this via dayCapabilities (canAddInterval=false,
  canEditEntries=false for future days), but server now enforces it too
2026-04-30 19:09:22 +02:00
aksdb 4c2b220482 feat(week): day selection with URL-driven state
- weekKey and selectedDay driven by ?week=&?day= query params
- Bare /week canonicalizes via replaceState (adds week+day params)
- Chip clicks: replaceState (no history push, no scroll jump)
- Week prev/next: goto with history push (back/forward works)
- Default day when week changes: today if in week, else Monday
- Keyboard navigation: ArrowLeft/Right cycles through chips
- Selected chip scrolls into view on selection change
- DayDetail always rendered for selectedDay (not just today)
- detailCaps reactive on closedDaysMap — updates immediately after
  close/reopen/mark without extra load()
- Chips now wired: selected prop, onclick handler
- DayChip tabindex: 0 for selected chip, -1 for others (roving tabindex)
2026-04-30 19:08:11 +02:00
aksdb d0c1f41c13 refactor: extract DayDetail component; render today inside week view
- New DayDetail.svelte: self-contained day panel with full capability
  gating (canStartStop, canAddInterval, canEditEntries, canMarkKind,
  canCloseDay, canReopenDay)
- Closed-day state: banner + read-only entry list with 'Reopen day to
  edit' hint; mark-kind buttons still available
- Close Day button disabled (with tooltip) when running entry exists
- Timer only ticks when dayKey === todayKey() and entry is running;
  properly cleaned up on dayKey change and component destroy
- oninvalidate() callback: called after every mutation so parent
  (week view) can refetch and update the chip strip
- /today route: refactored to thin wrapper using DayDetail
- Week page: renders DayDetail below summary when today is in the
  displayed week; oninvalidate triggers full week reload
2026-04-30 19:06:55 +02:00
aksdb 3e4e93a814 feat(week): add day strip with per-day progress bars and status
- New DayChip.svelte component: weekday label, date number, progress
  bar (worked/expected), kind badge (H/V/S), closed checkmark, today
  highlight, selected state, accessible role=tab/aria-selected
- Week page: replace days-grid with horizontal scroll-snap chip strip
- Per-day workedMs: uses closed_days.worked_ms when closed, else sums
  open entries for that day (so in-progress work shows immediately)
- dailyExpectedMs: evenly split hours_per_week across workdays; 0 for
  weekends (no progress bar rendered for non-workdays)
- Progress bar turns amber when worked > expected (overtime)
- weekEntries stored in state (was discarded after computing set);
  daysWithEntries now derived from weekEntries
2026-04-30 19:04:38 +02:00
aksdb 6c4f78d101 chore(web): add Vitest; add dayCapabilities helper with full test coverage
- Install vitest + jsdom
- Add test/test:watch scripts to package.json
- Add test:web and test:all tasks to mise.toml
- Add dayCapabilities() to utils.ts — single source of truth for
  what actions are permitted per day (future/today/past, open/closed)
- Add DayCapabilities interface to utils.ts
- 11 unit tests: dayCapabilities (5 cases), weekDayKeys (3 cases),
  isWorkday (3 cases)
2026-04-30 19:03:04 +02:00
aksdb 73e5b01577 docs: update PLAN.md — merge Today+Week view stages M7, add decisions 2026-04-30 19:01:47 +02:00
aksdb 47dd2c9779 fix: CloseWeek uses settings effective at close time, not week Monday
Settings configured mid-week (e.g. Thursday) have an effective_from
of that date. CloseWeek was looking up settings as-of Monday, which
predates the new settings row and fell back to the old default.

Now uses today's date for the settings lookup, so any settings change
made before closing the week is correctly reflected in expected_ms.
2026-04-30 18:23:13 +02:00
aksdb e37458f513 fix: weekDayKeys formula breaks when Jan 4 falls on Sunday
The naive formula used (jan4.Weekday() - time.Monday) produces -1
when Jan 4 is a Sunday (Weekday()==0), shifting the computed Monday
one week forward. 2026 is affected: Jan 4 is a Sunday, so every
week key in 2026 was mapped to the wrong 7-day range, causing
CloseWeek to look for closed_days on the wrong dates and finding
nothing — resulting in worked_ms=0 and a full -Nh delta.

Fix: use (weekday+6)%7 to get days-since-Monday (Mon=0…Sun=6),
which is always non-negative.

Adds table-driven TestWeekDayKeys covering 2024 (Thu), 2026 (Sun),
and 2023 (Wed) to prevent regression.
2026-04-30 18:20:37 +02:00
aksdb 185bb0c6a9 revert: display closedWeek.delta_ms in closed-week banner 2026-04-30 18:17:19 +02:00
aksdb 47c7a97d47 fix: keep closed week snapshot in sync when days change
When a day is closed, re-closed, or reopened, DayService now
recomputes worked_ms and delta_ms on the closed week containing
that day (if the week is already closed). This prevents stale
delta values after editing entries and re-closing a day.

- DayService.recomputeWeek: sums worked_ms from all closed_days
  in the week, updates closed_weeks row preserving expected_ms
- NewDayService now takes ClosedWeekStore
- WeekKeyForDayKey exported helper (used by DayService)
- TestWeekSnapshotUpdatesWhenDayReopened regression test
2026-04-30 18:16:22 +02:00
aksdb 78c2c7c8a5 fix: show live delta in closed-week banner instead of stale frozen value
closedWeek.delta_ms is a snapshot taken at close time and goes stale
if entries are edited or days are re-closed afterward. The summary
rows above already use the live totalWorkedMs - expectedMs; the
closed-week banner now uses the same expression.
2026-04-30 18:12:34 +02:00
aksdb 3fd1455704 fix: hide close-week button when a tracked day is still open
Fetch entries for the week alongside days/weeks in the week view.
canCloseWeek now mirrors the server rule: every past workday that
has at least one entry must have a closed_days record. Days with
no entries are still skipped (they count as 0h implicitly).
2026-04-30 18:10:44 +02:00
aksdb 563784d5fb fix: show Close week button without requiring all workdays closed
The frontend was blocking week close until every workday had a
closed_days record, which no longer matches the backend's rules
(untracked days are implicitly 0h). Replace the all-workdays-closed
guard with a simple check: week has started (Monday ≤ today) and
is not already closed. The server returns a clear error if a day
with entries still needs closing.

Also fixes a pre-existing TS type narrowing error on currentSettings
and removes the now-unused .hint CSS rule.
2026-04-30 18:08:06 +02:00
aksdb c675a7b01d fix: skip untracked workdays when closing a week
Previously any past workday without a closed_days record blocked week
close. Now only days that actually have entries require an explicit
close. Empty workdays count as 0h worked, which is reflected in the
weekly delta automatically.

- WeekService.CloseWeek: after finding no closed_days record, check
  whether the day has any entries; only error if it does
- NewWeekService: takes EntryStore to support the above check
- Updated TestCloseWeekMissingDayFails to reflect the new semantic
  (test now creates entries on Friday but leaves it unclosed)
2026-04-30 17:59:04 +02:00
aksdb 6fceda46b5 fix: allow closing current week when future workdays are not yet closed
CloseWeek was requiring every workday in the ISO week to have a
closed_days record, including days in the future. Now only workdays
up to and including today are checked; future workdays are skipped.

Adds TestCloseWeekMidWeek regression test.
2026-04-30 17:54:38 +02:00
aksdb 9d6233b116 feat: add manual interval creation and inline entry editing
- Service: CreateInterval() validates same-day, end>start, day not closed
- Service: Update() now rejects edits on closed-day entries (ErrDayAlreadyClosed)
- Handler: POST /api/entries creates a completed interval with explicit times
- API client: entries.createInterval(startMs, endMs, note)
- Utils: parseTimeInput / toTimeInput helpers for HH:MM <-> unix ms
- Today page: '+ Add interval' form (time pickers + optional note)
- Today page: pencil button on each entry opens inline edit row (start/end/note)
- Tests: TestCreateInterval, TestCreateIntervalEndBeforeStart,
         TestCreateIntervalCrossesMidnight, TestUpdateRejectsClosedDay
2026-04-30 17:45:02 +02:00
aksdb 245edf1534 chore: add mise.toml for tool versions and tasks, thin Makefile shim 2026-04-30 17:35:28 +02:00
aksdb 2055a46dee feat(m6): CSV export, Makefile, README, single-binary build 2026-04-30 16:48:44 +02:00
aksdb 4a328ad6cc feat(m5): PWA service worker, offline Dexie store, outbox, sync endpoints 2026-04-30 16:47:27 +02:00
aksdb df04d9d7a9 feat(m4): SvelteKit frontend - today, week, history, settings views 2026-04-30 16:45:00 +02:00
aksdb d0ef0387f2 feat(m3): week close, overtime/undertime delta, frozen settings snapshot 2026-04-30 16:39:42 +02:00
aksdb 4a0e0c8318 feat(m2): settings history, close day, holiday/vacation/sick marking 2026-04-30 16:37:56 +02:00
aksdb 3aa068efd2 feat(m1): backend scaffold - entries CRUD, start/stop, auth, migrations 2026-04-30 16:35:06 +02:00
aksdb 4905c6f570 docs: add implementation plan 2026-04-30 16:24:39 +02:00