From 6f213865f070fcd3487a2aa01f6dec211588b515 Mon Sep 17 00:00:00 2001 From: Dan Elbert Date: Sun, 15 Apr 2018 14:15:42 -0500 Subject: [PATCH] logs --- Gemfile | 2 +- app/controllers/logs_controller.rb | 6 +-- app/javascript/components/AppDatePicker.vue | 5 +- app/javascript/components/RecipeShow.vue | 6 +-- app/javascript/components/TheLogEditor.vue | 53 ++++++++++++++++++++- app/javascript/lib/Api.js | 11 +++-- app/models/log.rb | 2 +- 7 files changed, 69 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index 696cb58..c76c204 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'rails', '5.2.0.rc2' +gem 'rails', '5.2.0' gem 'pg', '~> 0.21.0' gem 'webpacker', '3.4.1' diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb index 8004977..bf50151 100644 --- a/app/controllers/logs_controller.rb +++ b/app/controllers/logs_controller.rb @@ -21,9 +21,9 @@ class LogsController < ApplicationController def update ensure_owner(@log) do if @log.update(log_params) - redirect_to logs_path, notice: 'Log Entry was successfully updated.' + render json: { success: true } else - render :edit + render json: @log.errors, status: :unprocessable_entity end end end @@ -61,7 +61,7 @@ class LogsController < ApplicationController private def set_log - @log = Log.find(params[:id]) + @log = Log.includes({recipe: {recipe_ingredients: {ingredient: :ingredient_units} }}).find(params[:id]) end def set_recipe diff --git a/app/javascript/components/AppDatePicker.vue b/app/javascript/components/AppDatePicker.vue index d0c0d9a..603b851 100644 --- a/app/javascript/components/AppDatePicker.vue +++ b/app/javascript/components/AppDatePicker.vue @@ -10,7 +10,7 @@ props: { value: { required: false, - type: Date + type: [Date, String] }, label: { @@ -22,7 +22,8 @@ computed: { stringValue() { - return DateTimeUtils.formatDateForEdit(this.value); + const d = DateTimeUtils.toDate(this.value); + return DateTimeUtils.formatDateForEdit(d); } }, diff --git a/app/javascript/components/RecipeShow.vue b/app/javascript/components/RecipeShow.vue index c7ae9e4..8ad661d 100644 --- a/app/javascript/components/RecipeShow.vue +++ b/app/javascript/components/RecipeShow.vue @@ -9,9 +9,9 @@ {{ recipe.total_time}} ({{recipe.active_time}}) -
-

Yields

-

{{recipe.yields}}

+
+

Yields

+

{{recipe.yields}}

diff --git a/app/javascript/components/TheLogEditor.vue b/app/javascript/components/TheLogEditor.vue index b49d99e..dc084fb 100644 --- a/app/javascript/components/TheLogEditor.vue +++ b/app/javascript/components/TheLogEditor.vue @@ -1,11 +1,62 @@ diff --git a/app/javascript/lib/Api.js b/app/javascript/lib/Api.js index a3b7f9f..50c4e13 100644 --- a/app/javascript/lib/Api.js +++ b/app/javascript/lib/Api.js @@ -289,10 +289,6 @@ class Api { buildLogParams(log) { const recParams = this.buildRecipeParams(log.recipe); - if (recParams.recipe && recParams.recipe.recipe_ingredients_attributes) { - recParams.recipe.recipe_ingredients_attributes.forEach(ri => ri.id = null); - } - return { log: { date: log.date, @@ -305,7 +301,12 @@ class Api { } postLog(log) { - return this.post("/recipes/" + log.original_recipe_id + "/logs/", this.buildLogParams(log)); + const params = this.buildLogParams(log); + const rec = params.log.recipe_attributes; + if (rec && rec.recipe_ingredients_attributes) { + rec.recipe_ingredients_attributes.forEach(ri => ri.id = null); + } + return this.post("/recipes/" + log.original_recipe_id + "/logs/", params); } patchLog(log) { diff --git a/app/models/log.rb b/app/models/log.rb index 21adfdf..cc086ad 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -1,6 +1,6 @@ class Log < ApplicationRecord - belongs_to :recipe + belongs_to :recipe, dependent: :destroy belongs_to :source_recipe, class_name: 'Recipe' belongs_to :user