1
0

Adding Meals, WIP

This commit is contained in:
cryptogopher 2020-04-13 15:36:59 +02:00
parent ced06a25bc
commit c3010a70e8
8 changed files with 29 additions and 1 deletions

View File

@ -0,0 +1,21 @@
class MealsController < ApplicationController
layout 'body_tracking'
menu_item :body_trackers
helper :body_trackers
include Concerns::Finders
before_action :find_project_by_project_id, only: [:index, :new, :create]
before_action :find_meal, only: [:edit, :update, :destroy]
before_action :authorize
def index
prepare_meals
end
private
def prepare_meals
@meals = @project.meals.includes(:ingredients)
end
end

0
app/models/meal.rb Normal file
View File

View File

@ -4,7 +4,7 @@ class MeasurementRoutine < ActiveRecord::Base
foreign_key: 'routine_id', dependent: :restrict_with_error,
extend: BodyTracking::ItemsWithQuantities
has_many :readout_columns, as: :column_view, dependent: :destroy,
class: 'QuantityColumn', extend: BodyTracking::TogglableColumns
class_name: 'QuantityColumn', extend: BodyTracking::TogglableColumns
has_many :quantities, -> { order "lft" }, through: :readout_columns
validates :name, presence: true, uniqueness: {scope: :project_id}

View File

@ -10,6 +10,7 @@
<h3><%= t ".heading_diet" %></h3>
<ul>
<li><%= link_to t(".link_meals"), project_meals_path(@project) %></li>
<li>
<%= link_to t(".link_ingredients"), project_ingredients_path(@project) %>
/

View File

@ -55,6 +55,7 @@ en:
heading_diet: 'Diet'
heading_common: 'Common'
link_summary: 'Summary'
link_meals: 'Meals'
link_measurements: 'Measurements'
link_ingredients: 'Ingredients'
link_nutrients: 'Nutrients'

View File

@ -7,6 +7,7 @@ resources :projects, shallow: true do
post 'defaults'
end
end
resources :meals, only: [:index, :new, :create, :edit, :update, :destroy]
resources :measurement_routines, only: [:show, :edit] do
member do
get 'readouts', to: 'measurements#readouts'

View File

@ -13,6 +13,7 @@ Redmine::Plugin.register :body_tracking do
project_module :body_tracking do
permission :view_body_trackers, {
body_trackers: [:index],
meals: [:index],
measurement_routines: [:show],
measurements: [:index, :readouts, :filter],
ingredients: [:index, :nutrients, :filter],
@ -22,6 +23,7 @@ Redmine::Plugin.register :body_tracking do
}, read: true
permission :manage_common, {
body_trackers: [:defaults],
meals: [:new, :create, :edit, :update, :destroy],
measurement_routines: [:edit],
measurements: [:new, :create, :edit, :update, :destroy, :retake, :toggle_column],
ingredients: [:new, :create, :edit, :update, :destroy, :toggle, :toggle_column,

View File

@ -1,5 +1,7 @@
module BodyTracking::ProjectPatch
Project.class_eval do
has_many :meals, -> { order "eaten_at DESC" }, dependent: :destroy
has_many :measurement_routines, dependent: :destroy
has_many :measurements, -> { order "taken_at DESC" }, dependent: :destroy,
extend: BodyTracking::ItemsWithQuantities, through: :measurement_routines