Updated Meals index
This commit is contained in:
parent
923df9c8b2
commit
620d86b18a
@ -1,6 +1,13 @@
|
||||
module Concerns::Finders
|
||||
private
|
||||
|
||||
def find_meal
|
||||
@meal = Meal.find(params[:id])
|
||||
@project = @meal.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_food
|
||||
@food = Food.find(params[:id])
|
||||
@project = @food.project
|
||||
|
@ -39,6 +39,7 @@ class MealsController < ApplicationController
|
||||
end
|
||||
|
||||
def toggle_eaten
|
||||
@meal.toggle_eaten!
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -17,4 +17,8 @@ class Meal < ActiveRecord::Base
|
||||
errors.add(:ingredients, :duplicated_ingredient)
|
||||
end
|
||||
end
|
||||
|
||||
def toggle_eaten!
|
||||
update(eaten_at: self.eaten_at ? nil : DateTime.current)
|
||||
end
|
||||
end
|
||||
|
@ -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 " #{i.amount} " } %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tr>
|
||||
<%= render partial: 'meals/show', locals: {m: m, index: index} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
30
app/views/meals/_show.html.erb
Normal file
30
app/views/meals/_show.html.erb
Normal 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 " #{i.amount} " } %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tr>
|
1
app/views/meals/toggle_eaten.js.erb
Normal file
1
app/views/meals/toggle_eaten.js.erb
Normal file
@ -0,0 +1 @@
|
||||
$('#readouts').html('<%= j render partial: 'measurements/readouts' %>');
|
@ -24,6 +24,8 @@ table.list td.form {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
table#meals, table#meals tr:not(.meal) td {border: none;}
|
||||
|
||||
fieldset#filters table.filter td {padding-left: 8px;}
|
||||
|
||||
a.icon:not(.icon-move) {margin-left: 0.3em;}
|
||||
|
@ -81,6 +81,7 @@ en:
|
||||
heading_new_meal: 'New meal'
|
||||
index:
|
||||
heading: 'Meals'
|
||||
show:
|
||||
label_meal: 'Meal'
|
||||
measurements:
|
||||
contextual:
|
||||
|
Reference in New Issue
Block a user