Commit Graph

3 Commits (main)

Author SHA1 Message Date
Boban Blaskovic 88945b47f6 feat(tasks): multi-type questions (cloze + geo-map) + Run.php type dispatch
Tasks Run page now switches on question $type and renders one of three layouts:
choice (existing multiple-choice), cloze (Lückentext text input), geo-map
(clickable SVG region picker). Adds Deutsch-Lückentexte + Geografie-Europa
question banks with the required type-specific keys.

- Run.php: replaces submitAnswer/lastAnswerIndex with submitChoice + submitCloze
  + submitRegion. lastAnswer is now an array { type, ...payload }. Cross-type
  calls are no-ops so a stray dispatch can't pollute state.
- run.blade.php: branches on $q['type']; cloze has wire:model.live debounce
  + Enter-to-submit; geo-map has SVG + accessible label-button grid; feedback
  pill below each layout.
- config/tasks.php: adds deutsch-lueckentexte + geografie-europa-laender.
- config/task-questions.php: type=cloze entries with correct+accept[] for
  case-insensitive alt-spelling match; type=geo-map entries with regions[]
  and SVG paths.
- Tests: renames submitAnswer→submitChoice across run page suite; adds full
  coverage for cloze (correct/wrong/empty/case/accept[]/payload shape/clear
  on next), geo-map (correct/wrong/payload/SVG render), and cross-type
  guards. TaskQuestionBank test is now type-aware (choice needs options[4],
  cloze needs correct string, geo-map needs regions[]+matching correct key).

Test: 204/204 Pest green. Smoke: 10/10 task routes 200, 4/4 modal components
mount cleanly, no errors written to laravel.log during the smoke pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 19:28:09 +02:00
Boban Blaskovic d3f976b18e feat(tasks): semantic slugs + per-slug question banks + Lerni AI-helper
Before:
  - Task slug "t1" was generic, meaningless to user and crawlers.
  - Question bank was keyed by `color`, so EVERY math task (multiplikation,
    geometrie, ...) shared identical questions.
  - No way for child / parent to ask AI for an explanation step-by-step.

Now (Workbook + Lerni variant from Übungsseite template):

Semantic slugs in config/tasks.php:
  math-multiplikation-bis-100
  math-geometrie-flaechen
  deutsch-wortarten-nomen-verben
  deutsch-gedicht-lernen
  englisch-vocab-animals
  englisch-past-simple
  sachkunde-wasserkreislauf

Each task now has:
  slug, title, topic, subject, meta, icon, color, points, status, due

config/task-questions.php re-keyed by `slug` (not color):
  Every task gets its OWN question set — math-multiplikation has
  multiplication questions, math-geometrie has area/perimeter, deutsch
  has wortarten/grammar, etc.

Each question now has 5 keys:
  question, options[4], correct, lerni_hint, lerni_steps[]

Lerni AI-helper (right sidebar in Workbook layout):
  - Closed by default; "Frag Lerni" button reveals
  - Hint box (💡) with short text-explanation
  - Numbered Lösungsweg with method-steps (colored badges per subject)
  - Shortlink URL `?lerni=1` (parents/teachers can deep-link to a
    pre-opened explanation)
  - #[Url(as: 'lerni')] hydrates from URL
  - Auto-closes on nextStep (fresh question = fresh thinking)

Route updated:
  Route::get('/tasks/{slug}/run', \App\Livewire\Tasks\Run::class)
    ->where('slug', '[a-z0-9-]+')   // tighter than whereAlphaNumeric;
                                     // allows hyphens, rejects UPPER
    ->name('tasks.run')

Tasks/Index::startTask / repeatTask: $slug arg + redirectRoute to
tasks.run with slug.

View livewire/tasks/run.blade.php switched from single column to
2-column grid (max-w-6xl): col-span-2 question card + col-span-1
Lerni aside. Per-subject color theming (focus-ring, progress bar,
step badges, option border on feedback).

Cleanup:
  - Removed App\Livewire\Tasks\Modals\Runner (obsolete; page-based now)
  - Removed livewire.tasks.modals.runner view
  - Removed TasksRunnerModalTest

Tests (TasksRunPageTest 22, TaskQuestionBankTest 6, TasksStartButton 8):
  - Semantic slug validation (no t[0-9]+ patterns)
  - Per-slug question selection (math vs deutsch vs english vs sachkunde)
  - math-multiplikation != math-geometrie (different content same color)
  - Lerni-panel renders; lerni-open trigger; toggleLerni reveals steps
  - Shortlink contains slug + ?lerni=1
  - ?lerni=1 query auto-opens helper
  - Route 404 for UPPER chars and unknown slugs
  - startTask redirects to tasks.run with slug

