diff --git a/app/controllers/concerns/finders.rb b/app/controllers/concerns/finders.rb index c2451fd..b1fb154 100644 --- a/app/controllers/concerns/finders.rb +++ b/app/controllers/concerns/finders.rb @@ -1,4 +1,4 @@ -module Concerns::Finders +module Finders private def find_goal(id = params[:id]) diff --git a/app/controllers/foods_controller.rb b/app/controllers/foods_controller.rb index e96bf55..86106ce 100644 --- a/app/controllers/foods_controller.rb +++ b/app/controllers/foods_controller.rb @@ -5,7 +5,7 @@ class FoodsController < ApplicationController menu_item :body_trackers helper :body_trackers - include Concerns::Finders + include Finders before_action :init_session_filters before_action :find_project_by_project_id, diff --git a/app/controllers/goals_controller.rb b/app/controllers/goals_controller.rb index 5d34705..0085e37 100644 --- a/app/controllers/goals_controller.rb +++ b/app/controllers/goals_controller.rb @@ -3,7 +3,7 @@ class GoalsController < ApplicationController menu_item :body_trackers helper :body_trackers - include Concerns::Finders + include Finders before_action :find_project_by_project_id, only: [:index, :new, :create] before_action :find_goal, only: [:edit, :update, :destroy] diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb index 253b82f..cb4885b 100644 --- a/app/controllers/ingredients_controller.rb +++ b/app/controllers/ingredients_controller.rb @@ -1,5 +1,5 @@ class IngredientsController < ApplicationController - include Concerns::Finders + include Finders before_action :authorize end diff --git a/app/controllers/meals_controller.rb b/app/controllers/meals_controller.rb index b29a40c..9e372eb 100644 --- a/app/controllers/meals_controller.rb +++ b/app/controllers/meals_controller.rb @@ -3,7 +3,7 @@ class MealsController < ApplicationController menu_item :body_trackers helper :body_trackers - include Concerns::Finders + include Finders before_action :find_project_by_project_id, only: [:index, :new, :create] before_action :find_quantity_by_quantity_id, only: [:toggle_exposure] diff --git a/app/controllers/measurement_routines_controller.rb b/app/controllers/measurement_routines_controller.rb index bd34ffc..0e108a0 100644 --- a/app/controllers/measurement_routines_controller.rb +++ b/app/controllers/measurement_routines_controller.rb @@ -1,5 +1,5 @@ class MeasurementRoutinesController < ApplicationController - include Concerns::Finders + include Finders before_action :find_measurement_routine, only: [:show, :edit] before_action :authorize diff --git a/app/controllers/measurements_controller.rb b/app/controllers/measurements_controller.rb index d2abacf..02e81bf 100644 --- a/app/controllers/measurements_controller.rb +++ b/app/controllers/measurements_controller.rb @@ -3,7 +3,7 @@ class MeasurementsController < ApplicationController menu_item :body_trackers helper :body_trackers - include Concerns::Finders + include Finders before_action :init_session_filters before_action :find_project_by_project_id, only: [:index, :new, :create, :filter] diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb index ae4e72f..ee27e5e 100644 --- a/app/controllers/quantities_controller.rb +++ b/app/controllers/quantities_controller.rb @@ -3,7 +3,7 @@ class QuantitiesController < ApplicationController menu_item :body_trackers helper :body_trackers - include Concerns::Finders + include Finders before_action :init_session_filters before_action :find_project_by_project_id, only: [:index, :new, :create, :filter, :parents] @@ -123,7 +123,7 @@ class QuantitiesController < ApplicationController end def prepare_quantities - @quantities = @project.quantities.filter(@project, session[:q_filters]) + @quantities = @project.quantities.apply_filter(@project, session[:q_filters]) .includes(:exposures, :formula, :parent) end end diff --git a/app/controllers/readouts_controller.rb b/app/controllers/readouts_controller.rb index 09ec3c7..231ad37 100644 --- a/app/controllers/readouts_controller.rb +++ b/app/controllers/readouts_controller.rb @@ -3,7 +3,7 @@ class ReadoutsController < ApplicationController menu_item :body_trackers helper :body_trackers - include Concerns::Finders + include Finders before_action :find_measurement_routine_by_measurement_routine_id, only: [:index, :toggle_exposure] diff --git a/app/controllers/targets_controller.rb b/app/controllers/targets_controller.rb index c5520b1..c51f8c3 100644 --- a/app/controllers/targets_controller.rb +++ b/app/controllers/targets_controller.rb @@ -3,7 +3,7 @@ class TargetsController < ApplicationController menu_item :body_trackers helper :body_trackers - include Concerns::Finders + include Finders before_action :find_goal_by_goal_id, only: [:index, :new, :create, :show, :edit, :update, :destroy, :reapply, :toggle_exposure] diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb index 4affd4c..6522f39 100644 --- a/app/controllers/units_controller.rb +++ b/app/controllers/units_controller.rb @@ -2,7 +2,7 @@ class UnitsController < ApplicationController layout 'body_tracking' menu_item :body_trackers - include Concerns::Finders + include Finders before_action :find_project_by_project_id, only: [:index, :create] before_action :find_unit, only: [:destroy] diff --git a/app/models/quantity.rb b/app/models/quantity.rb index cd25e3a..da54115 100644 --- a/app/models/quantity.rb +++ b/app/models/quantity.rb @@ -74,7 +74,7 @@ class Quantity < ActiveRecord::Base end # TODO: move as an association extension module - def self.filter(project, filters) + def self.apply_filter(project, filters) quantities = all if filters[:domain].present? diff --git a/app/views/layouts/body_tracking.html.erb b/app/views/layouts/body_tracking.html.erb index 7d8d04f..f0743db 100644 --- a/app/views/layouts/body_tracking.html.erb +++ b/app/views/layouts/body_tracking.html.erb @@ -6,4 +6,4 @@ <%= render partial: 'layouts/sidebar' %> <% end %> -<%= render :file => "layouts/base" %> +<%= render template: "layouts/base" %> diff --git a/init.rb b/init.rb index 3704adb..f083acd 100644 --- a/init.rb +++ b/init.rb @@ -1,8 +1,6 @@ -(Rails::VERSION::MAJOR < 5 ? ActionDispatch : ActiveSupport)::Reloader.to_prepare do - Project.include BodyTracking::ProjectPatch - CollectiveIdea.include BodyTracking::AwesomeNestedSetPatch - ActiveSupport::TestCase.include BodyTracking::PluginFixturesLoader if Rails.env == 'test' -end +Project.include BodyTracking::ProjectPatch +CollectiveIdea.include BodyTracking::AwesomeNestedSetPatch +ActiveSupport::TestCase.include BodyTracking::PluginFixturesLoader if Rails.env == 'test' Redmine::Plugin.register :body_tracking do name 'Body tracking plugin' diff --git a/lib/body_tracking/project_patch.rb b/lib/body_tracking/project_patch.rb index 0ff9fc2..d8423a2 100644 --- a/lib/body_tracking/project_patch.rb +++ b/lib/body_tracking/project_patch.rb @@ -9,7 +9,7 @@ module BodyTracking::ProjectPatch has_many :foods, -> { order "foods.name" }, dependent: :destroy, extend: BodyTracking::ItemsWithQuantities has_many :nutrient_exposures, -> { where view_type: "Nutrient" }, dependent: :destroy, - foreign_key: :view_id, foreign_type: :view_type, + foreign_key: :view_id, class_name: 'Exposure', extend: BodyTracking::TogglableExposures has_many :nutrient_quantities, -> { order "lft" }, through: :nutrient_exposures, source: 'quantity' @@ -24,7 +24,7 @@ module BodyTracking::ProjectPatch has_many :meal_foods, through: :meal_ingredients, source: 'food', extend: BodyTracking::ItemsWithQuantities has_many :meal_exposures, -> { where view_type: "Meal" }, dependent: :destroy, - foreign_key: :view_id, foreign_type: :view_type, + foreign_key: :view_id, class_name: 'Exposure', extend: BodyTracking::TogglableExposures has_many :meal_quantities, -> { order "lft" }, through: :meal_exposures, source: 'quantity'