diff --git a/app/controllers/meals_controller.rb b/app/controllers/meals_controller.rb
new file mode 100644
index 0000000..89ab654
--- /dev/null
+++ b/app/controllers/meals_controller.rb
@@ -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
diff --git a/app/models/meal.rb b/app/models/meal.rb
new file mode 100644
index 0000000..e69de29
diff --git a/app/models/measurement_routine.rb b/app/models/measurement_routine.rb
index 28e0c3b..04f304a 100644
--- a/app/models/measurement_routine.rb
+++ b/app/models/measurement_routine.rb
@@ -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}
diff --git a/app/views/layouts/_sidebar.html.erb b/app/views/layouts/_sidebar.html.erb
index 452c6eb..214d2df 100644
--- a/app/views/layouts/_sidebar.html.erb
+++ b/app/views/layouts/_sidebar.html.erb
@@ -10,6 +10,7 @@
<%= t ".heading_diet" %>
+ - <%= link_to t(".link_meals"), project_meals_path(@project) %>
-
<%= link_to t(".link_ingredients"), project_ingredients_path(@project) %>
/
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 6eb1375..6eb040c 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -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'
diff --git a/config/routes.rb b/config/routes.rb
index 20b21ae..5a255f5 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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'
diff --git a/init.rb b/init.rb
index 7751344..2c25d26 100644
--- a/init.rb
+++ b/init.rb
@@ -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,
diff --git a/lib/body_tracking/project_patch.rb b/lib/body_tracking/project_patch.rb
index d7eaf1c..0bc75c7 100644
--- a/lib/body_tracking/project_patch.rb
+++ b/lib/body_tracking/project_patch.rb
@@ -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