Affiche les 20 dernières entrées sur la page d'accueil
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
dd6a740645
commit
8488b9217d
5 files changed
+87
No files matched your search
@@ -26,6 +26,7 @@ pub fn router() -> Router<SqlitePool> {
|
||||
.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<ProjectGroup>,
|
||||
today_entries: Vec<Entry>,
|
||||
today_total: String,
|
||||
recent_entries: Vec<Entry>,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
@@ -222,6 +224,15 @@ struct TodayTpl {
|
||||
today_total: String,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "_recent.html")]
|
||||
struct RecentTpl {
|
||||
recent_entries: Vec<Entry>,
|
||||
}
|
||||
|
||||
/// How many entries the dashboard lists under "Dernières entrées".
|
||||
const RECENT_LIMIT: i64 = 20;
|
||||
|
||||
async fn timer_state(pool: &SqlitePool) -> PageResult<TimerTpl> {
|
||||
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<TodayTpl> {
|
||||
})
|
||||
}
|
||||
|
||||
async fn recent_state(pool: &SqlitePool) -> PageResult<RecentTpl> {
|
||||
let recent_entries = entries::recent(pool, RECENT_LIMIT, clock::now()).await?;
|
||||
Ok(RecentTpl { recent_entries })
|
||||
}
|
||||
|
||||
async fn dashboard(State(pool): State<SqlitePool>) -> 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<SqlitePool>) -> PageResult {
|
||||
render(today_state(&pool).await?)
|
||||
}
|
||||
|
||||
async fn recent_fragment(State(pool): State<SqlitePool>) -> PageResult {
|
||||
render(recent_state(&pool).await?)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct StartForm {
|
||||
project_id: i64,
|
||||
|
||||
Reference in new issue
Block a user