##// END OF EJS Templates
The following menus can now be extended by plugins: top_menu, account_menu, application_menu (empty by default)....
Jean-Philippe Lang -
r1123:c5d998528fed
parent child
Show More
@@ -31,14 +31,6 module ApplicationHelper
31 31 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
32 32 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
33 33 end
34
35 def link_to_signin
36 link_to l(:label_login), { :controller => 'account', :action => 'login' }, :class => 'signin'
37 end
38
39 def link_to_signout
40 link_to l(:label_logout), { :controller => 'account', :action => 'logout' }, :class => 'logout'
41 end
42 34
43 35 # Display a link to user's account page
44 36 def link_to_user(user)
@@ -21,20 +21,10
21 21 <div id="wrapper">
22 22 <div id="top-menu">
23 23 <div id="account">
24 <% if User.current.logged? %>
25 <%=l(:label_logged_as)%> <%= User.current.login %> -
26 <%= link_to l(:label_my_account), { :controller => 'my', :action => 'account' }, :class => 'myaccount' %>
27 <%= link_to_signout %>
28 <% else %>
29 <%= link_to_signin %>
30 <%= link_to(l(:label_register), { :controller => 'account',:action => 'register' }, :class => 'register') if Setting.self_registration? %>
31 <% end %>
24 <%= render_menu :account_menu -%>
32 25 </div>
33 <%= link_to l(:label_home), home_url, :class => 'home' %>
34 <%= link_to l(:label_my_page), { :controller => 'my', :action => 'page'}, :class => 'mypage' if User.current.logged? %>
35 <%= link_to l(:label_project_plural), { :controller => 'projects' }, :class => 'projects' %>
36 <%= link_to l(:label_administration), { :controller => 'admin' }, :class => 'admin' if User.current.admin? %>
37 <%= link_to l(:label_help), Redmine::Info.help_url, :class => 'help' %>
26 <%= content_tag('div', "#{l(:label_logged_as)} #{User.current.login}", :id => 'loggedas') if User.current.logged? %>
27 <%= render_menu :top_menu -%>
38 28 </div>
39 29
40 30 <div id="header">
@@ -7,7 +7,9 ActionController::Routing::Routes.draw do |map|
7 7 # Keep in mind you can assign values other than :controller and :action
8 8
9 9 map.home '', :controller => 'welcome'
10
10 map.signin 'login', :controller => 'account', :action => 'login'
11 map.signout 'logout', :controller => 'account', :action => 'logout'
12
11 13 map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil
12 14 map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
13 15 map.connect 'help/:ctrl/:page', :controller => 'help'
@@ -88,23 +88,41 Redmine::AccessControl.map do |map|
88 88 end
89 89 end
90 90
91 # Project menu configuration
91 Redmine::MenuManager.map :top_menu do |menu|
92 menu.push :home, :home_url, :html => { :class => 'home' }
93 menu.push :my_page, { :controller => 'my', :action => 'page' }, :html => { :class => 'mypage' }, :if => Proc.new { User.current.logged? }
94 menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural, :html => { :class => 'projects' }
95 menu.push :administration, { :controller => 'admin', :action => 'index' }, :html => { :class => 'admin' }, :if => Proc.new { User.current.admin? }
96 menu.push :help, Redmine::Info.help_url, :html => { :class => 'help' }
97 end
98
99 Redmine::MenuManager.map :account_menu do |menu|
100 menu.push :login, :signin_url, :html => { :class => 'login' }, :if => Proc.new { !User.current.logged? }
101 menu.push :register, { :controller => 'account', :action => 'register' }, :html => { :class => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
102 menu.push :my_account, { :controller => 'my', :action => 'account' }, :html => { :class => 'myaccount' }, :if => Proc.new { User.current.logged? }
103 menu.push :logout, :signout_url, :html => { :class => 'logout' }, :if => Proc.new { User.current.logged? }
104 end
105
106 Redmine::MenuManager.map :application_menu do |menu|
107 # Empty
108 end
109
92 110 Redmine::MenuManager.map :project_menu do |menu|
93 menu.push :overview, { :controller => 'projects', :action => 'show' }, :caption => :label_overview
94 menu.push :activity, { :controller => 'projects', :action => 'activity' }, :caption => :label_activity
111 menu.push :overview, { :controller => 'projects', :action => 'show' }
112 menu.push :activity, { :controller => 'projects', :action => 'activity' }
95 113 menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' },
96 :if => Proc.new { |p| p.versions.any? }, :caption => :label_roadmap
114 :if => Proc.new { |p| p.versions.any? }
97 115 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
98 116 menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new,
99 117 :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
100 118 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
101 119 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
102 120 menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil },
103 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }, :caption => :label_wiki
121 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
104 122 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
105 123 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
106 124 menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_attachment_plural
107 125 menu.push :repository, { :controller => 'repositories', :action => 'show' },
108 :if => Proc.new { |p| p.repository && !p.repository.new_record? }, :caption => :label_repository
109 menu.push :settings, { :controller => 'projects', :action => 'settings' }, :caption => :label_settings
126 :if => Proc.new { |p| p.repository && !p.repository.new_record? }
127 menu.push :settings, { :controller => 'projects', :action => 'settings' }
110 128 end
@@ -61,16 +61,28 module Redmine
61 61 @controller.current_menu_item
62 62 end
63 63
64 # Renders the application main menu as a ul element
64 # Renders the application main menu
65 65 def render_main_menu(project)
66 render_menu((project && !project.new_record?) ? :project_menu : :application_menu, project)
67 end
68
69 def render_menu(menu, project=nil)
66 70 links = []
67 Redmine::MenuManager.allowed_items(:project_menu, User.current, project).each do |item|
71 Redmine::MenuManager.allowed_items(menu, User.current, project).each do |item|
68 72 unless item.condition && !item.condition.call(project)
73 url = case item.url
74 when Hash
75 project.nil? ? item.url : {item.param => project}.merge(item.url)
76 when Symbol
77 send(item.url)
78 else
79 item.url
80 end
81 #url = (project && item.url.is_a?(Hash)) ? {item.param => project}.merge(item.url) : (item.url.is_a?(Symbol) ? send(item.url) : item.url)
69 82 links << content_tag('li',
70 link_to(l(item.caption), {item.param => project}.merge(item.url),
71 (current_menu_item == item.name ? item.html_options.merge(:class => 'selected') : item.html_options)))
83 link_to(l(item.caption), url, (current_menu_item == item.name ? item.html_options.merge(:class => 'selected') : item.html_options)))
72 84 end
73 end if project && !project.new_record?
85 end
74 86 links.empty? ? nil : content_tag('ul', links.join("\n"))
75 87 end
76 88 end
@@ -89,35 +101,37 module Redmine
89 101 end
90 102
91 103 def allowed_items(menu_name, user, project)
92 items(menu_name).select {|item| user && user.allowed_to?(item.url, project)}
104 project ? items(menu_name).select {|item| user && user.allowed_to?(item.url, project)} : items(menu_name)
93 105 end
94 106 end
95 107
96 108 class Mapper
97 109 # Adds an item at the end of the menu. Available options:
98 110 # * param: the parameter name that is used for the project id (default is :id)
99 # * condition: a proc that is called before rendering the item, the item is displayed only if it returns true
111 # * if: a proc that is called before rendering the item, the item is displayed only if it returns true
100 112 # * caption: the localized string key that is used as the item label
101 113 # * html_options: a hash of html options that are passed to link_to
102 114 def push(name, url, options={})
103 @items ||= []
104 @items << MenuItem.new(name, url, options)
115 items << MenuItem.new(name, url, options)
105 116 end
106 117
107 118 def items
108 @items
119 @items ||= []
109 120 end
110 121 end
111 122
112 123 class MenuItem
124 include GLoc
113 125 attr_reader :name, :url, :param, :condition, :caption, :html_options
114 126
115 127 def initialize(name, url, options)
128 raise "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
129 raise "Invalid option :html for menu item '#{name}'" if options[:html] && !options[:html].is_a?(Hash)
116 130 @name = name
117 131 @url = url
118 132 @condition = options[:if]
119 133 @param = options[:param] || :id
120 @caption = options[:caption] || name.to_s.humanize
134 @caption = options[:caption] || (l_has_string?("label_#{name}".to_sym) ? "label_#{name}".to_sym : name.to_s.humanize)
121 135 @html_options = options[:html] || {}
122 136 end
123 137 end
@@ -10,7 +10,17 h4, .wiki h3 {font-size: 12px;padding: 2px 10px 1px 0px;margin-bottom: 5px; bord
10 10 #wrapper {background: white;}
11 11
12 12 #top-menu {background: #2C4056;color: #fff;height:1.5em; padding: 2px 6px 0px 6px;}
13 #top-menu ul {margin: 0; padding: 0;}
14 #top-menu li {
15 float:left;
16 list-style-type:none;
17 margin: 0px 0px 0px 0px;
18 padding: 0px 0px 0px 0px;
19 white-space:nowrap;
20 }
13 21 #top-menu a {color: #fff; padding-right: 4px;}
22 #top-menu #loggedas { float: right; margin-right: 0.5em; color: #fff; }
23
14 24 #account {float:right;}
15 25
16 26 #header {height:5.3em;margin:0;background-color:#507AAA;color:#f8f8f8; padding: 4px 8px 0px 6px; position:relative;}
General Comments 0
You need to be logged in to leave comments. Login now