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/meals/_index.html.erb
2020-04-24 00:54:32 +02:00

25 lines
920 B
Plaintext

<% if @meals.any? { |m| m.persisted? } %>
<table id="meals" class="odd-even list">
<tbody>
<% @meals.group_by { |m| m.eaten_at ? m.eaten_at.to_date : Date.current }
.sort_by {|k,v| k }.reverse.each do |date, meals| %>
<tr id="day-<%= date.strftime('%Y%m%d') %>" class="date">
<td class="date" colspan="6">
<h3><%= date == Date.current ? 'Today' : date.strftime('%F') %></h3>
</td>
</tr>
<% eaten, not_eaten = meals.partition { |m| m.eaten_at }
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} %>
<% end %>
<% end %>
</tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>