Compare commits
4
Commits
40d416d551
...
cdb78c3e04
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdb78c3e04 | ||
|
|
71262d927e | ||
|
|
ab51591f54 | ||
|
|
4c751eb766 |
No files matched your search
+23
@@ -95,6 +95,8 @@ async def en_tetes_securite(request: Request, call_next):
|
|||||||
reponse.headers["Referrer-Policy"] = "no-referrer"
|
reponse.headers["Referrer-Policy"] = "no-referrer"
|
||||||
if request.url.path == "/" or request.url.path.startswith("/api/"):
|
if request.url.path == "/" or request.url.path.startswith("/api/"):
|
||||||
reponse.headers["Cache-Control"] = "no-store"
|
reponse.headers["Cache-Control"] = "no-store"
|
||||||
|
elif request.url.path.startswith("/static/") or request.url.path in ("/favicon.ico", "/apple-touch-icon.png"):
|
||||||
|
reponse.headers["Cache-Control"] = "no-cache"
|
||||||
return reponse
|
return reponse
|
||||||
|
|
||||||
@app.get("/", include_in_schema=False)
|
@app.get("/", include_in_schema=False)
|
||||||
@@ -165,6 +167,27 @@ def get_mails_du_jour(date: Optional[str] = None, n: int = 50):
|
|||||||
"mails": classified_results
|
"mails": classified_results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@api.get("/mails/periode")
|
||||||
|
def get_mails_periode(jours: int = 7):
|
||||||
|
"""Mails des N derniers jours (1 à 30), classés, pour la vue par groupe. Lecture seule."""
|
||||||
|
from datetime import date as _date, timedelta
|
||||||
|
jours = max(1, min(int(jours), 30))
|
||||||
|
fin = _date.fromisoformat(get_tunis_now_iso()[:10])
|
||||||
|
debut = (fin - timedelta(days=jours - 1)).isoformat()
|
||||||
|
try:
|
||||||
|
mails = mirror_client.get_mails_since(debut, max_items=min(150 * jours, 800))
|
||||||
|
except Exception as e:
|
||||||
|
return {"debut": debut, "fin": fin.isoformat(), "count": 0, "mails": [], "miroir_erreur": str(e)}
|
||||||
|
resultats = []
|
||||||
|
for m in mails:
|
||||||
|
if not m.get("message_id"):
|
||||||
|
continue
|
||||||
|
resultats.append({
|
||||||
|
"message_id": m["message_id"], "date": m.get("date"), "expediteur": m.get("expediteur"),
|
||||||
|
"objet": m.get("objet"), "etiquettes": m.get("etiquettes", []), "classement": classify_mail(m),
|
||||||
|
})
|
||||||
|
return {"debut": debut, "fin": fin.isoformat(), "count": len(resultats), "mails": resultats}
|
||||||
|
|
||||||
# --- Classements ---
|
# --- Classements ---
|
||||||
@api.get("/classements")
|
@api.get("/classements")
|
||||||
def get_classements(
|
def get_classements(
|
||||||
|
|||||||
@@ -216,3 +216,20 @@ class MirrorClient:
|
|||||||
}
|
}
|
||||||
filtered.append(m_normalized)
|
filtered.append(m_normalized)
|
||||||
return filtered
|
return filtered
|
||||||
|
|
||||||
|
def get_mails_since(self, debut: str, max_items: int = 400) -> List[Dict[str, Any]]:
|
||||||
|
"""Mails dont la date est >= debut (AAAA-MM-JJ), normalisés comme get_mails_for_day."""
|
||||||
|
out = []
|
||||||
|
for m in self.get_latest_mails(folder="*", n=max_items):
|
||||||
|
mid = m.get("message_id") or m.get("id") or m.get("hash")
|
||||||
|
d_mail = m.get("date") or m.get("date_reception") or m.get("date_heure") or ""
|
||||||
|
if d_mail[:10] >= debut:
|
||||||
|
out.append({
|
||||||
|
"message_id": mid,
|
||||||
|
"date": d_mail,
|
||||||
|
"expediteur": m.get("from") or m.get("expediteur") or "",
|
||||||
|
"objet": m.get("sujet") or m.get("subject") or m.get("objet") or "",
|
||||||
|
"etiquettes": m.get("tags") or m.get("etiquettes") or [],
|
||||||
|
"apercu": m.get("snippet") or m.get("apercu") or ""
|
||||||
|
})
|
||||||
|
return out
|
||||||
+10
-2
@@ -50,7 +50,7 @@ h1, h2, h3, p { margin: 0; }
|
|||||||
.btn-danger-ligne:hover { background: var(--ny-erreur-fond); }
|
.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; }
|
.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 { flex: none; min-height: max-content; 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); }
|
.repartition h2 { font: 600 15px/20px var(--ny-police); color: var(--ny-encre-2); }
|
||||||
.puces { display: flex; flex-wrap: wrap; gap: var(--ny-e2); }
|
.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 { 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; }
|
||||||
@@ -65,6 +65,13 @@ h1, h2, h3, p { margin: 0; }
|
|||||||
.barre > div { height: 100%; background: var(--ny-accent); transition: width var(--ny-duree) var(--ny-courbe); }
|
.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); }
|
.avancement b { font: 600 13px/18px var(--ny-police-chiffres); color: var(--ny-encre); }
|
||||||
|
|
||||||
|
/* Étiquettes du miroir et vue par groupe */
|
||||||
|
.etqs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
|
||||||
|
.etq { display: inline-flex; align-items: center; min-height: 20px; padding: 0 8px; border-radius: var(--ny-r-pastille); border: 1px solid var(--ny-trait); background: var(--ny-carte-2); color: var(--ny-encre-2); font: 500 12px/16px var(--ny-police); }
|
||||||
|
.objet.sans { font-style: italic; }
|
||||||
|
.titre-groupe { font: 600 17px/24px var(--ny-police); color: var(--ny-encre); }
|
||||||
|
.jour-titre { display: flex; align-items: baseline; justify-content: space-between; gap: var(--ny-e3); padding: var(--ny-e3) var(--ny-e5); background: var(--ny-carte-2); border-bottom: 1px solid var(--ny-trait); font: 600 14px/20px var(--ny-police); color: var(--ny-encre-2); }
|
||||||
|
|
||||||
/* Pastille de catégorie */
|
/* 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 { 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.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); }
|
||||||
@@ -179,8 +186,9 @@ h1, h2, h3, p { margin: 0; }
|
|||||||
.coque { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; height: 100dvh; min-height: 0; }
|
.coque { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; height: 100dvh; min-height: 0; }
|
||||||
.nav-bureau { display: none; }
|
.nav-bureau { display: none; }
|
||||||
.principal { padding: var(--ny-e4); gap: var(--ny-e3); overflow-y: auto; }
|
.principal { padding: var(--ny-e4); gap: var(--ny-e3); overflow-y: auto; }
|
||||||
|
.principal > * { flex-shrink: 0; }
|
||||||
.entete h1 { font: var(--ny-t2); }
|
.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 { display: grid; grid-template-columns: repeat(4, 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 { 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[aria-current="page"] { font-weight: 600; }
|
||||||
.nav-mobile .nav-btn svg { width: 22px; height: 22px; }
|
.nav-mobile .nav-btn svg { width: 22px; height: 22px; }
|
||||||
|
|||||||
+77
-10
@@ -13,10 +13,11 @@
|
|||||||
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',
|
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',
|
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',
|
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',
|
||||||
|
groupes: 'M3 7h7v7H3z|M14 7h7v7h-7z|M3 17h18',
|
||||||
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'
|
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 = [
|
var NAV = [
|
||||||
['tri', 'Tri du jour', true], ['categories', 'Catégories', true], ['regles', 'Règles', true],
|
['tri', 'Tri du jour', true], ['categories', 'Catégories', true], ['groupes', 'Groupes', true], ['regles', 'Règles', true],
|
||||||
['recherche', 'Recherche', false], ['courses', 'Courses pour Tunis', false], ['suivi', 'Suivi des demandes', false], ['pj', 'Pièces jointes', false]
|
['recherche', 'Recherche', false], ['courses', 'Courses pour Tunis', false], ['suivi', 'Suivi des demandes', false], ['pj', 'Pièces jointes', false]
|
||||||
];
|
];
|
||||||
var BIENTOT = {
|
var BIENTOT = {
|
||||||
@@ -28,7 +29,7 @@
|
|||||||
var COULEUR_NOM = { 'Tunis': 1, 'Demande FB': 2, 'CI': 3, 'Câbles': 4, 'Sans objet': 5, 'À classer': 0 };
|
var COULEUR_NOM = { 'Tunis': 1, 'Demande FB': 2, 'CI': 3, 'Câbles': 4, 'Sans objet': 5, 'À classer': 0 };
|
||||||
var SYSTEME = 'À classer';
|
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: '' };
|
var S = { vue: 'tri', jour: auj(), filtre: null, cats: [], mails: [], etat: 'chargement', banniere: null, notif: null, regles: [], reglesEtat: 'ok', miroirErreur: false, majHeure: '', groupe: { jours: 7, cat: null, etq: null, mails: [], etat: 'chargement' } };
|
||||||
|
|
||||||
/* ---------- Utilitaires ---------- */
|
/* ---------- Utilitaires ---------- */
|
||||||
function auj() { return new Intl.DateTimeFormat('en-CA', { timeZone: TZ }).format(new Date()); }
|
function auj() { return new Intl.DateTimeFormat('en-CA', { timeZone: TZ }).format(new Date()); }
|
||||||
@@ -118,11 +119,20 @@
|
|||||||
if (jour !== S.jour) return;
|
if (jour !== S.jour) return;
|
||||||
var r = rs[1];
|
var r = rs[1];
|
||||||
S.miroirErreur = !!r.miroir_erreur;
|
S.miroirErreur = !!r.miroir_erreur;
|
||||||
S.mails = (r.mails || []).map(normaliser).sort(function (a, b) { return String(a.date).localeCompare(String(b.date)); });
|
S.mails = (r.mails || []).map(normaliser).sort(function (a, b) { return String(b.date).localeCompare(String(a.date)); });
|
||||||
S.etat = 'ok'; S.majHeure = heureTunis(new Date().toISOString());
|
S.etat = 'ok'; S.majHeure = heureTunis(new Date().toISOString());
|
||||||
rendre();
|
rendre();
|
||||||
}).catch(function (e) { if (e.message === 'session') return; if (jour !== S.jour) return; S.etat = 'erreur'; rendre(); });
|
}).catch(function (e) { if (e.message === 'session') return; if (jour !== S.jour) return; S.etat = 'erreur'; rendre(); });
|
||||||
}
|
}
|
||||||
|
function chargerGroupe() {
|
||||||
|
var G = S.groupe, jours = G.jours;
|
||||||
|
G.etat = 'chargement'; rendre();
|
||||||
|
return Promise.all([chargerCats(), api('/mails/periode?jours=' + jours)]).then(function (rs) {
|
||||||
|
if (jours !== G.jours) return;
|
||||||
|
G.mails = (rs[1].mails || []).map(normaliser).sort(function (a, b) { return String(b.date).localeCompare(String(a.date)); });
|
||||||
|
G.miroirErreur = !!rs[1].miroir_erreur; G.etat = 'ok'; rendre();
|
||||||
|
}).catch(function (e) { if (e.message === 'session') return; if (jours !== G.jours) return; G.etat = 'erreur'; rendre(); });
|
||||||
|
}
|
||||||
function chargerRegles() {
|
function chargerRegles() {
|
||||||
S.reglesEtat = 'chargement'; rendre();
|
S.reglesEtat = 'chargement'; rendre();
|
||||||
return Promise.all([chargerCats(), api('/regles')]).then(function (rs) {
|
return Promise.all([chargerCats(), api('/regles')]).then(function (rs) {
|
||||||
@@ -140,6 +150,7 @@
|
|||||||
function allerA(vue) {
|
function allerA(vue) {
|
||||||
S.vue = vue; S.banniere = null;
|
S.vue = vue; S.banniere = null;
|
||||||
if (vue === 'tri' || vue === 'categories') chargerMails();
|
if (vue === 'tri' || vue === 'categories') chargerMails();
|
||||||
|
else if (vue === 'groupes') chargerGroupe();
|
||||||
else if (vue === 'regles') chargerRegles();
|
else if (vue === 'regles') chargerRegles();
|
||||||
else rendre();
|
else rendre();
|
||||||
document.getElementById('principal').focus();
|
document.getElementById('principal').focus();
|
||||||
@@ -157,7 +168,7 @@
|
|||||||
.then(function (r) {
|
.then(function (r) {
|
||||||
var rp = r.regle_proposee;
|
var rp = r.regle_proposee;
|
||||||
if (rp && rp.id) {
|
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;
|
var autres = (S.vue === 'groupes' ? S.groupe.mails : 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();
|
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.'); });
|
}).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.'); });
|
||||||
@@ -271,7 +282,7 @@
|
|||||||
}
|
}
|
||||||
var liste = h('div', { class: 'nav-liste' });
|
var liste = h('div', { class: 'nav-liste' });
|
||||||
NAV.forEach(function (n, i) {
|
NAV.forEach(function (n, i) {
|
||||||
if (i === 3) liste.appendChild(h('div', { class: 'nav-sep' }, 'Prochainement'));
|
if (i === 4) liste.appendChild(h('div', { class: 'nav-sep' }, 'Prochainement'));
|
||||||
liste.appendChild(bouton(n));
|
liste.appendChild(bouton(n));
|
||||||
if (n[2]) mobile.appendChild(bouton(n));
|
if (n[2]) mobile.appendChild(bouton(n));
|
||||||
});
|
});
|
||||||
@@ -297,6 +308,12 @@
|
|||||||
noms.forEach(function (n) { var o = h('option', { value: n }, n); if (n === m.cat) o.selected = true; sel.appendChild(o); });
|
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')));
|
return h('div', { class: 'sel' }, pastille(couleur(m.cat, c && c.id)), sel, h('span', { class: 'chev' }, icone('bas')));
|
||||||
}
|
}
|
||||||
|
function reperes(m) {
|
||||||
|
if (!m.etiquettes || !m.etiquettes.length) return null;
|
||||||
|
var d = h('div', { class: 'etqs', 'aria-label': 'Étiquettes du miroir' });
|
||||||
|
m.etiquettes.forEach(function (t) { d.appendChild(h('span', { class: 'etq', text: t })); });
|
||||||
|
return d;
|
||||||
|
}
|
||||||
function ligneMail(m) {
|
function ligneMail(m) {
|
||||||
var orig = m.source === 'manuel' ? 'manuel' : (m.cat === SYSTEME ? 'sans règle' : 'règle');
|
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 origCls = orig === 'manuel' ? ' manuel' : orig === 'sans règle' ? ' sansregle' : '';
|
||||||
@@ -307,12 +324,12 @@
|
|||||||
return h('div', { class: 'ligne' + (m.traite ? ' fait' : ''), role: 'listitem' },
|
return h('div', { class: 'ligne' + (m.traite ? ' fait' : ''), role: 'listitem' },
|
||||||
h('label', { class: 'coche' }, cb),
|
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: '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: 'corps d' }, h('div', { class: 'objet coupe' + (m.objet ? '' : ' sans'), text: objetAff }), reperes(m)),
|
||||||
h('div', { class: 'heure d', text: heureTunis(m.date) }),
|
h('div', { class: 'heure d', text: heureTunis(m.date) }),
|
||||||
h('div', { class: 'd' }, h('span', { class: 'origine' + origCls, text: orig })),
|
h('div', { class: 'd' }, h('span', { class: 'origine' + origCls, text: orig })),
|
||||||
h('div', { class: 'm-corps' },
|
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: '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 }))),
|
h('div', { class: 'm-meta' }, h('span', { class: 'heure', text: heureTunis(m.date) }), ' · ', h('span', { class: 'o' + (orig === 'manuel' ? ' manuel' : ''), text: orig })), reperes(m)),
|
||||||
selecteur(m));
|
selecteur(m));
|
||||||
}
|
}
|
||||||
function vueTri() {
|
function vueTri() {
|
||||||
@@ -333,7 +350,7 @@
|
|||||||
var tous = S.mails, nbT = tous.filter(function (m) { return m.traite; }).length;
|
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 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 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 }; }));
|
var defs = [{ nom: 'Tous', c: -1, n: tous.length, filtre: null }].concat(S.cats.map(function (c, i) { return { nom: c.nom, c: couleur(c.nom, c.id), n: compte[c.nom] || 0, filtre: c.nom, rang: i }; }).sort(function (x, y) { return y.n - x.n || x.rang - y.rang; }));
|
||||||
defs.forEach(function (p) {
|
defs.forEach(function (p) {
|
||||||
var actif = S.filtre === p.filtre;
|
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(); } },
|
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(); } },
|
||||||
@@ -409,6 +426,56 @@
|
|||||||
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.'));
|
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;
|
return frag;
|
||||||
}
|
}
|
||||||
|
function vueGroupes() {
|
||||||
|
var G = S.groupe, frag = document.createDocumentFragment();
|
||||||
|
frag.appendChild(h('header', { class: 'entete' }, h('div', null, h('h1', null, 'Groupes'), h('div', { class: 'maj' }, 'Un seul groupe, sur plusieurs jours · heure de Tunis'))));
|
||||||
|
if (S.notif) frag.appendChild(h('div', { class: 'notif', role: 'status', text: S.notif }));
|
||||||
|
var per = h('div', { class: 'puces', role: 'group', 'aria-label': 'Période' });
|
||||||
|
[[7, '7 jours'], [30, '30 jours']].forEach(function (p) {
|
||||||
|
per.appendChild(h('button', { type: 'button', class: 'puce', 'aria-pressed': G.jours === p[0] ? 'true' : 'false', onclick: function () { if (G.jours !== p[0]) { G.jours = p[0]; chargerGroupe(); } } }, h('span', { text: p[1] })));
|
||||||
|
});
|
||||||
|
frag.appendChild(h('section', { class: 'carte repartition', 'aria-label': 'Choisir un groupe' }, h('h2', null, 'Période'), per));
|
||||||
|
if (G.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.'), h('button', { type: 'button', class: 'btn-plein', onclick: chargerGroupe }, 'Réessayer')));
|
||||||
|
return frag;
|
||||||
|
}
|
||||||
|
if (G.etat === 'chargement') { frag.appendChild(h('section', { class: 'carte squelette', 'aria-busy': 'true' }, h('div', { class: 'sq-statut', role: 'status', text: 'Lecture des ' + G.jours + ' derniers jours…' }))); return frag; }
|
||||||
|
if (G.miroirErreur) frag.appendChild(h('div', { class: 'bandeau', role: 'status' }, h('div', { class: 'txt' }, 'Lecture du courrier momentanément indisponible')));
|
||||||
|
var cc = {}, ce = {};
|
||||||
|
G.mails.forEach(function (m) { cc[m.cat] = (cc[m.cat] || 0) + 1; (m.etiquettes || []).forEach(function (t) { ce[t] = (ce[t] || 0) + 1; }); });
|
||||||
|
var pc = h('div', { class: 'puces', role: 'group', 'aria-label': 'Catégorie' });
|
||||||
|
S.cats.map(function (c, i) { return { c: c, rang: i }; }).sort(function (x, y) { return (cc[y.c.nom] || 0) - (cc[x.c.nom] || 0) || x.rang - y.rang; }).forEach(function (o) {
|
||||||
|
var c = o.c, k = couleur(c.nom, c.id), actif = G.cat === c.nom;
|
||||||
|
pc.appendChild(h('button', { type: 'button', 'aria-pressed': actif ? 'true' : 'false', class: 'puce' + (k === 0 ? ' vide' : '') + (k > 0 ? ' t' + k : ''), onclick: function () { G.cat = actif ? null : c.nom; rendre(); } },
|
||||||
|
h('span', { class: 'pt c' + k, 'aria-hidden': 'true' }), h('span', { text: c.nom }), h('span', { class: 'n', text: d2(cc[c.nom] || 0) })));
|
||||||
|
});
|
||||||
|
var pe = h('div', { class: 'puces', role: 'group', 'aria-label': 'Étiquette du miroir' });
|
||||||
|
Object.keys(ce).sort(function (a, b) { return ce[b] - ce[a] || a.localeCompare(b); }).forEach(function (t) {
|
||||||
|
var actif = G.etq === t;
|
||||||
|
pe.appendChild(h('button', { type: 'button', 'aria-pressed': actif ? 'true' : 'false', class: 'puce', onclick: function () { G.etq = actif ? null : t; rendre(); } }, h('span', { text: t }), h('span', { class: 'n', text: d2(ce[t]) })));
|
||||||
|
});
|
||||||
|
frag.appendChild(h('section', { class: 'carte repartition', 'aria-label': 'Groupes' }, h('h2', null, 'Catégorie'), pc, h('h2', null, 'Étiquette du miroir'), pe));
|
||||||
|
if (!G.cat && !G.etq) {
|
||||||
|
frag.appendChild(h('section', { class: 'carte' }, h('div', { class: 'etat' }, icone('groupes', 28), h('h2', null, 'Choisissez un groupe'), h('p', null, G.mails.length + ' mails sur ' + G.jours + ' jours. Touchez une catégorie ou une étiquette pour ne voir que celle-ci.'))));
|
||||||
|
return frag;
|
||||||
|
}
|
||||||
|
var vis = G.mails.filter(function (m) { return (!G.cat || m.cat === G.cat) && (!G.etq || (m.etiquettes || []).indexOf(G.etq) !== -1); });
|
||||||
|
var titreG = [G.cat, G.etq].filter(Boolean).join(' + ');
|
||||||
|
if (!vis.length) {
|
||||||
|
frag.appendChild(h('section', { class: 'carte' }, h('div', { class: 'etat-filtre' }, 'Aucun mail dans « ' + titreG + ' » sur ' + G.jours + ' jours.', h('button', { type: 'button', class: 'btn-lien', onclick: function () { G.cat = null; G.etq = null; rendre(); } }, 'Changer de groupe'))));
|
||||||
|
return frag;
|
||||||
|
}
|
||||||
|
frag.appendChild(h('h2', { class: 'titre-groupe', text: titreG + ' · ' + vis.length + (vis.length > 1 ? ' mails' : ' mail') }));
|
||||||
|
var jours = [], par = {};
|
||||||
|
vis.forEach(function (m) { var j = String(m.date).slice(0, 10); if (!par[j]) { par[j] = []; jours.push(j); } par[j].push(m); });
|
||||||
|
jours.forEach(function (j) {
|
||||||
|
var carte = h('section', { class: 'carte', 'aria-label': nomJour(j) + ' ' + fr(j) });
|
||||||
|
carte.appendChild(h('div', { class: 'jour-titre' }, h('span', { text: nomJour(j) + ' ' + fr(j) }), h('span', { class: 'nb', text: par[j].length + (par[j].length > 1 ? ' mails' : ' mail') })));
|
||||||
|
var liste = h('div', { role: 'list' }); par[j].forEach(function (m) { liste.appendChild(ligneMail(m)); });
|
||||||
|
carte.appendChild(liste); frag.appendChild(carte);
|
||||||
|
});
|
||||||
|
return frag;
|
||||||
|
}
|
||||||
function vueBientot(k) {
|
function vueBientot(k) {
|
||||||
var t = BIENTOT[k];
|
var t = BIENTOT[k];
|
||||||
return h('div', null, h('header', { class: 'entete' }, h('h1', null, t[0])),
|
return h('div', null, h('header', { class: 'entete' }, h('h1', null, t[0])),
|
||||||
@@ -419,9 +486,9 @@
|
|||||||
var ancre = document.activeElement && document.activeElement.getAttribute && document.activeElement.getAttribute('aria-label');
|
var ancre = document.activeElement && document.activeElement.getAttribute && document.activeElement.getAttribute('aria-label');
|
||||||
rendreNav();
|
rendreNav();
|
||||||
var p = document.getElementById('principal'); p.textContent = '';
|
var p = document.getElementById('principal'); p.textContent = '';
|
||||||
var v = S.vue === 'tri' ? vueTri() : S.vue === 'categories' ? vueCategories() : S.vue === 'regles' ? vueRegles() : vueBientot(S.vue);
|
var v = S.vue === 'tri' ? vueTri() : S.vue === 'categories' ? vueCategories() : S.vue === 'regles' ? vueRegles() : S.vue === 'groupes' ? vueGroupes() : vueBientot(S.vue);
|
||||||
p.appendChild(v); p.scrollTop = pos;
|
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];
|
var titre = S.vue === 'tri' ? 'Tri du jour' : S.vue === 'categories' ? 'Catégories' : S.vue === 'regles' ? 'Règles' : S.vue === 'groupes' ? 'Groupes' : BIENTOT[S.vue][0];
|
||||||
document.title = titre + ' · Courrier';
|
document.title = titre + ' · Courrier';
|
||||||
if (ancre && !dialogue) { var r = p.querySelector('[aria-label="' + ancre.replace(/"/g, '\\"') + '"]'); if (r && document.activeElement === document.body) r.focus(); }
|
if (ancre && !dialogue) { var r = p.querySelector('[aria-label="' + ancre.replace(/"/g, '\\"') + '"]'); if (r && document.activeElement === document.body) r.focus(); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
||||||
<link rel="stylesheet" href="/static/fonts.css">
|
<link rel="stylesheet" href="/static/fonts.css">
|
||||||
<link rel="stylesheet" href="/static/nyora.css">
|
<link rel="stylesheet" href="/static/nyora.css">
|
||||||
<link rel="stylesheet" href="/static/app.css">
|
<link rel="stylesheet" href="/static/app.css?v=20261117d">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app" class="coque">
|
<div id="app" class="coque">
|
||||||
@@ -20,6 +20,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="calque"></div>
|
<div id="calque"></div>
|
||||||
<div id="annonce" class="sr" role="status" aria-live="polite"></div>
|
<div id="annonce" class="sr" role="status" aria-live="polite"></div>
|
||||||
<script src="/static/app.js"></script>
|
<script src="/static/app.js?v=20261117d"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from fastapi.testclient import TestClient
|
||||||
|
from app.main import app
|
||||||
|
|
||||||
|
STATIC = Path(__file__).resolve().parent.parent / "app" / "static"
|
||||||
|
|
||||||
|
|
||||||
|
def test_periode_exige_jeton():
|
||||||
|
assert TestClient(app).get("/api/v1/mails/periode?jours=7").status_code == 401
|
||||||
|
|
||||||
|
|
||||||
|
def test_vue_groupes_presente():
|
||||||
|
js = (STATIC / "app.js").read_text(encoding="utf-8")
|
||||||
|
assert "vueGroupes" in js and "/mails/periode" in js and "etiquettes" in js
|
||||||
|
assert "innerHTML" not in js
|
||||||
|
|
||||||
|
|
||||||
|
def test_statiques_sans_cache_navigateur():
|
||||||
|
r = TestClient(app).get("/static/app.css")
|
||||||
|
assert r.headers["cache-control"] == "no-cache"
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
STATIC = Path(__file__).resolve().parent.parent / "app" / "static"
|
||||||
|
|
||||||
|
|
||||||
|
def _js():
|
||||||
|
return (STATIC / "app.js").read_text(encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def test_tri_du_jour_du_plus_recent_au_plus_ancien():
|
||||||
|
"""Les mails du jour sont triés par date décroissante (b comparé à a)."""
|
||||||
|
js = _js()
|
||||||
|
assert "S.mails = (r.mails || []).map(normaliser).sort(function (a, b) { return String(b.date).localeCompare(String(a.date)); });" in js
|
||||||
|
assert "String(a.date).localeCompare(String(b.date))" not in js
|
||||||
|
|
||||||
|
|
||||||
|
def test_repartition_du_jour_par_nombre_de_mails_decroissant():
|
||||||
|
"""Tous reste en tête, puis catégories par nombre de mails décroissant, égalité = ordre d'origine."""
|
||||||
|
js = _js()
|
||||||
|
assert "return y.n - x.n || x.rang - y.rang;" in js
|
||||||
|
assert js.index("nom: 'Tous'") < js.index("y.n - x.n")
|
||||||
|
|
||||||
|
|
||||||
|
def test_groupes_categories_meme_classement():
|
||||||
|
js = _js()
|
||||||
|
assert "(cc[y.c.nom] || 0) - (cc[x.c.nom] || 0) || x.rang - y.rang" in js
|
||||||
Reference in new issue
Block a user