From cc62ef10027d06706bf1cec385975d53869e0cdd Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Fri, 27 Dec 2019 22:40:07 +0100 Subject: [PATCH] Added Ingredient comment attribute Minor view updates --- app/controllers/ingredients_controller.rb | 2 ++ app/views/ingredients/_form.html.erb | 2 ++ app/views/ingredients/_list.html.erb | 10 ++++++---- app/views/ingredients/_list_nutrients.html.erb | 3 ++- app/views/measurements/_index.html.erb | 2 +- app/views/quantities/_index.html.erb | 2 +- app/views/sources/index.html.erb | 2 +- app/views/units/index.html.erb | 2 +- config/locales/en.yml | 5 +++-- db/migrate/001_create_schema.rb | 1 + 10 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb index cc980b2..642b39b 100644 --- a/app/controllers/ingredients_controller.rb +++ b/app/controllers/ingredients_controller.rb @@ -88,6 +88,7 @@ class IngredientsController < ApplicationController i_params = { name: r.delete('Name'), + comment: r.delete('Comment'), ref_amount: 100.0, ref_unit: units['g'], group: r.delete('Group') || :other, @@ -176,6 +177,7 @@ class IngredientsController < ApplicationController def ingredient_params params.require(:ingredient).permit( :name, + :comment, :ref_amount, :ref_unit_id, :group, diff --git a/app/views/ingredients/_form.html.erb b/app/views/ingredients/_form.html.erb index 8ebdfec..c0d766d 100644 --- a/app/views/ingredients/_form.html.erb +++ b/app/views/ingredients/_form.html.erb @@ -9,6 +9,8 @@

<%= f.text_field :name, size: 40, required: true %>

+

<%= f.text_area :comment, cols: 40, rows: 3, required: false, + style: "width: 100%;" %>

<%= f.number_field :ref_amount, size: 8, required: true, min: 0, label: :field_reference %> diff --git a/app/views/ingredients/_list.html.erb b/app/views/ingredients/_list.html.erb index a79b070..8568a62 100644 --- a/app/views/ingredients/_list.html.erb +++ b/app/views/ingredients/_list.html.erb @@ -5,18 +5,19 @@ - + + - + <% @ingredients.each do |i| %> <% next if i.new_record? %> - + - diff --git a/app/views/ingredients/_list_nutrients.html.erb b/app/views/ingredients/_list_nutrients.html.erb index 0fde3df..d6e6ca2 100644 --- a/app/views/ingredients/_list_nutrients.html.erb +++ b/app/views/ingredients/_list_nutrients.html.erb @@ -18,7 +18,8 @@ <% @nutrients.each do |i, values| %> <% row_class = "ingredient#{' hidden' if i.hidden} #{cycle('odd', 'even')}" %> - <% values.each do |*, value| %> diff --git a/app/views/measurements/_index.html.erb b/app/views/measurements/_index.html.erb index dc4d5bc..375160c 100644 --- a/app/views/measurements/_index.html.erb +++ b/app/views/measurements/_index.html.erb @@ -8,7 +8,7 @@ - + diff --git a/app/views/quantities/_index.html.erb b/app/views/quantities/_index.html.erb index 9a0c0cd..d80b7c1 100644 --- a/app/views/quantities/_index.html.erb +++ b/app/views/quantities/_index.html.erb @@ -10,7 +10,7 @@ - + diff --git a/app/views/sources/index.html.erb b/app/views/sources/index.html.erb index 261e500..60c5609 100644 --- a/app/views/sources/index.html.erb +++ b/app/views/sources/index.html.erb @@ -30,7 +30,7 @@ - + diff --git a/app/views/units/index.html.erb b/app/views/units/index.html.erb index c125803..7878c26 100644 --- a/app/views/units/index.html.erb +++ b/app/views/units/index.html.erb @@ -30,7 +30,7 @@ - + diff --git a/config/locales/en.yml b/config/locales/en.yml index f4377da..ab2d241 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -5,6 +5,7 @@ en: field_taken_at_date: 'Taken at' field_order: 'Order' field_action: 'Action' + field_comment: 'Comment' field_reference: 'Reference' field_group: 'Group' field_source: 'Source' @@ -78,8 +79,8 @@ en: import_hints: 'CSV file has to include header with column names. Recognized column names are: (1) ingredient attributes, case sensitive: - "Name" - required, "Reference" - defaults to 100[g], "Group" - defaults to "other", - "Source" - optional, "SourceIdent" - optional, + "Name" - required, "Comment" - optional, "Reference" - defaults to 100[g], + "Group" - defaults to "other", "Source" - optional, "SourceIdent" - optional, (2) quantities'' names with unit short name in square brackets. Sample header: "Name,Reference,Group,Proteins[g],Fats[g],Carbohydrates[g]". Sample data row: "Brussels,100[g],other,3.4,300[mg],9". diff --git a/db/migrate/001_create_schema.rb b/db/migrate/001_create_schema.rb index 67a2043..11f94fa 100644 --- a/db/migrate/001_create_schema.rb +++ b/db/migrate/001_create_schema.rb @@ -41,6 +41,7 @@ class CreateSchema < ActiveRecord::Migration create_table :ingredients do |t| t.references :project t.string :name + t.text :comment t.decimal :ref_amount, precision: 12, scale: 6 t.references :ref_unit t.integer :group
<%= l(:field_name) %><%= l(:field_name) %><%= l(:field_comment) %> <%= l(:field_reference) %> <%= l(:field_group) %> <%= l(:field_source) %><%= l(:field_action) %><%= l(:field_action) %>
+ <%= link_to '', toggle_ingredient_path(i), { remote: true, method: :post, @@ -24,13 +25,14 @@ } %> <%= i.name %> <%= i.comment %> <%= i.ref_amount %> [<%= i.ref_unit.shortname %>] <%= i.group %> <%= i.source.name if i.source.present? %> <%= ", #{i.source_ident}" if i.source_ident.present? %> + <%= delete_link ingredient_path(i), {remote: true, data: {}} %>
+ <%= i.name %> <%= l(:field_taken_at_date) %> <%= l(:field_name) %> <%= l(:field_source) %><%= l(:field_action) %><%= l(:field_action) %>
<%= l(:field_domain) %> <%= l(:field_description) %> <%= l(:field_formula) %><%= l(:field_action) %><%= l(:field_action) %>
<%= l(:field_name) %> <%= l(:field_description) %><%= l(:field_action) %><%= l(:field_action) %>
<%= l(:field_shortname) %> <%= l(:field_name) %><%= l(:field_action) %><%= l(:field_action) %>