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,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

View File

@ -39,6 +39,7 @@ class MealsController < ApplicationController
end
def toggle_eaten
@meal.toggle_eaten!
end
private

View File

@ -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

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' %>');

View File

@ -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;}

View File

@ -81,6 +81,7 @@ en:
heading_new_meal: 'New meal'
index:
heading: 'Meals'
show:
label_meal: 'Meal'
measurements:
contextual: