Module: Redmine::MenuManager::MenuHelper
- Defined in:
- lib/redmine/menu_manager.rb
Instance Method Summary collapse
-
#allowed_node?(node, user, project) ⇒ Boolean
Checks if a user is allowed to access the menu item by:.
-
#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
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 |
#current_menu_item ⇒ Object
Returns the current menu item name
160 161 162 |
# File 'lib/redmine/menu_manager.rb', line 160 def @controller. end |
#display_main_menu?(project) ⇒ Boolean
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 |
#extract_node_details(node, project = nil) ⇒ Object
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 = item.(project) return [, url, ( == item.name)] end |
#menu_items_for(menu, project = nil) ⇒ Object
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 |
#render_main_menu(project) ⇒ Object
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 |
#render_menu(menu, project = nil) ⇒ Object
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 |
#render_menu_node(node, project = nil) ⇒ Object
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 , 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
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) , url, selected = extract_node_details(node, project) html = [].tap do |html| html << '<li>' # Parent html << (node, , url, selected) # Standard children standard_children_list = "".tap 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 |
#render_single_menu_node(item, caption, url, selected) ⇒ Object
235 236 237 |
# File 'lib/redmine/menu_manager.rb', line 235 def (item, , url, selected) link_to(h(), url, item.(:selected => selected)) end |
#render_unattached_children_menu(node, project) ⇒ Object
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. "".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)) end else raise MenuError, ":child_menus must be an array of MenuItems" end end end |
#render_unattached_menu_item(menu_item, project) ⇒ Object
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(.), .url, .) end end |