IngredientsController#index WIP
This commit is contained in:
parent
ed6b1b9fe7
commit
3ff36df168
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 %>
|
||||
|
@ -79,7 +79,6 @@ en:
|
||||
heading_new_meal: 'New meal'
|
||||
index:
|
||||
heading: 'Meals'
|
||||
show:
|
||||
label_meal: 'Meal'
|
||||
measurements:
|
||||
contextual:
|
||||
|
@ -7,6 +7,9 @@ resources :projects, shallow: true do
|
||||
post 'defaults'
|
||||
end
|
||||
end
|
||||
resources :ingredients, only: [] do
|
||||
post 'adjust/:adjustment', to: 'ingredients#adjust', as: :adjust, on: :member
|
||||
end
|
||||
resources :meals, only: [:index, :new, :create, :edit, :update, :destroy]
|
||||
resources :measurement_routines, only: [:show, :edit] do
|
||||
member do
|
||||
|
1
init.rb
1
init.rb
@ -23,6 +23,7 @@ Redmine::Plugin.register :body_tracking do
|
||||
}, read: true
|
||||
permission :manage_common, {
|
||||
body_trackers: [:defaults],
|
||||
ingredients: [:adjust],
|
||||
meals: [:new, :create, :edit, :update, :destroy],
|
||||
measurement_routines: [:edit],
|
||||
measurements: [:new, :create, :edit, :update, :destroy, :retake, :toggle_column],
|
||||
|
Reference in New Issue
Block a user