Displaying quantities in MEals index, WIP
This commit is contained in:
parent
4230d72206
commit
dfa20a55d1
@ -82,6 +82,18 @@ class MealsController < ApplicationController
|
|||||||
|
|
||||||
def prepare_meals
|
def prepare_meals
|
||||||
@quantities = @project.meal_quantities.includes(:formula)
|
@quantities = @project.meal_quantities.includes(:formula)
|
||||||
@foods = @project.meal_foods.compute_quantities(@quantities)
|
foods = @project.meal_foods.compute_quantities(@quantities)
|
||||||
|
ingredients = @project.meal_ingredients
|
||||||
|
|
||||||
|
@nutrients = {}
|
||||||
|
ingredients.each do |i|
|
||||||
|
@nutrients[i] = foods[i.food].map do |q, v|
|
||||||
|
[q, v && [v[0]*i.amount/i.food.ref_amount, v[1]]]
|
||||||
|
end.to_h
|
||||||
|
end
|
||||||
|
|
||||||
|
@meals_by_date = ingredients.group_by { |i| i.composition }.reject { |m,*| m.new_record? }
|
||||||
|
.sort_by { |m,*| m.eaten_at || m.created_at }
|
||||||
|
.group_by { |m,*| m.eaten_at ? m.eaten_at.to_date : Date.current }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,21 +1,16 @@
|
|||||||
<% if @meals.any? { |m| m.persisted? } %>
|
<% if @meals_by_date.any? %>
|
||||||
<%= render partial: 'meals/options' %>
|
<%= render partial: 'meals/options' %>
|
||||||
|
|
||||||
<table id="meals" class="odd-even list">
|
<table id="meals" class="odd-even list">
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @meals.group_by { |m| m.eaten_at ? m.eaten_at.to_date : Date.current }
|
<% @meals_by_date.reverse_each do |date, meals| %>
|
||||||
.sort_by {|k,v| k }.reverse.each do |date, meals| %>
|
<tr id="date-<%= date.strftime('%Y%m%d') %>" class="date">
|
||||||
<tr id="day-<%= date.strftime('%Y%m%d') %>" class="date">
|
|
||||||
<td class="date" colspan="4">
|
<td class="date" colspan="4">
|
||||||
<h3><%= date == Date.current ? 'Today' : date.strftime('%F') %></h3>
|
<h3><%= date == Date.current ? 'Today' : date.strftime('%F') %></h3>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% eaten, not_eaten = meals.partition { |m| m.eaten_at }
|
<% meals.each_with_index do |m, index| %>
|
||||||
eaten.sort_by! { |m| m.eaten_at }
|
|
||||||
not_eaten.sort_by! { |m| m.created_at }
|
|
||||||
(eaten + not_eaten).each_with_index do |m, index| %>
|
|
||||||
<% next if m.new_record? %>
|
|
||||||
<%= render partial: 'meals/show', locals: {m: m, index: index} %>
|
<%= render partial: 'meals/show', locals: {m: m, index: index} %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
{remote: true, method: :post, class: "icon icon-time"} %>
|
{remote: true, method: :post, class: "icon icon-time"} %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td id="notes-links-<%= m.id %>" class="unwrappable"
|
<td id="notes-links-<%= m.id %>" class="unwrappable"
|
||||||
style="text-align: left; border-right: none; width: 1%;">
|
style="text-align: left; border-right: none; width: 1%;">
|
||||||
<%= link_to l(:button_cancel), '', class: 'icon icon-cancel', style: 'display: none;',
|
<%= link_to l(:button_cancel), '', class: 'icon icon-cancel', style: 'display: none;',
|
||||||
@ -24,6 +25,7 @@
|
|||||||
<%= link_to l(:button_notes), edit_notes_meal_path(m), remote: true,
|
<%= link_to l(:button_notes), edit_notes_meal_path(m), remote: true,
|
||||||
class: "icon icon-wiki-page" %>
|
class: "icon icon-wiki-page" %>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td id="notes-<%= m.id %>" class="notes unwrappable"
|
<td id="notes-<%= m.id %>" class="notes unwrappable"
|
||||||
style="text-align: left; border-left: none;">
|
style="text-align: left; border-left: none;">
|
||||||
<%= notes(m) %>
|
<%= notes(m) %>
|
||||||
|
Reference in New Issue
Block a user