Compare commits
18
Commits
No files matched your search
@@ -31,8 +31,8 @@ Aucune authentification : le service est prévu pour tourner en local.
|
|||||||
|--------------|----------------------------------------------------|
|
|--------------|----------------------------------------------------|
|
||||||
| GET, POST | `/clients` (`?archived=true` pour inclure les archivés) — `{"name", "color"?}` |
|
| GET, POST | `/clients` (`?archived=true` pour inclure les archivés) — `{"name", "color"?}` |
|
||||||
| PATCH, DELETE| `/clients/{id}` — `{"name"?, "archived"?, "color"?}` |
|
| PATCH, DELETE| `/clients/{id}` — `{"name"?, "archived"?, "color"?}` |
|
||||||
| GET, POST | `/clients/{id}/projects` — `{"name", "color"?}` |
|
| GET, POST | `/clients/{id}/projects` — `{"name", "color"?, "repo_url"?}` |
|
||||||
| PATCH, DELETE| `/projects/{id}` — `"color": null` pour reprendre celle du client |
|
| PATCH, DELETE| `/projects/{id}` — `"color": null` pour reprendre celle du client, `"repo_url": ""` pour l'effacer |
|
||||||
| GET | `/timer` — entrée en cours ou `null` |
|
| GET | `/timer` — entrée en cours ou `null` |
|
||||||
| POST | `/timer/start` `{"project_id", "note"?}` · `/timer/stop` |
|
| POST | `/timer/start` `{"project_id", "note"?}` · `/timer/stop` |
|
||||||
| GET, POST | `/entries` (`?from&to&client_id&project_id`) |
|
| GET, POST | `/entries` (`?from&to&client_id&project_id`) |
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
-- Optional link to the project's source repository (http(s) URL).
|
||||||
|
ALTER TABLE projects ADD COLUMN repo_url TEXT;
|
||||||
@@ -25,6 +25,8 @@ pub struct Project {
|
|||||||
pub color: Option<String>,
|
pub color: Option<String>,
|
||||||
/// `color`, or the client's color.
|
/// `color`, or the client's color.
|
||||||
pub effective_color: String,
|
pub effective_color: String,
|
||||||
|
/// Link to the source repository.
|
||||||
|
pub repo_url: Option<String>,
|
||||||
pub archived: bool,
|
pub archived: bool,
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
@@ -39,6 +41,8 @@ pub struct Entry {
|
|||||||
/// The project's effective color.
|
/// The project's effective color.
|
||||||
pub color: String,
|
pub color: String,
|
||||||
pub client_color: String,
|
pub client_color: String,
|
||||||
|
/// The project's repository link.
|
||||||
|
pub repo_url: Option<String>,
|
||||||
pub started_at: DateTime<Utc>,
|
pub started_at: DateTime<Utc>,
|
||||||
/// `None` while the timer is running.
|
/// `None` while the timer is running.
|
||||||
pub ended_at: Option<DateTime<Utc>>,
|
pub ended_at: Option<DateTime<Utc>>,
|
||||||
@@ -97,6 +101,9 @@ pub struct NameInput {
|
|||||||
/// `#rrggbb`. Clients get one from the palette, projects inherit their client's.
|
/// `#rrggbb`. Clients get one from the palette, projects inherit their client's.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub color: Option<String>,
|
pub color: Option<String>,
|
||||||
|
/// Projects only: `http(s)://` link to the source repository.
|
||||||
|
#[serde(default)]
|
||||||
|
pub repo_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Deserialize)]
|
#[derive(Debug, Default, Deserialize)]
|
||||||
@@ -106,6 +113,9 @@ pub struct UpdateInput {
|
|||||||
/// Absent: unchanged. `null`: reset to the client's color (projects only).
|
/// Absent: unchanged. `null`: reset to the client's color (projects only).
|
||||||
#[serde(default, deserialize_with = "present")]
|
#[serde(default, deserialize_with = "present")]
|
||||||
pub color: Option<Option<String>>,
|
pub color: Option<Option<String>>,
|
||||||
|
/// Projects only. Absent: unchanged. `null` or `""`: removed.
|
||||||
|
#[serde(default, deserialize_with = "present")]
|
||||||
|
pub repo_url: Option<Option<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|||||||
+39
-2
@@ -1,4 +1,4 @@
|
|||||||
use chrono::{DateTime, Duration, Utc};
|
use chrono::{DateTime, Duration, Local, Utc};
|
||||||
use sqlx::SqlitePool;
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
use super::affected;
|
use super::affected;
|
||||||
@@ -9,7 +9,7 @@ use crate::models::{Entry, EntryFilter, NewEntry, UpdateEntry};
|
|||||||
/// `?1` is always "now", used to measure running entries.
|
/// `?1` is always "now", used to measure running entries.
|
||||||
const SELECT: &str =
|
const SELECT: &str =
|
||||||
"SELECT e.id, e.project_id, p.name AS project_name, p.client_id, c.name AS client_name,
|
"SELECT e.id, e.project_id, p.name AS project_name, p.client_id, c.name AS client_name,
|
||||||
COALESCE(p.color, c.color) AS color, c.color AS client_color,
|
COALESCE(p.color, c.color) AS color, c.color AS client_color, p.repo_url,
|
||||||
e.started_at, e.ended_at, e.note,
|
e.started_at, e.ended_at, e.note,
|
||||||
strftime('%s', COALESCE(e.ended_at, ?1)) - strftime('%s', e.started_at) AS seconds,
|
strftime('%s', COALESCE(e.ended_at, ?1)) - strftime('%s', e.started_at) AS seconds,
|
||||||
EXISTS (SELECT 1 FROM time_entries o
|
EXISTS (SELECT 1 FROM time_entries o
|
||||||
@@ -102,6 +102,43 @@ pub async fn start(pool: &SqlitePool, project_id: i64, note: &str) -> AppResult<
|
|||||||
get(pool, id).await
|
get(pool, id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Copies finished entries `days` days later (or earlier), keeping their local
|
||||||
|
/// wall-clock times, project and note. The running entry is skipped. All or
|
||||||
|
/// nothing: an archived project rejects the whole copy. Returns the count.
|
||||||
|
pub async fn duplicate(pool: &SqlitePool, ids: &[i64], days: i64) -> AppResult<usize> {
|
||||||
|
let shift = |dt: &DateTime<Utc>| {
|
||||||
|
clock::local_to_utc(dt.with_timezone(&Local).naive_local() + Duration::days(days))
|
||||||
|
};
|
||||||
|
let mut copies = Vec::new();
|
||||||
|
for &id in ids {
|
||||||
|
let e = get(pool, id).await?;
|
||||||
|
let Some(ended) = e.ended_at else { continue };
|
||||||
|
super::projects::get_active(pool, e.project_id).await?;
|
||||||
|
let (started, ended) = (shift(&e.started_at), shift(&ended));
|
||||||
|
validate_span(&started, Some(&ended))?;
|
||||||
|
copies.push((e.project_id, started, ended, e.note));
|
||||||
|
}
|
||||||
|
if copies.is_empty() {
|
||||||
|
return Err(AppError::Validation(
|
||||||
|
"aucune entrée terminée à copier".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let mut tx = pool.begin().await?;
|
||||||
|
for (project_id, started, ended, note) in &copies {
|
||||||
|
sqlx::query(
|
||||||
|
"INSERT INTO time_entries (project_id, started_at, ended_at, note) VALUES (?1, ?2, ?3, ?4)",
|
||||||
|
)
|
||||||
|
.bind(project_id)
|
||||||
|
.bind(clock::ts(started))
|
||||||
|
.bind(clock::ts(ended))
|
||||||
|
.bind(note)
|
||||||
|
.execute(&mut *tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
tx.commit().await?;
|
||||||
|
Ok(copies.len())
|
||||||
|
}
|
||||||
|
|
||||||
/// Stops the running timer.
|
/// Stops the running timer.
|
||||||
pub async fn stop(pool: &SqlitePool) -> AppResult<Entry> {
|
pub async fn stop(pool: &SqlitePool) -> AppResult<Entry> {
|
||||||
let entry = running(pool)
|
let entry = running(pool)
|
||||||
|
|||||||
@@ -33,6 +33,22 @@ fn clean_color(color: &str) -> AppResult<String> {
|
|||||||
Ok(color.to_ascii_lowercase())
|
Ok(color.to_ascii_lowercase())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Validates an optional repository URL; blank means none.
|
||||||
|
fn clean_repo_url(url: &str) -> AppResult<Option<String>> {
|
||||||
|
let url = url.trim();
|
||||||
|
if url.is_empty() {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
let valid = (url.starts_with("https://") || url.starts_with("http://"))
|
||||||
|
&& !url.contains(char::is_whitespace);
|
||||||
|
if !valid {
|
||||||
|
return Err(AppError::Validation(format!(
|
||||||
|
"URL du repo invalide « {url} » (doit commencer par http:// ou https://)"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
Ok(Some(url.to_owned()))
|
||||||
|
}
|
||||||
|
|
||||||
/// Maps "zero rows affected" to `NotFound`.
|
/// Maps "zero rows affected" to `NotFound`.
|
||||||
fn affected(result: sqlx::sqlite::SqliteQueryResult) -> AppResult<()> {
|
fn affected(result: sqlx::sqlite::SqliteQueryResult) -> AppResult<()> {
|
||||||
if result.rows_affected() == 0 {
|
if result.rows_affected() == 0 {
|
||||||
|
|||||||
+16
-4
@@ -1,12 +1,13 @@
|
|||||||
use sqlx::SqlitePool;
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
use super::{affected, clean_color, clean_name};
|
use super::{affected, clean_color, clean_name, clean_repo_url};
|
||||||
use crate::clock;
|
use crate::clock;
|
||||||
use crate::error::{AppError, AppResult};
|
use crate::error::{AppError, AppResult};
|
||||||
use crate::models::{Project, UpdateInput};
|
use crate::models::{Project, UpdateInput};
|
||||||
|
|
||||||
const SELECT: &str = "SELECT p.id, p.client_id, c.name AS client_name, p.name,
|
const SELECT: &str = "SELECT p.id, p.client_id, c.name AS client_name, p.name,
|
||||||
p.color, COALESCE(p.color, c.color) AS effective_color, p.archived, p.created_at
|
p.color, COALESCE(p.color, c.color) AS effective_color, p.repo_url, p.archived,
|
||||||
|
p.created_at
|
||||||
FROM projects p JOIN clients c ON c.id = p.client_id";
|
FROM projects p JOIN clients c ON c.id = p.client_id";
|
||||||
|
|
||||||
/// Lists projects, optionally for one client. Archived projects (or projects of
|
/// Lists projects, optionally for one client. Archived projects (or projects of
|
||||||
@@ -40,17 +41,21 @@ pub async fn create(
|
|||||||
client_id: i64,
|
client_id: i64,
|
||||||
name: &str,
|
name: &str,
|
||||||
color: Option<&str>,
|
color: Option<&str>,
|
||||||
|
repo_url: Option<&str>,
|
||||||
) -> AppResult<Project> {
|
) -> AppResult<Project> {
|
||||||
let name = clean_name(name)?;
|
let name = clean_name(name)?;
|
||||||
let color = color.map(clean_color).transpose()?;
|
let color = color.map(clean_color).transpose()?;
|
||||||
|
let repo_url = repo_url.map(clean_repo_url).transpose()?.flatten();
|
||||||
// Surface a missing client as 404 rather than a foreign key error.
|
// Surface a missing client as 404 rather than a foreign key error.
|
||||||
super::clients::get(pool, client_id).await?;
|
super::clients::get(pool, client_id).await?;
|
||||||
let id = sqlx::query(
|
let id = sqlx::query(
|
||||||
"INSERT INTO projects (client_id, name, color, created_at) VALUES (?1, ?2, ?3, ?4)",
|
"INSERT INTO projects (client_id, name, color, repo_url, created_at)
|
||||||
|
VALUES (?1, ?2, ?3, ?4, ?5)",
|
||||||
)
|
)
|
||||||
.bind(client_id)
|
.bind(client_id)
|
||||||
.bind(name)
|
.bind(name)
|
||||||
.bind(color)
|
.bind(color)
|
||||||
|
.bind(repo_url)
|
||||||
.bind(clock::ts(&clock::now()))
|
.bind(clock::ts(&clock::now()))
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?
|
.await?
|
||||||
@@ -64,10 +69,15 @@ pub async fn update(pool: &SqlitePool, id: i64, input: &UpdateInput) -> AppResul
|
|||||||
Some(Some(c)) => Some(clean_color(c)?),
|
Some(Some(c)) => Some(clean_color(c)?),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
let repo_url = match &input.repo_url {
|
||||||
|
Some(Some(u)) => clean_repo_url(u)?,
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
affected(
|
affected(
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
"UPDATE projects SET name = COALESCE(?2, name), archived = COALESCE(?3, archived),
|
"UPDATE projects SET name = COALESCE(?2, name), archived = COALESCE(?3, archived),
|
||||||
color = CASE WHEN ?4 THEN ?5 ELSE color END
|
color = CASE WHEN ?4 THEN ?5 ELSE color END,
|
||||||
|
repo_url = CASE WHEN ?6 THEN ?7 ELSE repo_url END
|
||||||
WHERE id = ?1",
|
WHERE id = ?1",
|
||||||
)
|
)
|
||||||
.bind(id)
|
.bind(id)
|
||||||
@@ -75,6 +85,8 @@ pub async fn update(pool: &SqlitePool, id: i64, input: &UpdateInput) -> AppResul
|
|||||||
.bind(input.archived)
|
.bind(input.archived)
|
||||||
.bind(input.color.is_some())
|
.bind(input.color.is_some())
|
||||||
.bind(color)
|
.bind(color)
|
||||||
|
.bind(input.repo_url.is_some())
|
||||||
|
.bind(repo_url)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await?,
|
.await?,
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
+10
-1
@@ -90,7 +90,16 @@ async fn create_project(
|
|||||||
) -> AppResult<(StatusCode, Json<Project>)> {
|
) -> AppResult<(StatusCode, Json<Project>)> {
|
||||||
Ok((
|
Ok((
|
||||||
StatusCode::CREATED,
|
StatusCode::CREATED,
|
||||||
Json(projects::create(&pool, client_id, &input.name, input.color.as_deref()).await?),
|
Json(
|
||||||
|
projects::create(
|
||||||
|
&pool,
|
||||||
|
client_id,
|
||||||
|
&input.name,
|
||||||
|
input.color.as_deref(),
|
||||||
|
input.repo_url.as_deref(),
|
||||||
|
)
|
||||||
|
.await?,
|
||||||
|
),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-6
@@ -44,18 +44,31 @@ pub fn app(pool: SqlitePool) -> Router {
|
|||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
.route("/static/app.js", get(|| asset("text/javascript", APP_JS)))
|
||||||
|
.route("/static/app.css", get(|| asset("text/css", APP_CSS)))
|
||||||
.route(
|
.route(
|
||||||
"/static/app.js",
|
"/static/favicon.svg",
|
||||||
get(|| asset("text/javascript", include_str!("../../static/app.js"))),
|
get(|| asset("image/svg+xml", include_str!("../../static/favicon.svg"))),
|
||||||
)
|
|
||||||
.route(
|
|
||||||
"/static/app.css",
|
|
||||||
get(|| asset("text/css", include_str!("../../static/app.css"))),
|
|
||||||
)
|
)
|
||||||
.layer(TraceLayer::new_for_http())
|
.layer(TraceLayer::new_for_http())
|
||||||
.with_state(pool)
|
.with_state(pool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const APP_CSS: &str = include_str!("../../static/app.css");
|
||||||
|
const APP_JS: &str = include_str!("../../static/app.js");
|
||||||
|
|
||||||
|
/// Hash of app.css + app.js, appended as `?v=` to their URLs so a deploy
|
||||||
|
/// bypasses the browser cache.
|
||||||
|
pub fn asset_version() -> &'static str {
|
||||||
|
static VERSION: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
|
let mut h = std::collections::hash_map::DefaultHasher::new();
|
||||||
|
(APP_CSS, APP_JS).hash(&mut h);
|
||||||
|
format!("{:x}", h.finish())
|
||||||
|
});
|
||||||
|
&VERSION
|
||||||
|
}
|
||||||
|
|
||||||
// En livereload, le CSS/JS doit être relu à chaque rechargement.
|
// En livereload, le CSS/JS doit être relu à chaque rechargement.
|
||||||
const CACHE_CONTROL: &str = if cfg!(feature = "livereload") {
|
const CACHE_CONTROL: &str = if cfg!(feature = "livereload") {
|
||||||
"no-cache"
|
"no-cache"
|
||||||
|
|||||||
+101
-2
@@ -27,6 +27,8 @@ pub fn router() -> Router<SqlitePool> {
|
|||||||
.route("/reports", get(reports_page))
|
.route("/reports", get(reports_page))
|
||||||
.route("/ui/today", get(today_fragment))
|
.route("/ui/today", get(today_fragment))
|
||||||
.route("/ui/dernieres-entrees", get(recent_fragment))
|
.route("/ui/dernieres-entrees", get(recent_fragment))
|
||||||
|
.route("/ui/timer", get(timer_fragment))
|
||||||
|
.route("/ui/timer/entete", get(mini_timer))
|
||||||
.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/timer/debut", post(set_timer_start))
|
.route("/ui/timer/debut", post(set_timer_start))
|
||||||
@@ -44,6 +46,8 @@ 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("/ui/jours/{date}/dupliquer", post(duplicate_day))
|
||||||
.route(
|
.route(
|
||||||
"/ui/entries/{id}/dupliquer",
|
"/ui/entries/{id}/dupliquer",
|
||||||
get(entry_duplicate).post(duplicate_entry),
|
get(entry_duplicate).post(duplicate_entry),
|
||||||
@@ -97,6 +101,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,
|
||||||
@@ -222,6 +236,13 @@ struct TimerTpl {
|
|||||||
groups: Vec<ProjectGroup>,
|
groups: Vec<ProjectGroup>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Compact running timer shown in the header of every page.
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "_mini_timer.html")]
|
||||||
|
struct MiniTimerTpl {
|
||||||
|
running: Option<Entry>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "_today.html")]
|
#[template(path = "_today.html")]
|
||||||
struct TodayTpl {
|
struct TodayTpl {
|
||||||
@@ -237,11 +258,33 @@ struct RecentTpl {
|
|||||||
|
|
||||||
/// Entries started on the same local day, with their total.
|
/// Entries started on the same local day, with their total.
|
||||||
struct DayGroup {
|
struct DayGroup {
|
||||||
|
date: NaiveDate,
|
||||||
day: String,
|
day: String,
|
||||||
total: String,
|
total: String,
|
||||||
entries: Vec<Entry>,
|
entries: Vec<Entry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DayGroup {
|
||||||
|
/// Comma-separated ids of the listed entries, for "copy this day".
|
||||||
|
fn ids(&self) -> String {
|
||||||
|
self.entries
|
||||||
|
.iter()
|
||||||
|
.map(|e| e.id.to_string())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(",")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Default target of "copy this day": today, or tomorrow for today itself.
|
||||||
|
fn copy_to(&self) -> NaiveDate {
|
||||||
|
let today = clock::today();
|
||||||
|
if self.date == today {
|
||||||
|
today + Duration::days(1)
|
||||||
|
} else {
|
||||||
|
today
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Groups a list sorted by start time into consecutive days.
|
/// Groups a list sorted by start time into consecutive days.
|
||||||
fn group_by_day(list: Vec<Entry>) -> Vec<DayGroup> {
|
fn group_by_day(list: Vec<Entry>) -> Vec<DayGroup> {
|
||||||
let mut days: Vec<(NaiveDate, i64, Vec<Entry>)> = Vec::new();
|
let mut days: Vec<(NaiveDate, i64, Vec<Entry>)> = Vec::new();
|
||||||
@@ -257,6 +300,7 @@ fn group_by_day(list: Vec<Entry>) -> Vec<DayGroup> {
|
|||||||
}
|
}
|
||||||
days.into_iter()
|
days.into_iter()
|
||||||
.map(|(date, secs, entries)| DayGroup {
|
.map(|(date, secs, entries)| DayGroup {
|
||||||
|
date,
|
||||||
day: clock::fmt_day(date),
|
day: clock::fmt_day(date),
|
||||||
total: clock::hhmm(secs),
|
total: clock::hhmm(secs),
|
||||||
entries,
|
entries,
|
||||||
@@ -318,6 +362,16 @@ async fn dashboard(State(pool): State<SqlitePool>) -> PageResult {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn timer_fragment(State(pool): State<SqlitePool>) -> PageResult {
|
||||||
|
render(timer_state(&pool).await?)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn mini_timer(State(pool): State<SqlitePool>) -> PageResult {
|
||||||
|
render(MiniTimerTpl {
|
||||||
|
running: entries::running(&pool).await?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async fn today_fragment(State(pool): State<SqlitePool>) -> PageResult {
|
async fn today_fragment(State(pool): State<SqlitePool>) -> PageResult {
|
||||||
render(today_state(&pool).await?)
|
render(today_state(&pool).await?)
|
||||||
}
|
}
|
||||||
@@ -344,7 +398,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()),
|
||||||
}
|
}
|
||||||
Ok(with_entries_changed(render(timer_state(&pool).await?)?))
|
Ok(with_timer_changed(render(timer_state(&pool).await?)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@@ -417,6 +471,9 @@ struct ItemForm {
|
|||||||
/// Projects only: go back to the client's color.
|
/// Projects only: go back to the client's color.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
inherit: bool,
|
inherit: bool,
|
||||||
|
/// Projects only; blank removes it.
|
||||||
|
#[serde(default)]
|
||||||
|
repo_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@@ -476,7 +533,14 @@ async fn create_project(
|
|||||||
// The color picker is prefilled with the client's color: keeping it means inheriting.
|
// The color picker is prefilled with the client's color: keeping it means inheriting.
|
||||||
let client = clients::get(&pool, client_id).await?;
|
let client = clients::get(&pool, client_id).await?;
|
||||||
let color = f.color.filter(|c| !c.eq_ignore_ascii_case(&client.color));
|
let color = f.color.filter(|c| !c.eq_ignore_ascii_case(&client.color));
|
||||||
projects::create(&pool, client_id, &f.name, color.as_deref()).await?;
|
projects::create(
|
||||||
|
&pool,
|
||||||
|
client_id,
|
||||||
|
&f.name,
|
||||||
|
color.as_deref(),
|
||||||
|
f.repo_url.as_deref(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
back_to_clients()
|
back_to_clients()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,6 +561,7 @@ async fn save_project(
|
|||||||
let input = UpdateInput {
|
let input = UpdateInput {
|
||||||
name: Some(f.name),
|
name: Some(f.name),
|
||||||
color,
|
color,
|
||||||
|
repo_url: f.repo_url.map(Some),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
projects::update(&pool, id, &input).await?;
|
projects::update(&pool, id, &input).await?;
|
||||||
@@ -691,6 +756,40 @@ 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()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct DuplicateDayForm {
|
||||||
|
/// Comma-separated entry ids.
|
||||||
|
ids: String,
|
||||||
|
vers: NaiveDate,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Copies the listed entries of `date` to another day, same times.
|
||||||
|
async fn duplicate_day(
|
||||||
|
State(pool): State<SqlitePool>,
|
||||||
|
Path(date): Path<NaiveDate>,
|
||||||
|
Form(f): Form<DuplicateDayForm>,
|
||||||
|
) -> PageResult {
|
||||||
|
if f.vers == date {
|
||||||
|
return Err(AppError::Validation("choisis un autre jour que celui copié".into()).into());
|
||||||
|
}
|
||||||
|
let ids = f
|
||||||
|
.ids
|
||||||
|
.split(',')
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
.map(|s| s.trim().parse::<i64>())
|
||||||
|
.collect::<Result<Vec<_>, _>>()
|
||||||
|
.map_err(|_| AppError::Validation("liste d'entrées invalide".into()))?;
|
||||||
|
entries::duplicate(&pool, &ids, (f.vers - date).num_days()).await?;
|
||||||
|
Ok(with_entries_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.
|
||||||
|
|||||||
+35
-7
@@ -1,4 +1,7 @@
|
|||||||
:root {
|
:root {
|
||||||
|
/* Hauteur commune des champs, pastilles de couleur et boutons-icônes. */
|
||||||
|
--control: 2.5rem;
|
||||||
|
--control-sm: 1.9rem;
|
||||||
--bg: #f6f5f2;
|
--bg: #f6f5f2;
|
||||||
--surface: #ffffff;
|
--surface: #ffffff;
|
||||||
--text: #1d1d1f;
|
--text: #1d1d1f;
|
||||||
@@ -49,6 +52,14 @@ h2 { font-size: 1.1rem; }
|
|||||||
padding: .35rem .75rem; border-radius: 999px; color: var(--muted); text-decoration: none;
|
padding: .35rem .75rem; border-radius: 999px; color: var(--muted); text-decoration: none;
|
||||||
}
|
}
|
||||||
.topbar nav a[aria-current="page"] { background: var(--bg); color: var(--text); font-weight: 600; }
|
.topbar nav a[aria-current="page"] { background: var(--bg); color: var(--text); font-weight: 600; }
|
||||||
|
#mini-timer { margin-left: auto; }
|
||||||
|
.mini-timer {
|
||||||
|
display: flex; align-items: center; gap: .6rem; min-width: 0;
|
||||||
|
border: 2px solid var(--color); border-radius: 999px; padding: .2rem .25rem .2rem .85rem;
|
||||||
|
}
|
||||||
|
.mini-timer-label { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
|
||||||
|
.mini-timer .clock { font-size: 1rem; }
|
||||||
|
.mini-timer .btn { border-radius: 50%; }
|
||||||
|
|
||||||
main { max-width: 960px; margin: 1.5rem auto; padding: 0 16px; display: grid; gap: 1rem; }
|
main { max-width: 960px; margin: 1.5rem auto; padding: 0 16px; display: grid; gap: 1rem; }
|
||||||
|
|
||||||
@@ -64,7 +75,8 @@ main { max-width: 960px; margin: 1.5rem auto; padding: 0 16px; display: grid; ga
|
|||||||
.row { display: flex; gap: .5rem; align-items: center; }
|
.row { display: flex; gap: .5rem; align-items: center; }
|
||||||
.row.wrap { flex-wrap: wrap; }
|
.row.wrap { flex-wrap: wrap; }
|
||||||
.grow { flex: 1; min-width: 0; }
|
.grow { flex: 1; min-width: 0; }
|
||||||
.row.grow input { flex: 1; min-width: 0; }
|
.row.grow input:not([type="color"]) { flex: 1; min-width: 0; }
|
||||||
|
.row input, .row select { height: var(--control); }
|
||||||
.stack { display: grid; gap: .35rem; }
|
.stack { display: grid; gap: .35rem; }
|
||||||
.muted, .empty { color: var(--muted); }
|
.muted, .empty { color: var(--muted); }
|
||||||
.empty { margin: .25rem 0; }
|
.empty { margin: .25rem 0; }
|
||||||
@@ -83,17 +95,23 @@ label { display: flex; align-items: center; gap: .35rem; color: var(--muted); }
|
|||||||
border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
|
border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
|
||||||
padding: .45rem .9rem; cursor: pointer; white-space: nowrap;
|
padding: .45rem .9rem; cursor: pointer; white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
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 { display: inline-flex; align-items: center; justify-content: center; padding: .3rem; line-height: 0; }
|
.btn.icon {
|
||||||
|
display: inline-flex; align-items: center; justify-content: center; flex: none;
|
||||||
|
width: var(--control); height: var(--control); padding: 0; line-height: 0;
|
||||||
|
}
|
||||||
|
.btn.small.icon { width: var(--control-sm); height: var(--control-sm); }
|
||||||
.btn.icon svg { display: block; }
|
.btn.icon svg { display: block; }
|
||||||
.btn-group { display: inline-flex; }
|
.btn-group { display: inline-flex; }
|
||||||
.btn-group > .btn { border-radius: 0; }
|
.btn-group > .btn { border-radius: 0; }
|
||||||
.btn-group > .btn + .btn { margin-left: -1px; }
|
.btn-group > .btn + .btn { margin-left: -1px; }
|
||||||
.btn-group > .btn:first-child { border-radius: 8px 0 0 8px; }
|
.btn-group > .btn:first-child { border-top-left-radius: 8px; border-bottom-left-radius: 8px; }
|
||||||
.btn-group > .btn:last-child { border-radius: 0 8px 8px 0; }
|
.btn-group > .btn:last-child { border-top-right-radius: 8px; border-bottom-right-radius: 8px; }
|
||||||
.btn-group > .btn:hover { position: relative; z-index: 1; }
|
.btn-group > .btn:hover { position: relative; z-index: 1; }
|
||||||
.htmx-request .btn, .btn.htmx-request { opacity: .6; }
|
.htmx-request .btn, .btn.htmx-request { opacity: .6; }
|
||||||
|
|
||||||
@@ -106,6 +124,8 @@ label { display: flex; align-items: center; gap: .35rem; color: var(--muted); }
|
|||||||
.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; }
|
||||||
|
|
||||||
@@ -118,8 +138,13 @@ tr:last-child td { border-bottom: 0; }
|
|||||||
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||||
.time { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
|
.time { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
|
||||||
.client { color: var(--muted); }
|
.client { color: var(--muted); }
|
||||||
|
.project-link { color: inherit; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
|
||||||
|
.project-link:hover { color: var(--accent); text-decoration-color: currentColor; }
|
||||||
tr.running { background: var(--running); }
|
tr.running { background: var(--running); }
|
||||||
tr.day-head th { color: var(--text); font-weight: 600; font-size: .9rem; padding-top: 1.1rem; }
|
tr.day-head th { color: var(--text); font-weight: 600; font-size: .9rem; padding-top: 1.1rem; }
|
||||||
|
tr.day-head th.actions { padding-top: .6rem; text-align: right; }
|
||||||
|
tr.day-copy td { background: var(--bg); }
|
||||||
|
tr.day-copy .row { justify-content: flex-end; flex-wrap: wrap; }
|
||||||
tbody:first-of-type tr.day-head th { padding-top: .6rem; }
|
tbody:first-of-type tr.day-head th { padding-top: .6rem; }
|
||||||
tr.editing td { background: var(--bg); }
|
tr.editing td { background: var(--bg); }
|
||||||
tr.editing input, tr.editing select { width: 100%; }
|
tr.editing input, tr.editing select { width: 100%; }
|
||||||
@@ -133,9 +158,10 @@ td.actions { text-align: right; white-space: nowrap; }
|
|||||||
}
|
}
|
||||||
.client-card { border-left: 6px solid var(--color); }
|
.client-card { border-left: 6px solid var(--color); }
|
||||||
input[type="color"] {
|
input[type="color"] {
|
||||||
width: 2.2rem; height: 2.2rem; padding: .15rem; flex: none; cursor: pointer;
|
width: var(--control); height: var(--control); padding: .15rem; flex: none; cursor: pointer;
|
||||||
}
|
}
|
||||||
.projects input[type="color"] { width: 1.8rem; height: 1.8rem; }
|
.projects input { height: var(--control-sm); padding-block: 0; }
|
||||||
|
.projects input[type="color"] { width: var(--control-sm); padding: .1rem; }
|
||||||
|
|
||||||
/* Projects list */
|
/* Projects list */
|
||||||
.projects { list-style: none; margin: 0 0 1rem; padding: 0; }
|
.projects { list-style: none; margin: 0 0 1rem; padding: 0; }
|
||||||
@@ -144,6 +170,8 @@ input[type="color"] {
|
|||||||
padding: .4rem 0; border-bottom: 1px solid var(--border);
|
padding: .4rem 0; border-bottom: 1px solid var(--border);
|
||||||
}
|
}
|
||||||
.projects li.archived { opacity: .6; }
|
.projects li.archived { opacity: .6; }
|
||||||
|
.row.grow input.repo-url { flex: 1.3; }
|
||||||
|
.projects li > form::before { content: "-"; color: var(--muted); flex: none; }
|
||||||
|
|
||||||
/* Periods & reports */
|
/* Periods & reports */
|
||||||
.presets { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .75rem; }
|
.presets { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .75rem; }
|
||||||
@@ -166,7 +194,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%; }
|
||||||
|
|||||||
+52
-2
@@ -3,13 +3,15 @@ function tick() {
|
|||||||
for (const el of document.querySelectorAll(".clock[data-started]")) {
|
for (const el of document.querySelectorAll(".clock[data-started]")) {
|
||||||
const secs = Math.max(0, Math.floor((Date.now() - Date.parse(el.dataset.started)) / 1000));
|
const secs = Math.max(0, Math.floor((Date.now() - Date.parse(el.dataset.started)) / 1000));
|
||||||
const h = Math.floor(secs / 3600);
|
const h = Math.floor(secs / 3600);
|
||||||
const m = String(Math.floor((secs % 3600) / 60)).padStart(2, "0");
|
const m = Math.floor((secs % 3600) / 60);
|
||||||
const s = String(secs % 60).padStart(2, "0");
|
const s = String(secs % 60).padStart(2, "0");
|
||||||
el.textContent = `${h}:${m}:${s}`;
|
// Pas d'heures à zéro : 4:07, puis 1:04:07.
|
||||||
|
el.textContent = h ? `${h}:${String(m).padStart(2, "0")}:${s}` : `${m}:${s}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tick();
|
tick();
|
||||||
setInterval(tick, 1000);
|
setInterval(tick, 1000);
|
||||||
|
htmx.onLoad(tick); // horloges arrivées par htmx (ex. header)
|
||||||
|
|
||||||
// Show server errors from htmx requests in a toast.
|
// Show server errors from htmx requests in a toast.
|
||||||
let toastTimer;
|
let toastTimer;
|
||||||
@@ -55,9 +57,57 @@ document.body.addEventListener("htmx:beforeCleanupElement", (event) => {
|
|||||||
event.target._flatpickr?.destroy();
|
event.target._flatpickr?.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Shows/hides the "copy this day" form under a day header.
|
||||||
|
function toggleDayCopy(button) {
|
||||||
|
const row = button.closest("tbody").querySelector(".day-copy");
|
||||||
|
row.hidden = !row.hidden;
|
||||||
|
if (!row.hidden) row.querySelector('input[type="date"]').focus();
|
||||||
|
}
|
||||||
|
|
||||||
// Removes a row without a request (e.g. cancelling a duplicate).
|
// Removes a row without a request (e.g. cancelling a duplicate).
|
||||||
function removeRow(button) {
|
function removeRow(button) {
|
||||||
const row = button.closest("tr");
|
const row = button.closest("tr");
|
||||||
for (const input of row.querySelectorAll("input")) input._flatpickr?.destroy();
|
for (const input of row.querySelectorAll("input")) input._flatpickr?.destroy();
|
||||||
row.remove();
|
row.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Favicon : point rouge clignotant tant qu'un enregistrement est en cours,
|
||||||
|
// sur toutes les pages (état lu sur /api/timer).
|
||||||
|
const favicon = document.getElementById("favicon");
|
||||||
|
const IDLE_ICON = favicon.href;
|
||||||
|
const recIcon = (opacity) =>
|
||||||
|
"data:image/svg+xml," +
|
||||||
|
encodeURIComponent(
|
||||||
|
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><circle cx="16" cy="16" r="13" fill="#e5322d" fill-opacity="${opacity}"/></svg>`,
|
||||||
|
);
|
||||||
|
const REC_ON = recIcon(1);
|
||||||
|
const REC_OFF = recIcon(0.2);
|
||||||
|
let recording = false;
|
||||||
|
let blinkOn = false;
|
||||||
|
|
||||||
|
function setRecording(value) {
|
||||||
|
if (value === recording) return;
|
||||||
|
recording = value;
|
||||||
|
blinkOn = true;
|
||||||
|
favicon.href = recording ? REC_ON : IDLE_ICON;
|
||||||
|
}
|
||||||
|
setInterval(() => {
|
||||||
|
if (!recording) return;
|
||||||
|
blinkOn = !blinkOn;
|
||||||
|
favicon.href = blinkOn ? REC_ON : REC_OFF;
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
async function refreshRecording() {
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/timer", { headers: { accept: "application/json" } });
|
||||||
|
if (res.ok) setRecording((await res.json()) !== null);
|
||||||
|
} catch {
|
||||||
|
// Serveur injoignable : on garde l'état connu.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
refreshRecording();
|
||||||
|
setInterval(refreshRecording, 20000);
|
||||||
|
document.addEventListener("visibilitychange", () => {
|
||||||
|
if (!document.hidden) refreshRecording();
|
||||||
|
});
|
||||||
|
document.body.addEventListener("htmx:afterRequest", refreshRecording);
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><circle cx="16" cy="16" r="12" fill="none" stroke="#2f6f5e" stroke-width="4"/><path d="M16 9v7l4 3" fill="none" stroke="#2f6f5e" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
||||||
|
After Width: | Height: | Size: 261 B |
@@ -1,6 +1,25 @@
|
|||||||
|
{% import "_icons.html" as icons %}
|
||||||
{% for d in days %}
|
{% for d in days %}
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr class="day-head"><th colspan="3">{{ d.day }}</th><th class="num">{{ d.total }}</th><th></th></tr>
|
<tr class="day-head">
|
||||||
|
<th colspan="3">{{ d.day }}</th>
|
||||||
|
<th class="num">{{ d.total }}</th>
|
||||||
|
<th class="actions">
|
||||||
|
<button class="btn small icon" title="Copier cette journée vers un autre jour" aria-label="Copier cette journée vers un autre jour" hx-on:click="toggleDayCopy(this)">{% call icons::icon("copy") %}{% endcall %}</button>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
<tr class="day-copy" hidden>
|
||||||
|
<td colspan="5">
|
||||||
|
<form class="row" hx-post="/ui/jours/{{ d.date }}/dupliquer" hx-swap="none">
|
||||||
|
<input type="hidden" name="ids" value="{{ d.ids() }}">
|
||||||
|
<label>Copier les entrées du {{ d.day }} vers le <input type="date" name="vers" value="{{ d.copy_to() }}" required></label>
|
||||||
|
<div class="btn-group">
|
||||||
|
<button class="btn small icon primary" title="Copier" aria-label="Copier">{% call icons::icon("check") %}{% endcall %}</button>
|
||||||
|
<button type="button" class="btn small icon" title="Annuler" aria-label="Annuler" hx-on:click="toggleDayCopy(this)">{% call icons::icon("close") %}{% endcall %}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
{% for e in d.entries %}{% include "_entry_row.html" %}{% endfor %}
|
{% for e in d.entries %}{% include "_entry_row.html" %}{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -1,16 +1,22 @@
|
|||||||
|
{% import "_icons.html" as icons %}
|
||||||
<tr id="entry-{{ e.id }}"{% if e.running() %} class="running"{% endif %}>
|
<tr id="entry-{{ e.id }}"{% if e.running() %} class="running"{% endif %}>
|
||||||
<td class="time">
|
<td class="time">
|
||||||
{{ e.start_time() }} – {{ e.end_time() }}
|
{{ e.start_time() }} – {{ e.end_time() }}
|
||||||
{% if e.overlaps %}<span class="warn" title="Chevauche une autre entrée">⚠</span>{% endif %}
|
{% if e.overlaps %}<span class="warn" title="Chevauche une autre entrée">⚠</span>{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td><span class="dot" style="--color: {{ e.color }}"></span><span class="client">{{ e.client_name }}</span> / {{ e.project_name }}</td>
|
<td><span class="dot" style="--color: {{ e.color }}"></span><span class="client">{{ e.client_name }}</span> / {% if let Some(u) = e.repo_url %}<a class="project-link" href="{{ u }}" target="_blank" rel="noopener noreferrer" title="Ouvrir le repo">{{ e.project_name }}</a>{% else %}{{ e.project_name }}{% endif %}</td>
|
||||||
<td class="note">{{ e.note }}</td>
|
<td class="note">{{ e.note }}</td>
|
||||||
<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">
|
||||||
<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"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg></button>
|
{% if e.running() %}
|
||||||
<button class="btn small icon" title="Dupliquer" aria-label="Dupliquer" hx-get="/ui/entries/{{ e.id }}/dupliquer" hx-target="closest tr" hx-swap="afterend"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg></button>
|
<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>
|
||||||
<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 ?"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 6h18"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><path d="M10 11v6"/><path d="M14 11v6"/></svg></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>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{# Icônes SVG (tracés Lucide), en couleur du texte. #}
|
||||||
|
{% macro icon(name) %}<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
||||||
|
{%- if name == "edit" -%}<path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z"/>
|
||||||
|
{%- else if name == "copy" -%}<rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
|
||||||
|
{%- else if name == "trash" -%}<path d="M3 6h18"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><path d="M10 11v6"/><path d="M14 11v6"/>
|
||||||
|
{%- else if name == "check" -%}<path d="M20 6 9 17l-5-5"/>
|
||||||
|
{%- else if name == "close" -%}<path d="M18 6 6 18"/><path d="m6 6 12 12"/>
|
||||||
|
{%- 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"/>
|
||||||
|
{%- else if name == "unarchive" -%}<rect x="2" y="3" width="20" height="5" rx="1"/><path d="M4 8v11a2 2 0 0 0 2 2h2"/><path d="M20 8v11a2 2 0 0 1-2 2h-2"/><path d="m9 15 3-3 3 3"/><path d="M12 12v9"/>
|
||||||
|
{%- endif -%}
|
||||||
|
</svg>{% endmacro %}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{% import "_icons.html" as icons %}
|
||||||
|
<div id="mini-timer" hx-get="/ui/timer/entete" hx-trigger="entries-changed from:body, every 30s" hx-swap="outerHTML">
|
||||||
|
{% if let Some(e) = running %}
|
||||||
|
<div class="mini-timer" style="--color: {{ e.color }}" title="{{ e.client_name }} / {{ e.project_name }}">
|
||||||
|
<span class="mini-timer-label">{% if e.note.is_empty() %}{{ e.project_name }}{% else %}{{ e.note }}{% endif %}</span>
|
||||||
|
<span class="clock" data-started="{{ e.started_rfc3339() }}">{{ e.duration() }}</span>
|
||||||
|
<button class="btn small icon danger" hx-post="/ui/timer/stop" hx-swap="none" title="Arrêter" aria-label="Arrêter le timer">{% call icons::icon("stop") %}{% endcall %}</button>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<section id="recent" class="card" hx-get="/ui/dernieres-entrees" hx-trigger="entries-changed from:body" hx-swap="outerHTML">
|
<section id="recent" hx-disinherit="*" class="card" hx-get="/ui/dernieres-entrees" hx-trigger="entries-changed from:body" hx-swap="outerHTML">
|
||||||
<div class="card-head">
|
<div class="card-head">
|
||||||
<h2>Dernières entrées</h2>
|
<h2>Dernières entrées</h2>
|
||||||
<a href="/entries">Tout voir</a>
|
<a href="/entries">Tout voir</a>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<section id="timer" class="card timer{% if running.is_some() %} is-running{% endif %}"{% if let Some(e) = running %} style="--color: {{ e.color }}"{% endif %}>
|
{% import "_icons.html" as icons %}
|
||||||
|
<section id="timer" hx-disinherit="*" 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">
|
||||||
<div class="current-label">
|
<div class="current-label">
|
||||||
@@ -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() %}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<section id="today" class="card" hx-get="/ui/today" hx-trigger="entries-changed from:body" hx-swap="outerHTML">
|
<section id="today" hx-disinherit="*" class="card" hx-get="/ui/today" hx-trigger="entries-changed from:body" hx-swap="outerHTML">
|
||||||
<div class="card-head">
|
<div class="card-head">
|
||||||
<h2>Aujourd'hui</h2>
|
<h2>Aujourd'hui</h2>
|
||||||
<span class="total">{{ today_total }}</span>
|
<span class="total">{{ today_total }}</span>
|
||||||
|
|||||||
+4
-2
@@ -4,12 +4,13 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>{% block title %}Tempus{% endblock %} · Tempus</title>
|
<title>{% block title %}Tempus{% endblock %} · Tempus</title>
|
||||||
|
<link rel="icon" id="favicon" type="image/svg+xml" href="/static/favicon.svg">
|
||||||
<link rel="stylesheet" href="/static/flatpickr/flatpickr.min.css">
|
<link rel="stylesheet" href="/static/flatpickr/flatpickr.min.css">
|
||||||
<link rel="stylesheet" href="/static/app.css">
|
<link rel="stylesheet" href="/static/app.css?v={{ crate::routes::asset_version() }}">
|
||||||
<script src="/static/htmx.min.js" defer></script>
|
<script src="/static/htmx.min.js" defer></script>
|
||||||
<script src="/static/flatpickr/flatpickr.min.js" defer></script>
|
<script src="/static/flatpickr/flatpickr.min.js" defer></script>
|
||||||
<script src="/static/flatpickr/fr.min.js" defer></script>
|
<script src="/static/flatpickr/fr.min.js" defer></script>
|
||||||
<script src="/static/app.js" defer></script>
|
<script src="/static/app.js?v={{ crate::routes::asset_version() }}" defer></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header class="topbar">
|
<header class="topbar">
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
<a href="/reports" {% if nav == "reports" %}aria-current="page"{% endif %}>Rapports</a>
|
<a href="/reports" {% if nav == "reports" %}aria-current="page"{% endif %}>Rapports</a>
|
||||||
<a href="/clients" {% if nav == "clients" %}aria-current="page"{% endif %}>Clients</a>
|
<a href="/clients" {% if nav == "clients" %}aria-current="page"{% endif %}>Clients</a>
|
||||||
</nav>
|
</nav>
|
||||||
|
<div id="mini-timer" hx-get="/ui/timer/entete" hx-trigger="load" hx-swap="outerHTML"></div>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
|
|||||||
+35
-17
@@ -1,4 +1,5 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% import "_icons.html" as icons %}
|
||||||
{% block title %}Clients{% endblock %}
|
{% block title %}Clients{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<section class="card">
|
<section class="card">
|
||||||
@@ -6,7 +7,7 @@
|
|||||||
<form method="post" action="/ui/clients" class="row">
|
<form method="post" action="/ui/clients" class="row">
|
||||||
<input type="color" name="color" value="{{ next_color }}" aria-label="Couleur du client">
|
<input type="color" name="color" value="{{ next_color }}" aria-label="Couleur du client">
|
||||||
<input name="name" required placeholder="Nom du client" aria-label="Nom du client" class="grow">
|
<input name="name" required placeholder="Nom du client" aria-label="Nom du client" class="grow">
|
||||||
<button class="btn primary">Ajouter</button>
|
<button class="btn icon primary" title="Ajouter le client" aria-label="Ajouter le client">{% call icons::icon("plus") %}{% endcall %}</button>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -20,17 +21,22 @@
|
|||||||
<form method="post" action="/ui/clients/{{ c.client.id }}" class="row grow">
|
<form method="post" action="/ui/clients/{{ c.client.id }}" class="row grow">
|
||||||
<input type="color" name="color" value="{{ c.client.color }}" aria-label="Couleur du client">
|
<input type="color" name="color" value="{{ c.client.color }}" aria-label="Couleur du client">
|
||||||
<input name="name" value="{{ c.client.name }}" required aria-label="Nom du client" class="title-input">
|
<input name="name" value="{{ c.client.name }}" required aria-label="Nom du client" class="title-input">
|
||||||
<button class="btn">Enregistrer</button>
|
<button class="btn icon primary" title="Enregistrer" aria-label="Enregistrer">{% call icons::icon("check") %}{% endcall %}</button>
|
||||||
</form>
|
</form>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% if c.client.archived %}<span class="badge">archivé</span>{% endif %}
|
{% if c.client.archived %}<span class="badge">archivé</span>{% endif %}
|
||||||
<form method="post" action="/ui/clients/{{ c.client.id }}/archive">
|
<form id="archive-client-{{ c.client.id }}" method="post" action="/ui/clients/{{ c.client.id }}/archive" hidden>
|
||||||
<input type="hidden" name="archived" value="{{ !c.client.archived }}">
|
<input type="hidden" name="archived" value="{{ !c.client.archived }}">
|
||||||
<button class="btn">{% if c.client.archived %}Réactiver{% else %}Archiver{% endif %}</button>
|
|
||||||
</form>
|
|
||||||
<form method="post" action="/ui/clients/{{ c.client.id }}/delete" data-confirm="Supprimer ce client, ses projets et tout le temps saisi ?">
|
|
||||||
<button class="btn danger">Supprimer</button>
|
|
||||||
</form>
|
</form>
|
||||||
|
<form id="delete-client-{{ c.client.id }}" method="post" action="/ui/clients/{{ c.client.id }}/delete" data-confirm="Supprimer ce client, ses projets et tout le temps saisi ?" hidden></form>
|
||||||
|
<div class="btn-group">
|
||||||
|
{% if c.client.archived %}
|
||||||
|
<button class="btn icon" form="archive-client-{{ c.client.id }}" title="Réactiver" aria-label="Réactiver">{% call icons::icon("unarchive") %}{% endcall %}</button>
|
||||||
|
{% else %}
|
||||||
|
<button class="btn icon" form="archive-client-{{ c.client.id }}" title="Archiver" aria-label="Archiver">{% call icons::icon("archive") %}{% endcall %}</button>
|
||||||
|
{% endif %}
|
||||||
|
<button class="btn icon danger" form="delete-client-{{ c.client.id }}" title="Supprimer" aria-label="Supprimer">{% call icons::icon("trash") %}{% endcall %}</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -41,20 +47,31 @@
|
|||||||
<input type="color" name="color" value="{{ p.effective_color }}" aria-label="Couleur du projet"
|
<input type="color" name="color" value="{{ p.effective_color }}" aria-label="Couleur du projet"
|
||||||
title="{% if p.color.is_some() %}Couleur propre au projet{% else %}Couleur du client{% endif %}">
|
title="{% if p.color.is_some() %}Couleur propre au projet{% else %}Couleur du client{% endif %}">
|
||||||
<input name="name" value="{{ p.name }}" required aria-label="Nom du projet">
|
<input name="name" value="{{ p.name }}" required aria-label="Nom du projet">
|
||||||
<button class="btn small">Enregistrer</button>
|
<input type="url" name="repo_url" value="{% if let Some(u) = p.repo_url %}{{ u }}{% endif %}" placeholder="URL du repo" aria-label="URL du repo" class="repo-url">
|
||||||
{% if p.color.is_some() %}
|
<div class="btn-group">
|
||||||
<button class="btn small" name="inherit" value="true" title="Reprendre la couleur du client">↺</button>
|
<button class="btn small icon primary" title="Enregistrer" aria-label="Enregistrer">{% call icons::icon("check") %}{% endcall %}</button>
|
||||||
{% endif %}
|
{% if p.color.is_some() %}
|
||||||
|
<button class="btn small icon" name="inherit" value="true" title="Reprendre la couleur du client" aria-label="Reprendre la couleur du client">{% call icons::icon("reset") %}{% endcall %}</button>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% if p.archived %}<span class="badge">archivé</span>{% endif %}
|
{% if p.archived %}<span class="badge">archivé</span>{% endif %}
|
||||||
<form method="post" action="/ui/projects/{{ p.id }}/archive">
|
<form id="archive-project-{{ p.id }}" method="post" action="/ui/projects/{{ p.id }}/archive" hidden>
|
||||||
<input type="hidden" name="archived" value="{{ !p.archived }}">
|
<input type="hidden" name="archived" value="{{ !p.archived }}">
|
||||||
<button class="btn small">{% if p.archived %}Réactiver{% else %}Archiver{% endif %}</button>
|
|
||||||
</form>
|
|
||||||
<form method="post" action="/ui/projects/{{ p.id }}/delete" data-confirm="Supprimer ce projet et tout le temps saisi dessus ?">
|
|
||||||
<button class="btn small danger">Supprimer</button>
|
|
||||||
</form>
|
</form>
|
||||||
|
<form id="delete-project-{{ p.id }}" method="post" action="/ui/projects/{{ p.id }}/delete" data-confirm="Supprimer ce projet et tout le temps saisi dessus ?" hidden></form>
|
||||||
|
<div class="btn-group">
|
||||||
|
{% if let Some(u) = p.repo_url %}
|
||||||
|
<a class="btn small icon" href="{{ u }}" target="_blank" rel="noopener noreferrer" title="Ouvrir le repo" aria-label="Ouvrir le repo">{% call icons::icon("link") %}{% endcall %}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if p.archived %}
|
||||||
|
<button class="btn small icon" form="archive-project-{{ p.id }}" title="Réactiver" aria-label="Réactiver">{% call icons::icon("unarchive") %}{% endcall %}</button>
|
||||||
|
{% else %}
|
||||||
|
<button class="btn small icon" form="archive-project-{{ p.id }}" title="Archiver" aria-label="Archiver">{% call icons::icon("archive") %}{% endcall %}</button>
|
||||||
|
{% endif %}
|
||||||
|
<button class="btn small icon danger" form="delete-project-{{ p.id }}" title="Supprimer" aria-label="Supprimer">{% call icons::icon("trash") %}{% endcall %}</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -63,7 +80,8 @@
|
|||||||
<form method="post" action="/ui/clients/{{ c.client.id }}/projects" class="row">
|
<form method="post" action="/ui/clients/{{ c.client.id }}/projects" class="row">
|
||||||
<input type="color" name="color" value="{{ c.client.color }}" aria-label="Couleur du projet" title="Garder la couleur du client ou en choisir une autre">
|
<input type="color" name="color" value="{{ c.client.color }}" aria-label="Couleur du projet" title="Garder la couleur du client ou en choisir une autre">
|
||||||
<input name="name" required placeholder="Nouveau projet" aria-label="Nouveau projet" class="grow">
|
<input name="name" required placeholder="Nouveau projet" aria-label="Nouveau projet" class="grow">
|
||||||
<button class="btn">Ajouter le projet</button>
|
<input type="url" name="repo_url" placeholder="URL du repo (facultatif)" aria-label="URL du repo" class="grow">
|
||||||
|
<button class="btn icon primary" title="Ajouter le projet" aria-label="Ajouter le projet">{% call icons::icon("plus") %}{% endcall %}</button>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="entries-list" class="card" hx-get="/entries?from={{ from }}&to={{ to }}{{ extra_query }}" hx-select="#entries-list" hx-trigger="entries-changed from:body" hx-swap="outerHTML">
|
<section id="entries-list" hx-disinherit="*" class="card" hx-get="/entries?from={{ from }}&to={{ to }}{{ extra_query }}" hx-select="#entries-list" hx-trigger="entries-changed from:body" hx-swap="outerHTML">
|
||||||
<div class="card-head">
|
<div class="card-head">
|
||||||
<h2>Entrées</h2>
|
<h2>Entrées</h2>
|
||||||
<span class="total">{{ total }}</span>
|
<span class="total">{{ total }}</span>
|
||||||
|
|||||||
+222
@@ -707,3 +707,225 @@ async fn move_timer_start() {
|
|||||||
let (status, _) = send_form(&app, "/ui/timer/debut", &format!("started_at={future}")).await;
|
let (status, _) = send_form(&app, "/ui/timer/debut", &format!("started_at={future}")).await;
|
||||||
assert_eq!(status, StatusCode::UNPROCESSABLE_ENTITY);
|
assert_eq!(status, StatusCode::UNPROCESSABLE_ENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn project_repo_url() {
|
||||||
|
let app = app().await;
|
||||||
|
let (_, c) = send(
|
||||||
|
&app,
|
||||||
|
"POST",
|
||||||
|
"/api/clients",
|
||||||
|
Some(json!({ "name": "Acme" })),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let uri = format!("/api/clients/{}/projects", c["id"]);
|
||||||
|
|
||||||
|
let (status, p) = send(
|
||||||
|
&app,
|
||||||
|
"POST",
|
||||||
|
&uri,
|
||||||
|
Some(json!({ "name": "Site", "repo_url": " https://git.example.com/acme/site " })),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(status, StatusCode::CREATED);
|
||||||
|
assert_eq!(p["repo_url"], "https://git.example.com/acme/site");
|
||||||
|
|
||||||
|
let (status, _) = send(
|
||||||
|
&app,
|
||||||
|
"POST",
|
||||||
|
&uri,
|
||||||
|
Some(json!({ "name": "Bad", "repo_url": "git@example.com:acme/site.git" })),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(status, StatusCode::UNPROCESSABLE_ENTITY);
|
||||||
|
|
||||||
|
// Absent: unchanged; "" clears it.
|
||||||
|
let project = format!("/api/projects/{}", p["id"]);
|
||||||
|
let (_, p) = send(&app, "PATCH", &project, Some(json!({ "name": "Site web" }))).await;
|
||||||
|
assert_eq!(p["repo_url"], "https://git.example.com/acme/site");
|
||||||
|
let (_, html) = get_html(&app, "/clients").await;
|
||||||
|
assert!(html.contains("href=\"https://git.example.com/acme/site\""));
|
||||||
|
// Entry lists link the project name to its repository.
|
||||||
|
let (status, _) = add_entry(
|
||||||
|
&app,
|
||||||
|
p["id"].as_i64().unwrap(),
|
||||||
|
local(2026, 3, 10, 9, 0),
|
||||||
|
local(2026, 3, 10, 10, 0),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(status, StatusCode::CREATED);
|
||||||
|
let (_, html) = get_html(&app, "/entries?from=2026-03-09&to=2026-03-15").await;
|
||||||
|
assert!(html.contains("class=\"project-link\" href=\"https://git.example.com/acme/site\""));
|
||||||
|
let (_, p) = send(&app, "PATCH", &project, Some(json!({ "repo_url": "" }))).await;
|
||||||
|
assert!(p["repo_url"].is_null());
|
||||||
|
|
||||||
|
// HTML form: the URL field is saved with the project.
|
||||||
|
let (status, _) = send_form(
|
||||||
|
&app,
|
||||||
|
&project.replace("/api/", "/ui/"),
|
||||||
|
"name=Site+web&repo_url=https%3A%2F%2Fgit.example.com%2Fx",
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(status, StatusCode::SEE_OTHER);
|
||||||
|
let (_, p) = send(&app, "GET", &format!("{uri}?archived=true"), None).await;
|
||||||
|
assert_eq!(p[0]["repo_url"], "https://git.example.com/x");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn header_mini_timer() {
|
||||||
|
let app = app().await;
|
||||||
|
let p = project(&app, "Acme", "Site web").await;
|
||||||
|
|
||||||
|
let (status, html) = get_html(&app, "/ui/timer/entete").await;
|
||||||
|
assert_eq!(status, StatusCode::OK);
|
||||||
|
assert!(!html.contains("mini-timer-label"));
|
||||||
|
|
||||||
|
send(
|
||||||
|
&app,
|
||||||
|
"POST",
|
||||||
|
"/api/timer/start",
|
||||||
|
Some(json!({ "project_id": p, "note": "Refonte" })),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let (_, html) = get_html(&app, "/ui/timer/entete").await;
|
||||||
|
assert!(html.contains("Refonte") && html.contains("data-started"));
|
||||||
|
assert!(html.contains("hx-post=\"/ui/timer/stop\""));
|
||||||
|
|
||||||
|
// Without a note, the project name is shown.
|
||||||
|
send(
|
||||||
|
&app,
|
||||||
|
"POST",
|
||||||
|
"/api/timer/start",
|
||||||
|
Some(json!({ "project_id": p })),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn duplicate_day() {
|
||||||
|
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, 15),
|
||||||
|
)
|
||||||
|
.await; // 1
|
||||||
|
add_entry(
|
||||||
|
&app,
|
||||||
|
b,
|
||||||
|
local(2026, 3, 10, 14, 0),
|
||||||
|
local(2026, 3, 10, 16, 0),
|
||||||
|
)
|
||||||
|
.await; // 2
|
||||||
|
|
||||||
|
// The day header carries the listed ids and posts to the copy route.
|
||||||
|
let (_, html) = get_html(&app, "/entries?from=2026-03-10&to=2026-03-10").await;
|
||||||
|
assert!(html.contains("hx-post=\"/ui/jours/2026-03-10/dupliquer\""));
|
||||||
|
// The self-refreshing list must not pass hx-select & co. down to row buttons
|
||||||
|
// (inline edit would swap in an empty row).
|
||||||
|
assert!(html.contains("id=\"entries-list\" hx-disinherit=\"*\""));
|
||||||
|
assert!(html.contains("name=\"ids\" value=\"2,1\""));
|
||||||
|
|
||||||
|
let (status, _) = send_form(
|
||||||
|
&app,
|
||||||
|
"/ui/jours/2026-03-10/dupliquer",
|
||||||
|
"ids=2,1&vers=2026-03-12",
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(status, StatusCode::OK);
|
||||||
|
let (_, list) = send(
|
||||||
|
&app,
|
||||||
|
"GET",
|
||||||
|
"/api/entries?from=2026-03-12&to=2026-03-12",
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let list = list.as_array().unwrap();
|
||||||
|
assert_eq!(list.len(), 2);
|
||||||
|
assert_eq!(list[0]["project_id"], b);
|
||||||
|
let parse = |v: &Value| chrono::DateTime::parse_from_rfc3339(v.as_str().unwrap()).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
parse(&list[1]["started_at"]),
|
||||||
|
parse(&json!(local(2026, 3, 12, 9, 0)))
|
||||||
|
);
|
||||||
|
assert_eq!(list[1]["seconds"], 4500);
|
||||||
|
|
||||||
|
// Same day, or an archived project: refused, nothing copied.
|
||||||
|
let (status, _) = send_form(
|
||||||
|
&app,
|
||||||
|
"/ui/jours/2026-03-10/dupliquer",
|
||||||
|
"ids=1&vers=2026-03-10",
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(status, StatusCode::UNPROCESSABLE_ENTITY);
|
||||||
|
send(
|
||||||
|
&app,
|
||||||
|
"PATCH",
|
||||||
|
&format!("/api/projects/{b}"),
|
||||||
|
Some(json!({ "archived": true })),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let (status, _) = send_form(
|
||||||
|
&app,
|
||||||
|
"/ui/jours/2026-03-10/dupliquer",
|
||||||
|
"ids=2,1&vers=2026-03-13",
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(status, StatusCode::UNPROCESSABLE_ENTITY);
|
||||||
|
let (_, list) = send(
|
||||||
|
&app,
|
||||||
|
"GET",
|
||||||
|
"/api/entries?from=2026-03-13&to=2026-03-13",
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert!(list.as_array().unwrap().is_empty());
|
||||||
|
}
|
||||||
Reference in new issue
Block a user