front-back integrated

This commit is contained in:
2026-09-30 02:25:03 +03:00
parent 93ca76c6e1
commit 1f81632083
13 changed files with 298 additions and 27 deletions
+21 -1
View File
@@ -1,6 +1,7 @@
import { state, saveState, genId } from '../state.js';
import { renderMainScreen } from '../render/main-screen.js';
import { showExerciseDialog } from '../modals/exercise-modal.js';
import { fetchExerciseHistory } from '../api.js';
export function addExercise(workoutId) {
const w = state.workouts.find(x => x.id === workoutId);
@@ -45,7 +46,26 @@ export function deleteExercise(workoutId, exerciseId) {
renderMainScreen();
}
export function getExerciseHistory(exerciseName) {
export async function getExerciseHistory(exerciseName) {
// Пытаемся получить с бэкенда
try {
const history = await fetchExerciseHistory(exerciseName, state.currentClientId);
if (history && history.length > 0) {
return history.map(h => ({
date: h.date,
sets: [{ // Адаптируем формат бэкенда под формат фронта
isDropset: h.is_dropset,
weight: h.weight,
reps: h.reps,
subSets: h.is_dropset ? [{weight: h.weight, reps: h.reps}] : undefined // Упрощение для отображения
}]
}));
}
} catch (e) {
console.warn('Не удалось загрузить историю с бэкенда, используем локальную', e);
}
// Fallback на локальные данные
const normalizedName = exerciseName.trim().toLowerCase();
const history = [];
for (const w of state.workouts) {
+25 -6
View File
@@ -112,6 +112,12 @@ export function _renderRefExercises() {
if (a.workoutType !== b.workoutType) return (a.workoutType || '').localeCompare(b.workoutType || '');
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('');
list.innerHTML = sorted.map(ex => {
let count = 0;
state.workouts.forEach(w => {
@@ -130,12 +136,7 @@ export function _renderRefExercises() {
<select onchange="SettingsLogic.updateRefExerciseType('${ex.id}', this.value)"
style="width:auto; min-width:100px; padding:6px; font-size:0.8rem;">
<option value="">тип...</option>
<option value="грудь-руки" ${ex.workoutType==='грудь-руки'?'selected':''}>грудь-руки</option>
<option value="ноги" ${ex.workoutType==='ноги'?'selected':''}>ноги</option>
<option value="спина-плечи" ${ex.workoutType==='спина-плечи'?'selected':''}>спина-плечи</option>
<option value="круговая" ${ex.workoutType==='круговая'?'selected':''}>круговая</option>
<option value="силовая" ${ex.workoutType==='силовая'?'selected':''}>силовая</option>
<option value="многоповторная" ${ex.workoutType==='многоповторная'?'selected':''}>многоповторная</option>
${state.workoutTypes.map(wt => `<option value="${wt.name}" ${ex.workoutType === wt.name ? 'selected' : ''}>${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>
@@ -145,6 +146,24 @@ export function _renderRefExercises() {
}).join('');
}
// Добавим отображение типов замеров в настройки (для тренера)
export function _renderMetricTypes() {
const container = document.getElementById('metric-types-list');
if (!container) return;
if (state.metricTypes.length === 0) {
container.innerHTML = '<p class="text-muted text-small">Нет типов замеров</p>';
return;
}
container.innerHTML = state.metricTypes.map(mt => `
<div class="exercise-ref-item">
<div>
<span class="name">${mt.name}</span>
<span class="type-badge">${mt.unit}</span>
</div>
</div>
`).join('');
}
export function _renderBodyMetricsList() {
const list = document.getElementById('body-metrics-list');
if (!list) return;
+11 -2
View File
@@ -60,7 +60,16 @@ export function editWorkoutDate(workoutId) {
});
}
export function cancelEmptyWorkout(workoutId) {
if (!confirm('Отменить эту тренировку? Все данные будут удалены.')) return;
deleteWorkout(workoutId);
}
window.WL = {
startWorkout, finishWorkout, deleteWorkout,
toggleWorkout, editWorkoutDate,
startWorkout,
finishWorkout,
deleteWorkout,
toggleWorkout,
editWorkoutDate,
cancelEmptyWorkout
};