Groupe les entrées par jour

/entries et « Dernières entrées » affichent un en-tête par jour avec son
total ; la colonne Jour disparaît des lignes. La liste de /entries se
recharge après une modification inline (date déplacée, totaux).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Romulus21andClaude Opus 5.5 committed 2026-11-13 18:27:16 +01:00
1 parent 6307be4f79
commit 467293a6bc
10 files changed
+63 -24

No files matched your search

+39 -8
View File
@@ -212,7 +212,7 @@ struct DashboardTpl {
groups: Vec<ProjectGroup>, groups: Vec<ProjectGroup>,
today_entries: Vec<Entry>, today_entries: Vec<Entry>,
today_total: String, today_total: String,
recent_entries: Vec<Entry>, recent_days: Vec<DayGroup>,
} }
#[derive(Template)] #[derive(Template)]
@@ -232,7 +232,36 @@ struct TodayTpl {
#[derive(Template)] #[derive(Template)]
#[template(path = "_recent.html")] #[template(path = "_recent.html")]
struct RecentTpl { struct RecentTpl {
recent_entries: Vec<Entry>, recent_days: Vec<DayGroup>,
}
/// Entries started on the same local day, with their total.
struct DayGroup {
day: String,
total: String,
entries: Vec<Entry>,
}
/// Groups a list sorted by start time into consecutive days.
fn group_by_day(list: Vec<Entry>) -> Vec<DayGroup> {
let mut days: Vec<(NaiveDate, i64, Vec<Entry>)> = Vec::new();
for e in list {
let date = clock::local_date(&e.started_at);
match days.last_mut() {
Some((d, secs, entries)) if *d == date => {
*secs += e.seconds;
entries.push(e);
}
_ => days.push((date, e.seconds, vec![e])),
}
}
days.into_iter()
.map(|(date, secs, entries)| DayGroup {
day: clock::fmt_day(date),
total: clock::hhmm(secs),
entries,
})
.collect()
} }
/// How many entries the dashboard lists under "Dernières entrées". /// How many entries the dashboard lists under "Dernières entrées".
@@ -266,8 +295,10 @@ async fn today_state(pool: &SqlitePool) -> PageResult<TodayTpl> {
} }
async fn recent_state(pool: &SqlitePool) -> PageResult<RecentTpl> { async fn recent_state(pool: &SqlitePool) -> PageResult<RecentTpl> {
let recent_entries = entries::recent(pool, RECENT_LIMIT, clock::now()).await?; let recent = entries::recent(pool, RECENT_LIMIT, clock::now()).await?;
Ok(RecentTpl { recent_entries }) Ok(RecentTpl {
recent_days: group_by_day(recent),
})
} }
async fn dashboard(State(pool): State<SqlitePool>) -> PageResult { async fn dashboard(State(pool): State<SqlitePool>) -> PageResult {
@@ -276,14 +307,14 @@ async fn dashboard(State(pool): State<SqlitePool>) -> PageResult {
today_entries, today_entries,
today_total, today_total,
} = today_state(&pool).await?; } = today_state(&pool).await?;
let RecentTpl { recent_entries } = recent_state(&pool).await?; let RecentTpl { recent_days } = recent_state(&pool).await?;
render(DashboardTpl { render(DashboardTpl {
nav: "dashboard", nav: "dashboard",
running, running,
groups, groups,
today_entries, today_entries,
today_total, today_total,
recent_entries, recent_days,
}) })
} }
@@ -499,7 +530,7 @@ struct EntriesTpl {
clients: Vec<ClientOption>, clients: Vec<ClientOption>,
filter_groups: Vec<ProjectGroup>, filter_groups: Vec<ProjectGroup>,
groups: Vec<ProjectGroup>, groups: Vec<ProjectGroup>,
entries: Vec<Entry>, days: Vec<DayGroup>,
total: String, total: String,
default_start: String, default_start: String,
default_end: String, default_end: String,
@@ -552,7 +583,7 @@ async fn entries_page(
clients: client_options(clients::list(&pool, true).await?, filter.client_id), clients: client_options(clients::list(&pool, true).await?, filter.client_id),
filter_groups: group_projects(projects::list(&pool, None, true).await?, filter.project_id), filter_groups: group_projects(projects::list(&pool, None, true).await?, filter.project_id),
groups: group_projects(projects::list(&pool, None, false).await?, last_project), groups: group_projects(projects::list(&pool, None, false).await?, last_project),
entries: list, days: group_by_day(list),
total, total,
default_start: format!("{today}T09:00"), default_start: format!("{today}T09:00"),
default_end: format!("{today}T10:00"), default_end: format!("{today}T10:00"),
+2
View File
@@ -119,6 +119,8 @@ tr:last-child td { border-bottom: 0; }
.time { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); } .time { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.client { color: var(--muted); } .client { color: var(--muted); }
tr.running { background: var(--running); } tr.running { background: var(--running); }
tr.day-head th { color: var(--text); font-weight: 600; font-size: .9rem; padding-top: 1.1rem; }
tbody:first-of-type tr.day-head th { padding-top: .6rem; }
tr.editing td { background: var(--bg); } tr.editing td { background: var(--bg); }
tr.editing input, tr.editing select { width: 100%; } tr.editing input, tr.editing select { width: 100%; }
td.actions { text-align: right; white-space: nowrap; } td.actions { text-align: right; white-space: nowrap; }
+6
View File
@@ -0,0 +1,6 @@
{% for d in days %}
<tbody>
<tr class="day-head"><th colspan="3">{{ d.day }}</th><th class="num">{{ d.total }}</th><th></th></tr>
{% for e in d.entries %}{% include "_entry_row.html" %}{% endfor %}
</tbody>
{% endfor %}
+1 -1
View File
@@ -1,5 +1,5 @@
<tr class="editing"> <tr class="editing">
<td colspan="2"> <td>
<div class="stack"> <div class="stack">
<input type="datetime-local" name="started_at" value="{{ e.start_input() }}" required aria-label="Début"> <input type="datetime-local" name="started_at" value="{{ e.start_input() }}" required aria-label="Début">
<input type="datetime-local" name="ended_at" value="{{ end }}" required aria-label="Fin"> <input type="datetime-local" name="ended_at" value="{{ end }}" required aria-label="Fin">
+1 -1
View File
@@ -1,5 +1,5 @@
<tr id="entry-{{ e.id }}" class="editing"> <tr id="entry-{{ e.id }}" class="editing">
<td colspan="2"> <td>
<div class="stack"> <div class="stack">
<input type="datetime-local" name="started_at" value="{{ e.start_input() }}" required aria-label="Début"> <input type="datetime-local" name="started_at" value="{{ e.start_input() }}" required aria-label="Début">
{% if e.running() %} {% if e.running() %}
-1
View File
@@ -1,5 +1,4 @@
<tr id="entry-{{ e.id }}"{% if e.running() %} class="running"{% endif %}> <tr id="entry-{{ e.id }}"{% if e.running() %} class="running"{% endif %}>
<td class="nowrap">{{ e.day() }}</td>
<td class="time"> <td class="time">
{{ e.start_time() }} – {{ e.end_time() }} {{ e.start_time() }} – {{ e.end_time() }}
{% if e.overlaps %}<span class="warn" title="Chevauche une autre entrée">⚠</span>{% endif %} {% if e.overlaps %}<span class="warn" title="Chevauche une autre entrée">⚠</span>{% endif %}
+3 -5
View File
@@ -3,15 +3,13 @@
<h2>Dernières entrées</h2> <h2>Dernières entrées</h2>
<a href="/entries">Tout voir</a> <a href="/entries">Tout voir</a>
</div> </div>
{% if recent_entries.is_empty() %} {% if recent_days.is_empty() %}
<p class="empty">Aucune entrée pour l'instant.</p> <p class="empty">Aucune entrée pour l'instant.</p>
{% else %} {% else %}
<div class="table-wrap"> <div class="table-wrap">
<table class="entries"> <table class="entries">
<thead><tr><th>Jour</th><th>Horaire</th><th>Projet</th><th>Note</th><th class="num">Durée</th><th></th></tr></thead> <thead><tr><th>Horaire</th><th>Projet</th><th>Note</th><th class="num">Durée</th><th></th></tr></thead>
<tbody> {% let days = recent_days %}{% include "_entry_days.html" %}
{% for e in recent_entries %}{% include "_entry_row.html" %}{% endfor %}
</tbody>
</table> </table>
</div> </div>
{% endif %} {% endif %}
+1 -1
View File
@@ -8,7 +8,7 @@
{% else %} {% else %}
<div class="table-wrap"> <div class="table-wrap">
<table class="entries"> <table class="entries">
<thead><tr><th>Jour</th><th>Horaire</th><th>Projet</th><th>Note</th><th class="num">Durée</th><th></th></tr></thead> <thead><tr><th>Horaire</th><th>Projet</th><th>Note</th><th class="num">Durée</th><th></th></tr></thead>
<tbody> <tbody>
{% for e in today_entries %}{% include "_entry_row.html" %}{% endfor %} {% for e in today_entries %}{% include "_entry_row.html" %}{% endfor %}
</tbody> </tbody>
+4 -6
View File
@@ -16,7 +16,7 @@
{% endif %} {% endif %}
</section> </section>
<section class="card"> <section id="entries-list" class="card" hx-get="/entries?from={{ from }}&to={{ to }}{{ extra_query }}" hx-select="#entries-list" hx-trigger="entries-changed from:body" hx-swap="outerHTML">
<div class="card-head"> <div class="card-head">
<h2>Entrées</h2> <h2>Entrées</h2>
<span class="total">{{ total }}</span> <span class="total">{{ total }}</span>
@@ -40,15 +40,13 @@
<button class="btn">Filtrer</button> <button class="btn">Filtrer</button>
</form> </form>
{% if entries.is_empty() %} {% if days.is_empty() %}
<p class="empty">Aucune entrée sur cette période.</p> <p class="empty">Aucune entrée sur cette période.</p>
{% else %} {% else %}
<div class="table-wrap"> <div class="table-wrap">
<table class="entries"> <table class="entries">
<thead><tr><th>Jour</th><th>Horaire</th><th>Projet</th><th>Note</th><th class="num">Durée</th><th></th></tr></thead> <thead><tr><th>Horaire</th><th>Projet</th><th>Note</th><th class="num">Durée</th><th></th></tr></thead>
<tbody> {% include "_entry_days.html" %}
{% for e in entries %}{% include "_entry_row.html" %}{% endfor %}
</tbody>
</table> </table>
</div> </div>
{% endif %} {% endif %}
+6 -1
View File
@@ -649,7 +649,12 @@ async fn duplicate_entry() {
) )
.await; .await;
assert_eq!(status, StatusCode::OK); assert_eq!(status, StatusCode::OK);
assert!(html.contains("id=\"entry-2\"") && html.contains("mer. 11/03/2026")); assert!(html.contains("id=\"entry-2\"") && html.contains("09:00 – 10:15"));
// /entries groups rows under one header per day, with the day total.
let (_, html) = get_html(&app, "/entries?from=2026-03-09&to=2026-03-15").await;
assert_eq!(html.matches("class=\"day-head\"").count(), 2);
assert!(html.contains("mer. 11/03/2026") && html.contains("mar. 10/03/2026"));
let (_, list) = send( let (_, list) = send(
&app, &app,