IngredientsController#index WIP
This commit is contained in:
10
app/controllers/ingredients_controller.rb
Normal file
10
app/controllers/ingredients_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class IngredientsController < ApplicationController
|
||||
include Concerns::Finders
|
||||
|
||||
before_action :find_ingredient, only: [:adjust]
|
||||
before_action :authorize
|
||||
|
||||
def adjust
|
||||
params.require(:ingredient).permit(:adjustment)
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,9 @@
|
||||
module MealsHelper
|
||||
def action_links(m)
|
||||
def meal_links(m)
|
||||
delete_link(meal_path(m), {remote: true, data: {}}) if m.persisted?
|
||||
end
|
||||
def adjust_ingredient_link(i, adjustment)
|
||||
link_to "%+d" % adjustment, adjust_ingredient_path(i, adjustment: adjustment),
|
||||
{remote: true, method: :post}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
<%= label_tag :food_name do %>
|
||||
<%= index > 0 ? '' : t(:field_ingredients) %><span class="required"> *</span>
|
||||
<% end %>
|
||||
<%= text_field_tag :food_name, nil, {class: "autocomplete autocomplete-label",
|
||||
style: "width: 80%;"} %>
|
||||
<%= text_field_tag :food_name, (i.food.name if i.food),
|
||||
{class: "autocomplete autocomplete-label", style: "width: 80%;"} %>
|
||||
<%= ff.number_field :amount, {style: "width: 8%", step: :any, label: ''} %>
|
||||
<%= i.food.ref_unit.shortname if i.food %>
|
||||
<%= ff.hidden_field :_destroy %>
|
||||
|
||||
@@ -3,14 +3,36 @@
|
||||
<tbody>
|
||||
<% @meals.group_by { |m| m.eaten_at.date if m.eaten_at }.each do |d, meals| %>
|
||||
<% meals.each_with_index do |m, index| %>
|
||||
<tr id="meal-<%= m.new_record? ? 'new' : m.id %>" class="primary meal">
|
||||
<td class="name">
|
||||
<% next if m.new_record? %>
|
||||
<tr id="meal-<%= m.id %>" class="primary meal">
|
||||
<td class="name" colspan="2">
|
||||
<h4>
|
||||
<%= "#{t '.label_meal'}" %><%= index ? " ##{index+1}" : " (new)" %>
|
||||
<%= ", #{m.eaten_at.time}" if m.eaten_at %>
|
||||
</h4>
|
||||
</td>
|
||||
<td class="action unwrappable" style="width:5%"><%= action_links(m) %></td>
|
||||
<td class="action unwrappable" style="width:5%"><%= meal_links(m) %></td>
|
||||
</tr>
|
||||
<% m.ingredients.each do |i| %>
|
||||
<tr id="ingredient-<%= i.id %>" class="ingredient">
|
||||
<td class="name" style="width: 100%;">
|
||||
<p>
|
||||
<%= i.food.name %>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p style='white-space: nowrap;'>
|
||||
<%= adjust_ingredient_link(i, -5) %>
|
||||
<%= adjust_ingredient_link(i, -1) %>
|
||||
<%= i.amount %>
|
||||
<%= adjust_ingredient_link(i, 1) %>
|
||||
<%= adjust_ingredient_link(i, 5) %>
|
||||
</p>
|
||||
</td>
|
||||
<td class="action unwrappable" style="width:5%">
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user