jonua
jonua

Reputation: 2005

How can I add a new setting tab into the Redmine project settings?

I create a plugin. I want to add an any settings for it into the projects settings. I want to create a new tab with my settings into the redmine project settings. I use the redmine version 3.1.0.devel. What can I do for that?

updated:

It's a code, which I created with help @General Failure

require 'projects_helper'

module ProjectsHelperPatch
  def self.included(base)
    base.send(:include, InstanceMethods)
    base.send(:include, ApplicationHelper)

    base.class_eval do
      unloadable

      alias_method_chain :project_settings_tabs, :sph
    end
  end

  module InstanceMethods
    def project_settings_tabs_with_sph

      abort('asdasd')

      tabs = project_settings_tabs_without_sph

      tabs.push({ :name => 'some_name',
                  :action => :some_action,
                  :partial => 'projects/settings/some_page',
                  :label => :label_some_label })
      return tabs
    end
  end
end

ProjectsHelper.send :include, ProjectsHelperPatch

init.rb:

require_relative '../../plugins/sph/app/patches/controllers/projects_helper_patch'

But its code don't works. Why?

Upvotes: 1

Views: 617

Answers (1)

General Failure
General Failure

Reputation: 2599

You can patch ProjectsHelper class and add alias_method_chain to project_settings_tabs method, see topic at Redmine forum.

In :partial => 'projects/settings/some_page' partial value is relative path to your view in plugin, also it must added to routes.rb.

If You have yet any questions, ask them in comments.


update:

My Redmine patching (no adding settings tab, just patching example):

require_dependency 'issues_controller'

module IssuesControllerPatch

  def self.included(base) # :nodoc:
    base.send(:include, InstanceMethods)
    base.send(:include, ApplicationHelper) # You can use helpers in patches

    base.class_eval do
      unloadable # Send unloadable so it will not be unloaded in development
      alias_method_chain :new, :patch
    end
  end

  module InstanceMethods

    def new_with_patch
        my_action # my code
        new_without_land_using # call original method
      end
    end

  end

end

IssuesController.send :include, IssuesControllerPatch

And init.rb row:

require 'patches/controllers/issues_controller_patch'

Upvotes: 2

Related Questions