From 205a29ce77fc4b8d79a43dba8b206ed1e7880f98 Mon Sep 17 00:00:00 2001 From: Dan Elbert Date: Sat, 30 Jan 2016 15:49:17 -0600 Subject: [PATCH] Updated style; ingredient editor work --- app/assets/stylesheets/application.scss | 5 +- .../stylesheets/journal_custom_colors.scss | 2 + app/helpers/ingredients_helper.rb | 9 +++ app/models/ingredient.rb | 19 +++++ app/views/ingredients/_form.html.erb | 73 ++++++++++--------- app/views/ingredients/edit.html.erb | 2 +- .../ingredients/usda_food_search.html.erb | 16 +++- 7 files changed, 87 insertions(+), 39 deletions(-) create mode 100644 app/assets/stylesheets/journal_custom_colors.scss diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index fee1554..5fbeb62 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,9 +16,10 @@ */ @import "bootstrap-sprockets"; -@import "readable/_variables"; +@import "journal_custom_colors"; +@import "journal/_variables"; @import "bootstrap"; -@import "readable/_bootswatch"; +@import "journal/_bootswatch"; @import "typeahead-bootstrap"; @import "recipes"; diff --git a/app/assets/stylesheets/journal_custom_colors.scss b/app/assets/stylesheets/journal_custom_colors.scss new file mode 100644 index 0000000..eff77a8 --- /dev/null +++ b/app/assets/stylesheets/journal_custom_colors.scss @@ -0,0 +1,2 @@ + +$brand-primary: darken(#93C54B, 10%); \ No newline at end of file diff --git a/app/helpers/ingredients_helper.rb b/app/helpers/ingredients_helper.rb index dd54783..e2c8b6e 100644 --- a/app/helpers/ingredients_helper.rb +++ b/app/helpers/ingredients_helper.rb @@ -1,2 +1,11 @@ module IngredientsHelper + + def ndbn_button_class(ingredient) + if ingredient.ndbn.present? + 'btn btn-success' + else + 'btn btn-default' + end + end + end diff --git a/app/models/ingredient.rb b/app/models/ingredient.rb index bf15369..059797c 100644 --- a/app/models/ingredient.rb +++ b/app/models/ingredient.rb @@ -14,6 +14,25 @@ class Ingredient < ActiveRecord::Base end end + def ndbn=(value) + @usda_food = nil + super + end + + def usda_food + if self.ndbn.present? + @usda_food ||= UsdaFood.find_by_ndbn(self.ndbn) + else + nil + end + end + + def usda_food_name + if usda_food + usda_food.long_description + end + end + def set_usda_food(food) return unless food diff --git a/app/views/ingredients/_form.html.erb b/app/views/ingredients/_form.html.erb index 12ef671..238b5f2 100644 --- a/app/views/ingredients/_form.html.erb +++ b/app/views/ingredients/_form.html.erb @@ -17,57 +17,65 @@ <%= f.label :ndbn, "Nutrient Databank Number", class: 'control-label' %>
-
-

<%= @ingredient.ndbn ? UsdaFood.find_by_ndbn(@ingredient.ndbn).long_description : '' %>

+ <%= f.text_field :usda_food_name, class: 'form-control', readonly: true %>
-
- <%= f.label :density, class: 'control-label' %> - <%= f.text_field :density, class: 'form-control', disabled: has_ndbn %> -
-
<%= f.label :notes, class: 'control-label' %> <%= f.text_area :notes, class: 'form-control' %>
-
- Per 100 Grams +
+ <%= f.label :density, class: 'control-label' %> + <%= f.text_field :density, class: 'form-control', disabled: has_ndbn %> +
-
- <%= f.label :water, "Grams of Water", class: 'control-label' %> - <%= f.text_field :water, class: 'form-control', disabled: has_ndbn %> +
+
+

Per 100 grams

+
+
> -
- <%= f.label :protein, "Grams of Protein", class: 'control-label' %> - <%= f.text_field :protein, class: 'form-control', disabled: has_ndbn %> -
+
+ <%= f.label :water, "Grams of Water", class: 'control-label' %> + <%= f.text_field :water, class: 'form-control' %> +
-
- <%= f.label :lipids, "Grams of Fat", class: 'control-label' %> - <%= f.text_field :lipids, class: 'form-control', disabled: has_ndbn %> -
+
+ <%= f.label :protein, "Grams of Protein", class: 'control-label' %> + <%= f.text_field :protein, class: 'form-control' %> +
-
- <%= f.label :kcal, "Calories", class: 'control-label' %> - <%= f.text_field :kcal, class: 'form-control', disabled: has_ndbn %> -
+
+ <%= f.label :lipids, "Grams of Fat", class: 'control-label' %> + <%= f.text_field :lipids, class: 'form-control' %> +
-
- <%= f.label :fiber, "Grams of Fiber", class: 'control-label' %> - <%= f.text_field :fiber, class: 'form-control', disabled: has_ndbn %> -
+
+ <%= f.label :kcal, "Calories", class: 'control-label' %> + <%= f.text_field :kcal, class: 'form-control' %> +
-
- <%= f.label :sugar, "Grams of Sugar", class: 'control-label' %> - <%= f.text_field :sugar, class: 'form-control', disabled: has_ndbn %> +
+ <%= f.label :fiber, "Grams of Fiber", class: 'control-label' %> + <%= f.text_field :fiber, class: 'form-control' %> +
+ +
+ <%= f.label :sugar, "Grams of Sugar", class: 'control-label' %> + <%= f.text_field :sugar, class: 'form-control' %> +
+
-
+ + +
<%= f.submit class: 'btn btn-primary' %> @@ -94,7 +102,6 @@
diff --git a/app/views/ingredients/edit.html.erb b/app/views/ingredients/edit.html.erb index e600543..9e14d8a 100644 --- a/app/views/ingredients/edit.html.erb +++ b/app/views/ingredients/edit.html.erb @@ -5,7 +5,7 @@ <%= render 'form' %> - <%= link_to 'Back', ingredients_path, class: 'btn btn-primary' %> + <%= link_to 'Back', ingredients_path, class: 'btn btn-default' %> \ No newline at end of file diff --git a/app/views/ingredients/usda_food_search.html.erb b/app/views/ingredients/usda_food_search.html.erb index defbdaf..d8db16a 100644 --- a/app/views/ingredients/usda_food_search.html.erb +++ b/app/views/ingredients/usda_food_search.html.erb @@ -1,18 +1,28 @@ - +
+ + + + + + + <% @foods.each do |f| %> - - + + + + + <% end %>
per 100 grams
NDBN NameKCalCarbsSugar
<%= f.ndbn %><%= link_to f.long_description, '#', class: 'food_result', data: {ndbn: f.ndbn} %><%= f.ndbn %><%= link_to f.long_description, '#', class: 'food_result', data: {ndbn: f.ndbn} %><%= f.kcal %><%= f.carbohydrates %><%= f.sugar %>