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"),
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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,5 +1,5 @@
|
||||
<tr class="editing">
|
||||
<td colspan="2">
|
||||
<td>
|
||||
<div class="stack">
|
||||
<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">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<tr id="entry-{{ e.id }}" class="editing">
|
||||
<td colspan="2">
|
||||
<td>
|
||||
<div class="stack">
|
||||
<input type="datetime-local" name="started_at" value="{{ e.start_input() }}" required aria-label="Début">
|
||||
{% if e.running() %}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<tr id="entry-{{ e.id }}"{% if e.running() %} class="running"{% endif %}>
|
||||
<td class="nowrap">{{ e.day() }}</td>
|
||||
<td class="time">
|
||||
{{ e.start_time() }} – {{ e.end_time() }}
|
||||
{% if e.overlaps %}<span class="warn" title="Chevauche une autre entrée">⚠</span>{% endif %}
|
||||
|
||||
@@ -3,15 +3,13 @@
|
||||
<h2>Dernières entrées</h2>
|
||||
<a href="/entries">Tout voir</a>
|
||||
</div>
|
||||
{% if recent_entries.is_empty() %}
|
||||
{% if recent_days.is_empty() %}
|
||||
<p class="empty">Aucune entrée pour l'instant.</p>
|
||||
{% else %}
|
||||
<div class="table-wrap">
|
||||
<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>
|
||||
<tbody>
|
||||
{% for e in recent_entries %}{% include "_entry_row.html" %}{% endfor %}
|
||||
</tbody>
|
||||
<thead><tr><th>Horaire</th><th>Projet</th><th>Note</th><th class="num">Durée</th><th></th></tr></thead>
|
||||
{% let days = recent_days %}{% include "_entry_days.html" %}
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
{% else %}
|
||||
<div class="table-wrap">
|
||||
<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>
|
||||
{% for e in today_entries %}{% include "_entry_row.html" %}{% endfor %}
|
||||
</tbody>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
{% endif %}
|
||||
</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">
|
||||
<h2>Entrées</h2>
|
||||
<span class="total">{{ total }}</span>
|
||||
@@ -40,15 +40,13 @@
|
||||
<button class="btn">Filtrer</button>
|
||||
</form>
|
||||
|
||||
{% if entries.is_empty() %}
|
||||
{% if days.is_empty() %}
|
||||
<p class="empty">Aucune entrée sur cette période.</p>
|
||||
{% else %}
|
||||
<div class="table-wrap">
|
||||
<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>
|
||||
<tbody>
|
||||
{% for e in entries %}{% include "_entry_row.html" %}{% endfor %}
|
||||
</tbody>
|
||||
<thead><tr><th>Horaire</th><th>Projet</th><th>Note</th><th class="num">Durée</th><th></th></tr></thead>
|
||||
{% include "_entry_days.html" %}
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
+6
-1
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user