Compare commits
2
Commits
dd6a740645
...
c05fb183c6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c05fb183c6 | ||
|
|
8488b9217d |
No files matched your search
@@ -47,6 +47,17 @@ pub async fn list(
|
|||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The `limit` most recent entries, whatever their date.
|
||||||
|
pub async fn recent(pool: &SqlitePool, limit: i64, now: DateTime<Utc>) -> AppResult<Vec<Entry>> {
|
||||||
|
Ok(
|
||||||
|
sqlx::query_as(&format!("{SELECT} ORDER BY e.started_at DESC LIMIT ?2"))
|
||||||
|
.bind(clock::ts(&now))
|
||||||
|
.bind(limit)
|
||||||
|
.fetch_all(pool)
|
||||||
|
.await?,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get(pool: &SqlitePool, id: i64) -> AppResult<Entry> {
|
pub async fn get(pool: &SqlitePool, id: i64) -> AppResult<Entry> {
|
||||||
Ok(sqlx::query_as(&format!("{SELECT} WHERE e.id = ?2"))
|
Ok(sqlx::query_as(&format!("{SELECT} WHERE e.id = ?2"))
|
||||||
.bind(clock::ts(&clock::now()))
|
.bind(clock::ts(&clock::now()))
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ pub fn router() -> Router<SqlitePool> {
|
|||||||
.route("/entries", get(entries_page))
|
.route("/entries", get(entries_page))
|
||||||
.route("/reports", get(reports_page))
|
.route("/reports", get(reports_page))
|
||||||
.route("/ui/today", get(today_fragment))
|
.route("/ui/today", get(today_fragment))
|
||||||
|
.route("/ui/recent", get(recent_fragment))
|
||||||
.route("/ui/timer/start", post(start_timer))
|
.route("/ui/timer/start", post(start_timer))
|
||||||
.route("/ui/timer/stop", post(stop_timer))
|
.route("/ui/timer/stop", post(stop_timer))
|
||||||
.route("/ui/clients", post(create_client))
|
.route("/ui/clients", post(create_client))
|
||||||
@@ -206,6 +207,7 @@ struct DashboardTpl {
|
|||||||
groups: Vec<ProjectGroup>,
|
groups: Vec<ProjectGroup>,
|
||||||
today_entries: Vec<Entry>,
|
today_entries: Vec<Entry>,
|
||||||
today_total: String,
|
today_total: String,
|
||||||
|
recent_entries: Vec<Entry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
@@ -222,6 +224,15 @@ struct TodayTpl {
|
|||||||
today_total: String,
|
today_total: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "_recent.html")]
|
||||||
|
struct RecentTpl {
|
||||||
|
recent_entries: Vec<Entry>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How many entries the dashboard lists under "Dernières entrées".
|
||||||
|
const RECENT_LIMIT: i64 = 20;
|
||||||
|
|
||||||
async fn timer_state(pool: &SqlitePool) -> PageResult<TimerTpl> {
|
async fn timer_state(pool: &SqlitePool) -> PageResult<TimerTpl> {
|
||||||
let running = entries::running(pool).await?;
|
let running = entries::running(pool).await?;
|
||||||
// Preselect the running project, else the most recently tracked one.
|
// Preselect the running project, else the most recently tracked one.
|
||||||
@@ -249,18 +260,25 @@ async fn today_state(pool: &SqlitePool) -> PageResult<TodayTpl> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn recent_state(pool: &SqlitePool) -> PageResult<RecentTpl> {
|
||||||
|
let recent_entries = entries::recent(pool, RECENT_LIMIT, clock::now()).await?;
|
||||||
|
Ok(RecentTpl { recent_entries })
|
||||||
|
}
|
||||||
|
|
||||||
async fn dashboard(State(pool): State<SqlitePool>) -> PageResult {
|
async fn dashboard(State(pool): State<SqlitePool>) -> PageResult {
|
||||||
let TimerTpl { running, groups } = timer_state(&pool).await?;
|
let TimerTpl { running, groups } = timer_state(&pool).await?;
|
||||||
let TodayTpl {
|
let TodayTpl {
|
||||||
today_entries,
|
today_entries,
|
||||||
today_total,
|
today_total,
|
||||||
} = today_state(&pool).await?;
|
} = today_state(&pool).await?;
|
||||||
|
let RecentTpl { recent_entries } = recent_state(&pool).await?;
|
||||||
render(DashboardTpl {
|
render(DashboardTpl {
|
||||||
nav: "dashboard",
|
nav: "dashboard",
|
||||||
running,
|
running,
|
||||||
groups,
|
groups,
|
||||||
today_entries,
|
today_entries,
|
||||||
today_total,
|
today_total,
|
||||||
|
recent_entries,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,6 +286,10 @@ async fn today_fragment(State(pool): State<SqlitePool>) -> PageResult {
|
|||||||
render(today_state(&pool).await?)
|
render(today_state(&pool).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn recent_fragment(State(pool): State<SqlitePool>) -> PageResult {
|
||||||
|
render(recent_state(&pool).await?)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct StartForm {
|
struct StartForm {
|
||||||
project_id: i64,
|
project_id: i64,
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<section id="recent" class="card" hx-get="/ui/recent" hx-trigger="entries-changed from:body" hx-swap="outerHTML">
|
||||||
|
<div class="card-head">
|
||||||
|
<h2>Dernières entrées</h2>
|
||||||
|
<a href="/entries">Tout voir</a>
|
||||||
|
</div>
|
||||||
|
{% if recent_entries.is_empty() %}
|
||||||
|
<p class="empty">Aucune entrée pour l'instant.</p>
|
||||||
|
{% else %}
|
||||||
|
<div class="table-wrap">
|
||||||
|
<table class="entries">
|
||||||
|
<tbody>
|
||||||
|
{% for e in recent_entries %}
|
||||||
|
<tr{% if e.running() %} class="running"{% endif %}>
|
||||||
|
<td class="nowrap">{{ e.day() }}</td>
|
||||||
|
<td class="time">{{ e.start_time() }} – {{ e.end_time() }}</td>
|
||||||
|
<td>
|
||||||
|
<span class="dot" style="--color: {{ e.color }}"></span><span class="client">{{ e.client_name }}</span> / {{ e.project_name }}
|
||||||
|
{% if !e.note.is_empty() %}<div class="note">{{ e.note }}</div>{% endif %}
|
||||||
|
</td>
|
||||||
|
<td class="num">{{ e.duration() }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
@@ -3,4 +3,5 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
{% include "_timer.html" %}
|
{% include "_timer.html" %}
|
||||||
{% include "_today.html" %}
|
{% include "_today.html" %}
|
||||||
|
{% include "_recent.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -444,6 +444,32 @@ async fn html_pages() {
|
|||||||
get_html(&app, "/reports?from=2026-03-01&to=2026-03-31&group_by=day").await;
|
get_html(&app, "/reports?from=2026-03-01&to=2026-03-31&group_by=day").await;
|
||||||
assert_eq!(status, StatusCode::OK);
|
assert_eq!(status, StatusCode::OK);
|
||||||
assert!(html.contains("1:15") && html.contains("mar. 10/03/2026"));
|
assert!(html.contains("1:15") && html.contains("mar. 10/03/2026"));
|
||||||
|
|
||||||
|
let (status, html) = get_html(&app, "/").await;
|
||||||
|
assert_eq!(status, StatusCode::OK);
|
||||||
|
assert!(html.contains("Dernières entrées") && html.contains("mar. 10/03/2026"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn dashboard_lists_20_most_recent_entries() {
|
||||||
|
let app = app().await;
|
||||||
|
let p = project(&app, "Acme", "Site web").await;
|
||||||
|
for day in 1..=25 {
|
||||||
|
let (status, _) = add_entry(
|
||||||
|
&app,
|
||||||
|
p,
|
||||||
|
local(2026, 3, day, 9, 0),
|
||||||
|
local(2026, 3, day, 10, 0),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(status, StatusCode::CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
let (status, html) = get_html(&app, "/ui/recent").await;
|
||||||
|
assert_eq!(status, StatusCode::OK);
|
||||||
|
assert_eq!(html.matches("<tr").count(), 20);
|
||||||
|
assert!(html.contains("25/03/2026") && html.contains("06/03/2026"));
|
||||||
|
assert!(!html.contains("05/03/2026"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
Reference in new issue
Block a user