Globals


Instance Methods

dayNumber(date)

A 'YYYY-MM-DD' date as a whole day number, so two dates are compared as calendar days, never as moments: a workout's date has no time of day, and new Date('YYYY-MM-DD') is midnight UTC, which in the evening west of UTC is already more than a day before the local "now" (21:30 in Toronto counted yesterday's workout as 2 days ago).

Parameters

  • date

Other

responsiveTable

Generates a menu with the provided index as the currently selected item.

Parameters

  • tableRows (Array)
  • tableHeadings (Array)
  • tableClass (string)

Returns

  • Object.<DomItem>

addExerciseForm

Builds the add-exercise form's DOM structure. No event wiring here - see exercisePicker.js's own note on why that has to happen after this is attached into the real document and rendered. Primary and secondary are two separate multi-selects (rather than one picker with a per-muscle rank) - a real exercise's muscles split cleanly into those two buckets, and a plain multi-select needs no dynamic add/remove row UI to support picking several of each.

Parameters

  • muscles (Array) — musclePriority()'s shape (every real muscle, not just priority ones) - becomes both selects' options

Returns

  • Object

wireAddExerciseFormEvents

Wires the form's submit button - see addExerciseForm's own note on timing.

Parameters

  • form (Object)
  • onSubmit (function) — ({ name, description, primaryMuscleIds, secondaryMuscleIds }) => void

detail

Generates a menu with the provided index as the currently selected item.

Parameters

  • currentIndex (number)

Returns

  • DomItem

exercisePicker

Builds the muscle -> exercise picker's DOM structure. No event wiring here - fullAddEventListener needs a complete parentItem chain up to the real document root (it throws otherwise), which a freshly-built, not-yet-attached DomItem doesn't have yet. Call wireExercisePickerEvents once this is attached into the real document and rendered.

Parameters

  • priorityRows (Array) — musclePriority()'s shape, ordered by priority - becomes the muscle dropdown's options, top priority first

Returns

  • Object

wireExercisePickerEvents

Wires the picker's change events, once it's attached into the real document and rendered - see exercisePicker's own note on why this can't happen at construction time.

Parameters

  • picker (Object)
  • onMuscleChange (function) — (muscleId: string) => void
  • onExerciseChange (function) — (exerciseId: string) => void

lastSessionDisplay

Parameters

  • session (Object | null) — getLastSession()'s shape, or null if never logged

Returns

  • DomItem

logWorkoutForm

Builds the log-workout form's DOM structure. No event wiring here - see exercisePicker.js's own note on why that has to happen after this is attached into the real document and rendered.

Returns

  • Object

readFormValues

Reads the form's current field values, independent of which button triggered it.

Parameters

  • form (Object)

wireLogWorkoutFormEvents

Wires the form's submit and update buttons - see logWorkoutForm's own note on timing.

Parameters

  • form (Object)
  • onSubmit (function) — ({ weightEffort, sets, reps, note, date }) => void, logs a brand new entry
  • onUpdate (function) — ({ weightEffort, sets, reps, note, date }) => void, corrects the most recently shown entry

musclePriorityList

Generates a table ranking muscles by how much they need attention right now.

Parameters

  • priorityRows (Array) — musclePriority()'s shape: [{ muscleId, name, daysSinceLastWorked, timesWorkedThisWeek, needsPriority }]

Returns

  • Object.<DomItem>

workout

Generates a table for a workout plan.

Returns

  • DomItem

localDate

A date as 'YYYY-MM-DD' in the machine's own timezone - the shape every workout's date uses. Not toISOString().slice(0, 10): that's the UTC date, which is already tomorrow in the evening anywhere west of UTC (21:30 in Toronto is 01:30 UTC).

Parameters

  • date — defaults to now

musclePriority

Rank muscles by how much they need attention right now, from a real read of the database: every muscle (including ones never worked at all), and every workout row with its muscles already joined on (see workout()/musclePriority.test.js for the exact query shape this expects). A muscle needs priority once it's past its recovery window, or hasn't been worked often enough this week yet - whichever muscle has gone longest without being worked sorts first.

Parameters

  • muscles — every row from read muscles
  • workoutsWithMuscles — every row from the workouts-joined-to-muscles query, each carrying a .muscles array (the muscles that workout's exercise worked)
  • today — injectable for testing; defaults to the real current time (only its local date counts)

createReads

The app's reads, given the json-fs-query query and quote to run them with: Node's (workoutQueries.js, for the API server and the tests) or the browser build's (browserReads.js, for the page, which reads database/ from its own origin over fetch()). Reads need no server; only writes do.

Parameters

  • jsonFsQuery (Object)

Returns

  • Object

exercise

A value that is the _id of the exercise with this name, once it's inserted: exercises' ids are generated on insert (json-fs-query's auto replaces any _id given), so rows refer to them through this.

Parameters

  • name (string)

Returns

  • function

seedRows

The rows every test database starts with: the app's original seed data (14 muscles, 3 exercises each linked to one muscle, and 6 workouts on 2024-06-02 and 2024-06-05). Fixed here, so tests never depend on the real database/, which changes with every workout logged.

createTestDatabase

Build a test database at destination: every record the real database has, with the same fields and keys (read from its record files, so a schema change reaches the tests), holding only the given rows. Configures json-fs-query to use it.

Parameters

  • destination (string) — The folder to create the test database in.
  • rows (Object.<string, Array.<Object>>, optional, default: "seedRows") — The rows to insert, by record, in an order that keeps the foreign keys valid.
  • source (string, optional, default: "'database/'") — The real database whose schema is copied.

Returns

  • Promise.<Object.<string, Array.<Object>>> — The inserted rows by record (with their generated ids).

logWorkout

Log a new workout entry.

Parameters

  • exerciseId
  • weightEffort
  • sets
  • reps
  • note
  • date — defaults to today (the local date, see localDate), in the same 'YYYY-MM-DD' shape the rest of the data uses
  • order — where this entry falls among others logged the same day (defaults to first)

updateWorkout

Update an existing workout entry - e.g. correcting the plan with what was actually done.

Parameters

  • workoutId
  • changes — any subset of weightEffort/sets/reps/note to change

addExercise

Add a new exercise, with the muscles it works (primary/secondary, by whatever rank you give).

Parameters

  • name
  • description
  • muscleAssignments (Array.<{muscleId: number, rank: number}>) — one row per muscle this exercise works