diff --git a/frontend/js/logic/settings.js b/frontend/js/logic/settings.js index 96efaa3..c10a42e 100644 --- a/frontend/js/logic/settings.js +++ b/frontend/js/logic/settings.js @@ -2,6 +2,7 @@ import { state, saveState, CLIENT_COLORS, DEFAULT_COLOR, genId, generateUUID } f import { showEditExerciseDialog } from '../modals/edit-exercise-modal.js'; import { showBodyMetricsDialog } from '../modals/metrics-modal.js'; import { showModal } from '../modals/modal-base.js'; +import { escapeHtml } from '../utils.js'; export function showSettings() { const app = document.getElementById('app'); @@ -34,6 +35,8 @@ export function showSettings() { +
@@ -96,6 +99,7 @@ export function _renderPersonalMetricsList() { export function addRefExercise() { const input = document.getElementById('new-ref-exercise'); const typeSelect = document.getElementById('new-ref-type'); + const groupInput = document.getElementById('new-ref-group'); const name = input.value.trim(); if (!name) return; const normalizedName = name.trim().toLowerCase(); @@ -107,11 +111,13 @@ export function addRefExercise() { id: (state.nextId++).toString(), name: name.trim(), workoutType: typeSelect.value, + group: groupInput.value.trim(), }); } saveState(); input.value = ''; typeSelect.value = ''; + groupInput.value = ''; _renderRefExercises(); } @@ -127,6 +133,16 @@ export function updateRefExerciseType(id, newType) { if (ex) { ex.workoutType = newType; saveState(); + _renderRefExercises(); // пересортировать: тип поменялся + } +} + +export function updateRefExerciseGroup(id, newGroup) { + const ex = state.exerciseRef.find(e => e.id === id); + if (ex) { + ex.group = newGroup.trim(); + saveState(); + _renderRefExercises(); // пересортировать: варианты должны стоять вместе } } @@ -155,42 +171,67 @@ export function _renderRefExercises() { list.innerHTML = '

Справочник пуст

'; return; } + + const groupNames = [...new Set(state.exerciseRef.map(e => e.group).filter(Boolean))].sort(); + + // Сортировка: тип → группа вариантов → имя (варианты стоят вместе) const sorted = [...state.exerciseRef].sort((a, b) => { - if (a.workoutType !== b.workoutType) return (a.workoutType || '').localeCompare(b.workoutType || ''); + const t = (a.workoutType || '').localeCompare(b.workoutType || ''); + if (t !== 0) return t; + const g = (a.group || '').localeCompare(b.group || ''); + if (g !== 0) return g; return a.name.localeCompare(b.name); }); - // Генерируем опции для select динамически из state.workoutTypes - const typeOptions = state.workoutTypes.map(wt => - `` - ).join(''); + let html = `${ + groupNames.map(g => ``).join('') + }`; + + let curType = null, curGroup = null; + sorted.forEach(ex => { + if ((ex.workoutType || '') !== curType) { + curType = ex.workoutType || ''; + curGroup = null; + html += `
${curType ? escapeHtml(curType) : 'без типа'}
`; + } + if ((ex.group || '') !== curGroup) { + curGroup = ex.group || ''; + html += curGroup ? `
🧩 ${escapeHtml(curGroup)}
` : ''; + } - list.innerHTML = sorted.map(ex => { let count = 0; state.workouts.forEach(w => { - w.exercises.forEach(e => { + (w.exercises || []).forEach(e => { if (e.name.trim().toLowerCase() === ex.name.trim().toLowerCase()) count++; }); }); - return ` -
-
- ${ex.name} - (${count}×) - ${ex.workoutType ? `${ex.workoutType}` : ''} + + html += ` +
+
+
+ ${escapeHtml(ex.name)} + (${count}×) +
+
+ + +
-
- - ${state.workoutTypes.map(wt => ``).join('')} + ${state.workoutTypes.map(wt => ``).join('')} - - +
`; - }).join(''); + }); + + list.innerHTML = html; } export function _renderMetricTypes() { @@ -484,7 +525,7 @@ export function deleteClientMetric(metricId, clientId) { // Обновляем экспорт window.SettingsLogic = { show: showSettings, - addRefExercise, deleteRefExercise, updateRefExerciseType, + addRefExercise, deleteRefExercise, updateRefExerciseType, updateRefExerciseGroup, editRefExercise, clearAllData, _renderRefExercises, _renderBodyMetricsList, // Клиенты: diff --git a/frontend/js/modals/edit-exercise-modal.js b/frontend/js/modals/edit-exercise-modal.js index 69eae25..6f64311 100644 --- a/frontend/js/modals/edit-exercise-modal.js +++ b/frontend/js/modals/edit-exercise-modal.js @@ -1,28 +1,41 @@ import { showModal, closeModal } from './modal-base.js'; +import { state } from '../state.js'; +import { escapeHtml } from '../utils.js'; let _cb = null; export function showEditExerciseDialog(exercise, callback) { _cb = callback; + const groups = [...new Set(state.exerciseRef.map(e => e.group).filter(Boolean))].sort(); + showModal(` `; + }).join(''); } export function updateSubset(i, field, value) { _data.subSets[i][field] = value; } -export function stepSubset(i, field, delta) { +export function stepSubset(i, field, dir) { const current = parseFloat(_data.subSets[i][field]) || 0; - const step = field === 'weight' ? 0.5 : 1; - const newVal = Math.max(0, current + delta); + // Вес в сбрасываниях — тоже адаптивный шаг + const step = field === 'weight' ? weightStep(current) : 1; + const newVal = Math.max(0, current + (dir > 0 ? step : -step)); _data.subSets[i][field] = parseFloat((Math.round(newVal / step) * step).toFixed(4)); - renderSubsets(); // Перерисовываем, чтобы обновить значение в input + renderSubsets(); // Перерисовываем, чтобы обновить значение и шаг в input } export function removeSubset(i) { @@ -115,7 +143,8 @@ export function submit() { } else { const w = parseFloat(document.getElementById('m-set-weight').value); const r = parseInt(document.getElementById('m-set-reps').value); - if (!w && !r) { alert('Укажите вес и повторения'); return; } + // Пустой или нулевой должен быть и вес, и повторы — например «вес 0, 15 раз» с собой легитимен + if (!(w > 0) && !(r > 0)) { alert('Укажите вес и повторения'); return; } closeModal(); _cb?.({ isDropset: false, weight: w||0, reps: r||0, rating: _data.rating }); } } diff --git a/frontend/js/render/set-row.js b/frontend/js/render/set-row.js index 818eca2..a5bd86a 100644 --- a/frontend/js/render/set-row.js +++ b/frontend/js/render/set-row.js @@ -8,14 +8,19 @@ export function renderSetRow(workoutId, exerciseId, set, index, isReadOnly = fal
`; + const setTime = set.timestamp + ? `
${new Date(set.timestamp).toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' })}
` + : '
'; + if (set.isDropset && set.subSets && set.subSets.length > 0) { row.className = 'dropset-group'; const subsText = set.subSets.map(s => `${s.weight}×${s.reps}`).join(' → '); - const ratingStars = '★'.repeat(set.rating || 3); + const ratingStars = '★'.repeat(set.rating || 5); row.innerHTML = ` -
+
${index + 1}
🔥 ${subsText}
+ ${setTime}
${ratingStars}
${actionsHtml}
@@ -26,7 +31,8 @@ export function renderSetRow(workoutId, exerciseId, set, index, isReadOnly = fal
${index + 1}
${set.weight || '—'} кг
${set.reps || '—'}
-
${'★'.repeat(set.rating || 3)}
+ ${setTime} +
${'★'.repeat(set.rating || 5)}
${actionsHtml}
`; diff --git a/frontend/styles/settings.css b/frontend/styles/settings.css index d109b86..0e9aaaf 100644 --- a/frontend/styles/settings.css +++ b/frontend/styles/settings.css @@ -16,3 +16,16 @@ .metric-card .label { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; margin-bottom: 4px; } .metric-card .value { font-size: 1.3rem; font-weight: 700; color: var(--primary); } .metric-card .date { font-size: 0.7rem; color: var(--text-secondary); margin-top: 4px; } + +/* === Справочник: типы и группы вариантов === */ +.ref-type-head { + font-weight: 700; color: var(--text-secondary); text-transform: uppercase; + font-size: 0.75rem; letter-spacing: 0.5px; margin: 14px 0 6px; +} +.ref-type-head:first-of-type { margin-top: 0; } +.ref-group-head { color: var(--primary); font-size: 0.8rem; font-weight: 600; margin: 8px 0 4px 8px; } +.exercise-ref-grouped { flex-direction: column; align-items: stretch; gap: 8px; margin-left: 8px; } +.ref-item-top { display: flex; justify-content: space-between; align-items: center; } +.ref-item-controls { display: flex; gap: 6px; } +.ref-item-controls select { width: auto; min-width: 110px; padding: 6px; font-size: 0.8rem; } +.ref-item-controls input { flex: 1; min-width: 0; padding: 6px 8px; font-size: 0.8rem; }