diff --git a/app/main.py b/app/main.py index e5499d3..0939acb 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,9 @@ from contextlib import asynccontextmanager from typing import Optional, List, Dict, Any -from fastapi import FastAPI, APIRouter, Depends, HTTPException, Query +from pathlib import Path +from fastapi import FastAPI, APIRouter, Depends, HTTPException, Query, Request +from fastapi.responses import FileResponse +from fastapi.staticfiles import StaticFiles from pydantic import BaseModel, Field from app.config import get_tunis_now_iso @@ -76,6 +79,41 @@ app = FastAPI( lifespan=lifespan ) +# STATIC-060 : interface web (HTML et ressources statiques ; /api reste protégé par le jeton Access) +STATIC_DIR = Path(__file__).parent / "static" +CSP = ("default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; " + "connect-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'") +ICONES = ["favicon.svg", "favicon.ico", "apple-touch-icon.png", "icon-192.png", "icon-512.png", + "safari-pinned-tab.svg", "favicon-16.png", "favicon-32.png", "favicon-48.png"] + +@app.middleware("http") +async def en_tetes_securite(request: Request, call_next): + reponse = await call_next(request) + reponse.headers["Content-Security-Policy"] = CSP + reponse.headers["X-Content-Type-Options"] = "nosniff" + reponse.headers["X-Frame-Options"] = "DENY" + reponse.headers["Referrer-Policy"] = "no-referrer" + if request.url.path == "/" or request.url.path.startswith("/api/"): + reponse.headers["Cache-Control"] = "no-store" + return reponse + +@app.get("/", include_in_schema=False) +def page_accueil(): + return FileResponse(STATIC_DIR / "index.html", media_type="text/html; charset=utf-8") + +def _servir_icone(nom: str): + def _f(): + chemin = STATIC_DIR / "icons" / nom + if not chemin.is_file(): + raise HTTPException(status_code=404, detail="Icône introuvable") + return FileResponse(chemin) + return _f + +for _nom in ICONES: + app.add_api_route("/" + _nom, _servir_icone(_nom), methods=["GET"], include_in_schema=False) + +app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static") + # Route de santé publique sans authentification @app.get("/health") def health(): @@ -173,6 +211,12 @@ def modifier_statut_traite(message_id: str, req: TraiteRequest): return res # --- CRUD Catégories --- +def _refuser_categorie_systeme(cat_id: int): + """« À classer » reçoit les mails sans règle : ni renommée ni supprimée.""" + for c in list_categories(): + if c["id"] == cat_id and c["name"] == "À classer": + raise HTTPException(status_code=400, detail="La catégorie « À classer » est protégée") + @api.get("/categories") def list_cats(): """Liste les catégories disponibles.""" @@ -189,7 +233,11 @@ def create_cat(req: CategoryCreate): @api.put("/categories/{cat_id}") def edit_cat(cat_id: int, req: CategoryUpdate): """Met à jour le nom d'une catégorie.""" - res = update_category(cat_id, req.name) + _refuser_categorie_systeme(cat_id) + try: + res = update_category(cat_id, req.name) + except Exception: + raise HTTPException(status_code=400, detail="Nom de catégorie invalide ou déjà utilisé") if not res: raise HTTPException(status_code=404, detail="Catégorie introuvable") return res @@ -197,6 +245,7 @@ def edit_cat(cat_id: int, req: CategoryUpdate): @api.delete("/categories/{cat_id}") def remove_cat(cat_id: int): """Supprime une catégorie.""" + _refuser_categorie_systeme(cat_id) ok = delete_category(cat_id) if not ok: raise HTTPException(status_code=404, detail="Catégorie introuvable") diff --git a/app/static/app.css b/app/static/app.css new file mode 100644 index 0000000..5c66fd4 --- /dev/null +++ b/app/static/app.css @@ -0,0 +1,209 @@ +/* Courrier : mise en page. Aucune couleur en dur : uniquement les jetons Nyora. */ +* { box-sizing: border-box; } +button, select, input { font: inherit; color: inherit; } +button { cursor: pointer; } +button:disabled { cursor: default; } +.sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } +h1, h2, h3, p { margin: 0; } + +.coque { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; } +.nav-bureau { background: var(--ny-carte); border-right: 1px solid var(--ny-trait); padding: var(--ny-e6) var(--ny-e4); display: flex; flex-direction: column; gap: var(--ny-e6); position: sticky; top: 0; height: 100vh; } +.marque { padding: 0 var(--ny-e2); display: flex; flex-direction: column; gap: 2px; } +.marque b { font: var(--ny-t2); } +.marque span { font: var(--ny-t4); color: var(--ny-encre-3); } +.nav-liste { display: flex; flex-direction: column; gap: var(--ny-e1); } +.nav-mobile .nav-sep { display: none; } +.nav-sep { font: var(--ny-t4); color: var(--ny-encre-3); padding: var(--ny-e2) var(--ny-e3) 0; } +.nav-btn { min-height: var(--ny-cible); display: flex; align-items: center; gap: var(--ny-e3); padding: 0 var(--ny-e3); border: none; border-radius: var(--ny-r-s); background: transparent; color: var(--ny-encre-2); font: 500 15px/20px var(--ny-police); text-align: left; transition: background var(--ny-duree) var(--ny-courbe); } +.nav-btn:hover { background: var(--ny-accent-teinte); } +.nav-btn:active { background: var(--ny-accent-teinte-2); } +.nav-btn[aria-current="page"] { background: var(--ny-accent-teinte); color: var(--ny-accent); font-weight: 600; } +.nav-btn svg { width: 20px; height: 20px; flex: none; } +.nav-btn .bientot { margin-left: auto; font: var(--ny-t4); color: var(--ny-encre-3); } +.pied-nyora { margin-top: auto; padding: 0 var(--ny-e2); font: var(--ny-t4); color: var(--ny-encre-3); } + +.principal { padding: var(--ny-e8) var(--ny-e10); display: flex; flex-direction: column; gap: var(--ny-e5); min-width: 0; outline: none; } +.entete { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--ny-e4); flex-wrap: wrap; } +.entete h1 { font: var(--ny-t1); } +.maj { font: var(--ny-t4); color: var(--ny-encre-3); margin-top: var(--ny-e1); } +.jour { display: flex; align-items: center; gap: var(--ny-e2); } +.btn-icone { width: var(--ny-cible); height: var(--ny-cible); display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--ny-trait-controle); border-radius: var(--ny-r-s); background: var(--ny-carte); transition: background var(--ny-duree) var(--ny-courbe); } +.btn-icone:hover:not(:disabled) { background: var(--ny-carte-2); border-color: var(--ny-encre-3); } +.btn-icone:active:not(:disabled) { background: var(--ny-accent-teinte); } +.btn-icone:disabled { opacity: 0.45; } +.btn-icone svg { width: 20px; height: 20px; } +.jour-carte { min-height: var(--ny-cible); display: inline-flex; align-items: center; gap: var(--ny-e2); padding: 0 var(--ny-e4); border: 1px solid var(--ny-trait); border-radius: var(--ny-r-s); background: var(--ny-carte); font: 600 15px/20px var(--ny-police); } +.jour-carte .num { font: 500 15px/20px var(--ny-police-chiffres); } +.btn-lien { min-height: var(--ny-cible); padding: 0 var(--ny-e3); border: none; background: transparent; color: var(--ny-accent); font: 600 15px/20px var(--ny-police); text-decoration: underline; text-underline-offset: 3px; border-radius: var(--ny-r-s); } +.btn-lien:hover { background: var(--ny-accent-teinte); } +.btn-lien:active { background: var(--ny-accent-teinte-2); } +.btn-plein { min-height: var(--ny-cible); padding: 0 var(--ny-e5); border: none; border-radius: var(--ny-r-s); background: var(--ny-accent); color: var(--ny-encre-inverse); font: 600 15px/20px var(--ny-police); transition: background var(--ny-duree) var(--ny-courbe); } +.btn-plein:hover { background: var(--ny-accent-survol); } +.btn-plein:active { background: var(--ny-accent-presse); } +.btn-ligne { min-height: var(--ny-cible); padding: 0 var(--ny-e5); border: 1px solid var(--ny-trait-controle); border-radius: var(--ny-r-s); background: var(--ny-carte); font: 600 15px/20px var(--ny-police); } +.btn-ligne:hover { background: var(--ny-carte-2); border-color: var(--ny-encre-3); } +.btn-ligne:active { background: var(--ny-accent-teinte); } +.btn-danger { min-height: var(--ny-cible); padding: 0 var(--ny-e5); border: none; border-radius: var(--ny-r-s); background: var(--ny-erreur); color: var(--ny-encre-inverse); font: 600 15px/20px var(--ny-police); } +.btn-danger:hover { background: var(--ny-erreur-survol); } +.btn-danger:active { background: var(--ny-erreur-presse); } +.btn-danger-ligne { min-height: var(--ny-cible); padding: 0 var(--ny-e4); border: 1px solid var(--ny-erreur-trait); border-radius: var(--ny-r-s); background: transparent; color: var(--ny-erreur); font: 600 15px/20px var(--ny-police); } +.btn-danger-ligne:hover { background: var(--ny-erreur-fond); } + +.carte { background: var(--ny-carte); border: 1px solid var(--ny-trait); border-radius: var(--ny-r-l); overflow: hidden; } +.repartition { padding: var(--ny-e4) var(--ny-e5); display: flex; flex-direction: column; gap: var(--ny-e3); } +.repartition h2 { font: 600 15px/20px var(--ny-police); color: var(--ny-encre-2); } +.puces { display: flex; flex-wrap: wrap; gap: var(--ny-e2); } +.puce { min-height: var(--ny-cible); padding: 0 var(--ny-e3) 0 10px; display: inline-flex; align-items: center; gap: 7px; border-radius: var(--ny-r-pastille); border: 1px solid var(--ny-trait-controle); background: var(--ny-carte); font: 500 15px/20px var(--ny-police); white-space: nowrap; } +.puce:hover { box-shadow: inset 0 0 0 1px var(--ny-accent); } +.puce:active { box-shadow: inset 0 0 0 2px var(--ny-accent); } +.puce .n { font: 600 14px/20px var(--ny-police-chiffres); color: var(--ny-encre-2); } +.puce[aria-pressed="true"] { background: var(--ny-encre); border-color: var(--ny-encre); color: var(--ny-encre-inverse); } +.puce[aria-pressed="true"] .n { color: var(--ny-encre-inverse); } +.puce.vide { border-style: dashed; } +.avancement { display: flex; align-items: center; gap: var(--ny-e3); font: var(--ny-t4); color: var(--ny-encre-2); } +.barre { flex: 1; height: 6px; background: var(--ny-carte-2); border: 1px solid var(--ny-trait); border-radius: var(--ny-r-pastille); overflow: hidden; } +.barre > div { height: 100%; background: var(--ny-accent); transition: width var(--ny-duree) var(--ny-courbe); } +.avancement b { font: 600 13px/18px var(--ny-police-chiffres); color: var(--ny-encre); } + +/* Pastille de catégorie */ +.pt { width: 10px; height: 10px; border-radius: var(--ny-r-pastille); flex: none; box-sizing: border-box; background: var(--ny-cat-vide); } +.pt.c1 { background: var(--ny-cat-1); } .pt.c2 { background: var(--ny-cat-2); } .pt.c3 { background: var(--ny-cat-3); } .pt.c4 { background: var(--ny-cat-4); } +.pt.c5 { background: var(--ny-cat-5); } .pt.c6 { background: var(--ny-cat-6); } .pt.c7 { background: var(--ny-cat-7); } .pt.c8 { background: var(--ny-cat-8); } +.pt.c0 { background: transparent; border: 1.5px dashed var(--ny-cat-vide); } +.pt.tous { background: var(--ny-encre-2); } +.puce[aria-pressed="true"] .pt.c0 { border-color: var(--ny-encre-inverse); } +.puce.t1 { background: var(--ny-cat-1-fond); border-color: var(--ny-cat-1-trait); } .puce.t2 { background: var(--ny-cat-2-fond); border-color: var(--ny-cat-2-trait); } +.puce.t3 { background: var(--ny-cat-3-fond); border-color: var(--ny-cat-3-trait); } .puce.t4 { background: var(--ny-cat-4-fond); border-color: var(--ny-cat-4-trait); } +.puce.t5 { background: var(--ny-cat-5-fond); border-color: var(--ny-cat-5-trait); } .puce.t6 { background: var(--ny-cat-6-fond); border-color: var(--ny-cat-6-trait); } +.puce.t7 { background: var(--ny-cat-7-fond); border-color: var(--ny-cat-7-trait); } .puce.t8 { background: var(--ny-cat-8-fond); border-color: var(--ny-cat-8-trait); } +.puce[aria-pressed="true"].t1, .puce[aria-pressed="true"].t2, .puce[aria-pressed="true"].t3, .puce[aria-pressed="true"].t4, +.puce[aria-pressed="true"].t5, .puce[aria-pressed="true"].t6, .puce[aria-pressed="true"].t7, .puce[aria-pressed="true"].t8 { background: var(--ny-encre); border-color: var(--ny-encre); } + +/* Bandeau de règle et notification */ +.bandeau { display: flex; align-items: center; gap: var(--ny-e4); flex-wrap: wrap; padding: var(--ny-e3) var(--ny-e5); background: var(--ny-info-fond); border: 1px solid var(--ny-accent-teinte-2); border-radius: var(--ny-r-m); animation: ny-apparition var(--ny-duree) var(--ny-courbe); } +.bandeau .txt { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 2px; font: 500 15px/22px var(--ny-police); } +.bandeau .txt small { font: var(--ny-t4); color: var(--ny-encre-2); } +.bandeau .acts { display: flex; gap: var(--ny-e2); } +.notif { padding: var(--ny-e3) var(--ny-e5); border-radius: var(--ny-r-m); border: 1px solid var(--ny-trait); background: var(--ny-carte); box-shadow: var(--ny-ombre-2); font: 500 15px/22px var(--ny-police); animation: ny-apparition var(--ny-duree) var(--ny-courbe); } + +/* Liste du tri */ +.liste-entete, .ligne { display: grid; grid-template-columns: 44px minmax(0, 1.1fr) minmax(0, 1.6fr) 64px 110px 200px; gap: var(--ny-e3); align-items: center; padding: 0 var(--ny-e5) 0 var(--ny-e2); } +.liste-entete { min-height: 40px; background: var(--ny-carte-2); border-bottom: 1px solid var(--ny-trait); font: var(--ny-t4); color: var(--ny-encre-2); } +.ligne { min-height: 64px; border-bottom: 1px solid var(--ny-trait); } +.ligne:last-child { border-bottom: none; } +.ligne .coche { width: var(--ny-cible); height: var(--ny-cible); display: flex; align-items: center; justify-content: center; } +.ligne .coche input { width: 22px; height: 22px; margin: 0; accent-color: var(--ny-accent); } +.ligne .corps { min-width: 0; } +.ligne .exp, .ligne .objet { transition: color 240ms var(--ny-courbe); } +/* Traité : encre atténuée (contraste conservé, jamais d'opacité sur le texte) */ +.ligne.fait .exp { color: var(--ny-encre-3); font-weight: 500; } +.ligne.fait .objet { color: var(--ny-encre-3); } +.coupe { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } +.exp { font: 600 15px/20px var(--ny-police); } +.objet { font: 400 15px/20px var(--ny-police); color: var(--ny-encre-2); } +.objet.sans { color: var(--ny-encre-3); } +.heure { font: 500 14px/20px var(--ny-police-chiffres); } +.origine { display: inline-flex; align-items: center; justify-self: start; padding: 0 10px; min-height: 24px; border-radius: var(--ny-r-pastille); border: 1px solid var(--ny-trait); background: var(--ny-carte-2); color: var(--ny-encre-2); font: 600 13px/18px var(--ny-police); } +.origine.manuel { background: var(--ny-accent-teinte); border-color: var(--ny-accent-teinte-2); color: var(--ny-accent); } +.origine.sansregle { background: transparent; border: 1px dashed var(--ny-trait-controle); } +.m-corps { display: none; } +.sel { position: relative; display: flex; align-items: center; } +.sel .pt { position: absolute; left: 12px; pointer-events: none; } +.sel .chev { position: absolute; right: 12px; width: 16px; height: 16px; display: flex; pointer-events: none; color: var(--ny-encre-2); } +.sel .chev svg { width: 16px; height: 16px; } +.sel select { appearance: none; -webkit-appearance: none; width: 100%; min-height: var(--ny-cible); padding: 0 34px 0 30px; border: 1px solid var(--ny-trait-controle); border-radius: var(--ny-r-s); background: var(--ny-carte); font: 500 15px/20px var(--ny-police); } +.sel select:hover { border-color: var(--ny-encre-2); background: var(--ny-carte-2); } + +/* États */ +.etat { padding: var(--ny-e10) var(--ny-e6); display: flex; flex-direction: column; gap: var(--ny-e2); align-items: flex-start; } +.etat svg { width: 28px; height: 28px; color: var(--ny-encre-2); } +.etat h2 { font: 600 18px/24px var(--ny-police); } +.etat p { font: 400 15px/22px var(--ny-police); color: var(--ny-encre-2); } +.etat-filtre { padding: var(--ny-e5); display: flex; align-items: center; gap: var(--ny-e2); flex-wrap: wrap; font: 400 15px/22px var(--ny-police); color: var(--ny-encre-2); } +.erreur { display: flex; flex-direction: column; gap: var(--ny-e3); align-items: flex-start; padding: var(--ny-e5) var(--ny-e6); background: var(--ny-erreur-fond); border: 1px solid var(--ny-erreur-trait); border-radius: var(--ny-r-l); } +.erreur h2 { font: 600 18px/24px var(--ny-police); color: var(--ny-erreur); } +.erreur p { font: 400 15px/22px var(--ny-police); color: var(--ny-encre); } +.squelette { padding: 0; } +.sq-ligne { display: grid; grid-template-columns: 44px minmax(0, 1.1fr) minmax(0, 1.6fr) 64px 110px 200px; gap: var(--ny-e3); align-items: center; min-height: 64px; padding: 0 var(--ny-e5) 0 var(--ny-e2); border-bottom: 1px solid var(--ny-trait); } +.sq-ligne span { height: 14px; border-radius: var(--ny-r-s); background: var(--ny-trait); } +.sq-ligne span:first-child { width: 22px; height: 22px; margin-left: 11px; } +.sq-statut { padding: var(--ny-e3) var(--ny-e5); font: var(--ny-t4); color: var(--ny-encre-2); border-bottom: 1px solid var(--ny-trait); } + +/* Catégories et règles */ +.rang { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto auto; gap: 14px; align-items: center; min-height: 56px; padding: 0 var(--ny-e5); border-bottom: 1px solid var(--ny-trait); } +.rang:last-child { border-bottom: none; } +.rang .pt { width: 12px; height: 12px; } +.rang .nom { font: 500 16px/22px var(--ny-police); } +.nb { font: var(--ny-t4); color: var(--ny-encre-2); } +.nb b { font: 600 14px/18px var(--ny-police-chiffres); color: var(--ny-encre); } +.btn-petit { min-height: var(--ny-cible); padding: 0 var(--ny-e3); border: none; border-radius: var(--ny-r-s); background: transparent; color: var(--ny-accent); font: 600 15px/20px var(--ny-police); text-decoration: underline; text-underline-offset: 3px; } +.btn-petit:hover { background: var(--ny-accent-teinte); } +.limite { max-width: 720px; } +.limite-l { max-width: 900px; } +.note { font: var(--ny-t4); color: var(--ny-encre-3); } +.regle { display: grid; grid-template-columns: minmax(0, 1fr) 20px 180px 130px 52px; gap: var(--ny-e3); align-items: center; min-height: 56px; padding: 0 var(--ny-e5); border-bottom: 1px solid var(--ny-trait); } +.regle:last-child { border-bottom: none; } +.regle .crit { font: 400 15px/22px var(--ny-police); color: var(--ny-encre-2); } +.regle .crit b { font-weight: 600; color: var(--ny-encre); } +.regle .fl { width: 16px; height: 16px; color: var(--ny-encre-3); } +.regle .cat { display: inline-flex; align-items: center; gap: var(--ny-e2); font: 500 15px/20px var(--ny-police); } +.regle.propose { background: var(--ny-attention-fond); } +.etiq { font: 600 13px/18px var(--ny-police); } +.etiq.propose { color: var(--ny-attention); } +.etiq.active { color: var(--ny-encre-3); } +.interrupteur { position: relative; width: 52px; height: var(--ny-cible); display: flex; align-items: center; justify-content: center; border: none; background: transparent; padding: 0; } +.interrupteur .piste { width: 44px; height: 24px; border-radius: var(--ny-r-pastille); background: var(--ny-carte); border: 2px solid var(--ny-trait-controle); display: flex; align-items: center; padding: 0 2px; transition: background var(--ny-duree) var(--ny-courbe); } +.interrupteur .bouton { width: 16px; height: 16px; border-radius: var(--ny-r-pastille); background: var(--ny-trait-controle); transition: transform var(--ny-duree) var(--ny-courbe); } +.interrupteur[aria-checked="true"] .piste { background: var(--ny-accent); border-color: var(--ny-accent); } +.interrupteur[aria-checked="true"] .bouton { background: var(--ny-encre-inverse); transform: translateX(20px); } + +/* Calques : dialogues et session expirée */ +.voile { position: fixed; inset: 0; background: var(--ny-fond); display: flex; align-items: center; justify-content: center; padding: var(--ny-e4); z-index: 50; } +.voile.leger { background: color-mix(in srgb, var(--ny-encre) 45%, transparent); } +.boite { width: 100%; max-width: 440px; background: var(--ny-carte); border: 1px solid var(--ny-trait); border-radius: var(--ny-r-l); box-shadow: var(--ny-ombre-2); padding: var(--ny-e6); display: flex; flex-direction: column; gap: var(--ny-e4); animation: ny-apparition var(--ny-duree) var(--ny-courbe); } +.boite h2 { font: var(--ny-t2); } +.boite p { font: 400 15px/22px var(--ny-police); color: var(--ny-encre-2); } +.boite .acts { display: flex; gap: var(--ny-e2); flex-wrap: wrap; justify-content: flex-end; } +.champ { display: flex; flex-direction: column; gap: var(--ny-e2); } +.champ label { font: 600 15px/20px var(--ny-police); } +.champ input { min-height: var(--ny-cible); padding: 0 var(--ny-e3); border: 1px solid var(--ny-trait-controle); border-radius: var(--ny-r-s); background: var(--ny-carte); font: 400 16px/24px var(--ny-police); } +.champ .err { font: 500 14px/20px var(--ny-police); color: var(--ny-erreur); } +.pave { display: flex; align-items: center; justify-content: space-between; gap: var(--ny-e4); flex-wrap: wrap; } + +.bientot-ecran { padding: var(--ny-e8) var(--ny-e6); display: flex; flex-direction: column; gap: var(--ny-e2); align-items: flex-start; } +.badge-bientot { display: inline-flex; padding: 0 10px; min-height: 24px; align-items: center; border: 1px dashed var(--ny-trait-controle); border-radius: var(--ny-r-pastille); font: 600 13px/18px var(--ny-police); color: var(--ny-encre-2); } + +.nav-mobile { display: none; } + +@media (max-width: 760px) { + .coque { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; height: 100dvh; min-height: 0; } + .nav-bureau { display: none; } + .principal { padding: var(--ny-e4); gap: var(--ny-e3); overflow-y: auto; } + .entete h1 { font: var(--ny-t2); } + .nav-mobile { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--ny-carte); border-top: 1px solid var(--ny-trait); padding: 4px 8px 16px; } + .nav-mobile .nav-btn { min-height: 56px; flex-direction: column; justify-content: center; gap: 4px; padding: 0; text-align: center; font: 500 13px/18px var(--ny-police); } + .nav-mobile .nav-btn[aria-current="page"] { font-weight: 600; } + .nav-mobile .nav-btn svg { width: 22px; height: 22px; } + .jour { width: 100%; } + .jour-carte { flex: 1; justify-content: center; } + .liste-entete { display: none; } + .ligne { grid-template-columns: 44px minmax(0, 1fr) 138px; gap: var(--ny-e2); min-height: 72px; padding: 6px 12px 6px 6px; } + .ligne .d { display: none; } + .m-corps { display: flex; flex-direction: column; gap: 2px; min-width: 0; } + .ligne .objet { font: 400 14px/20px var(--ny-police); } + .m-meta { display: block; font: 500 13px/18px var(--ny-police); color: var(--ny-encre-3); } + .m-meta .heure { font: 500 13px/18px var(--ny-police-chiffres); } + .m-meta .o { font-weight: 600; } + .m-meta .o.manuel { color: var(--ny-accent); } + .ligne .sel select { font: 500 14px/20px var(--ny-police); padding: 0 28px 0 26px; } + .ligne .sel .pt { left: 10px; } + .puces { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 4px; scrollbar-width: none; } + .puce { flex: none; } + .repartition { padding: var(--ny-e3) var(--ny-e4); } + .regle { grid-template-columns: minmax(0, 1fr) 52px; row-gap: 0; padding: var(--ny-e2) var(--ny-e4); } + .regle .fl { display: none; } + .regle .cat, .regle .etiq { grid-column: 1; } + .regle .interrupteur { grid-column: 2; grid-row: 1 / span 3; } + .sq-ligne { grid-template-columns: 44px minmax(0, 1fr) 138px; } + .sq-ligne span:nth-child(3), .sq-ligne span:nth-child(4), .sq-ligne span:nth-child(5) { display: none; } +} diff --git a/app/static/app.js b/app/static/app.js new file mode 100644 index 0000000..2b7cbe5 --- /dev/null +++ b/app/static/app.js @@ -0,0 +1,431 @@ +/* Courrier : interface v1 (lecture seule). Tout le texte passe par textContent, aucun balisage injecté. */ +(function () { + 'use strict'; + var TZ = 'Africa/Tunis'; + var API = '/api/v1'; + var NS = 'http://www.w3.org/2000/svg'; + + var ICONES = { + tri: 'M22 12h-6l-2 3h-4l-2-3H2|M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z', + categories: 'M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z|M7.5 7.5h.01', + regles: 'M3 6h18|M7 12h10|M10 18h4', + recherche: 'm21 21-4.34-4.34|M11 19a8 8 0 1 0 0-16 8 8 0 0 0 0 16', + courses: 'M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z|M12 13a3 3 0 1 0 0-6 3 3 0 0 0 0 6', + suivi: 'M12 6v6l4 2|M22 12a10 10 0 1 1-20 0 10 10 0 0 1 20 0', + pj: 'm21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48', + gauche: 'm15 18-6-6 6-6', droite: 'm9 18 6-6-6-6', bas: 'm6 9 6 6 6-6', fleche: 'M5 12h14|m12 5 7 7-7 7' + }; + var NAV = [ + ['tri', 'Tri du jour', true], ['categories', 'Catégories', true], ['regles', 'Règles', true], + ['recherche', 'Recherche', false], ['courses', 'Courses pour Tunis', false], ['suivi', 'Suivi des demandes', false], ['pj', 'Pièces jointes', false] + ]; + var BIENTOT = { + recherche: ['Recherche', 'Retrouver un mail par expéditeur, objet ou date, dans tout le courrier lu.'], + courses: ['Courses pour Tunis', 'Préparer les courses à partir des mails classés « Tunis ».'], + suivi: ['Suivi des demandes', 'Suivre les demandes envoyées et celles qui attendent une réponse.'], + pj: ['Pièces jointes', 'Lister et rechercher les pièces jointes des mails.'] + }; + var COULEUR_NOM = { 'Tunis': 1, 'Demande FB': 2, 'CI': 3, 'Câbles': 4, 'Sans objet': 5, 'À classer': 0 }; + var SYSTEME = 'À classer'; + + var S = { vue: 'tri', jour: auj(), filtre: null, cats: [], mails: [], etat: 'chargement', banniere: null, notif: null, regles: [], reglesEtat: 'ok', miroirErreur: false, majHeure: '' }; + + /* ---------- Utilitaires ---------- */ + function auj() { return new Intl.DateTimeFormat('en-CA', { timeZone: TZ }).format(new Date()); } + function d2(n) { return (n < 10 ? '0' : '') + n; } + function dateUTC(s) { var p = s.split('-'); return new Date(Date.UTC(+p[0], +p[1] - 1, +p[2], 12)); } + function versISO(d) { return d.getUTCFullYear() + '-' + d2(d.getUTCMonth() + 1) + '-' + d2(d.getUTCDate()); } + function fr(s) { var p = s.split('-'); return p[2] + '/' + p[1] + '/' + p[0]; } + function nomJour(s) { var n = new Intl.DateTimeFormat('fr-FR', { weekday: 'long', timeZone: 'UTC' }).format(dateUTC(s)); return n.charAt(0).toUpperCase() + n.slice(1); } + function heureTunis(v) { + if (!v) return '--:--'; + var d = new Date(v); + if (isNaN(d.getTime())) { var m = String(v).match(/(\d{2}):(\d{2})/); return m ? m[1] + ':' + m[2] : '--:--'; } + return new Intl.DateTimeFormat('fr-FR', { hour: '2-digit', minute: '2-digit', hour12: false, timeZone: TZ }).format(d); + } + function couleur(nom, id) { + if (Object.prototype.hasOwnProperty.call(COULEUR_NOM, nom)) return COULEUR_NOM[nom]; + return 6 + ((id || 0) % 3); + } + function h(tag, attrs) { + var el = document.createElement(tag); + if (attrs) for (var k in attrs) { + var v = attrs[k]; + if (v === null || v === undefined || v === false) continue; + if (k === 'class') el.className = v; + else if (k === 'text') el.textContent = v; + else if (k.slice(0, 2) === 'on') el.addEventListener(k.slice(2), v); + else el.setAttribute(k, v === true ? '' : v); + } + for (var i = 2; i < arguments.length; i++) { + var c = arguments[i]; + if (c === null || c === undefined || c === false) continue; + el.appendChild(typeof c === 'string' ? document.createTextNode(c) : c); + } + return el; + } + function icone(cle, taille) { + var svg = document.createElementNS(NS, 'svg'); + svg.setAttribute('viewBox', '0 0 24 24'); svg.setAttribute('fill', 'none'); svg.setAttribute('stroke', 'currentColor'); + svg.setAttribute('stroke-width', '2'); svg.setAttribute('stroke-linecap', 'round'); svg.setAttribute('stroke-linejoin', 'round'); + svg.setAttribute('aria-hidden', 'true'); + if (taille) { svg.setAttribute('width', taille); svg.setAttribute('height', taille); } + ICONES[cle].split('|').forEach(function (d) { var p = document.createElementNS(NS, 'path'); p.setAttribute('d', d); svg.appendChild(p); }); + return svg; + } + function pastille(c, extra) { return h('span', { class: 'pt c' + c + (extra ? ' ' + extra : ''), 'aria-hidden': 'true' }); } + function annoncer(t) { var a = document.getElementById('annonce'); a.textContent = ''; setTimeout(function () { a.textContent = t; }, 30); } + + /* ---------- API ---------- */ + function api(chemin, opts) { + opts = opts || {}; + var init = { method: opts.method || 'GET', credentials: 'same-origin', redirect: 'manual', headers: { 'Accept': 'application/json' } }; + if (opts.body !== undefined) { init.headers['Content-Type'] = 'application/json'; init.body = JSON.stringify(opts.body); } + return fetch(API + chemin, init).then(function (r) { + if (r.type === 'opaqueredirect' || r.status === 401 || r.status === 403) { sessionExpiree(); throw new Error('session'); } + if (!r.ok) throw new Error('http ' + r.status); + var ct = r.headers.get('content-type') || ''; + if (ct.indexOf('application/json') === -1) { sessionExpiree(); throw new Error('session'); } + return r.json(); + }); + } + + /* ---------- Données ---------- */ + function nomExp(brut) { + var x = String(brut || '').match(/^\s*"?([^"<]*?)"?\s*<([^>]+)>\s*$/); + if (!x) return brut || '(expéditeur inconnu)'; + return x[1].trim() || x[2]; + } + function normaliser(m) { + var c = m.classement || m; + var cat = c.categorie || SYSTEME; + return { + id: m.message_id, exp: nomExp(m.expediteur || c.expediteur || ''), expBrut: m.expediteur || c.expediteur || '', objet: m.objet || c.objet || '', + date: m.date || c.date_mail || '', cat: cat, source: c.source || 'regle', traite: !!c.traite, etiquettes: m.etiquettes || [] + }; + } + function chargerCats() { + return api('/categories').then(function (r) { + var l = (r.categories || []).map(function (c) { return { id: c.id, nom: c.name }; }); + l.sort(function (a, b) { return (a.nom === SYSTEME) - (b.nom === SYSTEME) || a.id - b.id; }); + S.cats = l; + }); + } + function chargerMails() { + S.etat = 'chargement'; S.miroirErreur = false; rendre(); + var jour = S.jour; + return Promise.all([chargerCats(), api('/mails?date=' + jour + '&n=200')]).then(function (rs) { + if (jour !== S.jour) return; + var r = rs[1]; + S.miroirErreur = !!r.miroir_erreur; + S.mails = (r.mails || []).map(normaliser).sort(function (a, b) { return String(a.date).localeCompare(String(b.date)); }); + S.etat = 'ok'; S.majHeure = heureTunis(new Date().toISOString()); + rendre(); + }).catch(function (e) { if (e.message === 'session') return; if (jour !== S.jour) return; S.etat = 'erreur'; rendre(); }); + } + function chargerRegles() { + S.reglesEtat = 'chargement'; rendre(); + return Promise.all([chargerCats(), api('/regles')]).then(function (rs) { + S.regles = rs[1].regles || []; S.reglesEtat = 'ok'; rendre(); + }).catch(function (e) { if (e.message === 'session') return; S.reglesEtat = 'erreur'; rendre(); }); + } + + /* ---------- Actions ---------- */ + function flash(t) { S.notif = t; rendre(); annoncer(t); clearTimeout(flash.t); flash.t = setTimeout(function () { S.notif = null; rendre(); }, 5000); } + function changerJour(delta) { + var d = dateUTC(S.jour); d.setUTCDate(d.getUTCDate() + delta); var j = versISO(d); + if (j > auj()) return; + S.jour = j; S.filtre = null; S.banniere = null; chargerMails(); annoncer(nomJour(j) + ' ' + fr(j)); + } + function allerA(vue) { + S.vue = vue; S.banniere = null; + if (vue === 'tri' || vue === 'categories') chargerMails(); + else if (vue === 'regles') chargerRegles(); + else rendre(); + document.getElementById('principal').focus(); + } + function basculerTraite(m, val) { + var avant = m.traite; m.traite = val; rendre(); + api('/classements/' + encodeURIComponent(m.id) + '/traite', { method: 'PATCH', body: { traite: val } }).catch(function (e) { + if (e.message === 'session') return; m.traite = avant; rendre(); flash('Impossible d\'enregistrer le statut « traité ». Réessayez.'); + }); + } + function corriger(m, cat) { + var avant = { cat: m.cat, source: m.source }; + m.cat = cat; m.source = 'manuel'; S.banniere = null; rendre(); + api('/classements/' + encodeURIComponent(m.id), { method: 'POST', body: { categorie: cat, mail_info: { message_id: m.id, expediteur: m.expBrut || m.exp, objet: m.objet, date: m.date, etiquettes: m.etiquettes } } }) + .then(function (r) { + var rp = r.regle_proposee; + if (rp && rp.id) { + var autres = S.mails.filter(function (x) { return x.exp === m.exp && x.id !== m.id && x.source !== 'manuel' && x.cat !== cat; }).length; + S.banniere = { id: rp.id, exp: m.exp, cat: cat, autres: autres }; rendre(); + } + }).catch(function (e) { if (e.message === 'session') return; m.cat = avant.cat; m.source = avant.source; rendre(); flash('La correction n\'a pas été enregistrée. Réessayez.'); }); + } + function confirmerRegle() { + var b = S.banniere; if (!b) return; + api('/regles/' + b.id + '/confirmer', { method: 'POST' }).then(function () { S.banniere = null; flash('Règle créée : ' + b.exp + ' → ' + b.cat + '.'); return chargerMails(); }) + .catch(function (e) { if (e.message !== 'session') flash('La règle n\'a pas pu être créée. Réessayez.'); }); + } + function ignorerRegle() { + var b = S.banniere; S.banniere = null; rendre(); + if (b) api('/regles/' + b.id, { method: 'DELETE' }).catch(function () {}); + } + function basculerRegle(r) { + var req = r.statut === 'active' ? api('/regles/' + r.id, { method: 'PUT', body: { statut: 'proposee' } }) : api('/regles/' + r.id + '/confirmer', { method: 'POST' }); + req.then(function () { return chargerRegles(); }).then(function () { annoncer(r.statut === 'active' ? 'Règle désactivée' : 'Règle activée'); }) + .catch(function (e) { if (e.message !== 'session') flash('La règle n\'a pas pu être modifiée. Réessayez.'); }); + } + + /* ---------- Dialogues ---------- */ + var dialogue = null; + function ouvrir(construire) { + fermer(true); + var retour = document.activeElement; + var voile = h('div', { class: 'voile leger' }); + var boite = construire(function () { fermer(); }); + voile.appendChild(boite); + document.getElementById('calque').appendChild(voile); + document.getElementById('app').setAttribute('inert', ''); + dialogue = { voile: voile, retour: retour, etiquette: retour && retour.getAttribute ? retour.getAttribute('aria-label') : null }; + var premier = boite.querySelector('[data-focus]') || boite.querySelector('input,button'); + if (premier) premier.focus(); + voile.addEventListener('keydown', function (e) { + if (e.key === 'Escape') { e.preventDefault(); fermer(); return; } + if (e.key === 'Tab') { + var f = boite.querySelectorAll('button,input,select,[href]'); if (!f.length) return; + var a = f[0], z = f[f.length - 1]; + if (e.shiftKey && document.activeElement === a) { e.preventDefault(); z.focus(); } + else if (!e.shiftKey && document.activeElement === z) { e.preventDefault(); a.focus(); } + } + }); + return boite; + } + function fermer(sansRetour) { + if (!dialogue) return; + dialogue.voile.remove(); document.getElementById('app').removeAttribute('inert'); + var r = dialogue.retour, et = dialogue.etiquette; dialogue = null; + if (sansRetour) return; + if (r && !document.body.contains(r) && et) r = document.querySelector('[aria-label="' + et.replace(/"/g, '\\"') + '"]'); + if (r && document.body.contains(r)) r.focus(); + } + function dialogueCategorie(cat) { + var nouveau = !cat, systeme = cat && cat.nom === SYSTEME; + ouvrir(function (clore) { + var champ = h('input', { id: 'cat-nom', type: 'text', maxlength: '100', 'data-focus': '', autocomplete: 'off', value: cat ? cat.nom : '' }); + if (systeme) { champ.setAttribute('readonly', ''); } + var err = h('div', { class: 'err', role: 'alert' }); + function enregistrer() { + var nom = champ.value.trim(); + if (!nom) { err.textContent = 'Saisissez un nom de catégorie.'; champ.focus(); return; } + if (S.cats.some(function (c) { return c.nom.toLowerCase() === nom.toLowerCase() && (!cat || c.id !== cat.id); })) { err.textContent = 'Cette catégorie existe déjà.'; champ.focus(); return; } + var req = nouveau ? api('/categories', { method: 'POST', body: { name: nom } }) : api('/categories/' + cat.id, { method: 'PUT', body: { name: nom } }); + req.then(function () { clore(); return chargerMails(); }).then(function () { flash(nouveau ? 'Catégorie ajoutée.' : 'Catégorie renommée.'); }) + .catch(function (e) { if (e.message !== 'session') err.textContent = 'Enregistrement impossible. Réessayez.'; }); + } + champ.addEventListener('keydown', function (e) { if (e.key === 'Enter' && !systeme) { e.preventDefault(); enregistrer(); } }); + var acts = h('div', { class: 'acts' }, h('button', { type: 'button', class: 'btn-ligne', onclick: clore }, 'Annuler'), + systeme ? null : h('button', { type: 'button', class: 'btn-plein', onclick: enregistrer }, nouveau ? 'Ajouter' : 'Enregistrer')); + var pied = null; + if (cat && !systeme) pied = h('div', { class: 'pave' }, h('button', { type: 'button', class: 'btn-danger-ligne', onclick: function () { clore(); dialogueSuppression(cat); } }, 'Supprimer la catégorie')); + return h('section', { class: 'boite', role: 'dialog', 'aria-modal': 'true', 'aria-labelledby': 'dlg-t' }, + h('h2', { id: 'dlg-t' }, nouveau ? 'Nouvelle catégorie' : systeme ? SYSTEME : 'Modifier la catégorie'), + systeme ? h('p', null, '« À classer » reçoit les mails qu\'aucune règle ne reconnaît. Elle ne peut être ni renommée ni supprimée.') : null, + h('div', { class: 'champ' }, h('label', { for: 'cat-nom' }, 'Nom'), champ, err), acts, pied); + }); + } + function dialogueSuppression(cat) { + ouvrir(function (clore) { + var err = h('div', { class: 'err', role: 'alert' }); + return h('section', { class: 'boite', role: 'alertdialog', 'aria-modal': 'true', 'aria-labelledby': 'sup-t', 'aria-describedby': 'sup-p' }, + h('h2', { id: 'sup-t' }, 'Supprimer « ' + cat.nom + ' » ?'), + h('p', { id: 'sup-p' }, 'La catégorie disparaît de la liste. Ses mails repassent dans « À classer » et ses règles sont supprimées. Votre messagerie n\'est pas modifiée.'), + err, + h('div', { class: 'acts' }, + h('button', { type: 'button', class: 'btn-ligne', 'data-focus': '', onclick: clore }, 'Annuler'), + h('button', { type: 'button', class: 'btn-danger', onclick: function () { + api('/categories/' + cat.id, { method: 'DELETE' }).then(function () { clore(); return chargerMails(); }).then(function () { flash('Catégorie supprimée.'); }) + .catch(function (e) { if (e.message !== 'session') err.textContent = 'Suppression impossible. Réessayez.'; }); + } }, 'Supprimer'))); + }); + } + function sessionExpiree() { + if (document.getElementById('sess')) return; + fermer(true); + var btn = h('button', { type: 'button', class: 'btn-plein', id: 'sess-b', 'data-focus': '', onclick: function () { location.reload(); } }, 'Se reconnecter'); + var voile = h('div', { class: 'voile', id: 'sess' }, h('section', { class: 'boite', role: 'alertdialog', 'aria-modal': 'true', 'aria-labelledby': 'sess-t' }, + h('h2', { id: 'sess-t' }, 'Session expirée'), + h('p', null, 'La connexion à la messagerie a pris fin. Vos corrections et vos règles sont conservées.'), btn)); + document.getElementById('calque').appendChild(voile); + document.getElementById('app').setAttribute('inert', ''); + btn.focus(); + voile.addEventListener('keydown', function (e) { if (e.key === 'Tab') { e.preventDefault(); btn.focus(); } }); + } + + /* ---------- Rendu ---------- */ + function rendreNav() { + var bureau = document.getElementById('nav-bureau'), mobile = document.getElementById('nav-mobile'); + bureau.textContent = ''; mobile.textContent = ''; + function bouton(n) { + return h('button', { type: 'button', class: 'nav-btn', 'aria-current': S.vue === n[0] ? 'page' : null, onclick: function () { allerA(n[0]); } }, icone(n[0]), h('span', null, n[1])); + } + var liste = h('div', { class: 'nav-liste' }); + NAV.forEach(function (n, i) { + if (i === 3) liste.appendChild(h('div', { class: 'nav-sep' }, 'Prochainement')); + liste.appendChild(bouton(n)); + if (n[2]) mobile.appendChild(bouton(n)); + }); + bureau.appendChild(h('div', { class: 'marque' }, h('b', null, 'Courrier'), h('span', null, 'Lecture seule'))); + bureau.appendChild(liste); + bureau.appendChild(h('div', { class: 'pied-nyora' }, 'Nyora')); + } + function enteteJour() { + var estAuj = S.jour === auj(); + return h('header', { class: 'entete' }, + h('div', null, h('h1', null, 'Tri du jour'), h('div', { class: 'maj' }, estAuj ? 'Dernière mise à jour à ' + (S.majHeure || '--:--') + ' · heure de Tunis' : 'Journée close')), + h('div', { class: 'jour' }, + h('button', { type: 'button', class: 'btn-icone', 'aria-label': 'Jour précédent', onclick: function () { changerJour(-1); } }, icone('gauche')), + h('div', { class: 'jour-carte' }, h('span', null, nomJour(S.jour)), h('span', { class: 'num' }, fr(S.jour))), + h('button', { type: 'button', class: 'btn-icone', 'aria-label': 'Jour suivant', disabled: estAuj, onclick: function () { changerJour(1); } }, icone('droite')), + estAuj ? null : h('button', { type: 'button', class: 'btn-lien', onclick: function () { S.jour = auj(); S.filtre = null; S.banniere = null; chargerMails(); } }, 'Aujourd\'hui'))); + } + function selecteur(m) { + var c = S.cats.find(function (x) { return x.nom === m.cat; }); + var sel = h('select', { 'aria-label': 'Catégorie : ' + m.exp + ', ' + (m.objet || 'sans objet'), onchange: function (e) { corriger(m, e.target.value); } }); + var noms = S.cats.map(function (x) { return x.nom; }); + if (noms.indexOf(m.cat) === -1) noms.push(m.cat); + noms.forEach(function (n) { var o = h('option', { value: n }, n); if (n === m.cat) o.selected = true; sel.appendChild(o); }); + return h('div', { class: 'sel' }, pastille(couleur(m.cat, c && c.id)), sel, h('span', { class: 'chev' }, icone('bas'))); + } + function ligneMail(m) { + var orig = m.source === 'manuel' ? 'manuel' : (m.cat === SYSTEME ? 'sans règle' : 'règle'); + var origCls = orig === 'manuel' ? ' manuel' : orig === 'sans règle' ? ' sansregle' : ''; + var objetAff = m.objet || '(sans objet)'; + var etq = 'Traité : ' + m.exp + ', ' + (m.objet || 'sans objet'); + var cb = h('input', { type: 'checkbox', 'aria-label': etq, onchange: function (e) { basculerTraite(m, e.target.checked); } }); + cb.checked = m.traite; + return h('div', { class: 'ligne' + (m.traite ? ' fait' : ''), role: 'listitem' }, + h('label', { class: 'coche' }, cb), + h('div', { class: 'corps d' }, h('div', { class: 'exp coupe', title: m.expBrut, text: m.exp })), + h('div', { class: 'corps d' }, h('div', { class: 'objet coupe' + (m.objet ? '' : ' sans'), text: objetAff })), + h('div', { class: 'heure d', text: heureTunis(m.date) }), + h('div', { class: 'd' }, h('span', { class: 'origine' + origCls, text: orig })), + h('div', { class: 'm-corps' }, + h('div', { class: 'exp coupe', title: m.expBrut, text: m.exp }), h('div', { class: 'objet coupe' + (m.objet ? '' : ' sans'), text: objetAff }), + h('div', { class: 'm-meta' }, h('span', { class: 'heure', text: heureTunis(m.date) }), ' · ', h('span', { class: 'o' + (orig === 'manuel' ? ' manuel' : ''), text: orig }))), + selecteur(m)); + } + function vueTri() { + var frag = document.createDocumentFragment(); + frag.appendChild(enteteJour()); + if (S.etat === 'chargement') { + var sq = h('section', { class: 'carte squelette', 'aria-busy': 'true' }, h('div', { class: 'sq-statut', role: 'status', text: 'Lecture du courrier du ' + fr(S.jour) + '…' })); + for (var i = 0; i < 8; i++) sq.appendChild(h('div', { class: 'sq-ligne' }, h('span'), h('span'), h('span'), h('span'), h('span'), h('span'))); + frag.appendChild(sq); return frag; + } + if (S.etat === 'erreur') { + frag.appendChild(h('div', { class: 'erreur', role: 'alert' }, h('h2', null, 'Lecture du courrier impossible'), + h('p', null, 'Le service de lecture n\'a pas répondu pour le ' + fr(S.jour) + '. Vos corrections et vos règles sont conservées.'), + h('button', { type: 'button', class: 'btn-plein', onclick: chargerMails }, 'Réessayer'))); + return frag; + } + if (S.miroirErreur) frag.appendChild(h('div', { class: 'bandeau', role: 'status' }, h('div', { class: 'txt' }, 'Lecture du courrier momentanément indisponible', h('small', null, 'Affichage des derniers classements enregistrés.')))); + var tous = S.mails, nbT = tous.filter(function (m) { return m.traite; }).length; + var compte = {}; tous.forEach(function (m) { compte[m.cat] = (compte[m.cat] || 0) + 1; }); + var puces = h('div', { class: 'puces', role: 'group', 'aria-label': 'Filtrer par catégorie' }); + var defs = [{ nom: 'Tous', c: -1, n: tous.length, filtre: null }].concat(S.cats.map(function (c) { return { nom: c.nom, c: couleur(c.nom, c.id), n: compte[c.nom] || 0, filtre: c.nom }; })); + defs.forEach(function (p) { + var actif = S.filtre === p.filtre; + puces.appendChild(h('button', { type: 'button', 'aria-pressed': actif ? 'true' : 'false', class: 'puce' + (p.c === 0 ? ' vide' : '') + (p.c > 0 ? ' t' + p.c : ''), onclick: function () { S.filtre = actif ? null : p.filtre; rendre(); } }, + h('span', { class: 'pt ' + (p.c === -1 ? 'tous' : 'c' + p.c), 'aria-hidden': 'true' }), h('span', { text: p.nom }), h('span', { class: 'n', text: d2(p.n) }))); + }); + var barre = h('div', null); barre.style.width = tous.length ? Math.round(nbT / tous.length * 100) + '%' : '0%'; + frag.appendChild(h('section', { class: 'carte repartition', 'aria-label': 'Répartition du jour' }, h('h2', null, 'Répartition du jour'), puces, + h('div', { class: 'avancement' }, h('div', { class: 'barre' }, barre), h('span', null, 'Traités ', h('b', { text: d2(nbT) + '/' + d2(tous.length) }))))); + if (S.banniere) { + var b = S.banniere; + frag.appendChild(h('div', { class: 'bandeau', role: 'region', 'aria-label': 'Règle proposée' }, + h('div', { class: 'txt' }, 'Toujours classer les mails de « ' + b.exp + ' » dans « ' + b.cat + ' » ?', + h('small', null, (b.autres ? b.autres + ' autre' + (b.autres > 1 ? 's' : '') + ' mail' + (b.autres > 1 ? 's' : '') + ' de ce jour ser' + (b.autres > 1 ? 'ont' : 'a') + ' aussi reclassé' + (b.autres > 1 ? 's' : '') + '. ' : '') + 'Votre messagerie n\'est pas modifiée.')), + h('div', { class: 'acts' }, h('button', { type: 'button', class: 'btn-plein', onclick: confirmerRegle }, 'Confirmer la règle'), h('button', { type: 'button', class: 'btn-ligne', onclick: ignorerRegle }, 'Pas maintenant')))); + } + if (S.notif) frag.appendChild(h('div', { class: 'notif', role: 'status', text: S.notif })); + var visibles = tous.filter(function (m) { return !S.filtre || m.cat === S.filtre; }); + var liste = h('div', { role: 'list' }); + var carte = h('section', { class: 'carte', 'aria-label': 'Mails du jour' }); + carte.appendChild(h('div', { class: 'liste-entete', 'aria-hidden': 'true' }, h('span'), h('span', null, 'Expéditeur'), h('span', null, 'Objet'), h('span', null, 'Heure'), h('span', null, 'Origine'), h('span', null, 'Catégorie'))); + visibles.forEach(function (m) { liste.appendChild(ligneMail(m)); }); + carte.appendChild(liste); + if (tous.length === 0) carte.appendChild(h('div', { class: 'etat' }, icone('tri', 28), h('h2', null, 'Aucun mail ce jour'), h('p', null, 'Rien n\'est arrivé le ' + fr(S.jour) + '.'))); + else if (visibles.length === 0) carte.appendChild(h('div', { class: 'etat-filtre' }, 'Aucun mail dans « ' + S.filtre + ' » ce jour.', h('button', { type: 'button', class: 'btn-lien', onclick: function () { S.filtre = null; rendre(); } }, 'Tout afficher'))); + frag.appendChild(carte); + return frag; + } + function vueCategories() { + var frag = document.createDocumentFragment(); + frag.appendChild(h('header', { class: 'entete' }, h('h1', null, 'Catégories'), h('button', { type: 'button', class: 'btn-plein', onclick: function () { dialogueCategorie(null); } }, 'Ajouter une catégorie'))); + if (S.notif) frag.appendChild(h('div', { class: 'notif', role: 'status', text: S.notif })); + if (S.etat === 'erreur') { frag.appendChild(h('div', { class: 'erreur', role: 'alert' }, h('h2', null, 'Chargement impossible'), h('p', null, 'Les catégories n\'ont pas pu être lues.'), h('button', { type: 'button', class: 'btn-plein', onclick: chargerMails }, 'Réessayer'))); return frag; } + var compte = {}; S.mails.forEach(function (m) { compte[m.cat] = (compte[m.cat] || 0) + 1; }); + var carte = h('section', { class: 'carte limite', 'aria-label': 'Catégories' }); + S.cats.forEach(function (c) { + carte.appendChild(h('div', { class: 'rang' }, pastille(couleur(c.nom, c.id)), h('span', { class: 'nom', text: c.nom }), + h('span', { class: 'nb' }, h('b', { text: d2(compte[c.nom] || 0) }), ' ce jour'), + h('button', { type: 'button', class: 'btn-petit', 'aria-label': (c.nom === SYSTEME ? 'Détails de ' : 'Modifier ') + c.nom, onclick: function () { dialogueCategorie(c); } }, c.nom === SYSTEME ? 'Détails' : 'Modifier'))); + }); + if (S.etat === 'chargement') carte.appendChild(h('div', { class: 'sq-statut', role: 'status', text: 'Chargement…' })); + frag.appendChild(carte); return frag; + } + function critere(r) { + var p = []; + if (r.expediteur) p.push(['Expéditeur', r.expediteur]); + if (r.mot_cle) p.push(['Mot-clé', r.mot_cle]); + if (r.etiquette_miroir) p.push(['Étiquette', r.etiquette_miroir]); + return p.length ? p : [['Règle', '']]; + } + function vueRegles() { + var frag = document.createDocumentFragment(); + var act = S.regles.filter(function (r) { return r.statut === 'active'; }).length, prop = S.regles.length - act; + frag.appendChild(h('header', { class: 'entete' }, h('div', null, h('h1', null, 'Règles'), h('div', { class: 'maj', text: act + ' active' + (act > 1 ? 's' : '') + (prop ? ' · ' + prop + ' à confirmer' : '') })))); + if (S.notif) frag.appendChild(h('div', { class: 'notif', role: 'status', text: S.notif })); + if (S.reglesEtat === 'erreur') { frag.appendChild(h('div', { class: 'erreur', role: 'alert' }, h('h2', null, 'Chargement impossible'), h('p', null, 'Les règles n\'ont pas pu être lues.'), h('button', { type: 'button', class: 'btn-plein', onclick: chargerRegles }, 'Réessayer'))); return frag; } + var carte = h('section', { class: 'carte limite-l', 'aria-label': 'Règles de classement' }); + var flv = icone('fleche', 16); flv.classList.add('fl'); + carte.appendChild(h('div', { class: 'regle' }, h('span', { class: 'crit' }, 'Objet ', h('b', { text: 'vide' })), flv, h('span', { class: 'cat' }, pastille(5), 'Sans objet'), h('span', { class: 'etiq active', text: 'règle de départ' }), h('span'))); + var tri = S.regles.slice().sort(function (a, b) { return (a.statut === 'active') - (b.statut === 'active') || a.id - b.id; }); + tri.forEach(function (r) { + var c = S.cats.find(function (x) { return x.nom === r.categorie; }); + var crit = h('span', { class: 'crit' }); + critere(r).forEach(function (p, i) { if (i) crit.appendChild(document.createTextNode(' · ')); crit.appendChild(document.createTextNode(p[0] + ' ')); crit.appendChild(h('b', { text: p[1] })); }); + var actif = r.statut === 'active'; + var sw = h('button', { type: 'button', class: 'interrupteur', role: 'switch', 'aria-checked': actif ? 'true' : 'false', 'aria-label': 'Règle ' + critere(r).map(function (p) { return p.join(' '); }).join(', ') + ' vers ' + r.categorie, onclick: function () { basculerRegle(r); } }, h('span', { class: 'piste' }, h('span', { class: 'bouton' }))); + carte.appendChild(h('div', { class: 'regle' + (actif ? '' : ' propose') }, crit, icone('fleche', 16), h('span', { class: 'cat' }, pastille(couleur(r.categorie, c && c.id)), r.categorie), + h('span', { class: 'etiq ' + (actif ? 'active' : 'propose'), text: actif ? 'règle active' : 'à confirmer' }), sw)); + carte.lastChild.querySelector('svg').classList.add('fl'); + }); + if (S.reglesEtat === 'chargement') carte.appendChild(h('div', { class: 'sq-statut', role: 'status', text: 'Chargement…' })); + else if (!S.regles.length) carte.appendChild(h('div', { class: 'etat' }, h('h2', null, 'Aucune règle'), h('p', null, 'Corrigez la catégorie d\'un mail pour en proposer une.'))); + frag.appendChild(carte); + frag.appendChild(h('p', { class: 'note' }, 'Une règle activée s\'applique aux mails du jour qui n\'ont pas été corrigés à la main.')); + return frag; + } + function vueBientot(k) { + var t = BIENTOT[k]; + return h('div', null, h('header', { class: 'entete' }, h('h1', null, t[0])), + h('section', { class: 'carte limite' }, h('div', { class: 'bientot-ecran' }, h('span', { class: 'badge-bientot' }, 'Prochainement'), h('p', { class: 'note', text: t[1] })))); + } + function rendre() { + var pos = document.getElementById('principal').scrollTop; + var ancre = document.activeElement && document.activeElement.getAttribute && document.activeElement.getAttribute('aria-label'); + rendreNav(); + var p = document.getElementById('principal'); p.textContent = ''; + var v = S.vue === 'tri' ? vueTri() : S.vue === 'categories' ? vueCategories() : S.vue === 'regles' ? vueRegles() : vueBientot(S.vue); + p.appendChild(v); p.scrollTop = pos; + var titre = S.vue === 'tri' ? 'Tri du jour' : S.vue === 'categories' ? 'Catégories' : S.vue === 'regles' ? 'Règles' : BIENTOT[S.vue][0]; + document.title = titre + ' · Courrier'; + if (ancre && !dialogue) { var r = p.querySelector('[aria-label="' + ancre.replace(/"/g, '\\"') + '"]'); if (r && document.activeElement === document.body) r.focus(); } + } + + rendre(); + chargerMails(); +})(); diff --git a/docker-compose.yml b/docker-compose.yml index 8083fbc..f23b93e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,9 +19,14 @@ services: - MIRROR_TOKEN_PATH=/app/secrets/mirror.token - MIRROR_URL=http://100.86.197.88:3125/mcp - TZ=Africa/Tunis + - CF_ACCESS_CERTS_URL=https://tiny-cell-4edd.cloudflareaccess.com/cdn-cgi/access/certs + - CF_ACCESS_AUD=7f0fc9227a3fead4fb34472791859fcd78b51b231bb37472bb105f3ff9a4daab networks: - courrier-net + - mcp-vps networks: courrier-net: driver: bridge + mcp-vps: + external: true