Proper sorting of meals, index
This commit is contained in:
parent
66cd7926e8
commit
baaefb2b68
@ -17,8 +17,8 @@ module MealsHelper
|
||||
end
|
||||
|
||||
def display_notes(m)
|
||||
content_tag(:span, m.notes) +
|
||||
link_to(l(:button_notes), edit_notes_meal_path(m),
|
||||
{remote: true, class: "icon icon-wiki-page"}) +
|
||||
content_tag(:span, m.notes.blank? ? "" : ": #{m.notes}")
|
||||
{remote: true, class: "icon icon-wiki-page", style: "float: right"})
|
||||
end
|
||||
end
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
<div class="box">
|
||||
<div class="tabular">
|
||||
<p><%= f.text_field :notes, required: false, style: "width: 95%;" %></p>
|
||||
|
||||
<% @meal.ingredients.each_with_index do |i, index| %>
|
||||
<table style="width:95%;">
|
||||
<%= f.fields_for 'ingredients_attributes', i, index: '' do |ff| %>
|
||||
|
@ -2,13 +2,16 @@
|
||||
<table id="meals" class="odd-even list">
|
||||
<tbody>
|
||||
<% @meals.group_by { |m| m.eaten_at ? m.eaten_at.to_date : Date.current }
|
||||
.each do |date, meals| %>
|
||||
.sort_by {|k,v| k }.reverse.each do |date, meals| %>
|
||||
<tr id="day-<%= date.strftime('%Y%m%d') %>" class="date">
|
||||
<td class="date" colspan="2">
|
||||
<h3><%= date == Date.current ? 'Today' : date.strftime('%F') %></h3>
|
||||
</td>
|
||||
</tr>
|
||||
<% meals.each_with_index do |m, index| %>
|
||||
<% 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 %>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<tr id="meal-<%= m.id %>" class="primary meal project idnt idnt-1">
|
||||
<td class="name unwrappable" style="width: 5%;">
|
||||
<tr id="meal-<%= m.id %>" class="primary meal project idnt idnt-1 odd">
|
||||
<td class="name unwrappable" style="width: 5%; border-right: none;">
|
||||
<b><%= "#{t '.label_meal'} ##{index+1}" %></b>
|
||||
<% if m.eaten_at %>
|
||||
<%= " at #{m.eaten_at.strftime('%R')}" %>
|
||||
@ -7,13 +7,13 @@
|
||||
{remote: true, method: :post, class: "icon icon-close"} %>
|
||||
<% else %>
|
||||
<%= link_to l(:button_eat), toggle_eaten_meal_path(m),
|
||||
{remote: true, method: :post, class: "icon icon-ok"} %>
|
||||
{remote: true, method: :post, class: "icon icon-time"} %>
|
||||
<% end %>
|
||||
<td id="notes-<%= m.id %>" class="notes" style="text-align: left;">
|
||||
<%= display_notes(m) %>
|
||||
</td>
|
||||
<td class="action" style="width: 5%;"><%= meal_links(m) %></td>
|
||||
</td>
|
||||
<td id="notes-<%= m.id %>" class="notes" style="text-align: left; border-left: none;">
|
||||
<%= display_notes(m) %>
|
||||
</td>
|
||||
<td class="action" style="width: 5%;"><%= meal_links(m) %></td>
|
||||
</tr>
|
||||
|
||||
<% m.ingredients.each do |i| %>
|
||||
|
Reference in New Issue
Block a user