Ajoute un bouton play sur les entrées
En tête du groupe d'actions : ▶ arrête le timer en cours et en relance
un sur le même projet et la même note (POST /ui/entries/{id}/relancer) ;
sur l'entrée en cours, ■ l'arrête. Les deux émettent timer-changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f612dbd764
commit
2ff27b2a65
5 files changed
+69
-7
No files matched your search
+19
-7
@@ -46,6 +46,7 @@ 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}/relancer", post(restart_entry))
|
||||
.route(
|
||||
"/ui/entries/{id}/dupliquer",
|
||||
get(entry_duplicate).post(duplicate_entry),
|
||||
@@ -99,6 +100,16 @@ fn with_entries_changed(resp: Response) -> Response {
|
||||
(AppendHeaders([("HX-Trigger", "entries-changed")]), resp).into_response()
|
||||
}
|
||||
|
||||
/// Same, plus `timer-changed` so the dashboard timer follows a start/stop
|
||||
/// made elsewhere (header, entry lists).
|
||||
fn with_timer_changed(resp: Response) -> Response {
|
||||
(
|
||||
AppendHeaders([("HX-Trigger", "entries-changed, timer-changed")]),
|
||||
resp,
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
|
||||
struct ProjectOption {
|
||||
id: i64,
|
||||
name: String,
|
||||
@@ -363,13 +374,7 @@ async fn stop_timer(State(pool): State<SqlitePool>) -> PageResult {
|
||||
Ok(_) | Err(AppError::Conflict(_)) => {}
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
// `timer-changed` refreshes the dashboard timer when stopped from the header.
|
||||
let resp = render(timer_state(&pool).await?)?;
|
||||
Ok((
|
||||
AppendHeaders([("HX-Trigger", "entries-changed, timer-changed")]),
|
||||
resp,
|
||||
)
|
||||
.into_response())
|
||||
Ok(with_timer_changed(render(timer_state(&pool).await?)?))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -727,6 +732,13 @@ async fn update_entry(
|
||||
Ok(with_entries_changed(render(EntryRowTpl { e })?))
|
||||
}
|
||||
|
||||
/// Stops the running timer and starts a new one on this entry's project and note.
|
||||
async fn restart_entry(State(pool): State<SqlitePool>, Path(id): Path<i64>) -> PageResult {
|
||||
let e = entries::get(&pool, id).await?;
|
||||
entries::start(&pool, e.project_id, &e.note).await?;
|
||||
Ok(with_timer_changed(StatusCode::OK.into_response()))
|
||||
}
|
||||
|
||||
async fn delete_entry(State(pool): State<SqlitePool>, Path(id): Path<i64>) -> PageResult {
|
||||
entries::delete(&pool, id).await?;
|
||||
// htmx swaps the row with this empty body, removing it.
|
||||
|
||||
@@ -99,6 +99,7 @@ a.btn { color: var(--text); text-decoration: none; }
|
||||
.btn:hover { border-color: var(--muted); }
|
||||
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
|
||||
.btn.danger { color: var(--danger); }
|
||||
.btn.play { color: var(--accent); }
|
||||
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
|
||||
.btn.icon {
|
||||
display: inline-flex; align-items: center; justify-content: center; flex: none;
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
<td class="num">{{ e.duration() }}</td>
|
||||
<td class="actions">
|
||||
<div class="btn-group">
|
||||
{% if e.running() %}
|
||||
<button class="btn small icon danger" title="Arrêter" aria-label="Arrêter le timer" hx-post="/ui/timer/stop" hx-swap="none">{% call icons::icon("stop") %}{% endcall %}</button>
|
||||
{% else %}
|
||||
<button class="btn small icon play" title="Relancer cette entrée" aria-label="Relancer cette entrée" hx-post="/ui/entries/{{ e.id }}/relancer" hx-swap="none">{% call icons::icon("play") %}{% endcall %}</button>
|
||||
{% endif %}
|
||||
<button class="btn small icon primary" title="Modifier" aria-label="Modifier" hx-get="/ui/entries/{{ e.id }}/edit" hx-target="closest tr" hx-swap="outerHTML">{% call icons::icon("edit") %}{% endcall %}</button>
|
||||
<button class="btn small icon" title="Dupliquer" aria-label="Dupliquer" hx-get="/ui/entries/{{ e.id }}/dupliquer" hx-target="closest tr" hx-swap="afterend">{% call icons::icon("copy") %}{% endcall %}</button>
|
||||
<button class="btn small icon danger" title="Supprimer" aria-label="Supprimer" hx-delete="/ui/entries/{{ e.id }}" hx-target="closest tr" hx-swap="outerHTML" hx-confirm="Supprimer cette entrée ?">{% call icons::icon("trash") %}{% endcall %}</button>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
{%- else if name == "check" -%}<path d="M20 6 9 17l-5-5"/>
|
||||
{%- else if name == "plus" -%}<path d="M5 12h14"/><path d="M12 5v14"/>
|
||||
{%- else if name == "reset" -%}<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/>
|
||||
{%- else if name == "play" -%}<path d="M7 4.5v15l12.5-7.5z" fill="currentColor"/>
|
||||
{%- else if name == "stop" -%}<rect x="6" y="6" width="12" height="12" rx="1.5" fill="currentColor"/>
|
||||
{%- else if name == "link" -%}<path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
|
||||
{%- else if name == "archive" -%}<rect x="2" y="3" width="20" height="5" rx="1"/><path d="M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8"/><path d="M10 12h4"/>
|
||||
|
||||
@@ -802,3 +802,46 @@ async fn header_mini_timer() {
|
||||
let (_, html) = get_html(&app, "/ui/timer/entete").await;
|
||||
assert!(html.contains("<span class=\"mini-timer-label\">Site web</span>"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn restart_entry_from_list() {
|
||||
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, 0)).await;
|
||||
send(
|
||||
&app,
|
||||
"PATCH",
|
||||
"/api/entries/1",
|
||||
Some(json!({ "note": "réunion" })),
|
||||
)
|
||||
.await;
|
||||
send(
|
||||
&app,
|
||||
"POST",
|
||||
"/api/timer/start",
|
||||
Some(json!({ "project_id": b })),
|
||||
)
|
||||
.await;
|
||||
|
||||
// ▶ on entry 1: the Globex timer stops, a new one runs on Acme / "réunion".
|
||||
let (status, _) = send_form(&app, "/ui/entries/1/relancer", "").await;
|
||||
assert_eq!(status, StatusCode::OK);
|
||||
let (_, running) = send(&app, "GET", "/api/timer", None).await;
|
||||
assert_eq!(running["project_id"], a);
|
||||
assert_eq!(running["note"], "réunion");
|
||||
let (_, list) = send(
|
||||
&app,
|
||||
"GET",
|
||||
"/api/entries?from=2020-01-01&to=2100-01-01",
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
let open = list
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|e| e["ended_at"].is_null())
|
||||
.count();
|
||||
assert_eq!(open, 1);
|
||||
}
|
||||
Reference in new issue
Block a user