Module: Redmine::MenuManager::MenuHelper
- Defined in:
- lib/redmine/menu_manager.rb
Instance Method Summary
-
- (Boolean) allowed_node?(node, user, project)
Checks if a user is allowed to access the menu item by:.
-
- (Object) current_menu_item
Returns the current menu item name.
- - (Boolean) display_main_menu?(project)
- - (Object) extract_node_details(node, project = nil)
- - (Object) menu_items_for(menu, project = nil)
-
- (Object) render_main_menu(project)
Renders the application main menu.
- - (Object) 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)
Returns a list of unattached children menu items.
- - (Object) render_unattached_menu_item(menu_item, project)
Instance Method Details
- (Boolean) allowed_node?(node, user, project)
Checks if a user is allowed to access the menu item by:
- Checking the conditions of the item
- Checking the url target (project only)
281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/redmine/menu_manager.rb', line 281 def allowed_node?(node, user, project) if node.condition && !node.condition.call(project) # Condition that doesn't pass return false end if project return user && user.allowed_to?(node.url, project) else # outside a project, all menu items allowed return true end end |
Returns the current menu item name
160 161 162 |
# File 'lib/redmine/menu_manager.rb', line 160 def @controller. end |
169 170 171 172 |
# File 'lib/redmine/menu_manager.rb', line 169 def (project) = project && !project.new_record? ? :project_menu : :application_menu Redmine::MenuManager.items().size > 1 # 1 element is the root end |
- (Object) extract_node_details(node, project = nil)
263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/redmine/menu_manager.rb', line 263 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 send(item.url) else item.url end caption = item.caption(project) return [caption, url, ( == item.name)] end |
249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/redmine/menu_manager.rb', line 249 def (, project=nil) items = [] Redmine::MenuManager.items().root.children.each do |node| if allowed_node?(node, User.current, project) if block_given? yield node else items << node # TODO: not used? end end end return block_given? ? nil : items end |
Renders the application main menu
165 166 167 |
# File 'lib/redmine/menu_manager.rb', line 165 def (project) ((project && !project.new_record?) ? :project_menu : :application_menu, project) end |
174 175 176 177 178 179 180 |
# File 'lib/redmine/menu_manager.rb', line 174 def (, project=nil) links = [] (, project) do |node| links << (node, project) end links.empty? ? nil : content_tag('ul', links.join("\n")) end |
182 183 184 185 186 187 188 189 190 |
# File 'lib/redmine/menu_manager.rb', line 182 def (node, project=nil) if node.hasChildren? || !node..nil? return (node, project) else caption, url, selected = extract_node_details(node, project) return content_tag('li', (node, caption, url, selected)) end end |
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/redmine/menu_manager.rb', line 192 def (node, project=nil) caption, url, selected = extract_node_details(node, project) html = returning [] do |html| html << '<li>' # Parent html << (node, caption, url, selected) # Standard children standard_children_list = returning "" do |child_html| node.children.each do |child| child_html << (child, 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") end |
235 236 237 |
# File 'lib/redmine/menu_manager.rb', line 235 def (item, caption, url, selected) link_to(h(caption), url, item.(:selected => selected)) end |
Returns a list of unattached children menu items
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/redmine/menu_manager.rb', line 219 def (node, project) return nil unless node. returning "" 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)) end else raise MenuError, ":child_menus must be an array of MenuItems" end end end |
239 240 241 242 243 244 245 246 247 |
# File 'lib/redmine/menu_manager.rb', line 239 def (, project) raise MenuError, ":child_menus must be an array of MenuItems" unless .is_a? MenuItem if User.current.allowed_to?(.url, project) link_to(h(.caption), .url, .) end end |