Added nutrient view on ingredients index
Created custom plugin's stylesheet
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class IngredientsController < ApplicationController
|
||||
require 'csv'
|
||||
|
||||
before_action :find_project_by_project_id, only: [:index, :create, :import]
|
||||
before_action :find_project_by_project_id, only: [:index, :create, :import, :nutrients]
|
||||
before_action :find_ingredient, only: [:destroy]
|
||||
before_action :authorize
|
||||
|
||||
@@ -133,6 +133,23 @@ class IngredientsController < ApplicationController
|
||||
redirect_to project_ingredients_url(@project)
|
||||
end
|
||||
|
||||
def nutrients
|
||||
ingredients = @project.ingredients.includes(:ref_unit, nutrients: [:quantity, :unit])
|
||||
@header = @project.quantities.where(displayed: 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
|
||||
|
||||
def ingredient_params
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
<% end %>
|
||||
|
||||
<div class="contextual">
|
||||
<%= link_to t(".heading_nutrient_view"), nutrients_project_ingredients_path(@project),
|
||||
:class => 'icon icon-stats' %>
|
||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||
<%= link_to t(".heading_import_ingredients"), '#', :class => 'icon icon-file',
|
||||
<%= 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;' %>
|
||||
|
||||
34
app/views/ingredients/nutrients.html.erb
Normal file
34
app/views/ingredients/nutrients.html.erb
Normal file
@@ -0,0 +1,34 @@
|
||||
<% content_for :sidebar do %>
|
||||
<%= render :partial => 'body_trackers/sidebar' %>
|
||||
<% end %>
|
||||
|
||||
<div class="contextual">
|
||||
<%= link_to t(".heading_ingredient_list"), project_ingredients_path(@project),
|
||||
:class => 'icon icon-list' %>
|
||||
</div>
|
||||
|
||||
<h2><%= t ".heading" %></h2>
|
||||
<% if @nutrients.any? %>
|
||||
<table class="nutrients list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<% @header.each do |q| %>
|
||||
<th><%= q.name %></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @nutrients.each do |name, values| %>
|
||||
<tr class="ingredient">
|
||||
<td class="name"><%= name %></td>
|
||||
<% @header.each do |q| %>
|
||||
<td class="value"><%= values[q.id] || '-' %></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
3
app/views/layouts/_body_tracking.html.erb
Normal file
3
app/views/layouts/_body_tracking.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<% content_for :header_tags do %>
|
||||
<%= stylesheet_link_tag 'body_tracking', :plugin => 'body_tracking' %>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user