Verification:
  - 188 tests passed, 0 failed, 0 skipped (1024 assertions)
  - npm build OK
  - All 8 page routes 302 unauth
  - All 7 task slug routes 302 unauth
  - tasks/UPPER/run 404 (route regex)
  - 7 modal aliases resolve (Runner removed)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 22:48:05 +02:00
Boban Blaskovic cae775ba93 feat(tasks): dedicated /tasks/{key}/run page with per-subject question bank
Before: tasks.modals.runner showed the same 4 multiplication questions
regardless of subject (Mathe / Deutsch / Englisch / Sachkunde / Musik).
Made no sense — Englisch task shouldn't ask 12 × 8.

Now: dedicated full-page route /tasks/{key}/run loads the subject-correct
question bank based on the task's `color` token, with structured URL,
proper auth + license middleware, and Lazy skeleton placeholder.

New artifacts:

  config/task-questions.php  — Question bank keyed by color/subject:
    primary -> Mathematik (5 multiplication / division questions)
    rose    -> Deutsch (5 grammar/wortart/artikel questions)
    violet  -> Englisch (5 vocab/grammar in English)
    green   -> Sachkunde (5 nature/animals/space)
    amber   -> Musik (5 musical notation / theory)

  config/tasks.php  — Placeholder task list extracted from Index so
    both Tasks\Index (list page) and Tasks\Run (quiz page) share data.
    Future: replace with DB-backed Task model.

  app/Livewire/Tasks/Run.php
    - Lazy page-component, #[Layout('layouts.dashboard', active=tasks)]
    - mount(string $key) -> abort 404 if task or question bank missing
    - findTask() reads config('tasks')
    - questions = config("task-questions.{$task['color']}")
    - submitAnswer(int) records lastAnswerIndex + lastAnswerCorrect +
      tallies correctAnswers (visual feedback before advance)
    - nextStep() advances or sets finished=true on final
    - restart() resets all progress
    - placeholder() returns livewire.tasks.run-placeholder (skeleton)

  resources/views/livewire/tasks/run.blade.php
    - Back link + task header card (icon, meta, title, points)
    - Progress bar (Frage X / Y + correct counter)
    - Question card with 2x2 option grid, A/B/C/D labels
    - Per-color theme (primary/rose/violet/green/amber bar + ring)
    - Two-step interaction: pick option -> show correct/wrong feedback ->
      "Nächste Frage" / "Aufgabe abschließen"
    - Finished card: trophy or arrow-path; points earned; restart / done
    - All buttons use design tokens + heroicons (no inline SVG)

  resources/views/livewire/tasks/run-placeholder.blade.php
    - Skeleton with same layout shape (back link, header card, question)
    - data-testid="task-run-skeleton"

  routes/web.php
    Route::get('/tasks/{key}/run', \App\Livewire\Tasks\Run::class)
      ->whereAlphaNumeric('key')->name('tasks.run')
    Behind auth + license group like other dashboard pages.

  Tasks/Index::startTask() simplified:
    $this->redirectRoute('tasks.run', ['key' => $key], navigate: true)
    (Server-side redirect; client navigates without full reload.)

Security:
- whereAlphaNumeric('key') restricts URL param to safe chars
- abort_if($task === null, 404) prevents directory probing
- auth+license middleware applies to whole route group
- Question bank is config (no user-supplied content interpolated)
- Answer index validated against question[correct] only — no dynamic eval

Tests (27 new + 0 broken):
- TaskQuestionBankTest (4): config exists; 5 buckets; required keys;
  per-color content differs
- TasksRunPageTest (15): route registered; auth happy path; 404 for
  unknown key; per-color question selection (math/deutsch/eng/sachkunde);
  submitAnswer correct/wrong; nextStep advances + clears feedback;
  finishing 5 steps -> finished=true; restart resets; Index.startTask
  redirects; unauth redirected to login; placeholder testid
- TasksStartButtonTest updated: Start now redirects, no longer
  dispatches modal

Full verification:
- 186 tests passed, 0 failed, 0 skipped (661 assertions)
- npm build OK, manifest generated
- All 8 page routes return 302 unauth (correct)
- All 5 /tasks/{key}/run routes return 302 unauth (correct)
- All 8 modal aliases still resolve (legacy Runner modal kept)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 22:13:32 +02:00