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