Created common contextual menu for ingredient/nutrients views
Restored sidebar for nutrients view
This commit is contained in:
parent
67efb6c6bc
commit
c4e89def0a
@ -9,10 +9,31 @@ class IngredientsController < ApplicationController
|
|||||||
@ingredient = @project.ingredients.new
|
@ingredient = @project.ingredients.new
|
||||||
# passing attr for Nutrient after_initialize
|
# passing attr for Nutrient after_initialize
|
||||||
@ingredient.nutrients.new(ingredient: @ingredient)
|
@ingredient.nutrients.new(ingredient: @ingredient)
|
||||||
|
|
||||||
@ingredients = @project.ingredients.includes(:ref_unit, :source)
|
@ingredients = @project.ingredients.includes(:ref_unit, :source)
|
||||||
@ingredients << @ingredient
|
@ingredients << @ingredient
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def nutrients
|
||||||
|
@ingredient = @project.ingredients.new
|
||||||
|
@ingredient.nutrients.new(ingredient: @ingredient)
|
||||||
|
|
||||||
|
ingredients = @project.ingredients.includes(:ref_unit, nutrients: [:quantity, :unit])
|
||||||
|
@header = @project.quantities.where(primary: true)
|
||||||
|
@nutrients = Hash.new { |h,k| h[k] = {} }
|
||||||
|
@descriptions = Hash.new { |h,k| h[k] = [] }
|
||||||
|
ingredients.each do |i|
|
||||||
|
i.nutrients.sort_by { |n| n.quantity.lft }.each do |n|
|
||||||
|
if @header.include?(n.quantity)
|
||||||
|
@nutrients[i.name][n.quantity_id] = "#{n.amount} [#{n.unit.shortname}]"
|
||||||
|
else
|
||||||
|
@descriptions[i.name] << "#{n.quantity.name}: #{n.amount} [#{n.unit.shortname}]"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@descriptions.each { |k, v| @descriptions[k] = v.join(", ") }
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@ingredient = @project.ingredients.new(ingredient_params)
|
@ingredient = @project.ingredients.new(ingredient_params)
|
||||||
if @ingredient.save
|
if @ingredient.save
|
||||||
@ -138,23 +159,6 @@ class IngredientsController < ApplicationController
|
|||||||
redirect_to project_ingredients_url(@project)
|
redirect_to project_ingredients_url(@project)
|
||||||
end
|
end
|
||||||
|
|
||||||
def nutrients
|
|
||||||
ingredients = @project.ingredients.includes(:ref_unit, nutrients: [:quantity, :unit])
|
|
||||||
@header = @project.quantities.where(primary: true)
|
|
||||||
@nutrients = Hash.new { |h,k| h[k] = {} }
|
|
||||||
@descriptions = Hash.new { |h,k| h[k] = [] }
|
|
||||||
ingredients.each do |i|
|
|
||||||
i.nutrients.sort_by { |n| n.quantity.lft }.each do |n|
|
|
||||||
if @header.include?(n.quantity)
|
|
||||||
@nutrients[i.name][n.quantity_id] = "#{n.amount} [#{n.unit.shortname}]"
|
|
||||||
else
|
|
||||||
@descriptions[i.name] << "#{n.quantity.name}: #{n.amount} [#{n.unit.shortname}]"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@descriptions.each { |k, v| @descriptions[k] = v.join(", ") }
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def ingredient_params
|
def ingredient_params
|
||||||
|
6
app/views/ingredients/_contextual.html.erb
Normal file
6
app/views/ingredients/_contextual.html.erb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||||
|
<%= link_to t(".heading_import_ingredients"), '#', :class => 'icon icon-multiple',
|
||||||
|
:onclick => 'showAndScrollTo("import-ingredients", "filename"); return false;' %>
|
||||||
|
<%= link_to t(".heading_new_ingredient"), '#', :class => 'icon icon-add',
|
||||||
|
:onclick => 'showAndScrollTo("add-ingredient", "ingredient_name"); return false;' %>
|
||||||
|
<% end %>
|
@ -1,15 +1,24 @@
|
|||||||
<%= error_messages_for @ingredient %>
|
<div id="add-ingredient" <%= 'style=display:none;' if @ingredient.errors.empty? %>>
|
||||||
|
<h2><%= t ".heading_new_ingredient" %></h2>
|
||||||
|
|
||||||
<div class="box tabular">
|
<%= labelled_form_for @ingredient,
|
||||||
|
:url => project_ingredients_path(@project),
|
||||||
|
:html => {:id => 'ingredient-form'} do |f| %>
|
||||||
|
<%= error_messages_for @ingredient %>
|
||||||
|
|
||||||
|
<div class="box tabular">
|
||||||
<p><%= f.text_field :name, size: 40, required: true %></p>
|
<p><%= f.text_field :name, size: 40, required: true %></p>
|
||||||
<p>
|
<p>
|
||||||
<%= f.number_field :ref_amount, size: 8, required: true, min: 0, label: :field_reference %>
|
<%= f.number_field :ref_amount, size: 8, required: true, min: 0,
|
||||||
|
label: :field_reference %>
|
||||||
<%= f.select :ref_unit_id, unit_options, {label: '', required: true} %>
|
<%= f.select :ref_unit_id, unit_options, {label: '', required: true} %>
|
||||||
</p>
|
</p>
|
||||||
<p><%= f.select :group, group_options, required: true %></p>
|
<p><%= f.select :group, group_options, required: true %></p>
|
||||||
<div class="splitcontent">
|
<div class="splitcontent">
|
||||||
<div class="splitcontentleft">
|
<div class="splitcontentleft">
|
||||||
<p><%= f.select :source_id, source_options, required: false, include_blank: true %></p>
|
<p>
|
||||||
|
<%= f.select :source_id, source_options, required: false, include_blank: true %>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="splitcontentright">
|
<div class="splitcontentright">
|
||||||
<p><%= f.text_field :source_ident, size: 25, required: false %></p>
|
<p><%= f.text_field :source_ident, size: 25, required: false %></p>
|
||||||
@ -30,8 +39,15 @@
|
|||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<p><%= link_to t(".button_add_nutrient"), '#', :class => 'icon icon-add',
|
<p>
|
||||||
:onclick => 'addNutrient(); return false;' %></p>
|
<%= link_to t(".button_add_nutrient"), '#', :class => 'icon icon-add',
|
||||||
|
:onclick => 'addNutrient(); return false;' %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<%= submit_tag l(:button_create) %>
|
||||||
|
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-ingredient").hide()' %>
|
||||||
|
<% end %>
|
||||||
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= javascript_tag do %>
|
<%= javascript_tag do %>
|
||||||
|
20
app/views/ingredients/_import.html.erb
Normal file
20
app/views/ingredients/_import.html.erb
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<div id="import-ingredients" style="display:none;">
|
||||||
|
<h2><%= t ".heading_import_ingredients" %></h2>
|
||||||
|
|
||||||
|
<%= form_tag import_project_ingredients_path(@project),
|
||||||
|
:multipart => true,
|
||||||
|
:id => 'import-form' do %>
|
||||||
|
<div class="box tabular">
|
||||||
|
<p>
|
||||||
|
<label><%= t ".label_import_select_csv_file" %></label>
|
||||||
|
<%= file_field_tag 'file' %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= t ".import_hints" %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<%= submit_tag l(:button_import) %>
|
||||||
|
<%= link_to l(:button_cancel), "#", :onclick => '$("#import-ingredients").hide()' %>
|
||||||
|
<% end %>
|
||||||
|
<hr>
|
||||||
|
</div>
|
@ -5,47 +5,12 @@
|
|||||||
<div class="contextual">
|
<div class="contextual">
|
||||||
<%= link_to t(".heading_nutrient_view"), nutrients_project_ingredients_path(@project),
|
<%= link_to t(".heading_nutrient_view"), nutrients_project_ingredients_path(@project),
|
||||||
:class => 'icon icon-stats' %>
|
:class => 'icon icon-stats' %>
|
||||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
<%= render :partial => 'ingredients/contextual' %>
|
||||||
<%= link_to t(".heading_import_ingredients"), '#', :class => 'icon icon-multiple',
|
|
||||||
:onclick => 'showAndScrollTo("import-ingredients", "filename"); return false;' %>
|
|
||||||
<%= link_to t(".heading_new_ingredient"), '#', :class => 'icon icon-add',
|
|
||||||
:onclick => 'showAndScrollTo("add-ingredient", "ingredient_name"); return false;' %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="import-ingredients" style="display:none;">
|
<%= render :partial => 'ingredients/import' %>
|
||||||
<h2><%= t ".heading_import_ingredients" %></h2>
|
|
||||||
|
|
||||||
<%= form_tag import_project_ingredients_path(@project),
|
<%= render :partial => 'ingredients/form' %>
|
||||||
:multipart => true,
|
|
||||||
:id => 'import-form' do %>
|
|
||||||
<div class="box tabular">
|
|
||||||
<p>
|
|
||||||
<label><%= t ".label_import_select_csv_file" %></label>
|
|
||||||
<%= file_field_tag 'file' %>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<%= t ".import_hints" %>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<%= submit_tag l(:button_import) %>
|
|
||||||
<%= link_to l(:button_cancel), "#", :onclick => '$("#import-ingredients").hide()' %>
|
|
||||||
<% end %>
|
|
||||||
<hr>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="add-ingredient" <%= 'style=display:none;' if @ingredient.errors.empty? %>>
|
|
||||||
<h2><%= t ".heading_new_ingredient" %></h2>
|
|
||||||
|
|
||||||
<%= labelled_form_for @ingredient,
|
|
||||||
:url => project_ingredients_path(@project),
|
|
||||||
:html => {:id => 'ingredient-form'} do |f| %>
|
|
||||||
<%= render :partial => 'ingredients/form', :locals => { :f => f } %>
|
|
||||||
<%= submit_tag l(:button_create) %>
|
|
||||||
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-ingredient").hide()' %>
|
|
||||||
<% end %>
|
|
||||||
<hr>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h2><%= t ".heading" %></h2>
|
<h2><%= t ".heading" %></h2>
|
||||||
<div id='ingredients'>
|
<div id='ingredients'>
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
<% content_for :sidebar do %>
|
<% content_for :sidebar do %>
|
||||||
<%#= render :partial => 'body_trackers/sidebar' %>
|
<%= render :partial => 'body_trackers/sidebar' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="contextual">
|
<div class="contextual">
|
||||||
<%= link_to t(".heading_ingredient_list"), project_ingredients_path(@project),
|
<%= link_to t(".heading_ingredient_list"), project_ingredients_path(@project),
|
||||||
:class => 'icon icon-list' %>
|
:class => 'icon icon-list' %>
|
||||||
|
<%= render :partial => 'ingredients/contextual' %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<%= render :partial => 'ingredients/import' %>
|
||||||
|
|
||||||
|
<%= render :partial => 'ingredients/form' %>
|
||||||
|
|
||||||
<h2><%= t ".heading" %></h2>
|
<h2><%= t ".heading" %></h2>
|
||||||
<% if @nutrients.any? %>
|
<% if @nutrients.any? %>
|
||||||
<table class="nutrients list">
|
<table class="nutrients list">
|
||||||
|
@ -39,11 +39,11 @@ en:
|
|||||||
link_defaults: 'Load defaults'
|
link_defaults: 'Load defaults'
|
||||||
confirm_defaults: 'This will load default quantities and units. Continue?'
|
confirm_defaults: 'This will load default quantities and units. Continue?'
|
||||||
ingredients:
|
ingredients:
|
||||||
index:
|
contextual:
|
||||||
heading: 'Ingredients'
|
|
||||||
heading_nutrient_view: 'Nutrient view'
|
|
||||||
heading_import_ingredients: 'Import'
|
heading_import_ingredients: 'Import'
|
||||||
heading_new_ingredient: 'New ingredient'
|
heading_new_ingredient: 'New ingredient'
|
||||||
|
import:
|
||||||
|
heading_import_ingredients: 'Import'
|
||||||
label_import_select_csv_file: 'Select CSV file'
|
label_import_select_csv_file: 'Select CSV file'
|
||||||
import_hints: 'CSV file has to include header with column names. Recognized column
|
import_hints: 'CSV file has to include header with column names. Recognized column
|
||||||
names are:
|
names are:
|
||||||
@ -54,15 +54,19 @@ en:
|
|||||||
Sample header: "Name,Reference,Group,Proteins[g],Fats[g],Carbohydrates[g]".
|
Sample header: "Name,Reference,Group,Proteins[g],Fats[g],Carbohydrates[g]".
|
||||||
Sample data row: "Brussels,100[g],other,3.4,300[mg],9".
|
Sample data row: "Brussels,100[g],other,3.4,300[mg],9".
|
||||||
Unit given in data row has precedence over that specified in header.'
|
Unit given in data row has precedence over that specified in header.'
|
||||||
nutrients:
|
|
||||||
heading: 'Nutrients'
|
|
||||||
heading_ingredient_list: 'Ingredient list'
|
|
||||||
form:
|
form:
|
||||||
|
heading_new_ingredient: 'New ingredient'
|
||||||
button_add_nutrient: 'Add nutrient'
|
button_add_nutrient: 'Add nutrient'
|
||||||
button_delete_nutrient: 'Delete'
|
button_delete_nutrient: 'Delete'
|
||||||
groups:
|
groups:
|
||||||
other: 'other'
|
other: 'other'
|
||||||
meat: 'meat'
|
meat: 'meat'
|
||||||
|
index:
|
||||||
|
heading: 'Ingredients'
|
||||||
|
heading_nutrient_view: 'Nutrient view'
|
||||||
|
nutrients:
|
||||||
|
heading: 'Nutrients'
|
||||||
|
heading_ingredient_list: 'Ingredient list'
|
||||||
sources:
|
sources:
|
||||||
index:
|
index:
|
||||||
heading: 'Data sources'
|
heading: 'Data sources'
|
||||||
|
Reference in New Issue
Block a user