feat(exercise-ref): группировка вариантов упражнения с общей историей
Поле group в справочнике, заголовки типа и группы в списке, автодополнение названий групп, объединение прошлых подходов вариантов в статистике упражнения.
This commit is contained in:
@@ -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() {
|
||||
</select>
|
||||
<button class="btn btn-small" style="width:auto; padding: 0 20px;" onclick="SettingsLogic.addRefExercise()">+</button>
|
||||
</div>
|
||||
<input type="text" id="new-ref-group" list="ref-groups-list" style="margin-top:6px;"
|
||||
placeholder="Группа вариантов — общая статистика (необязательно)">
|
||||
</div>
|
||||
<div id="ref-exercises-list"></div>
|
||||
</div>
|
||||
@@ -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 = '<p class="text-muted text-small">Справочник пуст</p>';
|
||||
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 =>
|
||||
`<option value="${wt.name}" ${a => a.workoutType === wt.name ? 'selected' : ''}>${wt.name}</option>`
|
||||
).join('');
|
||||
let html = `<datalist id="ref-groups-list">${
|
||||
groupNames.map(g => `<option value="${escapeHtml(g)}"></option>`).join('')
|
||||
}</datalist>`;
|
||||
|
||||
let curType = null, curGroup = null;
|
||||
sorted.forEach(ex => {
|
||||
if ((ex.workoutType || '') !== curType) {
|
||||
curType = ex.workoutType || '';
|
||||
curGroup = null;
|
||||
html += `<div class="ref-type-head">${curType ? escapeHtml(curType) : 'без типа'}</div>`;
|
||||
}
|
||||
if ((ex.group || '') !== curGroup) {
|
||||
curGroup = ex.group || '';
|
||||
html += curGroup ? `<div class="ref-group-head">🧩 ${escapeHtml(curGroup)}</div>` : '';
|
||||
}
|
||||
|
||||
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 `
|
||||
<div class="exercise-ref-item">
|
||||
<div style="flex:1;">
|
||||
<span class="name">${ex.name}</span>
|
||||
<span class="count">(${count}×)</span>
|
||||
${ex.workoutType ? `<span class="type-badge">${ex.workoutType}</span>` : ''}
|
||||
|
||||
html += `
|
||||
<div class="exercise-ref-item exercise-ref-grouped">
|
||||
<div class="ref-item-top">
|
||||
<div>
|
||||
<span class="name">${escapeHtml(ex.name)}</span>
|
||||
<span class="count">(${count}×)</span>
|
||||
</div>
|
||||
<div style="display:flex; gap:4px; align-items:center;">
|
||||
<button class="icon-btn" onclick="SettingsLogic.editRefExercise('${ex.id}')">✎</button>
|
||||
<button class="icon-btn danger" onclick="SettingsLogic.deleteRefExercise('${ex.id}')">✕</button>
|
||||
</div>
|
||||
</div>
|
||||
<div style="display:flex; gap:4px; align-items:center;">
|
||||
<select onchange="SettingsLogic.updateRefExerciseType('${ex.id}', this.value)"
|
||||
style="width:auto; min-width:100px; padding:6px; font-size:0.8rem;">
|
||||
<div class="ref-item-controls">
|
||||
<select onchange="SettingsLogic.updateRefExerciseType('${ex.id}', this.value)">
|
||||
<option value="">тип...</option>
|
||||
${state.workoutTypes.map(wt => `<option value="${wt.name}" ${ex.workoutType === wt.name ? 'selected' : ''}>${wt.name}</option>`).join('')}
|
||||
${state.workoutTypes.map(wt => `<option value="${escapeHtml(wt.name)}" ${ex.workoutType === wt.name ? 'selected' : ''}>${escapeHtml(wt.name)}</option>`).join('')}
|
||||
</select>
|
||||
<button class="icon-btn" onclick="SettingsLogic.editRefExercise('${ex.id}')">✎</button>
|
||||
<button class="icon-btn danger" onclick="SettingsLogic.deleteRefExercise('${ex.id}')">✕</button>
|
||||
<input type="text" list="ref-groups-list" value="${escapeHtml(ex.group || '')}"
|
||||
placeholder="группа вариантов"
|
||||
onchange="SettingsLogic.updateRefExerciseGroup('${ex.id}', this.value)">
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).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,
|
||||
// Клиенты:
|
||||
|
||||
Reference in New Issue
Block a user