Module: Redmine::MenuManager::MenuController

Included in:
ApplicationController
Defined in:
lib/redmine/menu_manager.rb

Overview

Since:

  • 0.7.0

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#current_menu(project) ⇒ Object

Since:

  • 3.4.0



58
59
60
61
62
63
64
# File 'lib/redmine/menu_manager.rb', line 58

def current_menu(project)
  if project && !project.new_record?
    :project_menu
  elsif self.class.main_menu
    :application_menu
  end
end

#current_menu_itemObject

Returns the menu item name according to the current action



67
68
69
70
# File 'lib/redmine/menu_manager.rb', line 67

def current_menu_item
  @current_menu_item ||= menu_items[controller_name.to_sym][:actions][action_name.to_sym] ||
                           menu_items[controller_name.to_sym][:default]
end


54
55
56
# File 'lib/redmine/menu_manager.rb', line 54

def menu_items
  self.class.menu_items
end

#redirect_to_menu_item(name) ⇒ Object

Redirects user to the menu item Returns false if user is not authorized

Since:

  • 3.4.0



74
75
76
# File 'lib/redmine/menu_manager.rb', line 74

def redirect_to_menu_item(name)
  redirect_to_project_menu_item(nil, name)
end

#redirect_to_project_menu_item(project, name) ⇒ Object

Redirects user to the menu item of the given project Returns false if user is not authorized

Since:

  • 0.8.1



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/redmine/menu_manager.rb', line 80

def redirect_to_project_menu_item(project, name)
  menu = project.nil? ? :application_menu : :project_menu
  item = Redmine::MenuManager.items(menu).detect {|i| i.name.to_s == name.to_s}
  if item && item.allowed?(User.current, project)
    url = item.url
    url = {item.param => project}.merge(url) if project
    redirect_to url
    return true
  end
  false
end