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:
1 parent
d89d71fee0
commit
7c22567b07
4 files changed
+104
No files matched your search
@@ -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>,
|
||||
|
||||
Reference in new issue
Block a user