1
0

Extra nutrients are displayed in table cells

Fixed column widths with content ellipsizing
This commit is contained in:
cryptogopher
2019-10-31 15:28:32 +01:00
parent 6f9e8926d7
commit 2f0b34d3fe
3 changed files with 49 additions and 27 deletions

View File

@@ -19,21 +19,20 @@ class IngredientsController < ApplicationController
@ingredient.nutrients.new(ingredient: @ingredient)
ingredients = @project.ingredients.includes(:ref_unit, nutrients: [:quantity, :unit])
@header = @project.quantities.where(primary: true)
@nutrients = {}
@descriptions = {}
@primary_quantities = @project.quantities.where(primary: true)
@primary_nutrients = {}
@extra_nutrients = {}
ingredients.each do |i|
@nutrients[i] = {}
@descriptions[i] = []
@primary_nutrients[i] = {}
@extra_nutrients[i] = {}
i.nutrients.sort_by { |n| n.quantity.lft }.each do |n|
if @header.include?(n.quantity)
@nutrients[i][n.quantity_id] = "#{n.amount} [#{n.unit.shortname}]"
if @primary_quantities.include?(n.quantity)
@primary_nutrients[i][n.quantity_id] = "#{n.amount} [#{n.unit.shortname}]"
else
@descriptions[i] << "#{n.quantity.name}: #{n.amount} [#{n.unit.shortname}]"
@extra_nutrients[i][n.quantity.name] = "#{n.amount} [#{n.unit.shortname}]"
end
end
end
@descriptions.each { |i, v| @descriptions[i] = v.join(", ") }
end
def create