Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13bbba1053 | ||
|
|
2ff27b2a65 | ||
|
|
f612dbd764 | ||
|
|
262ab07b03 |
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),
|
get(entry_row).put(update_entry).delete(delete_entry),
|
||||||
)
|
)
|
||||||
.route("/ui/entries/{id}/edit", get(entry_edit))
|
.route("/ui/entries/{id}/edit", get(entry_edit))
|
||||||
|
.route("/ui/entries/{id}/relancer", post(restart_entry))
|
||||||
.route(
|
.route(
|
||||||
"/ui/entries/{id}/dupliquer",
|
"/ui/entries/{id}/dupliquer",
|
||||||
get(entry_duplicate).post(duplicate_entry),
|
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()
|
(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 {
|
struct ProjectOption {
|
||||||
id: i64,
|
id: i64,
|
||||||
name: String,
|
name: String,
|
||||||
@@ -363,13 +374,7 @@ async fn stop_timer(State(pool): State<SqlitePool>) -> PageResult {
|
|||||||
Ok(_) | Err(AppError::Conflict(_)) => {}
|
Ok(_) | Err(AppError::Conflict(_)) => {}
|
||||||
Err(e) => return Err(e.into()),
|
Err(e) => return Err(e.into()),
|
||||||
}
|
}
|
||||||
// `timer-changed` refreshes the dashboard timer when stopped from the header.
|
Ok(with_timer_changed(render(timer_state(&pool).await?)?))
|
||||||
let resp = render(timer_state(&pool).await?)?;
|
|
||||||
Ok((
|
|
||||||
AppendHeaders([("HX-Trigger", "entries-changed, timer-changed")]),
|
|
||||||
resp,
|
|
||||||
)
|
|
||||||
.into_response())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@@ -727,6 +732,13 @@ async fn update_entry(
|
|||||||
Ok(with_entries_changed(render(EntryRowTpl { e })?))
|
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 {
|
async fn delete_entry(State(pool): State<SqlitePool>, Path(id): Path<i64>) -> PageResult {
|
||||||
entries::delete(&pool, id).await?;
|
entries::delete(&pool, id).await?;
|
||||||
// htmx swaps the row with this empty body, removing it.
|
// htmx swaps the row with this empty body, removing it.
|
||||||
|
|||||||
+4
-1
@@ -99,6 +99,7 @@ a.btn { color: var(--text); text-decoration: none; }
|
|||||||
.btn:hover { border-color: var(--muted); }
|
.btn:hover { border-color: var(--muted); }
|
||||||
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
|
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
|
||||||
.btn.danger { color: var(--danger); }
|
.btn.danger { color: var(--danger); }
|
||||||
|
.btn.play { color: var(--accent); }
|
||||||
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
|
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
|
||||||
.btn.icon {
|
.btn.icon {
|
||||||
display: inline-flex; align-items: center; justify-content: center; flex: none;
|
display: inline-flex; align-items: center; justify-content: center; flex: none;
|
||||||
@@ -123,6 +124,8 @@ a.btn { color: var(--text); text-decoration: none; }
|
|||||||
.timer-start { margin-top: .35rem; font-size: .9rem; }
|
.timer-start { margin-top: .35rem; font-size: .9rem; }
|
||||||
.timer-start input { width: 11rem; }
|
.timer-start input { width: 11rem; }
|
||||||
.clock { font-size: 2rem; font-weight: 600; font-variant-numeric: tabular-nums; }
|
.clock { font-size: 2rem; font-weight: 600; font-variant-numeric: tabular-nums; }
|
||||||
|
.btn.icon.timer-stop { width: 3rem; height: 3rem; border-radius: 50%; }
|
||||||
|
.timer-stop svg { width: 20px; height: 20px; }
|
||||||
.start { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) auto; gap: .5rem; }
|
.start { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) auto; gap: .5rem; }
|
||||||
.note { color: var(--muted); font-size: .9rem; }
|
.note { color: var(--muted); font-size: .9rem; }
|
||||||
|
|
||||||
@@ -188,7 +191,7 @@ input[type="color"] {
|
|||||||
|
|
||||||
@media (max-width: 640px) {
|
@media (max-width: 640px) {
|
||||||
.current { grid-template-columns: 1fr auto; }
|
.current { grid-template-columns: 1fr auto; }
|
||||||
.current .btn { grid-column: 1 / -1; }
|
.current-label { grid-column: 1 / -1; min-width: 0; }
|
||||||
.start { grid-template-columns: 1fr; }
|
.start { grid-template-columns: 1fr; }
|
||||||
.report .label { width: auto; }
|
.report .label { width: auto; }
|
||||||
.bar-cell { width: 30%; }
|
.bar-cell { width: 30%; }
|
||||||
|
|||||||
@@ -9,6 +9,11 @@
|
|||||||
<td class="num">{{ e.duration() }}</td>
|
<td class="num">{{ e.duration() }}</td>
|
||||||
<td class="actions">
|
<td class="actions">
|
||||||
<div class="btn-group">
|
<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 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" 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>
|
<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 == "check" -%}<path d="M20 6 9 17l-5-5"/>
|
||||||
{%- else if name == "plus" -%}<path d="M5 12h14"/><path d="M12 5v14"/>
|
{%- 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 == "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 == "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 == "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"/>
|
{%- 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"/>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
{% import "_icons.html" as icons %}
|
||||||
<section id="timer" hx-get="/ui/timer" hx-trigger="timer-changed from:body" hx-swap="outerHTML" class="card timer{% if running.is_some() %} is-running{% endif %}"{% if let Some(e) = running %} style="--color: {{ e.color }}"{% endif %}>
|
<section id="timer" hx-get="/ui/timer" hx-trigger="timer-changed from:body" hx-swap="outerHTML" class="card timer{% if running.is_some() %} is-running{% endif %}"{% if let Some(e) = running %} style="--color: {{ e.color }}"{% endif %}>
|
||||||
{% if let Some(e) = running %}
|
{% if let Some(e) = running %}
|
||||||
<div class="current">
|
<div class="current">
|
||||||
@@ -11,7 +12,7 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="clock" data-started="{{ e.started_rfc3339() }}">{{ e.duration() }}</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>
|
<button class="btn icon danger timer-stop" hx-post="/ui/timer/stop" hx-target="#timer" hx-swap="outerHTML" title="Arrêter" aria-label="Arrêter le timer">{% call icons::icon("stop") %}{% endcall %}</button>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if groups.is_empty() %}
|
{% if groups.is_empty() %}
|
||||||
|
|||||||
@@ -802,3 +802,46 @@ async fn header_mini_timer() {
|
|||||||
let (_, html) = get_html(&app, "/ui/timer/entete").await;
|
let (_, html) = get_html(&app, "/ui/timer/entete").await;
|
||||||
assert!(html.contains("<span class=\"mini-timer-label\">Site web</span>"));
|
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