Module: Redmine::MenuManager::MenuHelper
- Defined in:
- lib/redmine/menu_manager.rb
Overview
Instance Method Summary collapse
-
#allowed_node?(node, user, project) ⇒ Boolean
See MenuItem#allowed?.
-
#current_menu_item ⇒ Object
Returns the current menu item name.
- #display_main_menu?(project) ⇒ Boolean
- #extract_node_details(node, project = nil) ⇒ Object
- #menu_items_for(menu, project = nil) ⇒ Object
-
#render_main_menu(project) ⇒ Object
Renders the application main menu.
- #render_menu(menu, project = nil) ⇒ Object
- #render_menu_node(node, project = nil) ⇒ Object
- #render_menu_node_with_children(node, project = nil) ⇒ Object
- #render_single_menu_node(item, caption, url, selected) ⇒ Object
-
#render_unattached_children_menu(node, project) ⇒ Object
Returns a list of unattached children menu items.
- #render_unattached_menu_item(menu_item, project) ⇒ Object
Instance Method Details
#allowed_node?(node, user, project) ⇒ Boolean
See MenuItem#allowed?
225 226 227 228 |
# File 'lib/redmine/menu_manager.rb', line 225 def allowed_node?(node, user, project) raise MenuError, ":child_menus must be an array of MenuItems" unless node.is_a? MenuItem node.allowed?(user, project) end |
#current_menu_item ⇒ Object
Returns the current menu item name
95 96 97 |
# File 'lib/redmine/menu_manager.rb', line 95 def controller. end |
#display_main_menu?(project) ⇒ Boolean
106 107 108 109 |
# File 'lib/redmine/menu_manager.rb', line 106 def (project) = controller.(project) .present? && Redmine::MenuManager.items().children.present? end |
#extract_node_details(node, project = nil) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/redmine/menu_manager.rb', line 206 def extract_node_details(node, project=nil) item = node url = case item.url when Hash project.nil? ? item.url : {item.param => project}.merge(item.url) when Symbol if project send(item.url, project) else send(item.url) end else item.url end = item.(project) return [, url, ( == item.name)] end |
#menu_items_for(menu, project = nil) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/redmine/menu_manager.rb', line 192 def (, project=nil) items = [] Redmine::MenuManager.items().root.children.each do |node| if node.allowed?(User.current, project) if block_given? yield node else items << node # TODO: not used? end end end return block_given? ? nil : items end |
#render_main_menu(project) ⇒ Object
Renders the application main menu
100 101 102 103 104 |
# File 'lib/redmine/menu_manager.rb', line 100 def (project) if = controller.(project) (, project) end end |
#render_menu(menu, project = nil) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/redmine/menu_manager.rb', line 111 def (, project=nil) links = [] (, project) do |node| links << (node, project) end links.empty? ? nil : content_tag('ul', links.join.html_safe) end |
#render_menu_node(node, project = nil) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/redmine/menu_manager.rb', line 119 def (node, project=nil) if node.children.present? || !node..nil? return (node, project) else , url, selected = extract_node_details(node, project) return content_tag('li', (node, , url, selected)) end end |
#render_menu_node_with_children(node, project = nil) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/redmine/menu_manager.rb', line 129 def (node, project=nil) , url, selected = extract_node_details(node, project) html = [].tap do |html| html << '<li>' # Parent html << (node, , url, selected) # Standard children standard_children_list = "".html_safe.tap do |child_html| node.children.each do |child| child_html << (child, project) if allowed_node?(child, User.current, project) end end html << content_tag(:ul, standard_children_list, :class => 'menu-children') unless standard_children_list.empty? # Unattached children unattached_children_list = (node, project) html << content_tag(:ul, unattached_children_list, :class => 'menu-children unattached') unless unattached_children_list.blank? html << '</li>' end return html.join("\n").html_safe end |
#render_single_menu_node(item, caption, url, selected) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/redmine/menu_manager.rb', line 172 def (item, , url, selected) = item.(:selected => selected) # virtual nodes are only there for their children to be displayed in the menu # and should not do anything on click, except if otherwise defined elsewhere if url.blank? url = '#' .reverse_merge!(:onclick => 'return false;') end link_to(h(), url, ) end |
#render_unattached_children_menu(node, project) ⇒ Object
Returns a list of unattached children menu items
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/redmine/menu_manager.rb', line 156 def (node, project) return nil unless node. "".html_safe.tap do |child_html| unattached_children = node..call(project) # Tree nodes support #each so we need to do object detection if unattached_children.is_a? Array unattached_children.each do |child| child_html << content_tag(:li, (child, project)) if allowed_node?(child, User.current, project) end else raise MenuError, ":child_menus must be an array of MenuItems" end end end |