f1tness_parser/frontend/js/trainings-view.js

39 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// One table for all trainings: a row per exercise
import { alert, approachChips, formatDate, h, perArmBadge } from './common.js';
import { createTable } from './table.js';
export function trainingsView(trainings) {
if (!trainings.length) {
return alert('info', 'Тренировок нет.');
}
// A training without exercises still gets a row, so it doesn't disappear from the list
const rows = trainings.flatMap((training) =>
training.exercises?.length
? training.exercises.map((exercise) => ({ training, exercise }))
: [{ training, exercise: null }]);
const exerciseCount = rows.filter((row) => row.exercise).length;
return h('div', {},
h('p', { class: 'text-muted' },
'Тренировок: ', h('strong', {}, `${trainings.length}`),
', упражнений: ', h('strong', {}, `${exerciseCount}`)),
createTable({
id: 'trainings-table',
rows,
columns: [
{ title: 'Дата', className: 'text-nowrap date', sort: (row) => row.training.date, cell: (row) => formatDate(row.training.date) },
{ title: 'Тренер', className: 'text-nowrap', sort: (row) => row.training.trainer || '', cell: (row) => row.training.trainer || '' },
{
title: 'Упражнение',
sort: (row) => row.exercise?.name || '',
cell: (row) => row.exercise
? h('span', {}, row.exercise.name, ' ', row.exercise.splitted_weight ? perArmBadge() : null)
: h('span', { class: 'text-muted fst-italic' }, 'Упражнения не записаны'),
},
{ title: 'Подходы (вес × повторения)', cell: (row) => h('span', {}, ...(row.exercise ? approachChips(row.exercise.approaches) : [])) },
],
}));
}