Project

General

Profile

Plugin for Redmine 2.x to appear only in certain project menus

Added by A Eckert almost 12 years ago

got my Redmine (v2.0.3) working. It now shows in the project menu of every project but I can't figure out how to only activate it for selected projects. E.g. only for projects that have a project custom field set to a specific value. I got the custom field created and figured out where the data is stored. But how do I tell Redmine when to or not to show the plugin in the project menu?

I did come across the possibility to use :if to specify a proc but the proc doesn't allow me to call a method of one of my plugins created models. E.g. I created a model called Param and I want to call the method Param.check_to_display. But shows the error message

ActionView::Template::Error (undefined method 'check_to_display' for Param(....):Class)

My init.rb says:
menu :project_menu, :info, {:controller=>'info', :action=>'index'}, :caption=>'Ticker', :after=>:activity, :param=>:project_id, :if=>Proc.new(Param.check_to_display()}


Replies (1)

RE: Plugin for Redmine 2.x to appear only in certain project menus - Added by A Eckert over 11 years ago

How embarrassing, a simple mistake. I defined the method check_to_display as follows:

def check_to_display

obviously it should have been

def self.check_to_display

and a typo in the post above:
menu :project_menu, :info, {:controller=>'info', :action=>'index'}, :caption=>'Ticker', :after=>:activity, :param=>:project_id, :if=>Proc.new{|p| Param.check_to_display(p)}

And in case you are interested in the Param.check_to_display code:
class Param < ActiveRecord::Base
unloadable

def self.check_to_display(p)
cf = CustomField.where("type='ProjectCustomField' and name='THE_FLAG'").first
return false if cf.nil?
return false if p.nil?
cv = CustomValue.where("customized_type='Project' and customized_id=? and custom_field_id=?",p.id,cf.id).first
return false if cv.nil?
return false if cv.value.nil?
cv.value.strip!
return cv.value != ""
end
end
    (1-1/1)