From f0f09d7102db09ab5f81de299d7db9cf672d009e Mon Sep 17 00:00:00 2001 From: Glebova Date: Wed, 30 Sep 2026 14:42:50 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B0=D0=B7a=203:=20=D0=B1=D0=B0=D0=BB?= =?UTF-8?q?=D0=BB=D1=8B=20=D0=BD=D0=B0=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=20(=D1=84=D0=BE=D1=80=D0=BC=D0=B0/=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=BB=D0=B8=D1=86=D0=B0)=20+=20=D0=BF=D0=B0=D0=BD=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=20=D0=BD=D0=B0=D0=BF=D0=BE=D0=BC=D0=B8=D0=BD=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=BF=D0=BE=20=D0=BA=D0=BB=D0=B0=D0=B4=D0=BE?= =?UTF-8?q?=D0=B2=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++++- server.js | 36 +++++++++- 2 files changed, 230 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index e3f89be..438cb45 100644 --- a/index.html +++ b/index.html @@ -76,6 +76,23 @@ .clean-week[data-compact] .clean-day .clean-tip-pop[hidden] { display: none; } .clean-week[data-compact] .clean-day .clean-tip-pop::before { content: ""; position: absolute; top: -9px; left: 22px; border: 5px solid transparent; border-bottom-color: var(--kt-ai-border); } .clean-week[data-compact] .clean-day .clean-tip-pop::after { content: ""; position: absolute; top: -7px; left: 22px; border: 4px solid transparent; border-bottom-color: var(--kt-ai-bg-elevated); } + .points-ui { display: grid; gap: var(--kt-ai-space-4); } + .points-ui-row { display: grid; grid-template-columns: auto 110px 130px 1fr auto; gap: var(--kt-ai-space-3); align-items: center; padding: var(--kt-ai-space-3) 0; border-top: 1px solid var(--kt-ai-border); font-size: var(--kt-ai-text-md); } + .points-ui-row:first-child { border-top: 0; } + .points-ui-row-head { color: var(--kt-ai-fg-faint); font-size: var(--kt-ai-text-xs); text-transform: uppercase; letter-spacing: 0.06em; font-weight: var(--kt-ai-weight-medium); } + .points-val-cell { font-size: var(--kt-ai-text-xl); font-weight: var(--kt-ai-weight-semibold); text-align: right; } + .points-note-cell { color: var(--kt-ai-fg-muted); font-size: var(--kt-ai-text-sm); min-width: 0; } + .points-note-cell span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } + .points-actions { display: flex; gap: var(--kt-ai-space-2); flex-wrap: wrap; } + .points-form-row { display: grid; grid-template-columns: 1fr 1fr 90px 1.4fr auto; gap: var(--kt-ai-space-3); align-items: end; } + .points-empty { padding: var(--kt-ai-space-5); text-align: center; color: var(--kt-ai-fg-muted); font-size: var(--kt-ai-text-md); } + .remind-list { display: grid; gap: var(--kt-ai-space-2); } + .remind-item { padding: var(--kt-ai-space-3); border-radius: var(--kt-ai-radius-md); font-size: var(--kt-ai-text-md); } + .remind-item-red { background: var(--kt-ai-chip-red-bg); color: var(--kt-ai-chip-red-fg); } + .remind-item-orange { background: var(--kt-ai-chip-orange-bg); color: var(--kt-ai-chip-orange-fg); } + .remind-item-green { background: var(--kt-ai-chip-green-bg); color: var(--kt-ai-chip-green-fg); } + .remind-empty { padding: var(--kt-ai-space-4); text-align: center; color: var(--kt-ai-fg-muted); font-size: var(--kt-ai-text-md); } + @media (max-width: 720px) { .points-ui-row { grid-template-columns: auto 110px 1fr; } .points-ui-row .points-note-cell { grid-column: 1 / -1; } .points-ui-row .points-actions { grid-column: 1 / -1; } .points-form-row { grid-template-columns: 1fr 1fr; } .points-form-row .kt-ai-field:nth-child(4) { grid-column: 1 / -1; } .points-form-row .kt-ai-field:nth-child(5) { grid-column: 1 / -1; } } .clean-day.is-today { border-color: var(--kt-ai-primary); background: var(--kt-ai-primary-subtle); } .family-invite { padding: var(--kt-ai-space-6); } .family-head { display: flex; align-items: center; gap: var(--kt-ai-space-4); margin-bottom: var(--kt-ai-space-2); flex-wrap: wrap; } @@ -503,6 +520,63 @@ +
+
+
+

