1
0

Added nutrient view on ingredients index

Created custom plugin's stylesheet
This commit is contained in:
cryptogopher
2019-09-24 23:41:22 +02:00
parent 9664df4888
commit 0001b56ca6
9 changed files with 72 additions and 3 deletions

View File

@@ -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