diff --git a/app/controllers/body_trackers_controller.rb b/app/controllers/body_trackers_controller.rb index 2f86670..58b894e 100644 --- a/app/controllers/body_trackers_controller.rb +++ b/app/controllers/body_trackers_controller.rb @@ -1,6 +1,4 @@ -class BodyTrackersController < ApplicationController - menu_item :body_trackers - +class BodyTrackersController < BodyTrackingPluginController before_action :find_project_by_project_id, only: [:index, :defaults] before_action :authorize diff --git a/app/controllers/body_tracking_plugin_controller.rb b/app/controllers/body_tracking_plugin_controller.rb new file mode 100644 index 0000000..bb9732c --- /dev/null +++ b/app/controllers/body_tracking_plugin_controller.rb @@ -0,0 +1,17 @@ +class BodyTrackingPluginController < ApplicationController + menu_item :body_trackers + layout 'body_tracking' + + private + + def find_quantity(id = :id) + @quantity = Quantity.find(params[id]) + @project = @quantity.project + rescue ActiveRecord::RecordNotFound + render_404 + end + + def find_quantity_by_quantity_id + find_quantity(:quantity_id) + end +end diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb index cba1cc9..f9293b0 100644 --- a/app/controllers/ingredients_controller.rb +++ b/app/controllers/ingredients_controller.rb @@ -1,8 +1,6 @@ -class IngredientsController < ApplicationController +class IngredientsController < BodyTrackingPluginController require 'csv' - menu_item :body_trackers - helper :body_trackers helper_method :current_view diff --git a/app/controllers/measurements_controller.rb b/app/controllers/measurements_controller.rb index 2b7e7a6..c8056a9 100644 --- a/app/controllers/measurements_controller.rb +++ b/app/controllers/measurements_controller.rb @@ -1,6 +1,4 @@ -class MeasurementsController < ApplicationController - menu_item :body_trackers - +class MeasurementsController < BodyTrackingPluginController helper :body_trackers before_action :init_session_filters diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb index 944ac4b..5e3f1d3 100644 --- a/app/controllers/quantities_controller.rb +++ b/app/controllers/quantities_controller.rb @@ -1,6 +1,4 @@ -class QuantitiesController < ApplicationController - menu_item :body_trackers - +class QuantitiesController < BodyTrackingPluginController before_action :init_session_filters before_action :find_project_by_project_id, only: [:index, :new, :create, :filter, :parents] before_action :find_quantity, only: [:edit, :update, :destroy, :move, diff --git a/app/controllers/sources_controller.rb b/app/controllers/sources_controller.rb index 1cff136..1a5195f 100644 --- a/app/controllers/sources_controller.rb +++ b/app/controllers/sources_controller.rb @@ -1,6 +1,4 @@ -class SourcesController < ApplicationController - menu_item :body_trackers - +class SourcesController < BodyTrackingPluginController before_action :find_project_by_project_id, only: [:index, :create] before_action :find_source, only: [:destroy] before_action :authorize diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb index 158997d..65509cf 100644 --- a/app/controllers/units_controller.rb +++ b/app/controllers/units_controller.rb @@ -1,6 +1,4 @@ -class UnitsController < ApplicationController - menu_item :body_trackers - +class UnitsController < BodyTrackingPluginController before_action :find_project_by_project_id, only: [:index, :create] before_action :find_unit, only: [:destroy] before_action :authorize diff --git a/app/views/body_trackers/_sidebar.html.erb b/app/views/layouts/_sidebar.html.erb similarity index 100% rename from app/views/body_trackers/_sidebar.html.erb rename to app/views/layouts/_sidebar.html.erb diff --git a/app/views/layouts/_body_tracking.html.erb b/app/views/layouts/body_tracking.html.erb similarity index 65% rename from app/views/layouts/_body_tracking.html.erb rename to app/views/layouts/body_tracking.html.erb index f5f75f5..7d8d04f 100644 --- a/app/views/layouts/_body_tracking.html.erb +++ b/app/views/layouts/body_tracking.html.erb @@ -3,5 +3,7 @@ <% end %> <% content_for :sidebar do %> - <%= render partial: 'body_trackers/sidebar' %> + <%= render partial: 'layouts/sidebar' %> <% end %> + +<%= render :file => "layouts/base" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 797e84d..ed11c96 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -45,6 +45,7 @@ en: body_trackers: index: heading: 'Summary' + layouts: sidebar: heading_body_trackers: 'Body trackers' heading_measurements: 'Measurements' diff --git a/init.rb b/init.rb index 40478f0..6e04db0 100644 --- a/init.rb +++ b/init.rb @@ -1,7 +1,4 @@ -require_dependency 'body_tracking/body_trackers_view_listener' - (Rails::VERSION::MAJOR < 5 ? ActionDispatch : ActiveSupport)::Reloader.to_prepare do - ApplicationController.include BodyTracking::ApplicationControllerPatch Project.include BodyTracking::ProjectPatch end diff --git a/lib/body_tracking/application_controller_patch.rb b/lib/body_tracking/application_controller_patch.rb deleted file mode 100644 index 4ea9d52..0000000 --- a/lib/body_tracking/application_controller_patch.rb +++ /dev/null @@ -1,18 +0,0 @@ -module BodyTracking - module ApplicationControllerPatch - ApplicationController.class_eval do - private - - def find_quantity(id = :id) - @quantity = Quantity.find(params[id]) - @project = @quantity.project - rescue ActiveRecord::RecordNotFound - render_404 - end - - def find_quantity_by_quantity_id - find_quantity(:quantity_id) - end - end - end -end diff --git a/lib/body_tracking/body_trackers_view_listener.rb b/lib/body_tracking/body_trackers_view_listener.rb deleted file mode 100644 index 9ef4ad0..0000000 --- a/lib/body_tracking/body_trackers_view_listener.rb +++ /dev/null @@ -1,5 +0,0 @@ -module BodyTracking - class BodyTrackersViewListener < Redmine::Hook::ViewListener - render_on :view_layouts_base_html_head, partial: 'layouts/body_tracking' - end -end