diff --git a/app/controllers/concerns/finders.rb b/app/controllers/concerns/finders.rb index 643d4c7..6ad7216 100644 --- a/app/controllers/concerns/finders.rb +++ b/app/controllers/concerns/finders.rb @@ -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 diff --git a/app/controllers/meals_controller.rb b/app/controllers/meals_controller.rb index 8315068..9265428 100644 --- a/app/controllers/meals_controller.rb +++ b/app/controllers/meals_controller.rb @@ -39,6 +39,7 @@ class MealsController < ApplicationController end def toggle_eaten + @meal.toggle_eaten! end private diff --git a/app/models/meal.rb b/app/models/meal.rb index c36ade4..3cf1e01 100644 --- a/app/models/meal.rb +++ b/app/models/meal.rb @@ -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 diff --git a/app/views/meals/_index.html.erb b/app/views/meals/_index.html.erb index 244557e..e199011 100644 --- a/app/views/meals/_index.html.erb +++ b/app/views/meals/_index.html.erb @@ -1,38 +1,16 @@ <% if @meals.any? { |m| m.persisted? } %> - <% @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| %> + + + <% meals.each_with_index do |m, index| %> <% next if m.new_record? %> - - - - <% m.ingredients.each do |i| %> - - - - - <% end %> - + <%= render partial: 'meals/show', locals: {m: m, index: index} %> <% end %> <% end %> diff --git a/app/views/meals/_show.html.erb b/app/views/meals/_show.html.erb new file mode 100644 index 0000000..604273a --- /dev/null +++ b/app/views/meals/_show.html.erb @@ -0,0 +1,30 @@ + + + + +<% m.ingredients.each do |i| %> + + + + +<% end %> + diff --git a/app/views/meals/toggle_eaten.js.erb b/app/views/meals/toggle_eaten.js.erb new file mode 100644 index 0000000..19375ef --- /dev/null +++ b/app/views/meals/toggle_eaten.js.erb @@ -0,0 +1 @@ +$('#readouts').html('<%= j render partial: 'measurements/readouts' %>'); diff --git a/assets/stylesheets/body_tracking.css b/assets/stylesheets/body_tracking.css index f8fc0ae..db79efb 100644 --- a/assets/stylesheets/body_tracking.css +++ b/assets/stylesheets/body_tracking.css @@ -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;} diff --git a/config/locales/en.yml b/config/locales/en.yml index 8cc3bff..310a9de 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -81,6 +81,7 @@ en: heading_new_meal: 'New meal' index: heading: 'Meals' + show: label_meal: 'Meal' measurements: contextual:
+

<%= date == Date.current ? 'Today' : date.strftime('%F') %>

+
- <%= "#{t '.label_meal'} ##{index+1}" %> - <% 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"} %> -
- <%= meal_links(m) %> -
-
- <%= i.food.name %> - - <%= adjust_ingredient_links(i) { raw " #{i.amount} " } %> -
+ <%= "#{t '.label_meal'} ##{index+1}" %> + <% 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"} %> +
+ <%= meal_links(m) %> +
+
+ <%= i.food.name %> + + <%= adjust_ingredient_links(i) { raw " #{i.amount} " } %> +