From 3ca786281db38016a7fee3b0b0fd06cf13282220 Mon Sep 17 00:00:00 2001 From: Dan Elbert Date: Sat, 30 Jan 2016 21:20:15 -0600 Subject: [PATCH] Added about page; fixed bulk editing --- app/assets/javascripts/recipe_editor.js | 48 +++++++++++++++---- app/controllers/home_controller.rb | 5 ++ app/helpers/application_helper.rb | 3 +- app/models/recipe_ingredient.rb | 1 - app/views/home/about.html.erb | 24 ++++++++++ app/views/layouts/application.html.erb | 18 +++---- app/views/recipes/_form.html.erb | 4 ++ .../recipes/editor/_bulk_step_dialog.html.erb | 2 +- config/routes.rb | 2 + 9 files changed, 85 insertions(+), 22 deletions(-) create mode 100644 app/controllers/home_controller.rb create mode 100644 app/views/home/about.html.erb diff --git a/app/assets/javascripts/recipe_editor.js b/app/assets/javascripts/recipe_editor.js index 9db85b9..f39dd74 100644 --- a/app/assets/javascripts/recipe_editor.js +++ b/app/assets/javascripts/recipe_editor.js @@ -102,12 +102,12 @@ function addIngredient(item) { $("#ingredient-list").one("cocoon:before-insert", function(e, $container) { var $ingredientId = $container.find("input.ingredient_id"); - var $name = $container.find("input.ingredient-typeahead.tt-input"); + var $name = $container.find("input.ingredient-typeahead"); var $quantity = $container.find("input.quantity"); var $units = $container.find("input.units"); var $preparation = $container.find("input.preparation"); - $name.typeahead("val", item.name); + $name.val(item.name); $ingredientId.val(item.ingredient_id); $units.val(item.units); $quantity.val(item.quantity); @@ -143,6 +143,19 @@ $("#addStepButton").trigger("click"); } + function getSteps() { + var data = []; + $("#step-list .step-editor").each(function() { + var $container = $(this); + + var $step = $container.find("textarea.step"); + + data.push($step.val()); + }); + + return data; + } + $(document).on("ready page:load", function() { var $ingredientList = $("#ingredient-list"); @@ -160,6 +173,7 @@ initializeStepEditor(item); }) .on("cocoon:after-remove", function(e, item) { + item.detach().appendTo("#deleted_steps"); reorder($(this)); }) .on('changed', 'input.sort_order', function() { @@ -177,6 +191,7 @@ initializeIngredientEditor(item, ingredientSearchEngine); }) .on("cocoon:after-remove", function(e, item) { + item.detach().appendTo("#deleted_ingredients"); reorder($ingredientList); }) .on("typeahead:change", function(evt, value) { @@ -340,6 +355,8 @@ var parsed = $bulkIngredientsModal.data("bulkData"); var x; + $("#ingredient-list").find(".remove-button").trigger("click"); + if (parsed && parsed.length) { for (x = 0; x < parsed.length; x++) { var item = parsed[x]; @@ -362,14 +379,7 @@ var $stepBulkList = $("#step_bulk_parsed_list"); autosize($stepBulkInput); - $bulkStepsModal - .on('show.bs.modal', function (event) { - $stepBulkInput.val(''); - $stepBulkList.empty(); - autosize.update($stepBulkInput); - }); - - $stepBulkInput.on('keyup', function() { + var parseBulkSteps = function() { var data = $stepBulkInput.val(); $stepBulkList.empty(); @@ -402,12 +412,30 @@ ); } } + }; + + $bulkStepsModal + .on('show.bs.modal', function (event) { + var data = getSteps(); + $stepBulkInput.val(data.join("\n\n")); + $stepBulkList.empty(); + + setTimeout(function() { + parseBulkSteps(); + autosize.update($stepBulkInput); + }, 250); + }); + + $stepBulkInput.on('keyup', function() { + parseBulkSteps(); }); $("#bulkStepAddSubmit").on("click", function() { var parsed = $bulkStepsModal.data("bulkData"); var x; + $("#step-list").find(".remove-button").trigger("click"); + if (parsed && parsed.length) { for (x = 0; x < parsed.length; x++) { var item = parsed[x]; diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..3dfb671 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,5 @@ +class HomeController < ApplicationController + def about + + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 24837eb..fc75be6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,7 +7,8 @@ module ApplicationHelper def nav_items [ nav_item('Recipes', recipes_path, 'recipes'), - nav_item('Ingredients', ingredients_path, 'ingredients') + nav_item('Ingredients', ingredients_path, 'ingredients'), + nav_item('About', about_path, 'home') ] end diff --git a/app/models/recipe_ingredient.rb b/app/models/recipe_ingredient.rb index febd103..fe87f53 100644 --- a/app/models/recipe_ingredient.rb +++ b/app/models/recipe_ingredient.rb @@ -4,7 +4,6 @@ class RecipeIngredient < ActiveRecord::Base belongs_to :recipe, inverse_of: :recipe_ingredients validates :sort_order, presence: true - validates :custom_density, density: true, allow_blank: true def name if self.ingredient_id.present? diff --git a/app/views/home/about.html.erb b/app/views/home/about.html.erb new file mode 100644 index 0000000..010aff2 --- /dev/null +++ b/app/views/home/about.html.erb @@ -0,0 +1,24 @@ +
+
+ + + +

+ A Recipe manager. Source available on GitHub. +

+ +

+ Parsley is released under the MIT License. All code © Dan Elbert 2016. +

+ +

+ Food data provided by:
+ + US Department of Agriculture, Agricultural Research Service, Nutrient Data Laboratory. USDA National Nutrient Database for Standard Reference, Release 28. Version Current: September 2015. Internet: http://www.ars.usda.gov/nea/bhnrc/ndl + +

+ +
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f2bacc8..f5845cd 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -50,15 +50,15 @@ - + + + + + + + + + diff --git a/app/views/recipes/_form.html.erb b/app/views/recipes/_form.html.erb index 7b24e02..be57edc 100644 --- a/app/views/recipes/_form.html.erb +++ b/app/views/recipes/_form.html.erb @@ -54,6 +54,8 @@ <% end %> +
+ <%= link_to_add_association 'Add Ingredient', f, :recipe_ingredients, partial: 'recipes/editor/ingredient', :'data-association-insertion-node' => '#ingredient-list', :'data-association-insertion-method' => 'append', class: 'btn btn-primary', id: 'addIngredientButton' %> @@ -65,6 +67,8 @@ <% end %> +
+ <%= link_to_add_association 'Add Step', f, :recipe_steps, partial: 'recipes/editor/step', :'data-association-insertion-node' => '#step-list', :'data-association-insertion-method' => 'append', class: 'btn btn-primary', id: 'addStepButton' %>

diff --git a/app/views/recipes/editor/_bulk_step_dialog.html.erb b/app/views/recipes/editor/_bulk_step_dialog.html.erb index 5d617d8..e407abb 100644 --- a/app/views/recipes/editor/_bulk_step_dialog.html.erb +++ b/app/views/recipes/editor/_bulk_step_dialog.html.erb @@ -18,7 +18,7 @@
- +
diff --git a/config/routes.rb b/config/routes.rb index 328cf0f..c41b35c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,8 @@ Rails.application.routes.draw do post '/login' => 'users#verify_login' get '/logout' => 'users#logout', as: :logout + get '/about' => 'home#about', as: :about + root 'recipes#index'
#