feat(set-groups): добавление объединений упражнений в сеты с выводом по раундам

Новые модули logic/group.js, modals/group-modal.js, render/circuit-card.js. Тренировка получает поле setGroups, состояние нормализует отсутствующие поля в loadState, удаление упражнения распускает неполные сеты.
This commit is contained in:
Иван Овчинников
2026-11-20 00:51:20 +03:00
parent 2a5c9709e0
commit 340751dd17
8 changed files with 299 additions and 10 deletions
+38 -6
View File
@@ -38,7 +38,7 @@ export function addExercise(workoutId) {
});
}
export function addToRef(name, workoutType = '') {
export function addToRef(name, workoutType = '', group = '') {
const normalizedName = normalizeName(name);
const exists = state.exerciseRef.find(
@@ -50,9 +50,11 @@ export function addToRef(name, workoutType = '') {
id: genId(),
name: String(name).trim(),
workoutType,
group: String(group || '').trim(),
});
} else if (!exists.workoutType && workoutType) {
exists.workoutType = workoutType;
} else {
if (!exists.workoutType && workoutType) exists.workoutType = workoutType;
if (!exists.group && group) exists.group = String(group).trim();
}
}
@@ -71,10 +73,39 @@ export function deleteExercise(workoutId, exerciseId) {
w.exercises = w.exercises.filter(e => e.id !== exerciseId);
// Упражнение удалилось — чистим сеты, где оно состояло
if (Array.isArray(w.setGroups)) {
w.setGroups = w.setGroups
.map(g => ({ ...g, exerciseIds: g.exerciseIds.filter(id => id !== exerciseId) }))
.filter(g => g.exerciseIds.length >= 2);
}
saveState();
renderMainScreen();
}
/**
* Имена упражнений-вариантов в справочнике: та же «группа вариантов»
* и тот же тип тренировки (пустой тип ни у одной из записей не препятствие).
*/
function refVariantNames(exerciseName) {
const norm = normalizeName(exerciseName);
const names = new Set([norm]);
const entry = state.exerciseRef.find(e => normalizeName(e.name) === norm);
const group = String(entry?.group || '').trim().toLowerCase();
if (!group) return names;
const entryType = String(entry.workoutType || '').trim().toLowerCase();
for (const e of state.exerciseRef) {
if (String(e.group || '').trim().toLowerCase() !== group) continue;
const eType = String(e.workoutType || '').trim().toLowerCase();
if (entryType && eType && entryType !== eType) continue;
names.add(normalizeName(e.name));
}
return names;
}
/**
* Локальная история упражнения.
*
@@ -83,7 +114,7 @@ export function deleteExercise(workoutId, exerciseId) {
* @param {string|number|null} excludeWorkoutId - чтобы не показывать текущую тренировку как "прошлую"
*/
export function getExerciseHistory(exerciseName, clientId = null, excludeWorkoutId = null) {
const normalizedName = normalizeName(exerciseName);
const variantNames = refVariantNames(exerciseName);
const targetClient = normalizeClientId(clientId);
const history = [];
@@ -102,12 +133,13 @@ export function getExerciseHistory(exerciseName, clientId = null, excludeWorkout
for (const ex of w.exercises || []) {
if (
normalizeName(ex.name) === normalizedName &&
variantNames.has(normalizeName(ex.name)) &&
Array.isArray(ex.sets) &&
ex.sets.length > 0
) {
history.push({
date: w.startTime,
name: ex.name,
sets: ex.sets,
});
}
@@ -116,7 +148,7 @@ export function getExerciseHistory(exerciseName, clientId = null, excludeWorkout
history.sort((a, b) => new Date(b.date) - new Date(a.date));
return history.slice(0, 3);
return history.slice(0, 5);
}
window.EL = {
+47
View File
@@ -0,0 +1,47 @@
import { state, saveState, genId } from '../state.js';
import { renderMainScreen } from '../render/main-screen.js';
import { showGroupDialog } from '../modals/group-modal.js';
/**
* Открыть диалог создания (groupId = null) или редактирования состава сета.
*/
export function showGroupDialogFor(workoutId, groupId = null) {
const w = state.workouts.find(x => x.id === workoutId);
if (!w) return;
if ((w.exercises || []).length < 2) {
alert('Для сета нужно минимум 2 упражнения');
return;
}
const group = groupId ? (w.setGroups || []).find(g => g.id === groupId) : null;
showGroupDialog(w, group, (data) => {
if (!data) return;
if (!Array.isArray(w.setGroups)) w.setGroups = [];
if (group) {
group.name = data.name;
group.exerciseIds = data.exerciseIds;
} else {
w.setGroups.push({ id: genId(), name: data.name, exerciseIds: data.exerciseIds });
}
saveState();
renderMainScreen();
});
}
/**
* Расформировать сет: упражнения и подходы остаются.
*/
export function removeGroup(workoutId, groupId) {
if (!confirm('Разъединить сет? Упражнения и подходы останутся.')) return;
const w = state.workouts.find(x => x.id === workoutId);
if (!w) return;
w.setGroups = (w.setGroups || []).filter(g => g.id !== groupId);
saveState();
renderMainScreen();
}
window.GL = { showGroupDialogFor, removeGroup };
+1
View File
@@ -23,6 +23,7 @@ function _createWorkout(clientId) {
type: '',
exercises: [],
cardio: [],
setGroups: [],
notes: '',
synced: false,
};