Changement du code pour une nouvelle version en test

This commit is contained in:
serveur
2026-10-17 19:20:00 +02:00
parent 9dba07bc54
commit 044cd54f36
8 changed files with 909 additions and 264 deletions
+16
View File
@@ -0,0 +1,16 @@
FROM node:22-alpine
WORKDIR /app
COPY server.js ./
COPY public ./public
# La to-do list est enregistrée dans /data (à monter en volume pour la conserver)
ENV PORT=3000 \
DATA_FILE=/data/todos.json
RUN mkdir -p /data && chown node:node /data
VOLUME /data
USER node
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://localhost:3000/healthz || exit 1
CMD ["node", "server.js"]
-17
View File
@@ -1,17 +0,0 @@
{"bassines":[
{"Nom":"Grande bassine ronde en fer","tare":6.500},
{"Nom":"Grande bassine ronde verte","tare":2.700},
{"Nom":"Grande bassine ronde verte","tare":2.700},
{"Nom":"Grande bassine ronde verte","tare":2.700},
{"Nom":"Moyenne bassine ovale en fer","tare":6.000},
{"Nom":"Petite bassine ronde en fer","tare":2.700},
{"Nom":"Petite bassine ronde bleue (Tonton Pierre)","tare":1.700},
{"Nom":"Petite bassine ronde verte (JM)","tare":1.700},
{"Nom":"Grande bassine verte","tare":2.700},
{"Nom":"Moyenne bassine ronde (Couenne)","tare":4.900},
{"Nom":"Grande bassine ovale en fer (Jeannot)","tare":6.000},
{"Nom":"Caisse grise","tare":2.450},
{"Nom":"Caisse verte","tare":2.600},
{"Nom":"Bassine bleue (JM1)","tare":2.500},
{"Nom":"Bassine verte (JM3)","tare":2.700}
]}
-242
View File
@@ -1,242 +0,0 @@
:root {
--bg: #f6f1ea;
--card: #ffffff;
--ink: #2b2420;
--muted: #7a6e65;
--line: #e6ddd2;
--accent: #8c2f2f;
--accent-dark: #742626;
--accent-soft: #f7e8e5;
--warn: #b35a00;
--warn-soft: #fff1e0;
--radius: 16px;
--shadow: 0 1px 2px rgba(43, 36, 32, 0.06), 0 6px 18px rgba(43, 36, 32, 0.06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
body {
margin: 0;
background: var(--bg);
color: var(--ink);
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
line-height: 1.35;
padding-bottom: env(safe-area-inset-bottom);
}
/* ---------- Barre du haut (toujours visible) ---------- */
.topbar {
position: sticky;
top: 0;
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 10px 16px;
padding-top: calc(10px + env(safe-area-inset-top));
background: var(--accent);
color: #fff;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.topbar h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 1.15rem;
font-weight: 700;
}
.summary { display: flex; gap: 16px; text-align: right; }
.summary .lbl { display: block; font-size: 0.68rem; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.06em; }
.summary b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.wrap { max-width: 760px; margin: 0 auto; padding: 14px 14px 40px; }
/* ---------- Cartes génériques ---------- */
.card {
background: var(--card);
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 16px;
margin-bottom: 14px;
}
.card h2 {
margin: 0 0 12px;
font-size: 0.78rem;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--muted);
}
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 5px; }
/* 16px minimum : évite le zoom automatique d'iOS au focus */
input[type="text"], input[type="number"] {
width: 100%;
height: 48px;
font: inherit;
font-size: 1.1rem;
font-variant-numeric: tabular-nums;
padding: 0 12px;
border: 1.5px solid var(--line);
border-radius: 12px;
background: #fffdfa;
color: var(--ink);
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.18); }
/* ---------- Rendement ---------- */
.yield { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.yield .field { grid-column: 1 / -1; }
.stat { background: #fbf7f1; border-radius: 12px; padding: 10px 12px; }
.stat .label { font-size: 0.75rem; color: var(--muted); }
.stat .value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.big .value { color: var(--accent); }
/* ---------- Réglages repliables ---------- */
details.card { padding: 0; }
details summary {
list-style: none;
display: flex;
align-items: center;
justify-content: space-between;
min-height: 52px;
padding: 0 16px;
font-weight: 600;
cursor: pointer;
}
details summary::-webkit-details-marker { display: none; }
details summary::after { content: "▾"; color: var(--muted); transition: transform 0.15s; }
details[open] summary::after { transform: rotate(180deg); }
details .settings { padding: 0 16px 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
details .hint { grid-column: 1 / -1; margin: 0; font-size: 0.8rem; color: var(--muted); }
/* ---------- Interrupteurs (couenne, filtre) ---------- */
.switch {
position: relative;
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 44px;
padding: 0 14px 0 10px;
border: 1.5px solid var(--line);
border-radius: 999px;
background: #fff;
font-weight: 600;
font-size: 0.92rem;
cursor: pointer;
user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: #d9cfc3; position: relative; transition: background 0.15s; flex: none; }
.switch .track::after {
content: "";
position: absolute;
top: 2px; left: 2px;
width: 18px; height: 18px;
border-radius: 50%;
background: #fff;
transition: transform 0.15s;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.switch:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch:has(input:focus-visible) { box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.25); }
.filterbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 12px; flex-wrap: wrap; }
.count { font-size: 0.9rem; color: var(--muted); }
.count b { color: var(--accent); }
/* ---------- Cartes bassines ---------- */
.bassines { display: grid; gap: 12px; }
.bassine {
background: var(--card);
border-radius: var(--radius);
box-shadow: var(--shadow);
border: 2px solid transparent;
padding: 14px;
}
.bassine.filled { border-color: var(--accent); background: #fffaf9; }
.bassine.warn { border-color: var(--warn); background: var(--warn-soft); }
.b-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.b-name { font-weight: 700; font-size: 1.05rem; }
.b-tare { font-size: 0.8rem; color: var(--muted); }
.b-input label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.input-wrap { position: relative; }
.input-wrap input { height: 56px; font-size: 1.5rem; font-weight: 600; padding-right: 52px; }
.clear {
position: absolute;
right: 6px; top: 6px;
width: 44px; height: 44px;
border: none;
border-radius: 10px;
background: transparent;
color: var(--muted);
font-size: 1.1rem;
cursor: pointer;
}
.clear:active { background: var(--line); }
.input-wrap input:placeholder-shown + .clear { display: none; }
.b-results { margin-top: 12px; }
.b-net { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.b-net .lbl { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.b-net .val { font-size: 1.7rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.b-net .unit { font-size: 0.9rem; font-weight: 600; color: var(--muted); margin-left: 3px; }
.warn .b-net .val { color: var(--warn); }
.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.tile { grid-column: span 2; background: #fbf7f1; border-radius: 10px; padding: 8px 6px; text-align: center; }
.tile:nth-child(n+4) { grid-column: span 3; }
.tile .t-lbl { display: block; font-size: 0.7rem; color: var(--muted); }
.tile .t-val { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1rem; }
.b-warn { margin: 10px 0 0; font-size: 0.85rem; color: var(--warn); font-weight: 600; }
/* ---------- Totaux ---------- */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.totals .stat:first-child { grid-column: 1 / -1; background: var(--accent-soft); }
.totals .unit { font-size: 0.8rem; font-weight: 400; color: var(--muted); }
/* ---------- Actions ---------- */
.actions { display: grid; gap: 10px; }
.btn {
font: inherit;
font-weight: 700;
min-height: 52px;
border-radius: 14px;
border: 1.5px solid var(--line);
background: var(--card);
color: var(--ink);
cursor: pointer;
}
.btn:active { transform: scale(0.99); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-dark); }
/* ---------- Grands écrans : deux colonnes ---------- */
@media (min-width: 900px) {
.wrap { max-width: 1000px; }
.bassines { grid-template-columns: 1fr 1fr; }
.actions { grid-template-columns: 1fr 1fr; }
}
/* ---------- Impression : uniquement ce qui a été pesé ---------- */
@media print {
body { background: #fff; }
.topbar, .no-print, .clear { display: none !important; }
.card, .bassine { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
.bassine:not(.filled) { display: none; }
.bassines { grid-template-columns: 1fr 1fr; }
input { border: none; background: none; }
details { display: none; }
}
+11
View File
@@ -0,0 +1,11 @@
services:
epices:
build: .
restart: unless-stopped
ports:
- "3000:3000" # à retirer si tu passes par Traefik (labels à la place)
volumes:
- epices-data:/data
volumes:
epices-data:
+52
View File
@@ -0,0 +1,52 @@
/* En-tête commun : titre + menu de navigation (utilisé par toutes les pages) */
.topbar {
position: sticky;
top: 0;
z-index: 10;
background: var(--accent, #8c2f2f);
color: #fff;
padding: calc(8px + env(safe-area-inset-top)) 16px 0;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
.topbar-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 40px;
}
.topbar h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 1.15rem;
font-weight: 700;
}
.menu { display: flex; gap: 4px; margin: 2px -6px 0; }
.menu a {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
min-height: 42px;
padding: 0 14px;
color: rgba(255, 255, 255, 0.78);
text-decoration: none;
font-weight: 600;
font-size: 0.95rem;
border-bottom: 3px solid transparent;
}
.menu a:active { background: rgba(255, 255, 255, 0.12); }
.menu a[aria-current="page"] { color: #fff; border-bottom-color: #fff; }
@media (min-width: 600px) {
.menu a { flex: 0 0 auto; padding: 0 22px; }
}
@media print {
.topbar { display: none; }
}
+233 -5
View File
@@ -4,16 +4,244 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<meta name="theme-color" content="#8c2f2f" />
<link rel="stylesheet" href="assets/style.css" />
<title>Calculateur d'épices</title>
<link rel="stylesheet" href="assets/menu.css" />
<style>
:root {
--bg: #f6f1ea;
--card: #ffffff;
--ink: #2b2420;
--muted: #7a6e65;
--line: #e6ddd2;
--accent: #8c2f2f;
--accent-dark: #742626;
--accent-soft: #f7e8e5;
--warn: #b35a00;
--warn-soft: #fff1e0;
--radius: 16px;
--shadow: 0 1px 2px rgba(43, 36, 32, 0.06), 0 6px 18px rgba(43, 36, 32, 0.06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
body {
margin: 0;
background: var(--bg);
color: var(--ink);
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
line-height: 1.35;
padding-bottom: env(safe-area-inset-bottom);
}
/* ---------- Récapitulatif dans la barre du haut (le reste : assets/menu.css) ---------- */
.summary { display: flex; gap: 16px; text-align: right; }
.summary .lbl { display: block; font-size: 0.68rem; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.06em; }
.summary b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.wrap { max-width: 760px; margin: 0 auto; padding: 14px 14px 40px; }
/* ---------- Cartes génériques ---------- */
.card {
background: var(--card);
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 16px;
margin-bottom: 14px;
}
.card h2 {
margin: 0 0 12px;
font-size: 0.78rem;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--muted);
}
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 5px; }
/* 16px minimum : évite le zoom automatique d'iOS au focus */
input[type="text"], input[type="number"] {
width: 100%;
height: 48px;
font: inherit;
font-size: 1.1rem;
font-variant-numeric: tabular-nums;
padding: 0 12px;
border: 1.5px solid var(--line);
border-radius: 12px;
background: #fffdfa;
color: var(--ink);
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.18); }
/* ---------- Rendement ---------- */
.yield { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.yield .field { grid-column: 1 / -1; }
.stat { background: #fbf7f1; border-radius: 12px; padding: 10px 12px; }
.stat .label { font-size: 0.75rem; color: var(--muted); }
.stat .value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.big .value { color: var(--accent); }
/* ---------- Réglages repliables ---------- */
details.card { padding: 0; }
details summary {
list-style: none;
display: flex;
align-items: center;
justify-content: space-between;
min-height: 52px;
padding: 0 16px;
font-weight: 600;
cursor: pointer;
}
details summary::-webkit-details-marker { display: none; }
details summary::after { content: "▾"; color: var(--muted); transition: transform 0.15s; }
details[open] summary::after { transform: rotate(180deg); }
details .settings { padding: 0 16px 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
details .hint { grid-column: 1 / -1; margin: 0; font-size: 0.8rem; color: var(--muted); }
/* ---------- Interrupteurs (couenne, filtre) ---------- */
.switch {
position: relative;
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 44px;
padding: 0 14px 0 10px;
border: 1.5px solid var(--line);
border-radius: 999px;
background: #fff;
font-weight: 600;
font-size: 0.92rem;
cursor: pointer;
user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: #d9cfc3; position: relative; transition: background 0.15s; flex: none; }
.switch .track::after {
content: "";
position: absolute;
top: 2px; left: 2px;
width: 18px; height: 18px;
border-radius: 50%;
background: #fff;
transition: transform 0.15s;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.switch:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch:has(input:focus-visible) { box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.25); }
.filterbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 12px; flex-wrap: wrap; }
.count { font-size: 0.9rem; color: var(--muted); }
.count b { color: var(--accent); }
/* ---------- Cartes bassines ---------- */
.bassines { display: grid; gap: 12px; }
.bassine {
background: var(--card);
border-radius: var(--radius);
box-shadow: var(--shadow);
border: 2px solid transparent;
padding: 14px;
}
.bassine.filled { border-color: var(--accent); background: #fffaf9; }
.bassine.warn { border-color: var(--warn); background: var(--warn-soft); }
.b-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.b-name { font-weight: 700; font-size: 1.05rem; }
.b-tare { font-size: 0.8rem; color: var(--muted); }
.b-input label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.input-wrap { position: relative; }
.input-wrap input { height: 56px; font-size: 1.5rem; font-weight: 600; padding-right: 52px; }
.clear {
position: absolute;
right: 6px; top: 6px;
width: 44px; height: 44px;
border: none;
border-radius: 10px;
background: transparent;
color: var(--muted);
font-size: 1.1rem;
cursor: pointer;
}
.clear:active { background: var(--line); }
.input-wrap input:placeholder-shown + .clear { display: none; }
.b-results { margin-top: 12px; }
.b-net { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.b-net .lbl { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.b-net .val { font-size: 1.7rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.b-net .unit { font-size: 0.9rem; font-weight: 600; color: var(--muted); margin-left: 3px; }
.warn .b-net .val { color: var(--warn); }
.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.tile { grid-column: span 2; background: #fbf7f1; border-radius: 10px; padding: 8px 6px; text-align: center; }
.tile:nth-child(n+4) { grid-column: span 3; }
.tile .t-lbl { display: block; font-size: 0.7rem; color: var(--muted); }
.tile .t-val { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1rem; }
.b-warn { margin: 10px 0 0; font-size: 0.85rem; color: var(--warn); font-weight: 600; }
/* ---------- Totaux ---------- */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.totals .stat:first-child { grid-column: 1 / -1; background: var(--accent-soft); }
.totals .unit { font-size: 0.8rem; font-weight: 400; color: var(--muted); }
/* ---------- Actions ---------- */
.actions { display: grid; gap: 10px; }
.btn {
font: inherit;
font-weight: 700;
min-height: 52px;
border-radius: 14px;
border: 1.5px solid var(--line);
background: var(--card);
color: var(--ink);
cursor: pointer;
}
.btn:active { transform: scale(0.99); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-dark); }
/* ---------- Grands écrans : deux colonnes ---------- */
@media (min-width: 900px) {
.wrap { max-width: 1000px; }
.bassines { grid-template-columns: 1fr 1fr; }
.actions { grid-template-columns: 1fr 1fr; }
}
/* ---------- Impression : uniquement ce qui a été pesé ---------- */
@media print {
body { background: #fff; }
.topbar, .no-print, .clear { display: none !important; }
.card, .bassine { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
.bassine:not(.filled) { display: none; }
.bassines { grid-template-columns: 1fr 1fr; }
input { border: none; background: none; }
details { display: none; }
}
</style>
</head>
<body>
<header class="topbar">
<h1>Saucissons Murats</h1>
<div class="summary" aria-live="polite">
<div><span class="lbl">Viande nette</span><b id="Resume_Net">0.000</b> kg</div>
<div><span class="lbl">Rendement</span><b id="Resume_Rendement">0 %</b></div>
<div class="topbar-row">
<h1>Calcul des épices</h1>
<div class="summary" aria-live="polite">
<div><span class="lbl">Viande nette</span><b id="Resume_Net">0.000</b> kg</div>
<div><span class="lbl">Rendement</span><b id="Resume_Rendement">0 %</b></div>
</div>
</div>
<nav class="menu" aria-label="Menu principal">
<a href="index.html" aria-current="page">Calculateur</a>
<a href="todo.html">To-do</a>
</nav>
</header>
<main class="wrap">
+383
View File
@@ -0,0 +1,383 @@
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<meta name="theme-color" content="#8c2f2f" />
<title>To-do – Calcul des épices</title>
<link rel="stylesheet" href="assets/menu.css" />
<style>
:root {
--bg: #f6f1ea;
--card: #ffffff;
--ink: #2b2420;
--muted: #7a6e65;
--line: #e6ddd2;
--accent: #8c2f2f;
--accent-dark: #742626;
--accent-soft: #f7e8e5;
--ok: #2f6b4f;
--warn: #b35a00;
--radius: 16px;
--shadow: 0 1px 2px rgba(43, 36, 32, 0.06), 0 6px 18px rgba(43, 36, 32, 0.06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
body {
margin: 0;
background: var(--bg);
color: var(--ink);
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
line-height: 1.35;
padding-bottom: env(safe-area-inset-bottom);
}
.wrap { max-width: 760px; margin: 0 auto; padding: 14px 14px 40px; }
/* Statut de connexion (barre du haut) */
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; opacity: 0.95; }
.live::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #7be0a8; }
.live.off::before { background: #ffc266; }
/* Ajout */
.add { display: flex; gap: 10px; margin-bottom: 14px; }
.add input {
flex: 1;
min-width: 0;
height: 56px;
padding: 0 14px;
font: inherit;
font-size: 1.1rem; /* 16px minimum : pas de zoom iOS */
border: 1.5px solid var(--line);
border-radius: 14px;
background: var(--card);
color: var(--ink);
box-shadow: var(--shadow);
}
.add input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.18); }
.btn {
font: inherit;
font-weight: 700;
min-height: 52px;
padding: 0 18px;
border-radius: 14px;
border: 1.5px solid var(--line);
background: var(--card);
color: var(--ink);
cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; min-height: 56px; }
.btn.primary:active { background: var(--accent-dark); }
.info { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 10px; font-size: 0.9rem; color: var(--muted); }
.info b { color: var(--accent); }
/* Liste */
.liste { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
display: flex;
align-items: center;
background: var(--card);
border-radius: 14px;
box-shadow: var(--shadow);
border: 2px solid transparent;
}
.item.flash { animation: flash 1.8s ease-out; }
@keyframes flash {
0% { background: #fde9c4; border-color: var(--warn); }
100% { background: var(--card); border-color: transparent; }
}
.check {
position: relative;
flex: 1;
min-width: 0;
display: flex;
align-items: center;
gap: 14px;
min-height: 60px;
padding: 8px 6px 8px 14px;
cursor: pointer;
}
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.box {
flex: none;
width: 30px;
height: 30px;
border-radius: 9px;
border: 2px solid #cfc3b5;
background: #fffdfa;
display: grid;
place-items: center;
transition: background 0.12s, border-color 0.12s;
}
.box::after {
content: "";
width: 7px;
height: 14px;
border: solid #fff;
border-width: 0 3px 3px 0;
transform: translateY(-1px) rotate(45deg) scale(0);
transition: transform 0.12s;
}
.check input:checked + .box { background: var(--ok); border-color: var(--ok); }
.check input:checked + .box::after { transform: translateY(-1px) rotate(45deg) scale(1); }
.check input:focus-visible + .box { box-shadow: 0 0 0 3px rgba(140, 47, 47, 0.25); }
.txt { font-size: 1.05rem; overflow-wrap: anywhere; }
.item.done .txt { color: var(--muted); text-decoration: line-through; }
.del {
flex: none;
width: 52px;
height: 52px;
margin-right: 4px;
border: none;
border-radius: 12px;
background: transparent;
color: var(--muted);
font-size: 1.1rem;
cursor: pointer;
}
.del:active { background: var(--line); }
.vide { text-align: center; color: var(--muted); padding: 36px 12px; }
.erreur {
margin: 0 0 12px;
padding: 10px 14px;
border-radius: 12px;
background: #fff1e0;
color: var(--warn);
font-weight: 600;
font-size: 0.9rem;
}
.actions { margin-top: 16px; display: grid; }
</style>
</head>
<body>
<header class="topbar">
<div class="topbar-row">
<h1>Liste de tâches</h1>
<span class="live off" id="statut" role="status">Connexion…</span>
</div>
<nav class="menu" aria-label="Menu principal">
<a href="index.html">Calculateur</a>
<a href="todo.html" aria-current="page">To-do</a>
</nav>
</header>
<main class="wrap">
<form class="add" id="formAjout" autocomplete="off">
<input type="text" id="champAjout" placeholder="Nouvelle tâche…" maxlength="200" enterkeyhint="done"
aria-label="Nouvelle tâche" />
<button type="submit" class="btn primary">Ajouter</button>
</form>
<p class="erreur" id="erreur" hidden></p>
<div class="info">
<span><b id="restantes">0</b> à faire · <span id="faites">0</span> faites</span>
<span>Partagée en direct</span>
</div>
<ul class="liste" id="liste"></ul>
<p class="vide" id="vide" hidden>Aucune tâche pour l'instant.</p>
<div class="actions">
<button type="button" class="btn" id="btnNettoyer" hidden>Supprimer les tâches cochées</button>
</div>
</main>
<script>
const $ = (id) => document.getElementById(id);
let todos = [];
let premierChargement = true;
let minuterieErreur;
// ---------- Affichage ----------
function rendre(modifies = new Set()) {
const liste = $("liste");
liste.textContent = "";
for (const t of todos) {
const li = document.createElement("li");
li.className = "item" + (t.done ? " done" : "") + (modifies.has(t.id) ? " flash" : "");
li.dataset.id = t.id;
const etiquette = document.createElement("label");
etiquette.className = "check";
const caseACocher = document.createElement("input");
caseACocher.type = "checkbox";
caseACocher.checked = t.done;
const boite = document.createElement("span");
boite.className = "box";
const texte = document.createElement("span");
texte.className = "txt";
texte.textContent = t.text; // textContent : jamais de HTML injecté
etiquette.append(caseACocher, boite, texte);
const suppr = document.createElement("button");
suppr.type = "button";
suppr.className = "del";
suppr.setAttribute("aria-label", "Supprimer : " + t.text);
suppr.textContent = "✕";
li.append(etiquette, suppr);
liste.append(li);
}
const faites = todos.filter((t) => t.done).length;
$("restantes").textContent = todos.length - faites;
$("faites").textContent = faites;
$("vide").hidden = todos.length > 0;
$("btnNettoyer").hidden = faites === 0;
}
// Reçoit la liste du serveur ; met en évidence ce que les autres viennent de changer
function recevoir(nouvelle) {
const avant = new Map(todos.map((t) => [t.id, t]));
const modifies = new Set();
if (!premierChargement) {
for (const t of nouvelle) {
const p = avant.get(t.id);
if (!p || p.done !== t.done || p.text !== t.text) modifies.add(t.id);
}
}
premierChargement = false;
todos = nouvelle;
rendre(modifies);
}
function etat(enLigne) {
const el = $("statut");
el.classList.toggle("off", !enLigne);
el.textContent = enLigne ? "En direct" : "Hors ligne…";
}
function afficherErreur(message) {
const el = $("erreur");
el.textContent = message;
el.hidden = false;
clearTimeout(minuterieErreur);
minuterieErreur = setTimeout(() => (el.hidden = true), 4000);
}
// ---------- Appels au serveur ----------
async function appeler(methode, url, corps) {
const reponse = await fetch(url, {
method: methode,
headers: corps ? { "Content-Type": "application/json" } : undefined,
body: corps ? JSON.stringify(corps) : undefined,
});
if (!reponse.ok) throw new Error("HTTP " + reponse.status);
return reponse.json();
}
async function resynchroniser() {
try {
recevoir(await appeler("GET", "/api/todos"));
etat(true);
} catch {
etat(false);
}
}
async function basculer(id, done) {
const tache = todos.find((t) => t.id === id);
if (!tache) return;
tache.done = done; // affichage immédiat, le serveur confirme ensuite
rendre();
try {
await appeler("PATCH", "/api/todos/" + id, { done });
} catch {
afficherErreur("Action impossible, réessaie.");
resynchroniser();
}
}
async function supprimer(id) {
todos = todos.filter((t) => t.id !== id);
rendre();
try {
await appeler("DELETE", "/api/todos/" + id);
} catch {
afficherErreur("Suppression impossible, réessaie.");
resynchroniser();
}
}
async function ajouter(texte) {
try {
const tache = await appeler("POST", "/api/todos", { text: texte });
if (!todos.some((t) => t.id === tache.id)) {
todos.push(tache);
rendre();
}
} catch {
afficherErreur("Ajout impossible, réessaie.");
$("champAjout").value = texte;
}
}
// ---------- Temps réel ----------
function connecter() {
const flux = new EventSource("/api/events");
flux.onopen = () => etat(true);
flux.onmessage = (e) => {
etat(true);
recevoir(JSON.parse(e.data));
};
flux.onerror = () => {
etat(false);
// Le navigateur se reconnecte seul ; si la connexion est fermée pour de bon, on la relance
if (flux.readyState === EventSource.CLOSED) setTimeout(connecter, 3000);
};
}
// ---------- Interactions ----------
$("formAjout").addEventListener("submit", (e) => {
e.preventDefault();
const champ = $("champAjout");
const texte = champ.value.trim();
if (!texte) return;
champ.value = ""; // le champ garde le focus : on enchaîne les ajouts
ajouter(texte);
});
$("liste").addEventListener("change", (e) => {
if (!e.target.matches('input[type="checkbox"]')) return;
basculer(e.target.closest(".item").dataset.id, e.target.checked);
});
$("liste").addEventListener("click", (e) => {
const bouton = e.target.closest(".del");
if (bouton) supprimer(bouton.closest(".item").dataset.id);
});
$("btnNettoyer").addEventListener("click", async () => {
if (!confirm("Supprimer les tâches cochées pour tout le monde ?")) return;
try {
recevoir(await appeler("POST", "/api/todos/clear-done"));
} catch {
afficherErreur("Action impossible, réessaie.");
}
});
// Au retour sur l'onglet (téléphone en veille), on se remet à jour
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible") resynchroniser();
});
resynchroniser();
connecter();
</script>
</body>
</html>
+214
View File
@@ -0,0 +1,214 @@
"use strict";
/**
* Mini-serveur sans dépendance :
* - sert les fichiers du dossier public/
* - garde la to-do list partagée dans un fichier JSON
* - diffuse chaque changement en direct à tous les appareils connectés (SSE)
*/
const http = require("http");
const fs = require("fs");
const path = require("path");
const crypto = require("crypto");
const PORT = Number(process.env.PORT) || 3000;
const PUBLIC_DIR = path.join(__dirname, "public");
const DATA_FILE = process.env.DATA_FILE || path.join(__dirname, "data", "todos.json");
const MAX_ITEMS = 500;
const MAX_TEXT = 200;
const MAX_BODY = 10 * 1024;
const MIME = {
".html": "text/html; charset=utf-8",
".css": "text/css; charset=utf-8",
".js": "text/javascript; charset=utf-8",
".json": "application/json; charset=utf-8",
".svg": "image/svg+xml",
".png": "image/png",
".ico": "image/x-icon",
".webmanifest": "application/manifest+json",
};
// ---------- Données ----------
function charger() {
try {
const liste = JSON.parse(fs.readFileSync(DATA_FILE, "utf8"));
return Array.isArray(liste) ? liste : [];
} catch {
return [];
}
}
let todos = charger();
function sauvegarder() {
fs.mkdirSync(path.dirname(DATA_FILE), { recursive: true });
const tmp = DATA_FILE + ".tmp";
fs.writeFileSync(tmp, JSON.stringify(todos));
fs.renameSync(tmp, DATA_FILE); // écriture atomique
}
// ---------- Temps réel (Server-Sent Events) ----------
const clients = new Set();
function diffuser() {
const message = `data: ${JSON.stringify(todos)}\n\n`;
for (const res of clients) res.write(message);
}
// Un signe de vie régulier empêche les proxys de couper la connexion
setInterval(() => {
for (const res of clients) res.write(": ping\n\n");
}, 25000);
// ---------- Utilitaires HTTP ----------
function envoyerJson(res, statut, donnees) {
res.writeHead(statut, { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store" });
res.end(JSON.stringify(donnees));
}
function lireJson(req) {
return new Promise((resolve, reject) => {
let taille = 0;
const morceaux = [];
req.on("data", (morceau) => {
taille += morceau.length;
if (taille > MAX_BODY) {
reject(new Error("Requête trop volumineuse"));
req.destroy();
return;
}
morceaux.push(morceau);
});
req.on("end", () => {
try {
resolve(morceaux.length ? JSON.parse(Buffer.concat(morceaux).toString("utf8")) : {});
} catch {
reject(new Error("JSON invalide"));
}
});
req.on("error", reject);
});
}
const nettoyerTexte = (valeur) => String(valeur ?? "").replace(/\s+/g, " ").trim().slice(0, MAX_TEXT);
// ---------- API ----------
async function api(req, res, url) {
const [, ressource, id] = url.pathname.split("/").filter(Boolean); // /api/<ressource>/<id>
if (ressource === "events" && req.method === "GET") {
res.writeHead(200, {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache, no-transform",
Connection: "keep-alive",
"X-Accel-Buffering": "no",
});
res.write("retry: 3000\n\n");
res.write(`data: ${JSON.stringify(todos)}\n\n`);
clients.add(res);
req.on("close", () => clients.delete(res));
return;
}
if (ressource !== "todos") return envoyerJson(res, 404, { erreur: "Introuvable" });
// GET /api/todos
if (!id && req.method === "GET") return envoyerJson(res, 200, todos);
// POST /api/todos { text }
if (!id && req.method === "POST") {
const corps = await lireJson(req);
const text = nettoyerTexte(corps.text);
if (!text) return envoyerJson(res, 400, { erreur: "Texte vide" });
if (todos.length >= MAX_ITEMS) return envoyerJson(res, 400, { erreur: "Liste pleine" });
const tache = { id: crypto.randomUUID(), text, done: false, createdAt: Date.now() };
todos.push(tache);
sauvegarder();
diffuser();
return envoyerJson(res, 201, tache);
}
// POST /api/todos/clear-done : supprime toutes les tâches cochées
if (id === "clear-done" && req.method === "POST") {
todos = todos.filter((t) => !t.done);
sauvegarder();
diffuser();
return envoyerJson(res, 200, todos);
}
// PATCH /api/todos/:id { done?, text? }
if (id && req.method === "PATCH") {
const tache = todos.find((t) => t.id === id);
if (!tache) return envoyerJson(res, 404, { erreur: "Tâche introuvable" });
const corps = await lireJson(req);
if (typeof corps.done === "boolean") tache.done = corps.done;
if (typeof corps.text === "string" && nettoyerTexte(corps.text)) tache.text = nettoyerTexte(corps.text);
sauvegarder();
diffuser();
return envoyerJson(res, 200, tache);
}
// DELETE /api/todos/:id
if (id && req.method === "DELETE") {
const avant = todos.length;
todos = todos.filter((t) => t.id !== id);
if (todos.length === avant) return envoyerJson(res, 404, { erreur: "Tâche introuvable" });
sauvegarder();
diffuser();
return envoyerJson(res, 200, { ok: true });
}
return envoyerJson(res, 405, { erreur: "Méthode non autorisée" });
}
// ---------- Fichiers statiques ----------
function statique(req, res, url) {
if (req.method !== "GET" && req.method !== "HEAD") {
res.writeHead(405);
return res.end();
}
let relatif;
try {
relatif = decodeURIComponent(url.pathname);
} catch {
res.writeHead(400);
return res.end();
}
if (relatif.endsWith("/")) relatif += "index.html";
const fichier = path.normalize(path.join(PUBLIC_DIR, relatif));
if (!fichier.startsWith(PUBLIC_DIR + path.sep)) {
res.writeHead(403);
return res.end();
}
fs.readFile(fichier, (erreur, contenu) => {
if (erreur) {
res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
return res.end("Page introuvable");
}
res.writeHead(200, {
"Content-Type": MIME[path.extname(fichier).toLowerCase()] || "application/octet-stream",
"Cache-Control": "no-cache",
});
res.end(req.method === "HEAD" ? undefined : contenu);
});
}
// ---------- Serveur ----------
const serveur = http.createServer(async (req, res) => {
try {
const url = new URL(req.url, "http://localhost");
if (url.pathname === "/healthz") return envoyerJson(res, 200, { ok: true });
if (url.pathname.startsWith("/api/")) return await api(req, res, url);
return statique(req, res, url);
} catch (erreur) {
if (!res.headersSent) envoyerJson(res, 400, { erreur: erreur.message });
else res.end();
}
});
serveur.listen(PORT, "0.0.0.0", () => {
console.log(`Serveur démarré sur le port ${PORT} (données : ${DATA_FILE})`);
});