From 3164fa80483983a3d4a0152c6741442936f0296e Mon Sep 17 00:00:00 2001 From: Romulus21 Date: Fri, 13 Nov 2026 19:31:00 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Corrige=20l'=C3=A9dition=20inline=20sur=20/?= =?UTF-8?q?entries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La section qui se recharge seule transmettait hx-select="#entries-list" aux boutons des lignes : la réponse de « modifier » / « dupliquer » était filtrée à vide et la ligne disparaissait. hx-disinherit="*" sur les conteneurs auto-rafraîchis (liste, aujourd'hui, dernières entrées, timer). Co-Authored-By: Claude Opus 5.5 --- templates/_recent.html | 2 +- templates/_timer.html | 2 +- templates/_today.html | 2 +- templates/entries.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/_recent.html b/templates/_recent.html index f3ebe5c..f7c21cb 100644 --- a/templates/_recent.html +++ b/templates/_recent.html @@ -1,4 +1,4 @@ -
+

Dernières entrées

Tout voir diff --git a/templates/_timer.html b/templates/_timer.html index 7908e79..174acbc 100644 --- a/templates/_timer.html +++ b/templates/_timer.html @@ -1,5 +1,5 @@ {% import "_icons.html" as icons %} -
+
{% if let Some(e) = running %}
diff --git a/templates/_today.html b/templates/_today.html index bac889d..f4871a4 100644 --- a/templates/_today.html +++ b/templates/_today.html @@ -1,4 +1,4 @@ -
+

Aujourd'hui

{{ today_total }} diff --git a/templates/entries.html b/templates/entries.html index 0c6a6ad..2006062 100644 --- a/templates/entries.html +++ b/templates/entries.html @@ -16,7 +16,7 @@ {% endif %}
-
+

Entrées

