From 923836613736a2872d66eefecbc4822d07d164f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Mon, 20 Oct 2025 14:34:24 +0200 Subject: [PATCH] started with new design --- Cargo.lock | 121 ++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 33 +++++-- templates/food.html | 75 +++++++++------ templates/index-new.html | 193 +++++++++++++++++++++++++++++++++++++++ templates/index.html | 140 ++++++++++++++++++++++++++-- 6 files changed, 525 insertions(+), 38 deletions(-) create mode 100644 templates/index-new.html diff --git a/Cargo.lock b/Cargo.lock index 86a4212..ed74a88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "askama" version = "0.14.0" @@ -59,6 +68,12 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + [[package]] name = "axum" version = "0.8.6" @@ -154,6 +169,25 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "chrono" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "fallible-iterator" version = "0.3.0" @@ -339,6 +373,30 @@ dependencies = [ "tower-service", ] +[[package]] +name = "iana-time-zone" +version = "0.1.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "itoa" version = "1.0.15" @@ -440,6 +498,15 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "once_cell" version = "1.21.3" @@ -747,6 +814,7 @@ version = "0.1.0" dependencies = [ "askama", "axum", + "chrono", "parking_lot", "rusqlite", "tokio", @@ -1023,12 +1091,65 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.60.2" diff --git a/Cargo.toml b/Cargo.toml index 86f8dbc..5104d78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] askama = "0.14.0" axum = "0.8.6" +chrono = "0.4.42" parking_lot = "0.12.5" rusqlite = { version = "0.37.0", features = ["bundled"] } tokio = { version = "1.48.0", features = ["full"] } diff --git a/src/main.rs b/src/main.rs index d74ad86..b7ebff3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,18 +15,32 @@ use tower_request_id::{RequestId, RequestIdLayer}; use tracing::{debug, error, info, info_span}; use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _}; +#[derive(Debug)] +struct Sum { + kc: i32, + bs: i32, + protein: i32, +} + +impl std::fmt::Display for Sum { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} + #[derive(Template)] #[template(path = "index.html")] struct IndexTemplate { foods: Vec, - sum: i32, + sum: Sum, + date: String, } #[derive(Template)] #[template(path = "food-update.html")] struct FoodUpdateTemplate { food: Food, - sum: i32, + sum: Sum, } #[derive(Debug, Clone, PartialEq)] @@ -179,18 +193,25 @@ fn get_foods(conn: &ConnState) -> rusqlite::Result> { Ok(foods) } -fn get_sum(conn: &Arc>) -> rusqlite::Result { +fn get_sum(conn: &Arc>) -> rusqlite::Result { let conn = conn.lock(); let mut stmt = PreparedStatements::get_sum(&conn); - let sum = stmt.query_one((), |row| row.get(0))?; - debug!(sum); + let kc = stmt.query_one((), |row| row.get(0))?; + let sum = Sum { + kc, + bs: 99, + protein: 99, + }; + debug!(?sum); Ok(sum) } async fn root(State(conn): State) -> Result, StatusCode> { let foods = get_foods(&conn).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; let sum = get_sum(&conn).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; - let index = IndexTemplate { foods, sum }; + let now = chrono::Local::now(); + let date = format!("{}", now.format("%Y-%M-%d")); + let index = IndexTemplate { foods, sum, date }; Ok(Html( index .render() diff --git a/templates/food.html b/templates/food.html index 17f5d72..ecd18ec 100644 --- a/templates/food.html +++ b/templates/food.html @@ -1,28 +1,51 @@ -
-
-

- {{ food.name }} -

- {{ food.portion }} ({{ food.kc_per_serving }} kc.) -
- - food.target_servings %} - style="accent-color: red;" - {% endif %}> - - {{ food.actual_servings }}/{{ food.target_servings }} -
-
-
-
- - +
+

+ {{ food.name }} +

+
+
+

+ 14 Cup +

+

+ {{ food.kc_per_serving }} kc +

- +
+ + +
+
+ + + + + + + + + + +
+
\ No newline at end of file diff --git a/templates/index-new.html b/templates/index-new.html new file mode 100644 index 0000000..098ae7f --- /dev/null +++ b/templates/index-new.html @@ -0,0 +1,193 @@ + + + + + + + + + Food Tracker + + + + +
+ + Datum: {{ date }} + +
+ + kc: {{ sum.kc }} + + + Protein: {{ sum.protein }} + + + Balaststoffe: {{ sum.bs }} + +
+
+
+
+
+

+ {{ food.name }} +

+
+
+

+ 14 Cup +

+

+ {{ food.kc_per_serving }} kc +

+
+
+ + +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index c4d5354..36c2d8d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -10,14 +10,142 @@ -
-
- {% for food in foods %} - {% include "food.html" %} - {% endfor %} - {% include "sum.html" %} +
+ + Datum: {{ date }} + +
+ + kc: {{ sum.kc }} + + + Protein: {{ sum.protein }} + + + Balaststoffe: {{ sum.bs }} +
+
+
+
+ {% for food in foods %} + {% include "food.html" %} + {% if !loop.last %} +
+ {% endif %} + {% endfor %}
+ + \ No newline at end of file