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
+
+