1
0
This repository has been archived on 2023-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
body_tracking/app/views/foods/_nutrients.html.erb
2020-06-02 23:12:50 +02:00

94 lines
3.8 KiB
Plaintext

<%= render partial: 'foods/filters',
locals: {url: filter_project_foods_path(@project, view: :nutrients)} %>
<% if @foods.any? %>
<%= render partial: 'foods/options' %>
<% formulas = @quantities.map { |q| q.formula } %>
<% formulas.unshift(@filter_q.formula) if @filter_q %>
<%= error_messages_for *formulas %>
<table class="nutrients list odd-even">
<% total_width = 4 + @quantities.length %>
<thead>
<tr>
<th rowspan="2" style="width:<%= 3 * 100/total_width %>%"><%= l(:field_name) %></th>
<% @quantities.each do |q| %>
<th class="closable ellipsible"
style="width:<%= 100/total_width %>%; border-bottom:none;">
<div style="float:right;position:relative;">
<%= link_to '',
toggle_exposure_project_foods_path(@project, quantity_id: q.id),
{class: "icon icon-close", method: :post, remote: true} %>
</div>
<%= q.name %>
</th>
<% end %>
<th rowspan="2" style="width:<%= 100/total_width %>%"><%= l(:field_action) %></th>
</tr>
<% @quantities.each do |q| %>
<th><%= "[#{@food_summary[:mfu_unit][q].try(&:shortname) || '-'}]" %></th>
<% end %>
</thead>
<tbody>
<% extra_quantities = @foods.values.first.keys - @quantities %>
<% @foods.each do |food, nutrients| %>
<% row_class = "food#{' hidden' if food.hidden} #{cycle('odd', 'even')}" %>
<tr id="food-<%= food.id %>" class="primary <%= row_class %>">
<td class="name ellipsible" style="cursor: pointer;"
onclick="$(this).closest('tr').toggle(); $(this).closest('tr').nextUntil('tr.primary', '.food').toggle(); return false;">
<span class="icon icon-bullet-closed"><%= food.name %></span>
</td>
<% @quantities.each do |q| %>
<td class="primary value ellipsible">
<%= format_value(nutrients[q], @food_summary[:precision][q],
@food_summary[:mfu_unit][q]) %>
</td>
<% end %>
<td class="action unwrappable"><%= action_links(food, :nutrients) %></td>
</tr>
<tr class="<%= row_class %>" style="display:none">
<% if @quantities.length > 0
rows = (nutrients.length - 1) / @quantities.length + 1
else
rows = 1
end %>
<td rowspan="<%= rows %>" class="name ellipsible" style="cursor: pointer;"
onclick="$(this).closest('tr').prev('tr.primary').toggle(); $(this).closest('tr').prev('tr.primary').nextUntil('tr.primary', '.food').toggle(); return false;">
<span class="icon icon-bullet-open"><%= food.name %></span>
</td>
<% @quantities.each do |q| %>
<td class="primary quantity ellipsible">
<%= q.name %>
<p class="value"><%= format_value(nutrients[q]) %></p>
</td>
<% end %>
<td rowspan="<%= rows %>" class="action unwrappable">
<%= action_links(food, :nutrients) %>
</td>
</tr>
<% next unless @quantities.length > 0 %>
<% extra_quantities.each_slice(@quantities.length) do |eqs| %>
<tr class="extra <%= row_class %>" style="display:none">
<% eqs.each do |q| %>
<td class="extra quantity ellipsible">
<%= q.name if nutrients[q] %>
<p class="value"><%= format_value(nutrients[q]) %></p>
</td>
<% end %>
<% if @quantities.length > eqs.length %>
<td class="space" colspan="<%= @quantities.length - eqs.length %>"></td>
<% end %>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>