diff --git a/frontend/js/app.js b/frontend/js/app.js index 1cc0241..76757ef 100644 --- a/frontend/js/app.js +++ b/frontend/js/app.js @@ -9,6 +9,7 @@ import './logic/set.js'; import './logic/cardio.js'; import './logic/metrics.js'; import './logic/settings.js'; +import './logic/group.js'; // Подключаем модалки import './modals/modal-base.js'; @@ -19,6 +20,7 @@ import './modals/metrics-modal.js'; import './modals/client-select-modal.js'; import './modals/edit-exercise-modal.js'; import './modals/edit-workout-date-modal.js'; +import './modals/group-modal.js'; function renderHeader() { const modeLabel = state.mode === 'trainer' ? '👨🏫 Тренер' : '👤 Личный'; diff --git a/frontend/js/logic/exercise.js b/frontend/js/logic/exercise.js index ac70729..28323c8 100644 --- a/frontend/js/logic/exercise.js +++ b/frontend/js/logic/exercise.js @@ -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 = { diff --git a/frontend/js/logic/group.js b/frontend/js/logic/group.js new file mode 100644 index 0000000..e9ca669 --- /dev/null +++ b/frontend/js/logic/group.js @@ -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 }; diff --git a/frontend/js/logic/workout.js b/frontend/js/logic/workout.js index 6ef5a80..bd85feb 100644 --- a/frontend/js/logic/workout.js +++ b/frontend/js/logic/workout.js @@ -23,6 +23,7 @@ function _createWorkout(clientId) { type: '', exercises: [], cardio: [], + setGroups: [], notes: '', synced: false, }; diff --git a/frontend/js/modals/group-modal.js b/frontend/js/modals/group-modal.js new file mode 100644 index 0000000..35e0182 --- /dev/null +++ b/frontend/js/modals/group-modal.js @@ -0,0 +1,55 @@ +import { showModal, closeModal } from './modal-base.js'; +import { escapeHtml } from '../utils.js'; + +let _cb = null; + +/** + * Диалог создания/редактирования сета (суперсета). + * @param {object} workout - тренировка + * @param {object|null} group - существующая группа {id, name, exerciseIds} или null для новой + * @param {(data:{name:string, exerciseIds:string[]}|null)=>void} callback + */ +export function showGroupDialog(workout, group, callback) { + _cb = callback; + const memberIds = group ? [...group.exerciseIds] : []; + + showModal(`
`); +} + +export function submit() { + const name = document.getElementById('m-group-name').value.trim(); + const ids = [...document.querySelectorAll('#m-group-list input:checked')].map(i => i.value); + if (ids.length < 2) { + alert('Выберите минимум 2 упражнения'); + return; + } + closeModal(); + _cb?.({ name: name || 'Сет', exerciseIds: ids }); +} + +window.GroupModal = { submit }; diff --git a/frontend/js/render/circuit-card.js b/frontend/js/render/circuit-card.js new file mode 100644 index 0000000..30d9ffe --- /dev/null +++ b/frontend/js/render/circuit-card.js @@ -0,0 +1,103 @@ +/** + * Карточка сета (суперсета): подходы участников показываются по раундам — + * 1-й подход каждого упражнения, отдых, 2-й подход каждого, и т.д. + */ +export function renderCircuit(w, group, members, isReadOnly) { + const card = document.createElement('div'); + card.className = 'circuit-card'; + + const header = document.createElement('div'); + header.className = 'circuit-header'; + header.innerHTML = ` +Тренировка синхронизирована и завершена. Редактирование недоступно.
`; +Тренировка синхронизирована и завершена. Редактирование недоступно.
+ `; } else if (isActive) { // Проверяем, есть ли уже данные в тренировке const hasData = (w.exercises && w.exercises.length > 0) || (w.cardio && w.cardio.length > 0); @@ -192,6 +227,7 @@ export function renderWorkoutDetails(w) {