Считаем баллы: что записано в этой таблице

+

Доступно на этой платформе. Записи сохраняются на сервере, таблица видна всем членам семьи через Предпросмотр или в разделе «Данные». Лимиты на 10/25/50/100 из карточек ниже — обмениваются раз в воскресенье.

+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ +
+
+
+
+ КтоБаллы (накоплено)Последние операции  +
+
+
+
+
+
@@ -613,7 +687,11 @@

Календарь свежести продуктов и ежедневные 10 секунд перед обедом: что «горит» — то и готовим.

-
+
+

Сегодня: что горит (из кладовой)

+
+
+
Пн
22
Вт
23
@@ -875,6 +953,37 @@ var c1 = document.createElement("span"); c1.className = "kt-ai-chip"; c1.setAttribute("data-tone", "blue"); c1.textContent = "В доме: " + open; var c2 = document.createElement("span"); c2.className = "kt-ai-chip"; c2.setAttribute("data-tone", urgent ? "red" : "green"); c2.textContent = urgent ? "Горит: " + urgent + " поз." : "Критичных нет"; COUNTS.appendChild(c1); COUNTS.appendChild(c2); + renderRemind(sorted); + } + function renderRemind(sorted) { + var rem = document.getElementById("remind-panel"); + if (!rem) return; + rem.innerHTML = ""; + var red = [], orange = [], rest = []; + sorted.forEach(function (p) { + if (p.consumed) return; + var d = daysLeft(p.shelf); + var line = '' + esc(p.name) + '' + (p.qty ? ' ' + esc(p.qty) : '') + ' — ' + shelfLabel(d) + (p.meal ? ' → ' + esc(p.meal) : ''); + if (d === 0) red.push(line); else if (d === 1) red.push(line); else if (d <= 3) orange.push(line); else rest.push(line + ' (ещё в запасе)'); + }); + if (!red.length && !orange.length) { + rem.innerHTML = '
Всё спокойно: ничего не горит.
'; + return; + } + var make = function (arr, cls) { + var box = document.createElement("div"); + box.className = "remind-list"; + arr.forEach(function (line) { + var item = document.createElement("div"); + item.className = "remind-item " + cls; + item.innerHTML = line; + box.appendChild(item); + }); + return box; + }; + if (red.length) rem.appendChild(make(red, "remind-item-red")); + if (orange.length) rem.appendChild(make(orange, "remind-item-orange")); + if (rest.length && (red.length + orange.length) > 0) rem.appendChild(make(rest.slice(0, 3), "remind-item-green")); } STORE.addEventListener("click", async function (e) { var btn = e.target.closest("button[data-act]"); @@ -1016,6 +1125,91 @@ card.appendChild(btn); }); loadClean(); + + /* Баллы: таблица + форма */ + var MEMBERS = ["Ваня", "Ася", "Мам", "Пап"]; + async function loadPoints() { + var recs = []; + try { recs = await (await fetch("api/points")).json(); } catch (_) {} + var byWho = {}; + (recs || []).forEach(function (r) { + byWho[r.who] = (byWho[r.who] || 0) + r.amount; + }); + var order = MEMBERS.concat(Object.keys(byWho).filter(function (k) { return MEMBERS.indexOf(k) === -1; })); + var lastByWho = {}; + (recs || []).slice().reverse().forEach(function (r) { + if (!lastByWho[r.who] || lastByWho[r.who].when < r.when) lastByWho[r.who] = r; + }); + var tbody = document.getElementById("points-table"); + tbody.innerHTML = ""; + if (!recs.length) { + var empty = document.createElement("div"); + empty.className = "points-empty"; + empty.textContent = "Пока нет записей — добавьте первую через форму выше."; + tbody.appendChild(empty); + return; + } + order.forEach(function (who) { + var total = byWho[who] || 0; + var row = document.createElement("div"); + row.className = "points-ui-row"; + var tone = total >= 100 ? "green" : total >= 50 ? "blue" : total >= 25 ? "orange" : "blue"; + var last = lastByWho[who]; + row.innerHTML = + '' + esc(who) + '' + + '' + total + ' баллов' + + '' + (last ? (last.amount > 0 ? '+ ' + last.amount + ' за ' + esc(last.kind) + (last.note ? ' · ' + esc(last.note) : '') : '- ' + Math.abs(last.amount) + ' (' + esc(last.note || last.kind) + ')') : '—') + '' + + '' + + '' + + '' + + '' + + ''; + tbody.appendChild(row); + }); + tbody.querySelectorAll("button[data-who]").forEach(function (b) { + b.addEventListener("click", function () { + var who = b.getAttribute("data-who"); + var amt = b.textContent.trim(); + var n = parseInt(amt, 10); + submitPoint({ who: who, kind: amt > 0 ? "Бонус" : "Вернуть (списать)", amount: n, note: "клик из таблицы" }); + }); + }); + } + async function submitPoint(p) { + var out = document.getElementById("points-outcome"); + try { + var res = await fetch("api/points", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(p) }); + var data = await res.json(); + if (!res.ok || !data.item) throw new Error(); + out.hidden = false; + out.className = "buy-outcome buy-ok"; + out.textContent = (p.amount > 0 ? "Записали: " : "Списали: ") + p.who + " — " + Math.abs(p.amount) + " (" + p.kind + (p.note ? ", " + p.note : "") + ")"; + document.getElementById("points-form").reset(); + loadPoints(); + } catch (_) { + out.hidden = false; + out.className = "buy-outcome buy-err"; + out.textContent = "Не получилось сохранить запись. Попробуйте ещё раз."; + } + } + document.getElementById("points-form").addEventListener("submit", async function (e) { + e.preventDefault(); + var who = document.getElementById("pt-who").value; + var kind = document.getElementById("pt-kind").value; + var amountRaw = document.getElementById("pt-amount").value; + var amount = parseInt(amountRaw, 10) || 0; + var note = document.getElementById("pt-note").value.trim(); + if (!who || !kind || !amount) { + var out = document.getElementById("points-outcome"); + out.hidden = false; + out.className = "buy-outcome buy-err"; + out.textContent = "Заполните кто, за что и количество (не 0)."; + return; + } + var signed = kind === "Вернуть (списать)" ? -Math.abs(amount) : Math.abs(amount); + submitPoint({ who: who, kind: kind, amount: signed, note: note }); + }); + loadPoints(); })(); diff --git a/server.js b/server.js index 184470f..13a0942 100644 --- a/server.js +++ b/server.js @@ -4,7 +4,7 @@ const path = require("path"); const PORT = process.env.PORT || 3000; const DATA = path.join(__dirname, "data.json"); -const EMPTY = { purchases: [], clean: [], log: [] }; +const EMPTY = { purchases: [], clean: [], points: [], log: [] }; function load() { try { return JSON.parse(fs.readFileSync(DATA, "utf8")); } catch (_) { return { ...EMPTY }; } @@ -92,6 +92,40 @@ http.createServer(async (req, res) => { return res.end(JSON.stringify({ ok: true })); } + if (req.method === "GET" && url === "/api/points") { + res.writeHead(200, { "Content-Type": "application/json" }); + return res.end(JSON.stringify(load().points || [])); + } + + if (req.method === "POST" && url === "/api/points") { + const p = await body(req); + const when = new Date().toISOString(); + const who = String(p.who || "").slice(0, 40); + const kind = String(p.kind || "").slice(0, 40); + const amount = Math.round(Number(p.amount) || 0); + const note = String(p.note || "").slice(0, 120); + if (!who || !kind || amount === 0) { + res.writeHead(400, { "Content-Type": "application/json" }); + return res.end(JSON.stringify({ error: "who, kind and non-zero amount required" })); + } + const d = load(); + if (!Array.isArray(d.points)) d.points = []; + const rec = { + id: Date.now(), + who, + kind, + amount, + note, + when + }; + d.points.push(rec); + const verb = amount > 0 ? "получил(а)" : "вернул(а)"; + d.log.push({ when, what: "баллы: " + who + " " + verb + " " + Math.abs(amount) + (amount < 0 ? " (вернуло " + note + ")" : " за " + kind), who: "юзер" }); + save(d); + res.writeHead(200, { "Content-Type": "application/json" }); + return res.end(JSON.stringify({ ok: true, item: rec })); + } + let file = url === "/" ? "/index.html" : url; const full = path.join(__dirname, file); if (full.startsWith(__dirname) && fs.existsSync(full) && fs.statSync(full).isFile()) {