diff --git a/init.rb b/init.rb index d559d3879d55a9bbecefc7e295ab50dc83caae3f..b2a472ffa70a170016ad6ed05b97d3153778ed49 100644 --- a/init.rb +++ b/init.rb @@ -1,3 +1,5 @@ +require 'redmine' + Redmine::Plugin.register :sparkline do name 'Sparkline plugin' author 'Sperling' @@ -21,4 +23,10 @@ Redmine::Plugin.register :sparkline do } end + Rails.configuration.to_prepare do + require_dependency 'projects_helper' + unless ProjectsHelper.included_modules.include? SparklineProjectsHelperPatch + ProjectsHelper.send(:include, SparklineProjectsHelperPatch) + end + end end diff --git a/lib/patches/projects_helper_patch.rb b/lib/patches/projects_helper_patch.rb deleted file mode 100644 index e22b85b5e8af4289ce0d87d534c7d4791782ac94..0000000000000000000000000000000000000000 --- a/lib/patches/projects_helper_patch.rb +++ /dev/null @@ -1,54 +0,0 @@ -# frozen_string_literal: true - -# Redmine - project management software -# Copyright (C) 2006-2019 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - -module ProjectsHelperPatch - def self.included(base) - # :nodoc: - base.extend(ClassMethods) - - base.send(:include, InstanceMethods) - # Same as typing in the class - base.class_eval do - unloadable # Send unloadable so it will not be unloaded in development - - alias_method :project_settings_tabs_without_sparkline, :project_settings_tabs - alias_method :project_settings_tabs, :project_settings_tabs_with_sparkline - end - end - - module ClassMethods - end - - module InstanceMethods - def project_settings_tabs_with_sparkline - tabs = project_settings_tabs_without_sparkline - if @project.enabled_module(:sparkline) - tabs.push ( {:name => 'sparkline', :action => :sparkline, :partial => 'settings/plugin_sparkline', :label => :sparkline}) - end - tabs - end - end -end - - - -unless ProjectsHelper.included_modules.include? ProjectsHelperPatch - ProjectsHelper.send(:include, ProjectsHelperPatch) -end diff --git a/lib/patches/settings_controller_patch.rb b/lib/settings_controller_patch.rb similarity index 99% rename from lib/patches/settings_controller_patch.rb rename to lib/settings_controller_patch.rb index 8a7eba311d2f7e4515dc6a11ffcba073890595b1..a3d25c7fb7801372ff1985efcfce5beb42d62764 100644 --- a/lib/patches/settings_controller_patch.rb +++ b/lib/settings_controller_patch.rb @@ -62,4 +62,4 @@ end unless SettingsController.included_modules.include? SettingsControllerPatch SettingsController.send(:include, SettingsControllerPatch) -end \ No newline at end of file +end diff --git a/lib/sparkline_hook_listener.rb b/lib/sparkline_hook_listener.rb index 07a36519ae71fcbb6c5e4e11be4bdd7f6d046fe1..aceabb6ac1de97ee1e45c7b67975b2b292b34e6b 100644 --- a/lib/sparkline_hook_listener.rb +++ b/lib/sparkline_hook_listener.rb @@ -2,4 +2,4 @@ class SparklineHookListener < Redmine::Hook::ViewListener render_on :view_issues_index_bottom, partial: "hooks/sparkline_issues_list" render_on :view_issues_show_details_bottom, partial: "hooks/sparkline_issues_show" -end \ No newline at end of file +end diff --git a/lib/sparkline_projects_helper_patch.rb b/lib/sparkline_projects_helper_patch.rb new file mode 100644 index 0000000000000000000000000000000000000000..55a8f0ccedfc6797df55b06d9ca76e771eacdd19 --- /dev/null +++ b/lib/sparkline_projects_helper_patch.rb @@ -0,0 +1,17 @@ +require_dependency 'projects_helper' + +module SparklineProjectsHelperPatch + module ProjectsHelperPatch + def project_settings_tabs + tabs = super + action = {:name => 'sparkline', + :action => :sparkline, + :partial => 'settings/plugin_sparkline', + :label => :sparkline} + tabs << action if @project.enabled_module(:sparkline) + tabs + end + end +end + +ProjectsHelper.prepend SparklineProjectsHelperPatch::ProjectsHelperPatch