kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Implement AttendanceNewPage — attendance-taking form

Open akolson opened this issue 9 months ago • 4 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Implement AttendanceNewPage — the attendance-taking form coaches use to record a new session. The page presents a searchable, paginated list of class learners, each with a toggle to mark them present or absent. Coaches submit the session to save it to the database. Builds on the stub added in #14236.

Complexity: Medium Target branch: release-v0.19.x

Context

AttendanceNewPage is the core coach action in the attendance feature — coaches arrive here from the "Mark attendance" button in AttendanceBlock. The session timestamp is captured when the route is entered, so the date/time in the header accurately reflects when the session started.

The Change

AttendanceNewPage (kolibri/plugins/coach/frontend/views/attendance/AttendanceNewPage.vue):

  • CoachImmersivePage with an H1 showing the session date/time (captured on route enter, formatted via formatAttendanceDateTime)
  • Learner table (CoreTable) with two visibility-hidden headers — learner name and status:
    • Learners sorted alphabetically, paginated at 50 per page
    • Searchable via KTextbox — filters by learner name
    • Per-learner KSwitch (default false); when true, row shows "Present" label and $themePalette.blue.v_100 background
    • "Mark all learners present" KSwitch at the top of the table — triggers a KModal confirmation when marking all present
  • BottomAppBar — live present/absent count, Cancel and Submit buttons
  • Submit — calls createSession, redirects to ATTENDANCE_HISTORY with a success snackbar; shows error snackbar on failure
  • Unsaved changes guard — beforeRouteLeave prompts with a KModal if the coach navigates away with unsaved changes

Design Spec

Description Screen
Attendance taking form AttendanceNewPage
Present state — row highlight and bottom bar Present state
Mark all present confirmation modal Mark all modal

Out of Scope

  • Editing an existing session (separate issue — AttendanceEditPage)
  • Attendance history list (separate issue — AttendanceHistoryPage)

Acceptance Criteria

General

  • [ ] Session timestamp is captured when the route is entered and displayed in the page H1
  • [ ] Learners are sorted alphabetically and paginated at 50 per page
  • [ ] Learner list is filterable by name via a search box
  • [ ] Each learner row has a KSwitch defaulting to false; when true, the row shows a "Present" label and a $themePalette.blue.v_100 background
  • [ ] A "Mark all learners present" KSwitch at the top of the table triggers a KModal confirmation before applying
  • [ ] BottomAppBar displays live present and absent counts
  • [ ] Submitting calls createSession and redirects to ATTENDANCE_HISTORY with a success snackbar
  • [ ] On error, the user remains on the page and an error snackbar is shown
  • [ ] Navigating away with unsaved changes prompts a KModal confirmation

Styling

  • [ ] Present row background uses $themePalette.blue.v_100, not a hardcoded colour

Accessibility and i18n

  • [ ] Table headers are present in the DOM but visually hidden
  • [ ] Each KSwitch has an aria-labelledby referencing a visually hidden label
  • [ ] All user-visible strings are internationalised
  • [ ] Page is keyboard navigable

Testing

  • [ ] Learner list renders sorted and paginated correctly
  • [ ] Search filtering works correctly
  • [ ] KSwitch toggle updates present/absent counts in the bottom bar
  • [ ] Mark all present confirmation modal appears before applying
  • [ ] Successful submit redirects to history with snackbar
  • [ ] Failed submit shows error snackbar and stays on page
  • [ ] Unsaved changes guard fires on navigation away

References

  • Issue #14236 — stub page being fleshed out
  • Issue #14022 — original feature spec with design references
  • GroupMembersPage — example of an interactive learner table in the coach plugin

🤖 This issue was written with AI assistance, under supervision, review and final edits by [@akolson] 🤖

akolson avatar Feb 25 '26 11:02 akolson

Implementation Plan: AttendanceNewPage

Branch: issue-14242-a8a461 (target: release-v0.19.x)

Architecture

Replace the AttendanceNewPage stub with a full attendance-taking form using CoachImmersivePage, CoreTable, PaginatedListContainer, KSwitch, KModal, and BottomAppBar. Learner data comes from the existing classSummary Vuex store. Submission uses useAttendance composable's createSession. All strings use createTranslator.

Files Modified

