Extra nutrients are displayed in table cells
Fixed column widths with content ellipsizing
This commit is contained in:
parent
6f9e8926d7
commit
2f0b34d3fe
@ -19,21 +19,20 @@ class IngredientsController < ApplicationController
|
|||||||
@ingredient.nutrients.new(ingredient: @ingredient)
|
@ingredient.nutrients.new(ingredient: @ingredient)
|
||||||
|
|
||||||
ingredients = @project.ingredients.includes(:ref_unit, nutrients: [:quantity, :unit])
|
ingredients = @project.ingredients.includes(:ref_unit, nutrients: [:quantity, :unit])
|
||||||
@header = @project.quantities.where(primary: true)
|
@primary_quantities = @project.quantities.where(primary: true)
|
||||||
@nutrients = {}
|
@primary_nutrients = {}
|
||||||
@descriptions = {}
|
@extra_nutrients = {}
|
||||||
ingredients.each do |i|
|
ingredients.each do |i|
|
||||||
@nutrients[i] = {}
|
@primary_nutrients[i] = {}
|
||||||
@descriptions[i] = []
|
@extra_nutrients[i] = {}
|
||||||
i.nutrients.sort_by { |n| n.quantity.lft }.each do |n|
|
i.nutrients.sort_by { |n| n.quantity.lft }.each do |n|
|
||||||
if @header.include?(n.quantity)
|
if @primary_quantities.include?(n.quantity)
|
||||||
@nutrients[i][n.quantity_id] = "#{n.amount} [#{n.unit.shortname}]"
|
@primary_nutrients[i][n.quantity_id] = "#{n.amount} [#{n.unit.shortname}]"
|
||||||
else
|
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
|
end
|
||||||
end
|
end
|
||||||
@descriptions.each { |i, v| @descriptions[i] = v.join(", ") }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -13,38 +13,54 @@
|
|||||||
<%= render :partial => 'ingredients/form' %>
|
<%= render :partial => 'ingredients/form' %>
|
||||||
|
|
||||||
<h2><%= t ".heading" %></h2>
|
<h2><%= t ".heading" %></h2>
|
||||||
<% if @nutrients.any? %>
|
<% if @primary_nutrients.any? %>
|
||||||
<table class="nutrients list">
|
<table class="nutrients list">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= l(:field_name) %></th>
|
<th style="width:30%"><%= l(:field_name) %></th>
|
||||||
<% @header.each do |q| %>
|
<% @primary_quantities.each do |q| %>
|
||||||
<th><%= q.name %></th>
|
<th style="width:8%"><%= q.name %></th>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @nutrients.each do |i, values| %>
|
<% @primary_nutrients.each do |i, values| %>
|
||||||
<tr id="ingredient-<%= i.id %>" class="ingredient <%= 'hidden' if i.hidden %>">
|
<% row_class = "ingredient #{'hidden' if i.hidden}" %>
|
||||||
|
<tr id="ingredient-<%= i.id %>" class="primary <%= row_class %>">
|
||||||
<td class="name">
|
<td class="name">
|
||||||
<%= link_to '', '#', {
|
<%= 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"
|
class: "icon icon-bullet-closed"
|
||||||
} %>
|
} %>
|
||||||
<%= i.name %>
|
<%= i.name %>
|
||||||
</td>
|
</td>
|
||||||
<% @header.each do |q| %>
|
<% @primary_quantities.each do |q| %>
|
||||||
<td class="value"><%= values[q.id] || '-' %></td>
|
<td class="primary value">
|
||||||
|
<%= values[q.id] || '-' %>
|
||||||
|
</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
<tr id="ingredient-desc-<%= i.id %>" class="ingredient <%= 'hidden' if i.hidden %>"
|
<% @extra_nutrients[i].keys.each_slice(@primary_quantities.length) do |names| %>
|
||||||
style="display:none">
|
<tr class="extra <%= row_class %>" style="display:none">
|
||||||
<td></td>
|
<td rowspan="2"></td>
|
||||||
<td colspan="<%= @header.length %>" class="description">
|
<% names.each do |name| %>
|
||||||
<%= @descriptions[i] %>
|
<td class="extra name">
|
||||||
</td>
|
<%= name %>
|
||||||
</tr>
|
</td>
|
||||||
<tr style="display:none"></tr>
|
<% end %>
|
||||||
|
<% for index in names.length...@primary_quantities.length do %>
|
||||||
|
<td rowspan="2"></td>
|
||||||
|
<% end %>
|
||||||
|
</tr>
|
||||||
|
<tr class="extra <%= row_class %>" style="display:none">
|
||||||
|
<% names.each do |name| %>
|
||||||
|
<% title = %>
|
||||||
|
<td class="extra value">
|
||||||
|
<%= @extra_nutrients[i][name] %>
|
||||||
|
</td>
|
||||||
|
<% end %>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -2,8 +2,15 @@ table.list tr.quantity.primary td.name {font-weight: bold;}
|
|||||||
table.list tr.ingredient.hidden {opacity: 0.4}
|
table.list tr.ingredient.hidden {opacity: 0.4}
|
||||||
table.list td.action,
|
table.list td.action,
|
||||||
table.list td.value {text-align: right;}
|
table.list td.value {text-align: right;}
|
||||||
|
table.list th,
|
||||||
table.list td.action,
|
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-left { background-image: url(../images/1leftarrow.png); }
|
||||||
.icon-move-right { background-image: url(../images/1rightarrow.png); }
|
.icon-move-right { background-image: url(../images/1rightarrow.png); }
|
||||||
|
Reference in New Issue
Block a user