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:
1 parent
6307be4f79
commit
467293a6bc
10 files changed
+63
-24
No files matched your search
+39
-8
@@ -212,7 +212,7 @@ struct DashboardTpl {
|
||||
groups: Vec<ProjectGroup>,
|
||||
today_entries: Vec<Entry>,
|
||||
today_total: String,
|
||||
recent_entries: Vec<Entry>,
|
||||
recent_days: Vec<DayGroup>,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
@@ -232,7 +232,36 @@ struct TodayTpl {
|
||||
#[derive(Template)]
|
||||
#[template(path = "_recent.html")]
|
||||
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".
|
||||
@@ -266,8 +295,10 @@ 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 })
|
||||
let recent = entries::recent(pool, RECENT_LIMIT, clock::now()).await?;
|
||||
Ok(RecentTpl {
|
||||
recent_days: group_by_day(recent),
|
||||
})
|
||||
}
|
||||
|
||||
async fn dashboard(State(pool): State<SqlitePool>) -> PageResult {
|
||||
@@ -276,14 +307,14 @@ async fn dashboard(State(pool): State<SqlitePool>) -> 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<ClientOption>,
|
||||
filter_groups: Vec<ProjectGroup>,
|
||||
groups: Vec<ProjectGroup>,
|
||||
entries: Vec<Entry>,
|
||||
days: Vec<DayGroup>,
|
||||
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"),
|
||||
|
||||
Reference in new issue
Block a user