Compare commits
8 Commits
18dd991742
...
66e8080308
| Author | SHA1 | Date | |
|---|---|---|---|
| 66e8080308 | |||
| bb1af40e61 | |||
| e4bc4337a6 | |||
| 7e821a933b | |||
| a0e5eeae7f | |||
| 37d1b1fe57 | |||
| 48bd4ed123 | |||
| e948b8964e |
@ -20,5 +20,9 @@
|
|||||||
- TPTIP-21: мастер (шаг 1→2→«Готово», onboarded, кольца с «ккал/г белка/мл воды») проверен — код менять не пришлось, закреплено тестом в tests/wizard.test.js.
|
- TPTIP-21: мастер (шаг 1→2→«Готово», onboarded, кольца с «ккал/г белка/мл воды») проверен — код менять не пришлось, закреплено тестом в tests/wizard.test.js.
|
||||||
## Грабли
|
## Грабли
|
||||||
- На 17.11.2026 origin/main содержал только bootstrap, приложение было в task/tptip-8, сервер — в task/tptip-6; task/tptip-5 включает обе зависимости. При объединении server.js и Dockerfile использована версия TPTIP-6.
|
- На 17.11.2026 origin/main содержал только bootstrap, приложение было в task/tptip-8, сервер — в task/tptip-6; task/tptip-5 включает обе зависимости. При объединении server.js и Dockerfile использована версия TPTIP-6.
|
||||||
|
- TPTIP-22: ring(label,fact,target,unit,color) — единица полностью («килокалории/граммы/миллилитры») под названием, внутри кольца «из N»; CACHE sw.js tpt-v5-rings.
|
||||||
|
- TPTIP-23: поля мастера с what+required получают пометку «обязательно» и проверку при blur/input (numField); CACHE sw.js tpt-v6-required.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- TPTIP-3: каталог /recipes.html (ru/kk/en), локальные фото assets; npm run build перед npm start; браузер npx playwright test. Сохранить маршруты recipes и сборку telemetry при объединении server.js/Dockerfile.
|
- TPTIP-3: каталог /recipes.html (ru/kk/en), локальные фото assets; npm run build перед npm start; браузер npx playwright test. Сохранить маршруты recipes и сборку telemetry при объединении server.js/Dockerfile.
|
||||||
|
|||||||
19
index.html
19
index.html
@ -44,6 +44,7 @@ input,select,textarea{font:inherit;color:var(--text);background:var(--bg);border
|
|||||||
input:focus,select:focus,textarea:focus,button:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
|
input:focus,select:focus,textarea:focus,button:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
|
||||||
.field{display:block;margin:10px 0}
|
.field{display:block;margin:10px 0}
|
||||||
.field .lbl{display:block;font-size:.85rem;color:var(--muted);margin-bottom:4px}
|
.field .lbl{display:block;font-size:.85rem;color:var(--muted);margin-bottom:4px}
|
||||||
|
.field .req{color:var(--bad);font-size:.8rem}
|
||||||
.field .err{color:var(--bad);font-size:.85rem;min-height:0}
|
.field .err{color:var(--bad);font-size:.85rem;min-height:0}
|
||||||
.field.bad input,.field.bad select,.field.bad textarea{border-color:var(--bad)}
|
.field.bad input,.field.bad select,.field.bad textarea{border-color:var(--bad)}
|
||||||
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:0 10px}
|
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:0 10px}
|
||||||
@ -69,7 +70,7 @@ input:focus,select:focus,textarea:focus,button:focus-visible{outline:2px solid v
|
|||||||
.ring .val{stroke-linecap:round;transition:stroke-dasharray .3s}
|
.ring .val{stroke-linecap:round;transition:stroke-dasharray .3s}
|
||||||
.ring .c{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;font-size:.8rem;font-weight:700;line-height:1.1}
|
.ring .c{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;font-size:.8rem;font-weight:700;line-height:1.1}
|
||||||
.ring .c small{font-weight:400;color:var(--muted);font-size:.66rem}
|
.ring .c small{font-weight:400;color:var(--muted);font-size:.66rem}
|
||||||
.ring .t{font-size:.78rem;margin-top:2px}
|
.ring .t{font-size:.78rem;margin-top:2px}.ring .t small{font-size:.62rem}
|
||||||
.ring .over .val{stroke:var(--bad)}
|
.ring .over .val{stroke:var(--bad)}
|
||||||
.bar{height:10px;border-radius:6px;background:var(--line);overflow:hidden}
|
.bar{height:10px;border-radius:6px;background:var(--line);overflow:hidden}
|
||||||
.bar>i{display:block;height:100%;border-radius:6px}
|
.bar>i{display:block;height:100%;border-radius:6px}
|
||||||
@ -522,6 +523,12 @@ function numField(label, o) {
|
|||||||
const input = h('input', { type: 'text', inputmode: o.int ? 'numeric' : 'decimal', autocomplete: 'off', value: o.value == null ? '' : String(o.value).replace('.', ','), placeholder: o.placeholder || '' });
|
const input = h('input', { type: 'text', inputmode: o.int ? 'numeric' : 'decimal', autocomplete: 'off', value: o.value == null ? '' : String(o.value).replace('.', ','), placeholder: o.placeholder || '' });
|
||||||
const el = field(label, input, o.hint);
|
const el = field(label, input, o.hint);
|
||||||
el.input = input;
|
el.input = input;
|
||||||
|
if (o.what && o.required) {
|
||||||
|
el.querySelector('.lbl').append(h('span', { class: 'req' }, ' · обязательно'));
|
||||||
|
input.setAttribute('aria-required', 'true');
|
||||||
|
input.addEventListener('blur', () => el.read());
|
||||||
|
input.addEventListener('input', () => { if (el.classList.contains('bad')) el.read(); });
|
||||||
|
}
|
||||||
el.read = () => {
|
el.read = () => {
|
||||||
const r = parseNum(input.value, o);
|
const r = parseNum(input.value, o);
|
||||||
if (!r.ok && o.what) r.error = r.error === 'Заполните это поле' ? 'Укажите ' + o.what + ': поле пока пустое' : 'Проверьте ' + o.what + ': ' + (o.hint || '').toLowerCase();
|
if (!r.ok && o.what) r.error = r.error === 'Заполните это поле' ? 'Укажите ' + o.what + ': поле пока пустое' : 'Проверьте ' + o.what + ': ' + (o.hint || '').toLowerCase();
|
||||||
@ -586,8 +593,8 @@ function ring(label, fact, target, unit, color) {
|
|||||||
svg('svg', { viewBox: '0 0 100 100', 'aria-hidden': 'true' },
|
svg('svg', { viewBox: '0 0 100 100', 'aria-hidden': 'true' },
|
||||||
svg('circle', { class: 'bg', cx: 50, cy: 50, r: R, fill: 'none', 'stroke-width': 10 }),
|
svg('circle', { class: 'bg', cx: 50, cy: 50, r: R, fill: 'none', 'stroke-width': 10 }),
|
||||||
svg('circle', { class: 'val', cx: 50, cy: 50, r: R, fill: 'none', 'stroke-width': 10, stroke: color, 'stroke-dasharray': (pct * C) + ' ' + C })),
|
svg('circle', { class: 'val', cx: 50, cy: 50, r: R, fill: 'none', 'stroke-width': 10, stroke: color, 'stroke-dasharray': (pct * C) + ' ' + C })),
|
||||||
h('div', { class: 'c' }, fmtInt(fact), h('small', null, 'из ' + fmtInt(target) + ' ' + unit))),
|
h('div', { class: 'c' }, fmtInt(fact), h('small', null, 'из ' + fmtInt(target)))),
|
||||||
h('div', { class: 't' }, label));
|
h('div', { class: 't' }, h('b', null, label), h('small', { class: 'muted', style: 'display:block' }, unit)));
|
||||||
}
|
}
|
||||||
/** Линейный график по точкам [{x:'ГГГГ-ММ-ДД', y}]. */
|
/** Линейный график по точкам [{x:'ГГГГ-ММ-ДД', y}]. */
|
||||||
function lineChart(points, unit) {
|
function lineChart(points, unit) {
|
||||||
@ -672,12 +679,12 @@ function viewToday() {
|
|||||||
return h('div', null, dateNav(),
|
return h('div', null, dateNav(),
|
||||||
h('div', { class: 'card' },
|
h('div', { class: 'card' },
|
||||||
h('div', { class: 'rings' },
|
h('div', { class: 'rings' },
|
||||||
ring('Калории', t.kcal, s.kcal, 'ккал', 'var(--kcal)'), ring('Белки', t.protein, s.protein, 'г белка', 'var(--prot)'),
|
ring('Калории', t.kcal, s.kcal, 'килокалории', 'var(--kcal)'), ring('Белки', t.protein, s.protein, 'граммы', 'var(--prot)'),
|
||||||
ring('Жиры', t.fat, s.fat, 'г жиров', 'var(--fat)'), ring('Углеводы', t.carbs, s.carbs, 'г углеводов', 'var(--carb)'), ring('Вода', t.water, s.water, 'мл воды', 'var(--water)')),
|
ring('Жиры', t.fat, s.fat, 'граммы', 'var(--fat)'), ring('Углеводы', t.carbs, s.carbs, 'граммы', 'var(--carb)'), ring('Вода', t.water, s.water, 'миллилитры', 'var(--water)')),
|
||||||
h('div', { class: 'row', style: 'justify-content:center;margin-top:10px' },
|
h('div', { class: 'row', style: 'justify-content:center;margin-top:10px' },
|
||||||
t.water > 0 ? h('button', { class: 'chip minus', 'aria-label': 'Убрать 250 мл воды', onclick: removeLastWater }, '−250') : null,
|
t.water > 0 ? h('button', { class: 'chip minus', 'aria-label': 'Убрать 250 мл воды', onclick: removeLastWater }, '−250') : null,
|
||||||
h('button', { class: 'chip on', onclick: () => addWater(250) }, '+250 мл воды')),
|
h('button', { class: 'chip on', onclick: () => addWater(250) }, '+250 мл воды')),
|
||||||
t.meals === 0 && t.water === 0 ? h('p', { class: 'small muted', 'data-empty-hint': '', style: 'text-align:center;margin:8px 0 0' }, 'Пока ничего не добавлено, поэтому кольца пустые. Нажмите «+ Еда», «+250 мл воды» или выберите блюдо ниже — кольца заполнятся сами.') : null,
|
t.meals === 0 && t.water === 0 ? h('p', { class: 'small muted', 'data-empty-hint': '', style: 'text-align:center;margin:8px 0 0' }, 'Пока ничего не добавлено, поэтому кольца (калории, белки, жиры, углеводы, вода) пустые. Нажмите «+ Еда», «+250 мл воды» или выберите блюдо ниже — кольца заполнятся сами.') : null,
|
||||||
h('p', { class: 'left ' + (left >= 0 ? 'ok' : 'bad') }, leftText)),
|
h('p', { class: 'left ' + (left >= 0 ? 'ok' : 'bad') }, leftText)),
|
||||||
h('div', { class: 'quick two' },
|
h('div', { class: 'quick two' },
|
||||||
h('button', { onclick: () => openMealForm({ date: ui.date }) }, '+ Еда'),
|
h('button', { onclick: () => openMealForm({ date: ui.date }) }, '+ Еда'),
|
||||||
|
|||||||
2
sw.js
2
sw.js
@ -1,5 +1,5 @@
|
|||||||
// Сервис-воркер: приложение открывается без интернета (сначала сеть, при отсутствии — копия из кэша).
|
// Сервис-воркер: приложение открывается без интернета (сначала сеть, при отсутствии — копия из кэша).
|
||||||
const CACHE = 'tpt-v5-wizard-recipes';
|
const CACHE = 'tpt-v7-required-recipes';
|
||||||
const FILES = ['./', 'index.html', 'gym-plan.i18n.js', 'manifest.webmanifest', 'icon.svg', 'recipes.html', 'recipes.css', 'recipes.js', 'recipes-core.js', 'recipes-status.i18n.js', 'recipes.data.json', 'recipes.i18n.json', 'telemetry.js', 'assets/oats.jpg', 'assets/chicken.jpg', 'assets/salad.jpg'];
|
const FILES = ['./', 'index.html', 'gym-plan.i18n.js', 'manifest.webmanifest', 'icon.svg', 'recipes.html', 'recipes.css', 'recipes.js', 'recipes-core.js', 'recipes-status.i18n.js', 'recipes.data.json', 'recipes.i18n.json', 'telemetry.js', 'assets/oats.jpg', 'assets/chicken.jpg', 'assets/salad.jpg'];
|
||||||
self.addEventListener('install', e => { e.waitUntil(caches.open(CACHE).then(c => c.addAll(FILES)).then(() => self.skipWaiting())); });
|
self.addEventListener('install', e => { e.waitUntil(caches.open(CACHE).then(c => c.addAll(FILES)).then(() => self.skipWaiting())); });
|
||||||
self.addEventListener('activate', e => {
|
self.addEventListener('activate', e => {
|
||||||
|
|||||||
@ -90,9 +90,28 @@ test('Сценарий: после мастера кольца подписан
|
|||||||
assert.equal(document.querySelector('.sheet'), null);
|
assert.equal(document.querySelector('.sheet'), null);
|
||||||
const s = JSON.parse(dom.window.localStorage.getItem('tpt.v1')).settings;
|
const s = JSON.parse(dom.window.localStorage.getItem('tpt.v1')).settings;
|
||||||
const text = document.querySelector('.rings').textContent;
|
const text = document.querySelector('.rings').textContent;
|
||||||
assert.match(text, /ккал/); assert.match(text, /г белка/); assert.match(text, /мл воды/);
|
assert.match(text, /килокалории/); assert.match(text, /граммы/); assert.match(text, /миллилитры/);
|
||||||
for (const k of ['kcal', 'protein', 'water']) {
|
for (const k of ['kcal', 'protein', 'water']) {
|
||||||
assert.ok(s[k] > 0, k + ' больше нуля');
|
assert.ok(s[k] > 0, k + ' больше нуля');
|
||||||
assert.ok(text.includes(String(s[k])), k + ' ' + s[k] + ' виден в кольцах: ' + text);
|
assert.ok(text.includes(String(s[k])), k + ' ' + s[k] + ' виден в кольцах: ' + text);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Сценарий: у пяти колец есть названия и полные единицы, на пустом дне — подсказка', t => {
|
||||||
|
const { dom, document } = open(JSON.stringify({ settings: { onboarded: true, kcal: 2000, protein: 120, fat: 65, carbs: 230, water: 2000 } })); t.after(() => dom.window.close());
|
||||||
|
const names = [...document.querySelectorAll('.ring .t')].map(x => x.textContent);
|
||||||
|
assert.deepEqual(names, ['Калориикилокалории', 'Белкиграммы', 'Жирыграммы', 'Углеводыграммы', 'Водамиллилитры']);
|
||||||
|
assert.match(document.querySelector('[data-empty-hint]').textContent, /калории, белки, жиры, углеводы, вода/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Сценарий: поля первого шага помечены «обязательно», ошибка видна при уходе из пустого поля', t => {
|
||||||
|
const { dom, document } = open(); t.after(() => dom.window.close());
|
||||||
|
const marks = [...document.querySelectorAll('.sheet .req')];
|
||||||
|
assert.equal(marks.length, 3);
|
||||||
|
const [age] = inputs(document);
|
||||||
|
age.dispatchEvent(new dom.window.Event('blur'));
|
||||||
|
assert.match(document.querySelector('.sheet').textContent, /Укажите возраст: поле пока пустое/);
|
||||||
|
age.value = '30';
|
||||||
|
age.dispatchEvent(new dom.window.Event('input'));
|
||||||
|
assert.equal(document.querySelectorAll('.sheet .field.bad').length, 0);
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user