1
0

Updated Meals index

This commit is contained in:
cryptogopher
2020-04-19 00:02:39 +02:00
parent 923df9c8b2
commit 620d86b18a
8 changed files with 54 additions and 30 deletions

View File

@@ -1,38 +1,16 @@
<% if @meals.any? { |m| m.persisted? } %>
<table id="meals" class="odd-even list">
<tbody>
<% @meals.group_by { |m| m.eaten_at.date if m.eaten_at }.each do |d, meals| %>
<% @meals.group_by { |m| m.eaten_at ? m.eaten_at.date : Date.current }
.each do |date, meals| %>
<tr id="day-<%= date.strftime('%Y%m%d') %>" class="day">
<td class="date" colspan="2">
<h3><%= date == Date.current ? 'Today' : date.strftime('%F') %></h3>
</td>
</tr>
<% meals.each_with_index do |m, index| %>
<% next if m.new_record? %>
<tr id="meal-<%= m.id %>" class="primary meal">
<td class="name" colspan="2">
<b><%= "#{t '.label_meal'} ##{index+1}" %></b>
<% if m.eaten_at %>
<%= " - #{m.eaten_at.time}" %>
<%= link_to '', toggle_eaten_meal_path(m),
{remote: true, class: "icon icon-close"} %>
<% else %>
<%= link_to l(:button_eat), toggle_eaten_meal_path(m),
{remote: true, class: "icon icon-ok"} %>
<% end %>
<%= link_to l(:button_note), note_meal_path(m),
{remote: true, class: "icon icon-wiki-page"} %>
<div style="float: right; position: relative;">
<%= meal_links(m) %>
</div>
</td>
</tr>
<% m.ingredients.each do |i| %>
<tr id="ingredient-<%= i.id %>" class="ingredient project idnt idnt-1 buttonable">
<td class="name unwrappable" style="width: 5%;">
<%= i.food.name %>
</td>
<td style="text-align: left;" class="unwrappable">
<%= adjust_ingredient_links(i) { raw "&emsp;#{i.amount}&emsp;" } %>
</td>
</tr>
<% end %>
</tr>
<%= render partial: 'meals/show', locals: {m: m, index: index} %>
<% end %>
<% end %>
</tbody>

View File

@@ -0,0 +1,30 @@
<tr id="meal-<%= m.id %>" class="primary meal project idnt idnt-1">
<td class="name" colspan="2">
<b><%= "#{t '.label_meal'} ##{index+1}" %></b>
<% if m.eaten_at %>
<%= " - #{m.eaten_at.time}" %>
<%= link_to '', toggle_eaten_meal_path(m),
{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"} %>
<% end %>
<%= link_to l(:button_note), note_meal_path(m),
{remote: true, class: "icon icon-wiki-page"} %>
<div style="float: right; position: relative;">
<%= meal_links(m) %>
</div>
</td>
</tr>
<% m.ingredients.each do |i| %>
<tr id="ingredient-<%= i.id %>" class="ingredient project idnt idnt-2 buttonable">
<td class="name unwrappable" style="width: 5%;">
<%= i.food.name %>
</td>
<td style="text-align: left;" class="unwrappable">
<%= adjust_ingredient_links(i) { raw "&emsp;#{i.amount}&emsp;" } %>
</td>
</tr>
<% end %>
</tr>

View File

@@ -0,0 +1 @@
$('#readouts').html('<%= j render partial: 'measurements/readouts' %>');