diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb index 9834e5d..eadc642 100644 --- a/app/controllers/ingredients_controller.rb +++ b/app/controllers/ingredients_controller.rb @@ -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 diff --git a/app/views/ingredients/nutrients.html.erb b/app/views/ingredients/nutrients.html.erb index 3f3dbf5..3832307 100644 --- a/app/views/ingredients/nutrients.html.erb +++ b/app/views/ingredients/nutrients.html.erb @@ -13,38 +13,54 @@ <%= render :partial => 'ingredients/form' %>

<%= t ".heading" %>

-<% if @nutrients.any? %> +<% if @primary_nutrients.any? %> - - <% @header.each do |q| %> - + + <% @primary_quantities.each do |q| %> + <% end %> - <% @nutrients.each do |i, values| %> - + <% @primary_nutrients.each do |i, values| %> + <% row_class = "ingredient #{'hidden' if i.hidden}" %> + - <% @header.each do |q| %> - + <% @primary_quantities.each do |q| %> + <% end %> - - - - - + <% @extra_nutrients[i].keys.each_slice(@primary_quantities.length) do |names| %> + + + <% names.each do |name| %> + + <% end %> + <% for index in names.length...@primary_quantities.length do %> + + <% end %> + + + <% names.each do |name| %> + <% title = %> + + <% end %> + + <% end %> <% end %>
<%= l(:field_name) %><%= q.name %><%= l(:field_name) %><%= q.name %>
<%= link_to '', '#', { - onclick: "$(this).closest('tr').next('tr').toggle(); $(this).toggleClass('icon-bullet-closed'); $(this).toggleClass('icon-bullet-open'); return false;", + onclick: "$(this).closest('tr').nextUntil('tr.primary', 'tr').toggle(); $(this).toggleClass('icon-bullet-closed'); $(this).toggleClass('icon-bullet-open'); return false;", class: "icon icon-bullet-closed" } %> <%= i.name %> <%= values[q.id] || '-' %> + <%= values[q.id] || '-' %> +
diff --git a/assets/stylesheets/body_tracking.css b/assets/stylesheets/body_tracking.css index 5b554f3..179683c 100644 --- a/assets/stylesheets/body_tracking.css +++ b/assets/stylesheets/body_tracking.css @@ -2,8 +2,15 @@ table.list tr.quantity.primary td.name {font-weight: bold;} table.list tr.ingredient.hidden {opacity: 0.4} table.list td.action, table.list td.value {text-align: right;} +table.list th, table.list td.action, -table.list td.name {white-space: nowrap;} +table.list td.name, +table.list td.value { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + max-width: 1px; +} .icon-move-left { background-image: url(../images/1leftarrow.png); } .icon-move-right { background-image: url(../images/1rightarrow.png); }