[solved] Select project_menu item, but css class don't have 'selected'
Added by Tomofumi Murata about 1 year ago
I add handmaid plugin 'my-plugin'.
init.rb menu setting is :project_menu.
I click project menu 'my-plugin', but tab is not change tab-color.
I show 'my-plugin' list item's css class, don't have 'selected' class.
Why?
Where setting need.
Please help me.
# init.rb
Redmine::Plugin.register :my_plugin do
name 'MyPlugin'
author 'me'
description 'TBD'
version '0.1.0'
url 'TBD'
author_url 'TBD'
menu :project_menu, :my_plugin, {
controller: 'dashboard',
action: 'index'
},
caption: :menu_caption,
after: :issues,
param: :project_id,
if: Proc.new { |project|
project.module_enabled?('my_plugin') &&
User.current.allowed_to?(:view_my_plugin, project)
}
project_module :my_plugin do
permission :view_my_plugin, dashboard: :index
end
permission :view_my_plugin, dashboard: :index
end
# config/routes.rb
if Redmine::Plugin.installed?(:my_plugin)
get '(projects/:project_id)/my_plugin' => 'dashboard#index', as: 'my_plugin_dashboard'
end
Environment: Redmine version 5.1.1.stable Ruby version 3.1.4-p223 (2023-03-30) [x86_64-linux] Rails version 6.1.7.6 Environment production Database adapter PostgreSQL
Replies (3)
RE: Select project_menu item, but css class don't have 'selected' - Added by Holger Just about 1 year ago
In your controller, you can (or better: must) specify which menu item should be highlights, i.e. which menu item the controller (or the rendered action) belongs to. You can find several examples if you check the existing controllers in app/controllers
and theior calls to the menu_item
method towards the top.
In your case, you likely want to add something like menu_item :my_plugin
to your DashboardController
class so that it read similar to
class DashboardController < ApplicationController
menu_item :my_plugin
def index
# ...
end
# ...
end
This problem is solved. thank you! - Added by Tomofumi Murata about 1 year ago
To: Mx. Holger Just
Thanks to your answer I have solved the problem.
Very thank you!
RE: Select project_menu item, but css class don't have 'selected' - Added by Mischa The Evil about 1 year ago
Holger Just wrote in RE: Select project_menu item, but css class don't have 's...:
In your controller, you can (or better: must) specify which menu item [...]
FWIW and for future reference: additionally, declaring the menu_item
in a controller is mandatory only in specific or non-conventional cases as documented for Redmine::MenuManager::MenuController::ClassMethods#menu_item
in source:/trunk/lib/redmine/menu_manager.rb@22495#L38:
# Set the menu item name for a controller or specific actions # Examples: # * menu_item :tickets # => sets the menu name to :tickets for the whole controller # * menu_item :tickets, :only => :list # => sets the menu name to :tickets for the 'list' action only # * menu_item :tickets, :only => [:list, :show] # => sets the menu name to :tickets for 2 actions only # # The default menu item name for a controller is controller_name by default # Eg. the default menu item name for ProjectsController is :projects