{{ total }} From e6a1dd7e4b4985ec144d610f25573a7cd1631e53 Mon Sep 17 00:00:00 2001 From: Romulus21 Date: Fri, 13 Nov 2026 19:31:00 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Permet=20de=20copier=20une=20journ=C3=A9e?= =?UTF-8?q?=20vers=20un=20autre=20jour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bouton copier sur l'en-tête de chaque jour : les entrées affichées sont recopiées à la date choisie avec les mêmes heures, projet et note (POST /ui/jours/{date}/dupliquer, tout ou rien). L'entrée en cours est ignorée ; projet archivé ou même jour refusés. Co-Authored-By: Claude Opus 5.5 --- src/repo/entries.rs | 39 +++++++++++++++++- src/routes/pages.rs | 51 +++++++++++++++++++++++ static/app.css | 3 ++ static/app.js | 7 ++++ templates/_entry_days.html | 21 +++++++++- templates/_icons.html | 1 + tests/api.rs | 84 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 204 insertions(+), 2 deletions(-) diff --git a/src/repo/entries.rs b/src/repo/entries.rs index 339d730..de1c4c5 100644 --- a/src/repo/entries.rs +++ b/src/repo/entries.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, Duration, Utc}; +use chrono::{DateTime, Duration, Local, Utc}; use sqlx::SqlitePool; use super::affected; @@ -102,6 +102,43 @@ pub async fn start(pool: &SqlitePool, project_id: i64, note: &str) -> AppResult< get(pool, id).await } +/// Copies finished entries `days` days later (or earlier), keeping their local +/// wall-clock times, project and note. The running entry is skipped. All or +/// nothing: an archived project rejects the whole copy. Returns the count. +pub async fn duplicate(pool: &SqlitePool, ids: &[i64], days: i64) -> AppResult { + let shift = |dt: &DateTime| { + clock::local_to_utc(dt.with_timezone(&Local).naive_local() + Duration::days(days)) + }; + let mut copies = Vec::new(); + for &id in ids { + let e = get(pool, id).await?; + let Some(ended) = e.ended_at else { continue }; + super::projects::get_active(pool, e.project_id).await?; + let (started, ended) = (shift(&e.started_at), shift(&ended)); + validate_span(&started, Some(&ended))?; + copies.push((e.project_id, started, ended, e.note)); + } + if copies.is_empty() { + return Err(AppError::Validation( + "aucune entrée terminée à copier".into(), + )); + } + let mut tx = pool.begin().await?; + for (project_id, started, ended, note) in &copies { + sqlx::query( + "INSERT INTO time_entries (project_id, started_at, ended_at, note) VALUES (?1, ?2, ?3, ?4)", + ) + .bind(project_id) + .bind(clock::ts(started)) + .bind(clock::ts(ended)) + .bind(note) + .execute(&mut *tx) + .await?; + } + tx.commit().await?; + Ok(copies.len()) +} + /// Stops the running timer. pub async fn stop(pool: &SqlitePool) -> AppResult { let entry = running(pool) diff --git a/src/routes/pages.rs b/src/routes/pages.rs index 8d2df6a..4d667b7 100644 --- a/src/routes/pages.rs +++ b/src/routes/pages.rs @@ -47,6 +47,7 @@ pub fn router() -> Router { ) .route("/ui/entries/{id}/edit", get(entry_edit)) .route("/ui/entries/{id}/relancer", post(restart_entry)) + .route("/ui/jours/{date}/dupliquer", post(duplicate_day)) .route( "/ui/entries/{id}/dupliquer", get(entry_duplicate).post(duplicate_entry), @@ -257,11 +258,33 @@ struct RecentTpl { /// Entries started on the same local day, with their total. struct DayGroup { + date: NaiveDate, day: String, total: String, entries: Vec, } +impl DayGroup { + /// Comma-separated ids of the listed entries, for "copy this day". + fn ids(&self) -> String { + self.entries + .iter() + .map(|e| e.id.to_string()) + .collect::>() + .join(",") + } + + /// Default target of "copy this day": today, or tomorrow for today itself. + fn copy_to(&self) -> NaiveDate { + let today = clock::today(); + if self.date == today { + today + Duration::days(1) + } else { + today + } + } +} + /// 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(); @@ -277,6 +300,7 @@ fn group_by_day(list: Vec) -> Vec { } days.into_iter() .map(|(date, secs, entries)| DayGroup { + date, day: clock::fmt_day(date), total: clock::hhmm(secs), entries, @@ -739,6 +763,33 @@ async fn restart_entry(State(pool): State, Path(id): Path) -> P Ok(with_timer_changed(StatusCode::OK.into_response())) } +#[derive(Deserialize)] +struct DuplicateDayForm { + /// Comma-separated entry ids. + ids: String, + vers: NaiveDate, +} + +/// Copies the listed entries of `date` to another day, same times. +async fn duplicate_day( + State(pool): State, + Path(date): Path, + Form(f): Form, +) -> PageResult { + if f.vers == date { + return Err(AppError::Validation("choisis un autre jour que celui copié".into()).into()); + } + let ids = f + .ids + .split(',') + .filter(|s| !s.is_empty()) + .map(|s| s.trim().parse::()) + .collect::, _>>() + .map_err(|_| AppError::Validation("liste d'entrées invalide".into()))?; + entries::duplicate(&pool, &ids, (f.vers - date).num_days()).await?; + Ok(with_entries_changed(StatusCode::OK.into_response())) +} + async fn delete_entry(State(pool): State, Path(id): Path) -> PageResult { entries::delete(&pool, id).await?; // htmx swaps the row with this empty body, removing it. diff --git a/static/app.css b/static/app.css index e0ec7dc..51229f7 100644 --- a/static/app.css +++ b/static/app.css @@ -142,6 +142,9 @@ tr:last-child td { border-bottom: 0; } .project-link:hover { color: var(--accent); text-decoration-color: currentColor; } tr.running { background: var(--running); } tr.day-head th { color: var(--text); font-weight: 600; font-size: .9rem; padding-top: 1.1rem; } +tr.day-head th.actions { padding-top: .6rem; text-align: right; } +tr.day-copy td { background: var(--bg); } +tr.day-copy .row { justify-content: flex-end; flex-wrap: wrap; } 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%; } diff --git a/static/app.js b/static/app.js index fd6445e..9575ed5 100644 --- a/static/app.js +++ b/static/app.js @@ -57,6 +57,13 @@ document.body.addEventListener("htmx:beforeCleanupElement", (event) => { event.target._flatpickr?.destroy(); }); +// Shows/hides the "copy this day" form under a day header. +function toggleDayCopy(button) { + const row = button.closest("tbody").querySelector(".day-copy"); + row.hidden = !row.hidden; + if (!row.hidden) row.querySelector('input[type="date"]').focus(); +} + // Removes a row without a request (e.g. cancelling a duplicate). function removeRow(button) { const row = button.closest("tr"); diff --git a/templates/_entry_days.html b/templates/_entry_days.html index cfd5711..7c8a667 100644 --- a/templates/_entry_days.html +++ b/templates/_entry_days.html @@ -1,6 +1,25 @@ +{% import "_icons.html" as icons %} {% for d in days %} - {{ d.day }}{{ d.total }} + + {{ d.day }} + {{ d.total }} + + + + + + +
+ + +
+ + +
+
+ + {% for e in d.entries %}{% include "_entry_row.html" %}{% endfor %} {% endfor %} diff --git a/templates/_icons.html b/templates/_icons.html index 2021988..825530d 100644 --- a/templates/_icons.html +++ b/templates/_icons.html @@ -4,6 +4,7 @@ {%- else if name == "copy" -%} {%- else if name == "trash" -%} {%- else if name == "check" -%} +{%- else if name == "close" -%} {%- else if name == "plus" -%} {%- else if name == "reset" -%} {%- else if name == "play" -%} diff --git a/tests/api.rs b/tests/api.rs index f758a63..90cbfa8 100644 --- a/tests/api.rs +++ b/tests/api.rs @@ -845,3 +845,87 @@ async fn restart_entry_from_list() { .count(); assert_eq!(open, 1); } + +#[tokio::test] +async fn duplicate_day() { + let app = app().await; + let a = project(&app, "Acme", "Site web").await; + let b = project(&app, "Globex", "API").await; + add_entry( + &app, + a, + local(2026, 3, 10, 9, 0), + local(2026, 3, 10, 10, 15), + ) + .await; // 1 + add_entry( + &app, + b, + local(2026, 3, 10, 14, 0), + local(2026, 3, 10, 16, 0), + ) + .await; // 2 + + // The day header carries the listed ids and posts to the copy route. + let (_, html) = get_html(&app, "/entries?from=2026-03-10&to=2026-03-10").await; + assert!(html.contains("hx-post=\"/ui/jours/2026-03-10/dupliquer\"")); + // The self-refreshing list must not pass hx-select & co. down to row buttons + // (inline edit would swap in an empty row). + assert!(html.contains("id=\"entries-list\" hx-disinherit=\"*\"")); + assert!(html.contains("name=\"ids\" value=\"2,1\"")); + + let (status, _) = send_form( + &app, + "/ui/jours/2026-03-10/dupliquer", + "ids=2,1&vers=2026-03-12", + ) + .await; + assert_eq!(status, StatusCode::OK); + let (_, list) = send( + &app, + "GET", + "/api/entries?from=2026-03-12&to=2026-03-12", + None, + ) + .await; + let list = list.as_array().unwrap(); + assert_eq!(list.len(), 2); + assert_eq!(list[0]["project_id"], b); + let parse = |v: &Value| chrono::DateTime::parse_from_rfc3339(v.as_str().unwrap()).unwrap(); + assert_eq!( + parse(&list[1]["started_at"]), + parse(&json!(local(2026, 3, 12, 9, 0))) + ); + assert_eq!(list[1]["seconds"], 4500); + + // Same day, or an archived project: refused, nothing copied. + let (status, _) = send_form( + &app, + "/ui/jours/2026-03-10/dupliquer", + "ids=1&vers=2026-03-10", + ) + .await; + assert_eq!(status, StatusCode::UNPROCESSABLE_ENTITY); + send( + &app, + "PATCH", + &format!("/api/projects/{b}"), + Some(json!({ "archived": true })), + ) + .await; + let (status, _) = send_form( + &app, + "/ui/jours/2026-03-10/dupliquer", + "ids=2,1&vers=2026-03-13", + ) + .await; + assert_eq!(status, StatusCode::UNPROCESSABLE_ENTITY); + let (_, list) = send( + &app, + "GET", + "/api/entries?from=2026-03-13&to=2026-03-13", + None, + ) + .await; + assert!(list.as_array().unwrap().is_empty()); +}