From 248700778f238c1ce3c2122c431fdffc5cc41d2d Mon Sep 17 00:00:00 2001 From: Dan Elbert Date: Sat, 14 Apr 2018 15:04:08 -0500 Subject: [PATCH] show log --- app/javascript/components/AppDateTime.vue | 11 ++++- app/javascript/components/LogShow.vue | 55 ++++++++++++++++++++++- app/javascript/components/RecipeShow.vue | 5 --- app/javascript/components/TheLog.vue | 39 +++++++++++++++- app/javascript/components/TheLogList.vue | 2 +- app/javascript/components/TheRecipe.vue | 5 +++ app/javascript/lib/Api.js | 4 ++ app/views/logs/show.json.jbuilder | 6 +++ app/views/recipes/_recipe.json.jbuilder | 32 +++++++++++++ app/views/recipes/show.json.jbuilder | 31 +------------ 10 files changed, 151 insertions(+), 39 deletions(-) create mode 100644 app/views/logs/show.json.jbuilder create mode 100644 app/views/recipes/_recipe.json.jbuilder diff --git a/app/javascript/components/AppDateTime.vue b/app/javascript/components/AppDateTime.vue index ba189f9..c118690 100644 --- a/app/javascript/components/AppDateTime.vue +++ b/app/javascript/components/AppDateTime.vue @@ -1,5 +1,8 @@ diff --git a/app/javascript/components/RecipeShow.vue b/app/javascript/components/RecipeShow.vue index 0204c4b..c7ae9e4 100644 --- a/app/javascript/components/RecipeShow.vue +++ b/app/javascript/components/RecipeShow.vue @@ -4,11 +4,6 @@ Loading...
-

{{ recipe.name }}

-
- {{tag}} -
-
{{ recipe.total_time}} ({{recipe.active_time}}) diff --git a/app/javascript/components/TheLog.vue b/app/javascript/components/TheLog.vue index b49d99e..6251bf8 100644 --- a/app/javascript/components/TheLog.vue +++ b/app/javascript/components/TheLog.vue @@ -1,11 +1,48 @@ diff --git a/app/javascript/components/TheLogList.vue b/app/javascript/components/TheLogList.vue index 5009512..ec4bd3b 100644 --- a/app/javascript/components/TheLogList.vue +++ b/app/javascript/components/TheLogList.vue @@ -13,7 +13,7 @@ - {{l.recipe.name}} + {{l.recipe.name}} {{l.notes}} diff --git a/app/javascript/components/TheRecipe.vue b/app/javascript/components/TheRecipe.vue index e3b802d..fb99aa9 100644 --- a/app/javascript/components/TheRecipe.vue +++ b/app/javascript/components/TheRecipe.vue @@ -4,6 +4,11 @@ Loading...
+

{{ recipe.name }}

+
+ {{tag}} +
+
diff --git a/app/javascript/lib/Api.js b/app/javascript/lib/Api.js index 621576c..a3b7f9f 100644 --- a/app/javascript/lib/Api.js +++ b/app/javascript/lib/Api.js @@ -282,6 +282,10 @@ class Api { return this.get("/logs", params); } + getLog(id) { + return this.get("/logs/" + id); + } + buildLogParams(log) { const recParams = this.buildRecipeParams(log.recipe); diff --git a/app/views/logs/show.json.jbuilder b/app/views/logs/show.json.jbuilder new file mode 100644 index 0000000..4498db8 --- /dev/null +++ b/app/views/logs/show.json.jbuilder @@ -0,0 +1,6 @@ + +json.extract! @log, :id, :date, :rating, :notes + +json.recipe do + json.partial! 'recipes/recipe', recipe: @log.recipe +end \ No newline at end of file diff --git a/app/views/recipes/_recipe.json.jbuilder b/app/views/recipes/_recipe.json.jbuilder new file mode 100644 index 0000000..5264a39 --- /dev/null +++ b/app/views/recipes/_recipe.json.jbuilder @@ -0,0 +1,32 @@ + + +json.extract! recipe, :id, :name, :rating, :yields, :total_time, :active_time, :created_at, :updated_at, :step_text + +json.rendered_steps MarkdownProcessor.render(recipe.step_text) + +json.tags recipe.tag_names + +json.ingredients recipe.recipe_ingredients do |ri| + json.extract! ri, :id, :ingredient_id, :display_name, :name, :quantity, :units, :preparation, :sort_order + + json.ingredient do + if ri.ingredient.nil? + json.null! + else + json.extract! ri.ingredient, :id, :name, :density, :notes + end + end + + json._destroy false +end + +json.nutrition_data do + json.errors recipe.nutrition_data.errors + + json.nutrients NutritionData::NUTRIENTS.select { |_, v| v.present? } do |name, label| + json.name name + json.label label + json.value recipe.nutrition_data.send(name) + end + +end \ No newline at end of file diff --git a/app/views/recipes/show.json.jbuilder b/app/views/recipes/show.json.jbuilder index af16b43..084c7fe 100644 --- a/app/views/recipes/show.json.jbuilder +++ b/app/views/recipes/show.json.jbuilder @@ -1,34 +1,5 @@ json.cache_root! [@recipe] do - json.extract! @recipe, :id, :name, :rating, :yields, :total_time, :active_time, :created_at, :updated_at, :step_text - - json.rendered_steps MarkdownProcessor.render(@recipe.step_text) - - json.tags @recipe.tag_names - - json.ingredients @recipe.recipe_ingredients do |ri| - json.extract! ri, :id, :ingredient_id, :display_name, :name, :quantity, :units, :preparation, :sort_order - - json.ingredient do - if ri.ingredient.nil? - json.null! - else - json.extract! ri.ingredient, :id, :name, :density, :notes - end - end - - json._destroy false - end - - json.nutrition_data do - json.errors @recipe.nutrition_data.errors - - json.nutrients NutritionData::NUTRIENTS.select { |_, v| v.present? } do |name, label| - json.name name - json.label label - json.value @recipe.nutrition_data.send(name) - end - - end + json.partial! 'recipe', recipe: @recipe end