Skip to content

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.

Übungs-Bibliothek: +Plan-Button direkt in der Suche und Detail-Ansicht — Übung ohne Umweg in eine Routine (oder neue Routine) übernehmen

Duarte Santos0edb16a28781
diff --git a/app/app.js b/app/app.js
index 393f6e084..078a56bcb 100644
--- a/app/app.js
+++ b/app/app.js
@@ -1097,6 +1097,34 @@ function exercisePicker(onPick) {
draw();
}
+/* ---------- add exercise straight to a routine (from library browsing) ---------- */
+function addToRoutineSheet(ex) {
+ const m = openModal(`
+ <h3 class="capitalize">Add “${esc(ex.n)}”</h3>
+ <div class="muted small" style="margin-bottom:12px">Pick a routine — sets, reps & weight come next.</div>
+ <div class="list">
+ ${S.routines.map(r => `<div class="item" data-r="${r.id}">
+ <div style="font-size:1.3rem;flex:none">${r.emoji || '💪'}</div>
+ <div class="grow"><div class="tt">${esc(r.name)}</div><div class="ss">${r.ex.length} exercises</div></div>
+ ${r.ex.some(e => e.id === ex.id) ? '<span class="tag">already in</span>' : ''}<span class="chev">+</span></div>`).join('')}
+ <div class="item" data-r="_new"><div style="font-size:1.3rem;flex:none">✨</div>
+ <div class="grow"><div class="tt">New routine</div><div class="ss">Create one and start with this exercise</div></div><span class="chev">+</span></div>
+ </div>`);
+ m.el.querySelectorAll('[data-r]').forEach(el => el.addEventListener('click', () => {
+ m.close();
+ const isNew = el.dataset.r === '_new';
+ let r = isNew ? null : S.routines.find(x => x.id === el.dataset.r);
+ exConfigSheet(ex, null, cfg => {
+ if (isNew) { r = { id: uid(), name: 'New routine', emoji: '💪', ex: [] }; S.routines.push(r); }
+ if (!r) return;
+ r.ex.push({ id: ex.id, ...cfg });
+ save();
+ toast('“' + ex.n + '” added to ' + r.name + ' ✓');
+ if (isNew) nav('#plan/r/' + r.id);
+ });
+ }));
+}
+
/* ---------- exercise config (sets/reps/weight) ---------- */
function stepperHTML(id, val, step, label) {
return `<div><div class="small muted" style="margin-bottom:5px;text-align:center">${label}</div>
@@ -1658,9 +1686,13 @@ function viewLibrary(app) {
<div class="grow"><div class="tt">${esc(e.n)}</div>
<div class="ss">${e.tg || e.bp} · ${e.eq}</div></div>
${bestWeightFor(e.id) ? `<span class="tag acc">${fmtNum(bestWeightFor(e.id))}</span>` : ''}
- <span class="chev">›</span></div>`).join('') || '<div class="empty">No match 🤷</div>';
+ <button class="btn sm primary" data-addex="${e.id}" aria-label="Add to plan">+ Plan</button></div>`).join('') || '<div class="empty">No match 🤷</div>';
moreBtn.style.display = f.length > libShown ? '' : 'none';
listEl.querySelectorAll('[data-ex]').forEach(el => el.addEventListener('click', () => exerciseDetailSheet(EXIDX[el.dataset.ex])));
+ listEl.querySelectorAll('[data-addex]').forEach(b => b.addEventListener('click', ev => {
+ ev.stopPropagation();
+ addToRoutineSheet(EXIDX[b.dataset.addex]);
+ }));
}
moreBtn.onclick = () => { libShown += 40; draw(); };
$('#lib-q').addEventListener('input', ev => { libQ = ev.target.value.toLowerCase().trim(); libShown = 40; draw(); });
@@ -1680,9 +1712,11 @@ function exerciseDetailSheet(ex) {
${(ex.sm || []).slice(0, 3).map(s => `<span class="tag">${s}</span>`).join('')}
</div>
${best ? `<div class="small" style="margin-bottom:6px">🏆 Best: <b class="accent">${fmtNum(best)} ${S.unit}</b>${last ? ` · last ${fmtDate(last.d)}: ${last.sets.map(s => fmtNum(s.w) + '×' + s.r).join(', ')}` : ''}</div>` : ''}
+ <button class="btn primary" id="dt-add" style="margin:10px 0 4px">+ Add to my plan</button>
${ex.st && ex.st.length ? `<h4 class="sec">How to</h4><ol class="steps-list">${ex.st.map(s => `<li>${esc(s)}</li>`).join('')}</ol>` : ''}
`);
bindMediaToggle(m.el.querySelector('.exmedia'), ex);
+ m.el.querySelector('#dt-add').onclick = () => { m.close(); addToRoutineSheet(ex); };
}
/* ============================================================
diff --git a/app/index.html b/app/index.html
index 22a25ba29..d144674d4 100644
--- a/app/index.html
+++ b/app/index.html
@@ -13,7 +13,7 @@
<link rel="manifest" href="manifest.json">
<link rel="apple-touch-icon" href="icon-180.png">
<link rel="icon" type="image/png" href="icon-180.png">
-<link rel="stylesheet" href="style.css?v=11">
+<link rel="stylesheet" href="style.css?v=12">
</head>
<body>
<div id="app"><div style="padding-top:42vh;text-align:center;font-size:2.2rem">🏋️</div></div>
@@ -45,7 +45,7 @@
<div id="modal-root"></div>
<div id="toast"></div>
-<script src="data.js?v=11"></script>
-<script src="app.js?v=11"></script>
+<script src="data.js?v=12"></script>
+<script src="app.js?v=12"></script>
</body>
</html>
diff --git a/app/sw.js b/app/sw.js
index 8eda0e5e2..fcd1466cb 100644
--- a/app/sw.js
+++ b/app/sw.js
@@ -1,6 +1,6 @@
/* GymLog service worker — network-first for app shell, cache-first for media */
-const CACHE = 'gymlog-v11';
-const SHELL = ['./', 'index.html', 'style.css?v=11', 'app.js?v=11', 'data.js?v=11', 'manifest.json'];
+const CACHE = 'gymlog-v12';
+const SHELL = ['./', 'index.html', 'style.css?v=12', 'app.js?v=12', 'data.js?v=12', 'manifest.json'];
self.addEventListener('install', e => {
e.waitUntil(caches.open(CACHE).then(c => c.addAll(SHELL)).then(() => self.skipWaiting()));