Permet de modifier l'heure de début du chrono en cours
Champ « Début » sur le timer en cours (POST /ui/timer/debut) ; le chrono continue. Une heure dans le futur est refusée. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
092bc2fb3e
commit
35df6b52e8
4 files changed
+70
No files matched your search
@@ -29,6 +29,7 @@ pub fn router() -> Router<SqlitePool> {
|
||||
.route("/ui/dernieres-entrees", get(recent_fragment))
|
||||
.route("/ui/timer/start", post(start_timer))
|
||||
.route("/ui/timer/stop", post(stop_timer))
|
||||
.route("/ui/timer/debut", post(set_timer_start))
|
||||
.route("/ui/clients", post(create_client))
|
||||
.route("/ui/clients/{id}", post(save_client))
|
||||
.route("/ui/clients/{id}/archive", post(archive_client))
|
||||
@@ -315,6 +316,32 @@ async fn stop_timer(State(pool): State<SqlitePool>) -> PageResult {
|
||||
Ok(with_entries_changed(render(timer_state(&pool).await?)?))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct TimerStartForm {
|
||||
started_at: String,
|
||||
}
|
||||
|
||||
/// Moves the start of the running timer (e.g. started a bit late).
|
||||
async fn set_timer_start(
|
||||
State(pool): State<SqlitePool>,
|
||||
Form(f): Form<TimerStartForm>,
|
||||
) -> PageResult {
|
||||
let started = parse_datetime(&f.started_at, "début")?;
|
||||
let running = entries::running(&pool)
|
||||
.await?
|
||||
.ok_or_else(|| AppError::Conflict("aucun timer en cours".into()))?;
|
||||
entries::update(
|
||||
&pool,
|
||||
running.id,
|
||||
&UpdateEntry {
|
||||
started_at: Some(started.fixed_offset()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
Ok(with_entries_changed(render(timer_state(&pool).await?)?))
|
||||
}
|
||||
|
||||
// --- Clients & projects -----------------------------------------------------
|
||||
|
||||
struct ClientCard {
|
||||
|
||||
@@ -95,6 +95,8 @@ label { display: flex; align-items: center; gap: .35rem; color: var(--muted); }
|
||||
.timer.is-running { background: var(--running); border-color: var(--color, var(--accent)); border-left-width: 6px; }
|
||||
.current { display: grid; grid-template-columns: 1fr auto auto; gap: 1rem; align-items: center; margin-bottom: 1rem; }
|
||||
.current-project { font-size: 1.3rem; font-weight: 600; }
|
||||
.timer-start { margin-top: .35rem; font-size: .9rem; }
|
||||
.timer-start input { width: 11rem; }
|
||||
.clock { font-size: 2rem; font-weight: 600; font-variant-numeric: tabular-nums; }
|
||||
.start { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) auto; gap: .5rem; }
|
||||
.note { color: var(--muted); font-size: .9rem; }
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
<div class="muted"><span class="dot" style="--color: {{ e.client_color }}"></span>{{ e.client_name }}</div>
|
||||
<div class="current-project">{{ e.project_name }}</div>
|
||||
{% if !e.note.is_empty() %}<div class="note">{{ e.note }}</div>{% endif %}
|
||||
<form class="row timer-start" hx-post="/ui/timer/debut" hx-target="#timer" hx-swap="outerHTML">
|
||||
<label>Début <input type="datetime-local" name="started_at" value="{{ e.start_input() }}" required aria-label="Heure de début"></label>
|
||||
<button class="btn small">Modifier</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="clock" data-started="{{ e.started_rfc3339() }}">{{ e.duration() }}</div>
|
||||
<button class="btn danger" hx-post="/ui/timer/stop" hx-target="#timer" hx-swap="outerHTML">Arrêter</button>
|
||||
|
||||
@@ -665,3 +665,40 @@ async fn duplicate_entry() {
|
||||
let (status, _) = get_html(&app, "/ui/entries/99/dupliquer").await;
|
||||
assert_eq!(status, StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn move_timer_start() {
|
||||
let app = app().await;
|
||||
let p = project(&app, "Acme", "Site web").await;
|
||||
|
||||
let (status, _) = send_form(&app, "/ui/timer/debut", "started_at=2026-03-10T09%3A00").await;
|
||||
assert_eq!(status, StatusCode::CONFLICT, "no running timer");
|
||||
|
||||
let (status, _) = send_form(&app, "/ui/timer/start", &format!("project_id={p}")).await;
|
||||
assert_eq!(status, StatusCode::OK);
|
||||
|
||||
let earlier = (Local::now() - chrono::Duration::minutes(90))
|
||||
.format("%Y-%m-%dT%H:%M")
|
||||
.to_string();
|
||||
let (status, html) = send_form(&app, "/ui/timer/debut", &format!("started_at={earlier}")).await;
|
||||
assert_eq!(status, StatusCode::OK);
|
||||
assert!(html.contains(&earlier) && html.contains("Arrêter"));
|
||||
|
||||
let (_, timer) = send(&app, "GET", "/api/timer", None).await;
|
||||
let started =
|
||||
chrono::DateTime::parse_from_rfc3339(timer["started_at"].as_str().unwrap()).unwrap();
|
||||
assert_eq!(
|
||||
started
|
||||
.with_timezone(&Local)
|
||||
.format("%Y-%m-%dT%H:%M")
|
||||
.to_string(),
|
||||
earlier
|
||||
);
|
||||
assert!(timer["ended_at"].is_null(), "still running");
|
||||
|
||||
let future = (Local::now() + chrono::Duration::hours(1))
|
||||
.format("%Y-%m-%dT%H:%M")
|
||||
.to_string();
|
||||
let (status, _) = send_form(&app, "/ui/timer/debut", &format!("started_at={future}")).await;
|
||||
assert_eq!(status, StatusCode::UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
Reference in new issue
Block a user