diff --git a/app/static/app.js b/app/static/app.js index 7446993..58cb63b 100644 --- a/app/static/app.js +++ b/app/static/app.js @@ -119,7 +119,7 @@ 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.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()); rendre(); }).catch(function (e) { if (e.message === 'session') return; if (jour !== S.jour) return; S.etat = 'erreur'; rendre(); }); @@ -350,7 +350,7 @@ 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 }; })); + 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) { 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(); } }, @@ -444,8 +444,8 @@ 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.forEach(function (c) { - var k = couleur(c.nom, c.id), actif = G.cat === c.nom; + 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) }))); }); diff --git a/app/static/index.html b/app/static/index.html index cebd93d..74dc55b 100644 --- a/app/static/index.html +++ b/app/static/index.html @@ -10,7 +10,7 @@ - +