different colors for different foods!

This commit is contained in:
Khaïs COLIN 2025-10-19 14:33:32 +02:00
parent 5cf4a12eae
commit e47b9810d2
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
5 changed files with 9 additions and 5 deletions

BIN
foods.db

Binary file not shown.

View file

@ -4,5 +4,6 @@ CREATE TABLE IF NOT EXISTS food (
name TEXT NOT NULL,
kc_per_serving INTEGER NOT NULL DEFAULT 0,
target_servings INTEGER NOT NULL DEFAULT 1,
actual_servings INTEGER NOT NULL DEFAULT 0
actual_servings INTEGER NOT NULL DEFAULT 0,
color TEXT NOT NULL DEFAULT 'white'
);

View file

@ -31,6 +31,7 @@ struct Food {
kc_per_serving: i32,
target_servings: i32,
actual_servings: i32,
color: String,
}
#[tokio::main]
@ -55,7 +56,7 @@ fn get_foods(conn: &Arc<Mutex<Connection>>) -> Vec<Food> {
let conn = conn.lock().unwrap();
let mut stmt = conn
.prepare(
"SELECT id, portion, name, kc_per_serving, target_servings, actual_servings FROM food",
"SELECT id, portion, name, kc_per_serving, target_servings, actual_servings, color FROM food",
)
.unwrap();
let foods = stmt
@ -67,6 +68,7 @@ fn get_foods(conn: &Arc<Mutex<Connection>>) -> Vec<Food> {
kc_per_serving: row.get(3).unwrap(),
target_servings: row.get(4).unwrap(),
actual_servings: row.get(5).unwrap(),
color: row.get(6).unwrap(),
})
})
.unwrap()
@ -99,7 +101,7 @@ fn do_increase(conn: &Arc<Mutex<Connection>>, id: i32) {
fn get_food(conn: &Arc<Mutex<Connection>>, id: i32) -> Food {
let conn = conn.lock().unwrap();
let mut stmt = conn.prepare("SELECT id, portion, name, kc_per_serving, target_servings, actual_servings FROM food WHERE id = ?1").unwrap();
let mut stmt = conn.prepare("SELECT id, portion, name, kc_per_serving, target_servings, actual_servings, color FROM food WHERE id = ?1").unwrap();
let food = stmt
.query_one((id,), |row| {
Ok(Food {
@ -109,6 +111,7 @@ fn get_food(conn: &Arc<Mutex<Connection>>, id: i32) -> Food {
kc_per_serving: row.get(3).unwrap(),
target_servings: row.get(4).unwrap(),
actual_servings: row.get(5).unwrap(),
color: row.get(6).unwrap(),
})
})
.unwrap();

View file

@ -1,4 +1,4 @@
<div style="border: 1px solid black; margin: 1em; padding: 1em;" id="food-{{ food.id }}">
<div style="border: 1px solid black; margin: 1em; padding: 1em; background: {{ food.color }};" id="food-{{ food.id }}">
<div style="text-align: center;">
<p>
<b>{{ food.name }}</b>

View file

@ -1,3 +1,3 @@
<div style="background-color: lightblue; margin: 1em;" id="sum" hx-swap-oob="true">
<div style="background-color: #a8c8a6; margin: 1em;" id="sum" hx-swap-oob="true">
<b style="font-size: 24px; padding: 1em;">Total: {{ sum }} kc.</b>
</div>