From 8488b9217dcfbbf8e19b3bbf8f434f3dc8ff96df Mon Sep 17 00:00:00 2001 From: Romulus21 Date: Mon, 26 Oct 2026 15:28:25 +0100 Subject: [PATCH] =?UTF-8?q?Affiche=20les=2020=20derni=C3=A8res=20entr?= =?UTF-8?q?=C3=A9es=20sur=20la=20page=20d'accueil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajoute une carte « Dernières entrées » sous « Aujourd'hui », rafraîchie via htmx sur entries-changed (route /ui/recent). Closes #1 Co-Authored-By: Claude Opus 5.5 --- src/repo/entries.rs | 11 +++++++++++ src/routes/pages.rs | 22 ++++++++++++++++++++++ templates/_recent.html | 27 +++++++++++++++++++++++++++ templates/dashboard.html | 1 + tests/api.rs | 26 ++++++++++++++++++++++++++ 5 files changed, 87 insertions(+) create mode 100644 templates/_recent.html diff --git a/src/repo/entries.rs b/src/repo/entries.rs index 2e04d2e..d20a88c 100644 --- a/src/repo/entries.rs +++ b/src/repo/entries.rs @@ -47,6 +47,17 @@ pub async fn list( .await?) } +/// The `limit` most recent entries, whatever their date. +pub async fn recent(pool: &SqlitePool, limit: i64, now: DateTime) -> AppResult> { + Ok( + sqlx::query_as(&format!("{SELECT} ORDER BY e.started_at DESC LIMIT ?2")) + .bind(clock::ts(&now)) + .bind(limit) + .fetch_all(pool) + .await?, + ) +} + pub async fn get(pool: &SqlitePool, id: i64) -> AppResult { Ok(sqlx::query_as(&format!("{SELECT} WHERE e.id = ?2")) .bind(clock::ts(&clock::now())) diff --git a/src/routes/pages.rs b/src/routes/pages.rs index 0e70d40..56abe53 100644 --- a/src/routes/pages.rs +++ b/src/routes/pages.rs @@ -26,6 +26,7 @@ pub fn router() -> Router { .route("/entries", get(entries_page)) .route("/reports", get(reports_page)) .route("/ui/today", get(today_fragment)) + .route("/ui/recent", get(recent_fragment)) .route("/ui/timer/start", post(start_timer)) .route("/ui/timer/stop", post(stop_timer)) .route("/ui/clients", post(create_client)) @@ -206,6 +207,7 @@ struct DashboardTpl { groups: Vec, today_entries: Vec, today_total: String, + recent_entries: Vec, } #[derive(Template)] @@ -222,6 +224,15 @@ struct TodayTpl { today_total: String, } +#[derive(Template)] +#[template(path = "_recent.html")] +struct RecentTpl { + recent_entries: Vec, +} + +/// How many entries the dashboard lists under "Dernières entrées". +const RECENT_LIMIT: i64 = 20; + async fn timer_state(pool: &SqlitePool) -> PageResult { let running = entries::running(pool).await?; // Preselect the running project, else the most recently tracked one. @@ -249,18 +260,25 @@ 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 }) +} + async fn dashboard(State(pool): State) -> PageResult { let TimerTpl { running, groups } = timer_state(&pool).await?; let TodayTpl { today_entries, today_total, } = today_state(&pool).await?; + let RecentTpl { recent_entries } = recent_state(&pool).await?; render(DashboardTpl { nav: "dashboard", running, groups, today_entries, today_total, + recent_entries, }) } @@ -268,6 +286,10 @@ async fn today_fragment(State(pool): State) -> PageResult { render(today_state(&pool).await?) } +async fn recent_fragment(State(pool): State) -> PageResult { + render(recent_state(&pool).await?) +} + #[derive(Deserialize)] struct StartForm { project_id: i64, diff --git a/templates/_recent.html b/templates/_recent.html new file mode 100644 index 0000000..377be41 --- /dev/null +++ b/templates/_recent.html @@ -0,0 +1,27 @@ +
+
+

Dernières entrées

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

Aucune entrée pour l'instant.

+ {% else %} +
+ + + {% for e in recent_entries %} + + + + + + + {% endfor %} + +
{{ e.day() }}{{ e.start_time() }} – {{ e.end_time() }} + {{ e.client_name }} / {{ e.project_name }} + {% if !e.note.is_empty() %}
{{ e.note }}
{% endif %} +
{{ e.duration() }}
+
+ {% endif %} +
diff --git a/templates/dashboard.html b/templates/dashboard.html index 837555d..8edbd2d 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -3,4 +3,5 @@ {% block content %} {% include "_timer.html" %} {% include "_today.html" %} +{% include "_recent.html" %} {% endblock %} diff --git a/tests/api.rs b/tests/api.rs index 185539d..3dc2867 100644 --- a/tests/api.rs +++ b/tests/api.rs @@ -444,6 +444,32 @@ async fn html_pages() { get_html(&app, "/reports?from=2026-03-01&to=2026-03-31&group_by=day").await; assert_eq!(status, StatusCode::OK); assert!(html.contains("1:15") && html.contains("mar. 10/03/2026")); + + let (status, html) = get_html(&app, "/").await; + assert_eq!(status, StatusCode::OK); + assert!(html.contains("Dernières entrées") && html.contains("mar. 10/03/2026")); +} + +#[tokio::test] +async fn dashboard_lists_20_most_recent_entries() { + let app = app().await; + let p = project(&app, "Acme", "Site web").await; + for day in 1..=25 { + let (status, _) = add_entry( + &app, + p, + local(2026, 3, day, 9, 0), + local(2026, 3, day, 10, 0), + ) + .await; + assert_eq!(status, StatusCode::CREATED); + } + + let (status, html) = get_html(&app, "/ui/recent").await; + assert_eq!(status, StatusCode::OK); + assert_eq!(html.matches("