diff --git a/index.html b/index.html index 1bdffc8..83d42e9 100644 --- a/index.html +++ b/index.html @@ -36,6 +36,11 @@ .item .i-sub { font-size: var(--kt-ai-text-2xs); color: var(--kt-ai-fg-muted); } .item .i-end { margin-left: auto; display: flex; align-items: center; gap: var(--kt-ai-space-3); flex: 0 0 auto; } + /* группа физзанятий и подпункты */ + .item.group { background: var(--kt-ai-bg-soft); border: 1px solid var(--kt-ai-border); } + .item.group.done { border-color: var(--kt-ai-primary); } + .task.child { margin-left: var(--kt-ai-space-6); padding: var(--kt-ai-space-2) var(--kt-ai-space-4); } + /* сегмент-кнопки отметки оценок */ .seg-sm { display: inline-flex; gap: 2px; background: var(--kt-ai-bg-soft); border: 1px solid var(--kt-ai-border); border-radius: var(--kt-ai-radius-lg); padding: 2px; } .seg-sm .s { min-width: 30px; height: 24px; display: inline-grid; place-items: center; border: none; background: transparent; border-radius: var(--kt-ai-radius-md); font-size: var(--kt-ai-text-2xs); font-weight: var(--kt-ai-weight-medium); color: var(--kt-ai-fg-muted); cursor: pointer; padding: 0 5px; } diff --git a/script.js b/script.js index 780d0be..612ea0a 100644 --- a/script.js +++ b/script.js @@ -14,6 +14,10 @@ const LESSONS = [ const SPORT = [ { id: "training", name: "Дзюдо", sub: "Секция, 1,5 часа", pts: 10, done: false }, + { id: "phys", type: "group", name: "Физические занятия", sub: "Подтягивания и отжимания, 3 подхода", pts: 10, children: [ + { id: "pullups", name: "Подтягивания", sub: "3 подхода" }, + { id: "pushups", name: "Отжимания", sub: "3 подхода" } + ] }, { id: "walk", name: "Активность", sub: "Прогулка 6000+ шагов", pts: 5, done: false }, { id: "sleep", name: "Сон", sub: "Выспался ≥ 8 часов", pts: 5, done: false } ]; @@ -59,7 +63,10 @@ function load() { const d = JSON.parse(raw); if (!d || d.day !== todayStr()) return; if (Array.isArray(d.lessons)) lessons = d.lessons; - if (Array.isArray(d.sport)) sport = d.sport.map((s) => ({ ...s, pts: (SPORT.find((x) => x.id === s.id) || {}).pts, done: !!s.done })); + if (Array.isArray(d.sport)) sport = d.sport.map((s) => { + const tmpl = SPORT.find((x) => x.id === s.id) || {}; + return { ...s, pts: tmpl.pts, done: !!s.done, children: tmpl.children ? (s.children ? s.children.map((c) => ({ ...c, done: !!c.done })) : tmpl.children.map((c) => ({ ...c }))) : undefined }; + }); if (Array.isArray(d.home)) home = d.home.map((t) => ({ ...t, pts: (HOME.find((x) => x.id === t.id) || {}).pts, done: !!t.done })); if (Array.isArray(d.routine)) routine = d.routine.map((r) => ({ ...r, pts: (ROUTINE.find((x) => x.id === r.id) || {}).pts, done: !!r.done })); } catch (e) {} @@ -111,9 +118,43 @@ function renderLessons() { } function renderSport() { + syncSportGroups(); const box = document.getElementById("sport-list"); box.innerHTML = ""; sport.forEach((s) => { + if (s.type === "group") { + const doneCount = s.children.filter((c) => c.done).length; + const row = el(` +
+ +
+
${esc(s.name)}
+
${esc(s.sub)} · ${doneCount}/${s.children.length}
+
+
+ +${s.pts} + +
+
+ `); + box.appendChild(row); + s.children.forEach((c) => { + const childRow = el(` +
+ +
+
${esc(c.name)}
+
${esc(c.sub)}
+
+ +
+ `); + box.appendChild(childRow); + }); + return; + } const row = el(`
@@ -179,6 +220,13 @@ function renderRoutine() { }); } +function syncSportGroups() { + sport.forEach((s) => { + if (s.type !== "group" || !s.children) return; + s.done = s.children.every((c) => c.done); + }); +} + // ---------- Прогресс ---------- function counts() { @@ -240,6 +288,38 @@ function renderAll() { // ---------- Действия ---------- document.addEventListener("click", (e) => { + if (e.target.closest("#sport-list")) e.stopPropagation(); + + const task = e.target.closest("#home-list .task"); + if (task) { + const item = home.find((t) => t.id === task.dataset.id); + if (item) { item.done = !item.done; } + renderAll(); save(); + return; + } + + const subTask = e.target.closest('#sport-list .task[data-child-of]'); + if (subTask) { + const g = sport.find((s) => s.id === subTask.dataset.childOf); + if (g) { + const c = g.children.find((x) => x.id === subTask.dataset.id); + if (c) c.done = !c.done; + } + renderAll(); save(); + return; + } + + const grpBtn = e.target.closest("[data-toggle-group]"); + if (grpBtn) { + const g = sport.find((s) => s.id === grpBtn.dataset.toggleGroup); + if (g && g.children) { + const toSet = !g.children.every((c) => c.done); + g.children.forEach((c) => { c.done = toSet; }); + } + renderAll(); save(); + return; + } + const gBtn = e.target.closest("[data-grade]"); if (gBtn) { const row = gBtn.closest("[data-id]"); @@ -267,15 +347,10 @@ document.addEventListener("click", (e) => { renderAll(); save(); return; } - - const task = e.target.closest("#home-list .task"); - if (task) { - const item = home.find((t) => t.id === task.dataset.id); - if (item) { item.done = !item.done; } - renderAll(); save(); - } }); +// (home-list обрабатывается в основном click-обработчике выше) + document.getElementById("btn-reset").addEventListener("click", () => { if (!confirm("Сбросить все отметки за сегодня?")) return; lessons = LESSONS.map((l) => ({ ...l, grade: 0 }));