feat(set-groups): добавление объединений упражнений в сеты с выводом по раундам
Новые модули logic/group.js, modals/group-modal.js, render/circuit-card.js. Тренировка получает поле setGroups, состояние нормализует отсутствующие поля в loadState, удаление упражнения распускает неполные сеты.
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user