Permet de dupliquer une entrée

Bouton « Dupliquer » sur chaque ligne de /entries : ouvre sous l'entrée
un formulaire prérempli (début, fin, projet, note) à ajuster avant de
créer la copie. Une entrée en cours propose « maintenant » comme fin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Romulus21andClaude Opus 5.5 committed 2026-10-26 15:49:07 +01:00
1 parent d89d71fee0
commit 7c22567b07
4 files changed
+104

No files matched your search

+41
View File
@@ -43,6 +43,10 @@ pub fn router() -> Router<SqlitePool> {
get(entry_row).put(update_entry).delete(delete_entry),
)
.route("/ui/entries/{id}/edit", get(entry_edit))
.route(
"/ui/entries/{id}/dupliquer",
get(entry_duplicate).post(duplicate_entry),
)
}
// --- Plumbing ---------------------------------------------------------------
@@ -487,6 +491,15 @@ struct EntryEditTpl {
groups: Vec<ProjectGroup>,
}
#[derive(Template)]
#[template(path = "_entry_duplicate.html")]
struct EntryDuplicateTpl {
e: Entry,
/// A running entry has no end yet: offer "now".
end: String,
groups: Vec<ProjectGroup>,
}
async fn entries_page(
State(pool): State<SqlitePool>,
Query(filter): Query<EntryFilter>,
@@ -568,6 +581,34 @@ async fn entry_edit(State(pool): State<SqlitePool>, Path(id): Path<i64>) -> Page
render(EntryEditTpl { e, groups })
}
/// Form to create a copy of an entry, prefilled with its values.
async fn entry_duplicate(State(pool): State<SqlitePool>, Path(id): Path<i64>) -> PageResult {
let e = entries::get(&pool, id).await?;
let end = clock::input_value(&e.ended_at.unwrap_or_else(clock::now));
let groups = group_projects(
projects::list(&pool, None, false).await?,
Some(e.project_id),
);
render(EntryDuplicateTpl { e, end, groups })
}
/// Creates the copy and swaps the form for its row.
async fn duplicate_entry(State(pool): State<SqlitePool>, Form(f): Form<EntryForm>) -> PageResult {
let started = parse_datetime(&f.started_at, "début")?;
let ended = parse_datetime(&f.ended_at, "fin")?;
let e = entries::create(
&pool,
&NewEntry {
project_id: f.project_id,
started_at: started.fixed_offset(),
ended_at: ended.fixed_offset(),
note: f.note,
},
)
.await?;
Ok(with_entries_changed(render(EntryRowTpl { e })?))
}
async fn update_entry(
State(pool): State<SqlitePool>,
Path(id): Path<i64>,
+15
View File
@@ -0,0 +1,15 @@
<tr class="editing">
<td colspan="2">
<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">
</div>
</td>
<td><select name="project_id" aria-label="Projet">{% include "_project_select.html" %}</select></td>
<td><input name="note" value="{{ e.note }}" aria-label="Note"></td>
<td></td>
<td class="actions">
<button class="btn small primary" hx-post="/ui/entries/{{ e.id }}/dupliquer" hx-include="closest tr" hx-target="closest tr" hx-swap="outerHTML">Créer</button>
<button class="btn small" hx-on:click="this.closest('tr').remove()">Annuler</button>
</td>
</tr>
+1
View File
@@ -9,6 +9,7 @@
<td class="num">{{ e.duration() }}</td>
<td class="actions">
<button class="btn small" hx-get="/ui/entries/{{ e.id }}/edit" hx-target="closest tr" hx-swap="outerHTML">Modifier</button>
<button class="btn small" hx-get="/ui/entries/{{ e.id }}/dupliquer" hx-target="closest tr" hx-swap="afterend">Dupliquer</button>
<button class="btn small danger" hx-delete="/ui/entries/{{ e.id }}" hx-target="closest tr" hx-swap="outerHTML" hx-confirm="Supprimer cette entrée ?">Suppr.</button>
</td>
</tr>
+47
View File
@@ -618,3 +618,50 @@ async fn colors() {
assert_eq!(status, StatusCode::OK);
assert!(html.contains("--color: #000000"));
}
#[tokio::test]
async fn duplicate_entry() {
let app = app().await;
let p = project(&app, "Acme", "Site web").await;
let (status, _) = send(
&app,
"POST",
"/api/entries",
Some(json!({
"project_id": p,
"started_at": local(2026, 3, 10, 9, 0),
"ended_at": local(2026, 3, 10, 10, 15),
"note": "réunion",
})),
)
.await;
assert_eq!(status, StatusCode::CREATED);
let (status, html) = get_html(&app, "/ui/entries/1/dupliquer").await;
assert_eq!(status, StatusCode::OK);
assert!(html.contains("2026-03-10T09:00") && html.contains("2026-03-10T10:15"));
assert!(html.contains("réunion"));
let (status, html) = send_form(
&app,
"/ui/entries/1/dupliquer",
&format!("project_id={p}&started_at=2026-03-11T09%3A00&ended_at=2026-03-11T10%3A15&note=r%C3%A9union"),
)
.await;
assert_eq!(status, StatusCode::OK);
assert!(html.contains("id=\"entry-2\"") && html.contains("mer. 11/03/2026"));
let (_, list) = send(
&app,
"GET",
"/api/entries?from=2026-03-09&to=2026-03-15",
None,
)
.await;
let list = list.as_array().unwrap();
assert_eq!(list.len(), 2);
assert!(list.iter().all(|e| e["note"] == "réunion"));
let (status, _) = get_html(&app, "/ui/entries/99/dupliquer").await;
assert_eq!(status, StatusCode::NOT_FOUND);
}