From: Greg Burri Date: Wed, 15 Jan 2025 19:30:19 +0000 (+0100) Subject: Add some fields to recipe view X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=afd42ba1d01da1e9dd69461ec29d9e428a0279f6;p=recipes.git Add some fields to recipe view --- diff --git a/backend/.sass-cache/d70ab564c432d2c06df1c9e8f54ea9071c59f25f/style.scssc b/backend/.sass-cache/d70ab564c432d2c06df1c9e8f54ea9071c59f25f/style.scssc new file mode 100644 index 0000000..2675380 Binary files /dev/null and b/backend/.sass-cache/d70ab564c432d2c06df1c9e8f54ea9071c59f25f/style.scssc differ diff --git a/backend/src/data/db/recipe.rs b/backend/src/data/db/recipe.rs index 0e41b8f..f474220 100644 --- a/backend/src/data/db/recipe.rs +++ b/backend/src/data/db/recipe.rs @@ -172,7 +172,7 @@ WHERE [Ingredient].[id] = $1 AND [user_id] = $2 .map_err(DBError::from) } - pub async fn get_recipe(&self, id: i64, with_groups: bool) -> Result> { + pub async fn get_recipe(&self, id: i64, complete: bool) -> Result> { match sqlx::query_as::<_, model::Recipe>( r#" SELECT @@ -186,7 +186,8 @@ FROM [Recipe] WHERE [id] = $1 .fetch_optional(&self.pool) .await? { - Some(mut recipe) if with_groups => { + Some(mut recipe) if complete => { + recipe.tags = self.get_recipes_tags(id).await?; recipe.groups = self.get_groups(id).await?; Ok(Some(recipe)) } diff --git a/backend/src/data/model.rs b/backend/src/data/model.rs index c1aed25..a0aff3b 100644 --- a/backend/src/data/model.rs +++ b/backend/src/data/model.rs @@ -32,6 +32,9 @@ pub struct Recipe { pub servings: Option, pub is_published: bool, + #[sqlx(skip)] + pub tags: Vec, + #[sqlx(skip)] pub groups: Vec, } diff --git a/backend/src/translation.rs b/backend/src/translation.rs index 7e85874..157a707 100644 --- a/backend/src/translation.rs +++ b/backend/src/translation.rs @@ -107,6 +107,11 @@ pub enum Sentence { RecipeIngredientQuantity, RecipeIngredientUnit, RecipeIngredientComment, + + // View Recipe. + RecipeOneServing, + RecipeSomeServings, + RecipeEstimatedTimeMinAbbreviation, } pub const DEFAULT_LANGUAGE_CODE: &str = "en"; diff --git a/backend/templates/recipe_view.html b/backend/templates/recipe_view.html index 7a5f7a6..926aa91 100644 --- a/backend/templates/recipe_view.html +++ b/backend/templates/recipe_view.html @@ -9,6 +9,31 @@ Edit {% endif %} +
+ {% for tag in recipe.tags %} + {{ tag }} + {% endfor %} +
+ + {% match recipe.servings %} + {% when Some(servings) %} + + {% if *servings == 1 %} + {{ tr.t(Sentence::RecipeOneServing) }} + {% else %} + {{ tr.tp(Sentence::RecipeSomeServings, [Box::new(**servings)]) }} + {% endif %} + + {% else %} + {% endmatch %} + + + {% match recipe.estimated_time %} + {% when Some(time) %} + {{ time +}} {{+ tr.t(Sentence::RecipeEstimatedTimeMinAbbreviation) }} + {% else %} + {% endmatch %} + {% if !recipe.description.is_empty() %}
{{ recipe.description.clone() }} diff --git a/backend/translation.ron b/backend/translation.ron index 8638f71..dc02b19 100644 --- a/backend/translation.ron +++ b/backend/translation.ron @@ -94,6 +94,10 @@ (RecipeIngredientQuantity, "Quantity"), (RecipeIngredientUnit, "Unit"), (RecipeIngredientComment, "Comment"), + + (RecipeOneServing, "1 serving"), + (RecipeSomeServings, "{} servings"), + (RecipeEstimatedTimeMinAbbreviation, "min"), ] ), ( @@ -191,6 +195,10 @@ (RecipeIngredientQuantity, "Quantité"), (RecipeIngredientUnit, "Unité"), (RecipeIngredientComment, "Commentaire"), + + (RecipeOneServing, "pour 1 personne"), + (RecipeSomeServings, "pour {} personnes"), + (RecipeEstimatedTimeMinAbbreviation, "min"), ] ) ] \ No newline at end of file