From bc4203aee067dbfd46888683f78aab20d0d0f288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Sat, 18 Oct 2025 21:21:58 +0200 Subject: [PATCH] table rendering --- flake.nix | 2 ++ tasks.db => foods.db | Bin 8192 -> 8192 bytes src/create_tables.sql | 8 ++++--- src/main.rs | 30 +++++++++++++----------- templates/index.html | 53 ++++++++++++++++++++++++++++-------------- 5 files changed, 59 insertions(+), 34 deletions(-) rename tasks.db => foods.db (85%) diff --git a/flake.nix b/flake.nix index f70093f..c98584e 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,8 @@ pkgs.rust-analyzer pkgs.clippy pkgs.sqlite + pkgs.superhtml + pkgs.vscode-langservers-extracted ]; }; } diff --git a/tasks.db b/foods.db similarity index 85% rename from tasks.db rename to foods.db index 768836bc1bac7425ecc863dd3c9c65f437a854e2..5ad494afa329b061886f94d9f8af5207b6e393c7 100644 GIT binary patch literal 8192 zcmWFz^vNtqRY=P(%1ta$FlG>7U}R))P*7lCU|?ooU|?cE07eD|1{MUD0mMh*Vr4Qj z=v5W+GB7YO@_l3A`-WA`sNiS_jE2By2#kinXb6mkz-S1JhQMeDjE2By2#kinXb8|K z1e(|x*~LXg8Ji1B5|eUL)AI9EK$yun$kj2#RUyRD$;VXzB%+|frJ$gokeQ<3=@;Va z?i!>J5aj9W7!;}C?HZ{AmMh3FD#^^xQwVX52vP9!4^i+7_3?p7kaB1@L zEo0#0EobA8;Md|8=H1Nqkhh$#gwLLTHyK51;HhUmlS2EW+dj6WTvMUE4ZiT z9^O-&s-O{GT2z&qlc%HLo0wUwkXn+gry0O3%)-tfF3QLV(d(a7ToS;{q{7S2AZp9V z!C|Nn;uBSxoSj;vqu`OBmzfUIT$G!dlbDh!BFoLrAg#{C$ziB(1hUvICpEJ;IYZwK zL^7N(;9_SG4Q6Bn8{(E)Qlg;YR9aF3GRm*CxHt*QK0GZ4;uZ~NV-9u(@kmBa4zNG` zGLth(6pFF?Mn@q%H9J2!qr}L7ot;5E5NwTeX#oLEMfn+$%=}FZ)?_9N16E|qoN^LN zO44D$8=RPvSON;4y!8B>6o{X=m_?b{8ARp5escBkNzKeFPRvcslha{hXOMPf;^Z{c zHvxrRKz>1Teo>x|LQ#H(f`+YOa%q8rdumBhW=g6i!wC&Wb_Qu%kRKr-4U$RCOi9)E zD@_5%C^RrqnE9VG2%-8-fRCL)QV<-M!6n&xu9@CKJnRgTq974d1BKk2;Ka0&00u2i tb_QujuoYkj`DW%MXXq$+<)>$q7M18I1ePWiWrICs1DeVgLA38Vn-*aPOE8oP1FwI62Ms{&gQN||klEkE( z)RM&FY!GI04svx2aa9O$bn, + foods: Vec, } #[derive(Debug, Clone, PartialEq)] -struct Task { +struct Food { id: i32, - name: String, - worth: f32, - times_completed: i32, + portion: String, + name: String, + kc_per_serving: i32, + target_servings: i32, + actual_servings: i32, } #[tokio::main] async fn main() { - let db_connecion_str = "./tasks.db".to_string(); + let db_connecion_str = "./foods.db".to_string(); let conn = Connection::open(db_connecion_str).unwrap(); conn.execute(include_str!("create_tables.sql"), ()).unwrap(); let conn = Arc::new(Mutex::new(conn)); @@ -36,16 +38,18 @@ async fn root( State(conn): State>> ) -> Html { let conn = conn.lock().unwrap(); - let mut stmt = conn.prepare("SELECT id, name, worth, times_completed FROM task").unwrap(); - let tasks = stmt.query_map((), |row| { - Ok(Task { + let mut stmt = conn.prepare("SELECT id, portion, name, kc_per_serving, target_servings, actual_servings FROM food").unwrap(); + let foods = stmt.query_map((), |row| { + Ok(Food { id: row.get(0).unwrap(), - name: row.get(1).unwrap(), - worth: row.get(2).unwrap(), - times_completed: row.get(3).unwrap(), + portion: row.get(1).unwrap(), + name: row.get(2).unwrap(), + kc_per_serving: row.get(3).unwrap(), + target_servings: row.get(4).unwrap(), + actual_servings: row.get(5).unwrap(), }) }).unwrap().collect::>().unwrap(); - let index = IndexTemplate {tasks}; + let index = IndexTemplate {foods}; Html( index.render().unwrap() ) diff --git a/templates/index.html b/templates/index.html index ca97d97..ee967bd 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,21 +1,38 @@ - - - - - Task Counter - - -
-

Task Counter!

-
-
-
    - {% for task in tasks %} -
  • {{ task.name }}
  • + + + + + + Food Tracker + + + +
    + + + + + + + + {% for food in foods %} + + + + + + {% endfor %} - - - - +
    PortionLebensmittelkc.Servings (target)
    {{ food.portion }}{{ food.name }}{{ food.kc_per_serving }} + + food.target_servings %}style="accent-color: red;"{% endif %}> + {{ food.actual_servings }}/{{ food.target_servings }} + + +
    +
    + + + \ No newline at end of file