File Change
kolibri/plugins/coach/frontend/views/attendance/AttendanceNewPage.vue Full page implementation
kolibri/plugins/coach/frontend/views/attendance/__tests__/AttendancePages.spec.js Expanded tests

Phases

Phase 1: Core component structure & learner table

  • CoachImmersivePage shell with session timestamp in H1 (captured on route enter)
  • Searchable, paginated learner table (PaginatedListContainer + CoreTable, 50/page, sorted alphabetically)
  • Visually hidden table headers for accessibility

Phase 2: Toggle, mark-all, and bottom bar

  • Per-learner KSwitch (default false) with present-row highlighting ($themePalette.blue.v_100)
  • "Mark all learners present" KSwitch with KModal confirmation
  • BottomAppBar with live present/absent counts, Cancel and Save buttons

Phase 3: Submit, error handling, unsaved-changes guard

  • Submit calls createSession, redirects to ATTENDANCE_HISTORY with success snackbar
  • Error handling: stays on page with error snackbar
  • beforeRouteLeave guard with KModal when isDirty is true

Phase 4: Tests (9 tasks)

  • Sorted rendering, search filtering, toggle counts, mark-all modal, submit success/failure, unsaved-changes guard (full flow including modal confirm/cancel)

Key Decisions

  • isDirty flag for unsaved-changes detection (set on first toggle, never unset except on submit/confirm-leave) — more robust than checking attendanceMap values
  • Reuses existing attendanceStrings for present/absent counts from kolibri-common
  • @vue/test-utils for complex tests — follows the pattern from AttendanceBlock.spec.js; simpler stub tests keep Vue Testing Library

rtibblesbot avatar Mar 11 '26 18:03 rtibblesbot

Implementation Complete: AttendanceNewPage

All 4 phases implemented and verified:

What was built

  • CoachImmersivePage wrapper with session timestamp captured on mount
  • Searchable, paginated learner table (50/page, alphabetically sorted) using PaginatedListContainer + CoreTable
  • Per-learner KSwitch toggles with present-row highlighting via $themePalette.blue.v_100
  • Mark-all-present switch with KModal confirmation before applying
  • BottomAppBar with live present/absent counts (reusing attendanceStrings)
  • Submit flow: calls createSession, redirects to history with success snackbar; error snackbar on failure
  • Unsaved-changes guard: beforeRouteLeave with KModal confirmation when dirty
  • Shared strings: Cancel/Confirm/Save use coreString() from commonCoreStrings

Test evidence

Test Suites: 3 passed, 3 total
Tests:       35 passed, 35 total (14 new for AttendanceNewPage)

Code quality

  • Ran /simplify review: removed redundant .visuallyhidden CSS (global exists), replaced duplicate Cancel/Confirm/Save strings with coreString(), extracted $store/$router from proxy, moved $themePalette to template
  • Lint: all hooks pass
  • Follows established patterns from AttendanceBlock.spec.js for test infrastructure

Files changed

  • kolibri/plugins/coach/frontend/views/attendance/AttendanceNewPage.vue — full implementation
  • kolibri/plugins/coach/frontend/views/attendance/__tests__/AttendancePages.spec.js — 14 tests

rtibblesbot avatar Mar 11 '26 18:03 rtibblesbot

Self-Review Summary

Reviewed git diff release-v0.19.x...HEAD (2 files, 703 lines added).

Acceptance Criteria

All 20 acceptance criteria verified as met (general, styling, a11y/i18n, testing). All 14 tests pass.

Findings & Fixes

Fixed (suggestion):

  • Removed unused visuallyhidden span with status-label-* id that was never referenced by any aria-* attribute
  • Removed present-label CSS class usage with no corresponding style rules
  • Consolidated into a single conditional <span> — committed in 981f18d

Noted (nitpick, no action):

  • Test file uses @vue/test-utils — follows existing coach plugin pattern (10+ existing spec files use it)

Praised:

  • Thorough unsaved-changes guard logic with correct isDirty/submitting interaction
  • Clean composable mock patterns following established __mocks__/ conventions

rtibblesbot avatar Mar 11 '26 18:03 rtibblesbot

Mostly fixed in #14364 - will need some follow up for full product conformance.

rtibbles avatar Mar 13 '26 05:03 rtibbles