diff --git a/src/routes/pages.rs b/src/routes/pages.rs index 78fd6ca..0564fa9 100644 --- a/src/routes/pages.rs +++ b/src/routes/pages.rs @@ -212,7 +212,7 @@ struct DashboardTpl { groups: Vec, today_entries: Vec, today_total: String, - recent_entries: Vec, + recent_days: Vec, } #[derive(Template)] @@ -232,7 +232,36 @@ struct TodayTpl { #[derive(Template)] #[template(path = "_recent.html")] struct RecentTpl { - recent_entries: Vec, + recent_days: Vec, +} + +/// Entries started on the same local day, with their total. +struct DayGroup { + day: String, + total: String, + entries: Vec, +} + +/// Groups a list sorted by start time into consecutive days. +fn group_by_day(list: Vec) -> Vec { + let mut days: Vec<(NaiveDate, i64, Vec)> = 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". @@ -266,8 +295,10 @@ async fn today_state(pool: &SqlitePool) -> PageResult { } async fn recent_state(pool: &SqlitePool) -> PageResult { - let recent_entries = entries::recent(pool, RECENT_LIMIT, clock::now()).await?; - Ok(RecentTpl { recent_entries }) + let recent = entries::recent(pool, RECENT_LIMIT, clock::now()).await?; + Ok(RecentTpl { + recent_days: group_by_day(recent), + }) } async fn dashboard(State(pool): State) -> PageResult { @@ -276,14 +307,14 @@ async fn dashboard(State(pool): State) -> PageResult { today_entries, today_total, } = today_state(&pool).await?; - let RecentTpl { recent_entries } = recent_state(&pool).await?; + let RecentTpl { recent_days } = recent_state(&pool).await?; render(DashboardTpl { nav: "dashboard", running, groups, today_entries, today_total, - recent_entries, + recent_days, }) } @@ -499,7 +530,7 @@ struct EntriesTpl { clients: Vec, filter_groups: Vec, groups: Vec, - entries: Vec, + days: Vec, total: String, default_start: String, default_end: String, @@ -552,7 +583,7 @@ async fn entries_page( clients: client_options(clients::list(&pool, true).await?, filter.client_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), - entries: list, + days: group_by_day(list), total, default_start: format!("{today}T09:00"), default_end: format!("{today}T10:00"), diff --git a/static/app.css b/static/app.css index 331372f..518b728 100644 --- a/static/app.css +++ b/static/app.css @@ -119,6 +119,8 @@ tr:last-child td { border-bottom: 0; } .time { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); } .client { color: var(--muted); } 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 input, tr.editing select { width: 100%; } td.actions { text-align: right; white-space: nowrap; } diff --git a/templates/_entry_days.html b/templates/_entry_days.html new file mode 100644 index 0000000..cfd5711 --- /dev/null +++ b/templates/_entry_days.html @@ -0,0 +1,6 @@ +{% for d in days %} + + {{ d.day }}{{ d.total }} + {% for e in d.entries %}{% include "_entry_row.html" %}{% endfor %} + +{% endfor %} diff --git a/templates/_entry_duplicate.html b/templates/_entry_duplicate.html index 1b239f6..01ac63e 100644 --- a/templates/_entry_duplicate.html +++ b/templates/_entry_duplicate.html @@ -1,5 +1,5 @@ - +
diff --git a/templates/_entry_edit.html b/templates/_entry_edit.html index 7a5e5bb..261faff 100644 --- a/templates/_entry_edit.html +++ b/templates/_entry_edit.html @@ -1,5 +1,5 @@ - +
{% if e.running() %} diff --git a/templates/_entry_row.html b/templates/_entry_row.html index ed55cf3..c580190 100644 --- a/templates/_entry_row.html +++ b/templates/_entry_row.html @@ -1,5 +1,4 @@ - {{ e.day() }} {{ e.start_time() }} – {{ e.end_time() }} {% if e.overlaps %}⚠{% endif %} diff --git a/templates/_recent.html b/templates/_recent.html index 8a70fc9..f3ebe5c 100644 --- a/templates/_recent.html +++ b/templates/_recent.html @@ -3,15 +3,13 @@

Dernières entrées

Tout voir
- {% if recent_entries.is_empty() %} + {% if recent_days.is_empty() %}

Aucune entrée pour l'instant.

{% else %}
- - - {% for e in recent_entries %}{% include "_entry_row.html" %}{% endfor %} - + + {% let days = recent_days %}{% include "_entry_days.html" %}
JourHoraireProjetNoteDurée
HoraireProjetNoteDurée
{% endif %} diff --git a/templates/_today.html b/templates/_today.html index 4e0ff0f..bac889d 100644 --- a/templates/_today.html +++ b/templates/_today.html @@ -8,7 +8,7 @@ {% else %}
- + {% for e in today_entries %}{% include "_entry_row.html" %}{% endfor %} diff --git a/templates/entries.html b/templates/entries.html index da90dcf..0c6a6ad 100644 --- a/templates/entries.html +++ b/templates/entries.html @@ -16,7 +16,7 @@ {% endif %} -
+

Entrées

{{ total }} @@ -40,15 +40,13 @@ - {% if entries.is_empty() %} + {% if days.is_empty() %}

Aucune entrée sur cette période.

{% else %}
JourHoraireProjetNoteDurée
HoraireProjetNoteDurée
- - - {% for e in entries %}{% include "_entry_row.html" %}{% endfor %} - + + {% include "_entry_days.html" %}
JourHoraireProjetNoteDurée
HoraireProjetNoteDurée
{% endif %} diff --git a/tests/api.rs b/tests/api.rs index f3723be..68e504a 100644 --- a/tests/api.rs +++ b/tests/api.rs @@ -649,7 +649,12 @@ async fn duplicate_entry() { ) .await; 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( &app,