97 lines
4.5 KiB
JavaScript
97 lines
4.5 KiB
JavaScript
// frontend/js/render/dashboard-screen.js
|
|
|
|
import { state } from '../state.js';
|
|
import { drawExerciseProgress, drawBodyMetricsGraph } from './dashboard.js';
|
|
|
|
export function renderDashboard() {
|
|
const app = document.getElementById('app');
|
|
if (!app) return;
|
|
|
|
app.innerHTML = `
|
|
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:20px;">
|
|
<h2>📊 Статистика</h2>
|
|
<button class="btn btn-small btn-secondary" onclick="App.backToMain()">← Назад</button>
|
|
</div>
|
|
|
|
<!-- Секция 1: Прогресс упражнений -->
|
|
<div class="card mb-20">
|
|
<h3>💪 Прогресс упражнения</h3>
|
|
<div class="field-group">
|
|
<label>Выберите упражнение</label>
|
|
<select id="dash-ex-select" onchange="DashboardLogic.updateExerciseChart()">
|
|
<option value="">— Выберите —</option>
|
|
${getUniqueExercises().map(ex => `<option value="${ex}">${ex}</option>`).join('')}
|
|
</select>
|
|
</div>
|
|
<canvas id="chart-exercise" width="400" height="200" style="width:100%; background:#1e1e1e; border-radius:8px;"></canvas>
|
|
<p class="text-muted text-small mt-10">Главное — рабочий максимум «вес × повторы»: зелёный — прогресс (вес выше или тот же вес и больше повторов), красный — откат. Тусклые точки — остальные подходы, «×N» — их число. Последние 10 тренировок.</p>
|
|
</div>
|
|
|
|
<!-- Секция 2: Динамика тела -->
|
|
<div class="card">
|
|
<h3>⚖️ Динамика тела</h3>
|
|
<div class="field-row">
|
|
<div class="field-group">
|
|
<label>Клиент (если тренер)</label>
|
|
<select id="dash-client-select" onchange="DashboardLogic.updateBodyChart()">
|
|
<option value="">Личные замеры</option>
|
|
${state.clients.map(c => `<option value="${c.id}">${c.full_name}</option>`).join('')}
|
|
</select>
|
|
</div>
|
|
<div class="field-group">
|
|
<label>Тип замера</label>
|
|
<select id="dash-metric-select" onchange="DashboardLogic.updateBodyChart()">
|
|
${state.metricTypes.map(mt => `<option value="${mt.id}">${mt.name} (${mt.unit})</option>`).join('')}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<canvas id="chart-body" width="400" height="200" style="width:100%; background:#1e1e1e; border-radius:8px;"></canvas>
|
|
</div>
|
|
`;
|
|
|
|
window.DashboardLogic = {
|
|
updateExerciseChart: () => {
|
|
const select = document.getElementById('dash-ex-select');
|
|
const canvas = document.getElementById('chart-exercise');
|
|
if (select.value) {
|
|
drawExerciseProgress(canvas, select.value);
|
|
} else {
|
|
const ctx = canvas.getContext('2d');
|
|
ctx.clearRect(0,0,canvas.width,canvas.height);
|
|
ctx.fillStyle='#666';
|
|
ctx.textAlign='center';
|
|
ctx.fillText('Выберите упражнение выше', canvas.width/2, canvas.height/2);
|
|
}
|
|
},
|
|
updateBodyChart: () => {
|
|
const clientSel = document.getElementById('dash-client-select');
|
|
const metricSel = document.getElementById('dash-metric-select');
|
|
const canvas = document.getElementById('chart-body');
|
|
|
|
const clientId = clientSel.value ? parseInt(clientSel.value) : null;
|
|
const metricId = metricSel.value ? parseInt(metricSel.value) : null;
|
|
|
|
if (metricId) {
|
|
drawBodyMetricsGraph(canvas, clientId, metricId);
|
|
}
|
|
}
|
|
};
|
|
|
|
// Первичная отрисовка (пустые состояния)
|
|
DashboardLogic.updateExerciseChart();
|
|
if(state.metricTypes.length > 0) {
|
|
document.getElementById('dash-metric-select').value = state.metricTypes[0].id;
|
|
DashboardLogic.updateBodyChart();
|
|
}
|
|
}
|
|
|
|
function getUniqueExercises() {
|
|
const set = new Set();
|
|
state.workouts.forEach(w => {
|
|
w.exercises.forEach(ex => {
|
|
set.add(ex.name);
|
|
});
|
|
});
|
|
return Array.from(set).sort();
|
|
}
|