-
-
-
+
+
+
@@ -66,6 +66,14 @@
} else {
return this.currentTaskList.name;
}
+ },
+
+ completedItemCount() {
+ return this.currentTaskList === null ? 0 : this.currentTaskList.task_items.filter(i => i.completed).length;
+ },
+
+ uncompletedItemCount() {
+ return this.currentTaskList === null ? 0 : this.currentTaskList.task_items.filter(i => !i.completed).length;
}
},
diff --git a/app/javascript/lib/Api.js b/app/javascript/lib/Api.js
index a1681b1..4c05040 100644
--- a/app/javascript/lib/Api.js
+++ b/app/javascript/lib/Api.js
@@ -205,10 +205,11 @@ class Api {
return this.get("/ingredients/search", params);
}
- getCalculate(input, output_unit, density) {
+ getCalculate(input, output_unit, ingredient_id, density) {
const params = {
input,
output_unit,
+ ingredient_id,
density
};
return this.get("/calculator/calculate", params);
diff --git a/app/javascript/styles/_transitions.scss b/app/javascript/styles/_transitions.scss
index cd9bc7f..8fc0edc 100644
--- a/app/javascript/styles/_transitions.scss
+++ b/app/javascript/styles/_transitions.scss
@@ -15,7 +15,8 @@
overflow: hidden;
}
-//.expand-enter,
-//.expand-leave-to {
-// height: 0;
-//}
\ No newline at end of file
+
+
+.list-item-move-move {
+ transition: transform 0.25s;
+}
\ No newline at end of file
diff --git a/app/models/food.rb b/app/models/food.rb
index 5e1f4bf..229c034 100644
--- a/app/models/food.rb
+++ b/app/models/food.rb
@@ -1,4 +1,4 @@
-class Food < ApplicationRecord
+class Food < Ingredient
include TokenizedLike
belongs_to :user
@@ -33,18 +33,10 @@ class Food < ApplicationRecord
self
end
- def nutrition_errors
- []
- end
-
def nutrition_unit
UnitConversion.parse('100 grams')
end
- def density?
- !density.nil?
- end
-
def ndbn=(value)
@usda_food = nil
super
diff --git a/app/models/ingredient.rb b/app/models/ingredient.rb
new file mode 100644
index 0000000..a91dcff
--- /dev/null
+++ b/app/models/ingredient.rb
@@ -0,0 +1,41 @@
+class Ingredient < ApplicationRecord
+ self.abstract_class = true
+
+ class << self
+
+ def find_by_ingredient_id(ingredient_id)
+ puts "looking up |#{ingredient_id}|"
+ case ingredient_id
+ when /^R(\d+)$/
+ puts 'rec'
+ Recipe.find($1)
+ when /^F(\d+)$/
+ puts 'food'
+ Food.find($1)
+ else
+ raise ActiveRecord::RecordNotFound
+ end
+ end
+
+ end
+
+ def ingredient_id
+ case self
+ when Recipe
+ "R#{id}"
+ when Food
+ "F#{id}"
+ else
+ raise 'Unknown ingredient'
+ end
+ end
+
+ def nutrition_errors
+ []
+ end
+
+ def density?
+ !self.density.nil?
+ end
+
+end
\ No newline at end of file
diff --git a/app/models/nutrition_data.rb b/app/models/nutrition_data.rb
index 8abbd19..39c9f23 100644
--- a/app/models/nutrition_data.rb
+++ b/app/models/nutrition_data.rb
@@ -50,7 +50,7 @@ class NutritionData
end
unless i.ingredient.nutrition_errors.empty?
- @errors << "#{i.name} has errors: #{i.ingredient.nutrition_errors.join(", ")}"
+ @errors << "#{i.name}: #{i.ingredient.nutrition_errors.join(", ")}"
end
missing = []
diff --git a/app/models/recipe.rb b/app/models/recipe.rb
index c5f21a0..afdfced 100644
--- a/app/models/recipe.rb
+++ b/app/models/recipe.rb
@@ -1,4 +1,4 @@
-class Recipe < ApplicationRecord
+class Recipe < Ingredient
include DefaultValues
include TokenizedLike
@@ -157,10 +157,6 @@ class Recipe < ApplicationRecord
end
end
- def density?
- !density.nil?
- end
-
def custom_units
arbitrary = self.yields_list.select { |y| !y.mass? && !y.volume? }
mass = self.yields_list.select { |y| y.mass? }
diff --git a/app/views/ingredients/search.json.jbuilder b/app/views/ingredients/search.json.jbuilder
index 9093115..ce8f998 100644
--- a/app/views/ingredients/search.json.jbuilder
+++ b/app/views/ingredients/search.json.jbuilder
@@ -1,15 +1,7 @@
json.array! @ingredients do |i|
- json.extract! i, :name
-
- case i
- when Recipe
- json.id "R#{i.id}"
- when Food
- json.id "F#{i.id}"
- else
- json.id nil
- end
+ json.extract! i, :ingredient_id, :name, :density
+ json.id i.ingredient_id
end
\ No newline at end of file
diff --git a/db/seeds.rb b/db/seeds.rb
index ef03f4d..bd2d91a 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -12,7 +12,7 @@ puts "Seeding..."
dan = User.create!({username: 'dan', full_name: 'Dan', email: 'dan.elbert@gmail.com', password: 'qwerty', password_confirmation: 'qwerty'})
-ingredients = {
+foods = {
water: {name: 'Water', density: '1 g/ml'},
butter: {name: 'Butter, Salted', ndbn: '01001'},
butter_sal: {name: 'Butter, Unsalted', density: '226 gram/cup'},
@@ -43,8 +43,8 @@ ingredients = {
}
-ingredients.each do |k, v|
- ingredients[k] = Food.create!({user_id: dan.id}.merge(v))
+foods.each do |k, v|
+ foods[k] = Food.create!({user_id: dan.id}.merge(v))
end
g = Recipe.create!({
@@ -69,19 +69,19 @@ bb = Recipe.create!({
bb.tag_names = ['beef', 'dinner', 'stirfry']
[
- {quantity: '1', units: 'pound', preparation: 'flank steak, skirt steak, hanger steak, or flap meat, cut into 1/4-inch thick strips', food: ingredients[:flank]},
- {quantity: '1/4', units: 'cup', preparation: 'divided', food: ingredients[:soy_sauce]},
- {quantity: '1/4', units: 'cup', preparation: 'divided', food: ingredients[:shaoxing]},
- {quantity: '2', units: 'teaspoons', preparation: '', food: ingredients[:cornstarch]},
- {quantity: '1/3', units: 'cup', preparation: '', food: ingredients[:stock]},
- {quantity: '1/4', units: 'cup', preparation: '', food: ingredients[:oyster_sauce]},
- {quantity: '1', units: 'tablespoon', preparation: '', food: ingredients[:sugar]},
- {quantity: '1', units: 'teaspoon', preparation: '', food: ingredients[:seasame_oil]},
- {quantity: '2', units: 'medium cloves', preparation: 'finely minced', food: ingredients[:garlic]},
+ {quantity: '1', units: 'pound', preparation: 'flank steak, skirt steak, hanger steak, or flap meat, cut into 1/4-inch thick strips', food: foods[:flank]},
+ {quantity: '1/4', units: 'cup', preparation: 'divided', food: foods[:soy_sauce]},
+ {quantity: '1/4', units: 'cup', preparation: 'divided', food: foods[:shaoxing]},
+ {quantity: '2', units: 'teaspoons', preparation: '', food: foods[:cornstarch]},
+ {quantity: '1/3', units: 'cup', preparation: '', food: foods[:stock]},
+ {quantity: '1/4', units: 'cup', preparation: '', food: foods[:oyster_sauce]},
+ {quantity: '1', units: 'tablespoon', preparation: '', food: foods[:sugar]},
+ {quantity: '1', units: 'teaspoon', preparation: '', food: foods[:seasame_oil]},
+ {quantity: '2', units: 'medium cloves', preparation: 'finely minced', food: foods[:garlic]},
{quantity: '2', units: 'teaspoons', preparation: 'finely minced', name: 'ginger root'},
{quantity: '3', units: '', preparation: 'whites finely sliced, greens cut into 1/2-inch segments, reserved separately', name: 'Scallions'},
- {quantity: '4', units: 'tablespoons', preparation: '', food: ingredients[:peanut_oil]},
- {quantity: '1', units: 'pound', preparation: '', food: ingredients[:broccoli]},
+ {quantity: '4', units: 'tablespoons', preparation: '', food: foods[:peanut_oil]},
+ {quantity: '1', units: 'pound', preparation: '', food: foods[:broccoli]},
].each_with_index do |ri, i|
RecipeIngredient.create!({recipe: bb, sort_order: i}.merge(ri))
end
diff --git a/lib/unit_conversion/unitwise_patch.rb b/lib/unit_conversion/unitwise_patch.rb
index 7f8ffe8..9266459 100644
--- a/lib/unit_conversion/unitwise_patch.rb
+++ b/lib/unit_conversion/unitwise_patch.rb
@@ -20,23 +20,26 @@ module Unitwise
def self.with_custom_units(unit_list, &block)
atoms = []
+ ret_val = nil
- unit_list.each do |u|
- atom = Unitwise::Atom.new(u)
- atom.validate!
- Unitwise::Atom.all.push(atom)
- atoms.push(atom)
+ begin
+ unit_list.each do |u|
+ atom = Unitwise::Atom.new(u)
+ atom.validate!
+ Unitwise::Atom.all.push(atom)
+ atoms.push(atom)
+ end
+ rem = Unitwise::Expression::Decomposer.send(:reset)
+
+ ret_val = block.call
+ ensure
+ atoms.each do |a|
+ idx = Unitwise::Atom.all.index { |b| b.equal?(a) }
+ Unitwise::Atom.all.delete_at(idx)
+ # Unitwise::Atom.all.pop
+ end
+ Unitwise::Expression::Decomposer.send(:reset, rem)
end
- rem = Unitwise::Expression::Decomposer.send(:reset)
-
- ret_val = block.call
-
- atoms.each do |a|
- idx = Unitwise::Atom.all.index { |b| b.equal?(a) }
- Unitwise::Atom.all.delete_at(idx)
- # Unitwise::Atom.all.pop
- end
- Unitwise::Expression::Decomposer.send(:reset, rem)
ret_val
end