Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Plan share: a shared superset keeps its name and rest between rounds (#292)
Pawel0e412b5c8576
diff --git a/frontend/src/lib/plan-share.js b/frontend/src/lib/plan-share.jsindex e72a2ce46..5a63137f7 100644--- a/frontend/src/lib/plan-share.js+++ b/frontend/src/lib/plan-share.js@@ -21,6 +21,7 @@ import { t, exerciseNameFor, exerciseNameClass, getLang, RTL_LANGS } from './i18import { convertWeight } from './units.js'import { fmtSpeed, speedUnitOf } from './speed.js'import { MUSCLES, inMuscleOrder } from './muscles.js'+import { SG_NAME_MAX } from './superset-meta.js'const PLAN_FMT = 1const WEEK_DAYS = [1, 2, 3, 4, 5, 6, 0] // every getDay() index; only the reader's own@@ -119,7 +120,14 @@ function cleanEx(e) {// timer in charge. parsePlan and mergePlan carry it through by spread.if (e.restSec > 0) o.restSec = e.restSecif (e.warmupRestSec > 0) o.warmupRestSec = e.warmupRestSec // the ramp's own rest travels with the work rest- if (e.sg) o.sg = e.sg+ if (e.sg) {+ o.sg = e.sg+ // A superset's name and its rest between rounds (#292) ride on every member, so they travel+ // with the group; without them a shared "Arms · 90 s" arrives nameless, resting the default.+ const name = cleanSgName(e.sgName), rest = cleanRestSec(e.sgRest)+ if (name) o.sgName = name+ if (rest) o.sgRest = rest+ }if (e.note) o.note = e.noteconst warm = cleanWarmupSets(e.warmupSets)if (warm) o.warmupSets = warm@@ -145,6 +153,11 @@ function cleanRestSec(v) {return n > 0 ? n : 0}+/** A superset name as setSupersetMeta writes it: a trimmed string of at most SG_NAME_MAX, or nothing. */+function cleanSgName(v) {+ return typeof v === 'string' ? v.trim().slice(0, SG_NAME_MAX) : ''+}+/** Keep the floors the config sheet and applyIntensifierPlan already enforce, and nothing else:* a plan file is someone else's data, so anything unrecognised is dropped rather than trusted. */function cleanIntensifier(x) {@@ -246,12 +259,15 @@ export function parsePlan(raw, destinationUnit = 'kg') {const intens = cleanIntensifier(e.intensifier)const rest = cleanRestSec(e.restSec)const warmRest = cleanRestSec(e.warmupRestSec)+ // Superset meta only means something on a member of a superset; on a lone exercise it is dropped.+ const sgName = e.sg ? cleanSgName(e.sgName) : ''+ const sgRest = e.sg ? cleanRestSec(e.sgRest) : 0const pyramid = normalizePyramid(e.pyramid)const pyramidRest = pyramid.length ? normalizePyramidRest(e.pyramidRest, pyramid.length) : []const pyramidWeight = pyramid.length ? normalizePyramidWeight(e.pyramidWeight, pyramid.length) : []- const { warmupSets, intensifier, restSec, warmupRestSec, pyramid: _pyramid, pyramidRest: _pyramidRest, pyramidWeight: _pyramidWeight, ...passthrough } = e+ const { warmupSets, intensifier, restSec, warmupRestSec, pyramid: _pyramid, pyramidRest: _pyramidRest, pyramidWeight: _pyramidWeight, sgName: _sgName, sgRest: _sgRest, ...passthrough } = eif (!known.has(passthrough.id)) passthrough.id = canonicalExId(passthrough.id)- return convertedExercise({ ...passthrough, ...(pyramid.length ? { pyramid } : {}), ...(pyramidRest.length ? { pyramidRest } : {}), ...(pyramidWeight.length ? { pyramidWeight } : {}), ...(warm ? { warmupSets: warm } : {}), ...(intens ? { intensifier: intens } : {}), ...(rest ? { restSec: rest } : {}), ...(warmRest ? { warmupRestSec: warmRest } : {}) }, sourceUnit || destination, destination)+ return convertedExercise({ ...passthrough, ...(pyramid.length ? { pyramid } : {}), ...(pyramidRest.length ? { pyramidRest } : {}), ...(pyramidWeight.length ? { pyramidWeight } : {}), ...(warm ? { warmupSets: warm } : {}), ...(intens ? { intensifier: intens } : {}), ...(rest ? { restSec: rest } : {}), ...(warmRest ? { warmupRestSec: warmRest } : {}), ...(sgName ? { sgName } : {}), ...(sgRest ? { sgRest } : {}) }, sourceUnit || destination, destination)})}))return {diff --git a/frontend/src/lib/plan-share.test.js b/frontend/src/lib/plan-share.test.jsindex daa08a4f8..5e1a3e52f 100644--- a/frontend/src/lib/plan-share.test.js+++ b/frontend/src/lib/plan-share.test.js@@ -159,6 +159,60 @@ describe('what survives a shared plan', () => {})})+// A superset's name and rest between rounds (#292) live on every member of the group. The+// export used to copy `sg` alone, so a shared superset arrived nameless and resting the default.+describe('superset meta in a shared plan', () => {+ const superset = {+ routines: [{ id: 'r1', name: 'Arms', ex: [+ { id: '0025', sets: 3, reps: 10, sg: 'a', sgName: 'Arms finisher', sgRest: 90 },+ { id: '0007', sets: 3, reps: 12, sg: 'a', sgName: 'Arms finisher', sgRest: 90 },+ { id: '0025', sets: 2, reps: 8 },+ ] }],+ week: {}, customEx: [],+ }+ const withEx = ex => ({ opengym_plan: 1, name: 'x', routines: [{ id: 'r', name: 'R', ex }], week: {}, customEx: [] })++ it('carries the name and rest through export, parsePlan and mergePlan', () => {+ const bundle = buildPlanBundle(superset, 'Plan')+ expect(bundle.routines[0].ex[0]).toMatchObject({ sg: 'a', sgName: 'Arms finisher', sgRest: 90 })+ const parsed = parsePlan(JSON.stringify(bundle))+ const s = { routines: [], customEx: [], week: {} }+ mergePlan(s, parsed, { schedule: false })+ const [a, b, lone] = s.routines[0].ex+ expect(a).toMatchObject({ sg: 'a', sgName: 'Arms finisher', sgRest: 90 })+ expect(b).toMatchObject({ sg: 'a', sgName: 'Arms finisher', sgRest: 90 })+ expect('sgName' in lone || 'sgRest' in lone).toBe(false)+ })++ it('leaves the fields out when the superset has neither', () => {+ const plain = { ...superset, routines: [{ id: 'r1', name: 'A', ex: [{ id: '0025', sets: 3, reps: 10, sg: 'a' }] }] }+ const e = parsePlan(JSON.stringify(buildPlanBundle(plain, 'Plan'))).routines[0].ex[0]+ expect(e.sg).toBe('a')+ expect('sgName' in e || 'sgRest' in e).toBe(false)+ })++ // A plan file is someone else's data: the name is trimmed and capped the way setSupersetMeta+ // writes it, the rest becomes a positive whole number of seconds or nothing.+ it('normalises a hand-edited name and rest, or drops them', () => {+ const long = ' ' + 'x'.repeat(100) + ' '+ const [e] = parsePlan(withEx([{ id: '0025', sets: 3, reps: 5, sg: 'a', sgName: long, sgRest: '75.4' }])).routines[0].ex+ expect(e.sgName).toBe('x'.repeat(40))+ expect(e.sgRest).toBe(75)+ const [bad] = parsePlan(withEx([{ id: '0025', sets: 3, reps: 5, sg: 'a', sgName: { evil: 1 }, sgRest: -30 }])).routines[0].ex+ expect('sgName' in bad || 'sgRest' in bad).toBe(false)+ const [blank] = parsePlan(withEx([{ id: '0025', sets: 3, reps: 5, sg: 'a', sgName: ' ', sgRest: 'abc' }])).routines[0].ex+ expect('sgName' in blank || 'sgRest' in blank).toBe(false)+ })++ it('drops the meta from an exercise that is not in a superset', () => {+ const [e] = parsePlan(withEx([{ id: '0025', sets: 3, reps: 5, sgName: 'Orphan', sgRest: 60 }])).routines[0].ex+ expect('sgName' in e || 'sgRest' in e).toBe(false)+ // and the export never writes it there either+ const out = buildPlanBundle(stateWith({ sgName: 'Orphan', sgRest: 60 }), 'Plan').routines[0].ex[0]+ expect('sgName' in out || 'sgRest' in out).toBe(false)+ })+})+// ---- combine routines: a weekday holds a routine-id list (ENG-9 §5) ----describe('week schedule as a routine-id list', () => {const twoRoutines = {