@@ -31,14 +31,6 module ApplicationHelper | |||||
31 | def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference) |
|
31 | def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference) | |
32 | link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) |
|
32 | link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) | |
33 | end |
|
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 | # Display a link to user's account page |
|
35 | # Display a link to user's account page | |
44 | def link_to_user(user) |
|
36 | def link_to_user(user) |
@@ -21,20 +21,10 | |||||
21 | <div id="wrapper"> |
|
21 | <div id="wrapper"> | |
22 | <div id="top-menu"> |
|
22 | <div id="top-menu"> | |
23 | <div id="account"> |
|
23 | <div id="account"> | |
24 | <% if User.current.logged? %> |
|
24 | <%= render_menu :account_menu -%> | |
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 %> |
|
|||
32 | </div> |
|
25 | </div> | |
33 | <%= link_to l(:label_home), home_url, :class => 'home' %> |
|
26 | <%= content_tag('div', "#{l(:label_logged_as)} #{User.current.login}", :id => 'loggedas') if User.current.logged? %> | |
34 | <%= link_to l(:label_my_page), { :controller => 'my', :action => 'page'}, :class => 'mypage' if User.current.logged? %> |
|
27 | <%= render_menu :top_menu -%> | |
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' %> |
|
|||
38 | </div> |
|
28 | </div> | |
39 |
|
29 | |||
40 | <div id="header"> |
|
30 | <div id="header"> |
@@ -7,7 +7,9 ActionController::Routing::Routes.draw do |map| | |||||
7 | # Keep in mind you can assign values other than :controller and :action |
|
7 | # Keep in mind you can assign values other than :controller and :action | |
8 |
|
8 | |||
9 | map.home '', :controller => 'welcome' |
|
9 | map.home '', :controller => 'welcome' | |
10 |
|
10 | map.signin 'login', :controller => 'account', :action => 'login' | ||
|
11 | map.signout 'logout', :controller => 'account', :action => 'logout' | |||
|
12 | ||||
11 | map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil |
|
13 | map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil | |
12 | map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow' |
|
14 | map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow' | |
13 | map.connect 'help/:ctrl/:page', :controller => 'help' |
|
15 | map.connect 'help/:ctrl/:page', :controller => 'help' |
@@ -88,23 +88,41 Redmine::AccessControl.map do |map| | |||||
88 | end |
|
88 | end | |
89 | end |
|
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 | Redmine::MenuManager.map :project_menu do |menu| |
|
110 | Redmine::MenuManager.map :project_menu do |menu| | |
93 |
menu.push :overview, { :controller => 'projects', :action => 'show' } |
|
111 | menu.push :overview, { :controller => 'projects', :action => 'show' } | |
94 |
menu.push :activity, { :controller => 'projects', :action => 'activity' } |
|
112 | menu.push :activity, { :controller => 'projects', :action => 'activity' } | |
95 | menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' }, |
|
113 | menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' }, | |
96 |
:if => Proc.new { |p| p.versions.any? } |
|
114 | :if => Proc.new { |p| p.versions.any? } | |
97 | menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural |
|
115 | menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural | |
98 | menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new, |
|
116 | menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new, | |
99 | :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) } |
|
117 | :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) } | |
100 | menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural |
|
118 | menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural | |
101 | menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural |
|
119 | menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural | |
102 | menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil }, |
|
120 | menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil }, | |
103 |
:if => Proc.new { |p| p.wiki && !p.wiki.new_record? } |
|
121 | :if => Proc.new { |p| p.wiki && !p.wiki.new_record? } | |
104 | menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, |
|
122 | menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, | |
105 | :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural |
|
123 | :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural | |
106 | menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_attachment_plural |
|
124 | menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_attachment_plural | |
107 | menu.push :repository, { :controller => 'repositories', :action => 'show' }, |
|
125 | menu.push :repository, { :controller => 'repositories', :action => 'show' }, | |
108 |
:if => Proc.new { |p| p.repository && !p.repository.new_record? } |
|
126 | :if => Proc.new { |p| p.repository && !p.repository.new_record? } | |
109 |
menu.push :settings, { :controller => 'projects', :action => 'settings' } |
|
127 | menu.push :settings, { :controller => 'projects', :action => 'settings' } | |
110 | end |
|
128 | end |
@@ -61,16 +61,28 module Redmine | |||||
61 | @controller.current_menu_item |
|
61 | @controller.current_menu_item | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 |
# Renders the application main menu |
|
64 | # Renders the application main menu | |
65 | def render_main_menu(project) |
|
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 | links = [] |
|
70 | links = [] | |
67 |
Redmine::MenuManager.allowed_items( |
|
71 | Redmine::MenuManager.allowed_items(menu, User.current, project).each do |item| | |
68 | unless item.condition && !item.condition.call(project) |
|
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 | links << content_tag('li', |
|
82 | links << content_tag('li', | |
70 | link_to(l(item.caption), {item.param => project}.merge(item.url), |
|
83 | link_to(l(item.caption), url, (current_menu_item == item.name ? item.html_options.merge(:class => 'selected') : item.html_options))) | |
71 | (current_menu_item == item.name ? item.html_options.merge(:class => 'selected') : item.html_options))) |
|
|||
72 | end |
|
84 | end | |
73 | end if project && !project.new_record? |
|
85 | end | |
74 | links.empty? ? nil : content_tag('ul', links.join("\n")) |
|
86 | links.empty? ? nil : content_tag('ul', links.join("\n")) | |
75 | end |
|
87 | end | |
76 | end |
|
88 | end | |
@@ -89,35 +101,37 module Redmine | |||||
89 | end |
|
101 | end | |
90 |
|
102 | |||
91 | def allowed_items(menu_name, user, project) |
|
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 | end |
|
105 | end | |
94 | end |
|
106 | end | |
95 |
|
107 | |||
96 | class Mapper |
|
108 | class Mapper | |
97 | # Adds an item at the end of the menu. Available options: |
|
109 | # Adds an item at the end of the menu. Available options: | |
98 | # * param: the parameter name that is used for the project id (default is :id) |
|
110 | # * param: the parameter name that is used for the project id (default is :id) | |
99 |
# * |
|
111 | # * if: a proc that is called before rendering the item, the item is displayed only if it returns true | |
100 | # * caption: the localized string key that is used as the item label |
|
112 | # * caption: the localized string key that is used as the item label | |
101 | # * html_options: a hash of html options that are passed to link_to |
|
113 | # * html_options: a hash of html options that are passed to link_to | |
102 | def push(name, url, options={}) |
|
114 | def push(name, url, options={}) | |
103 | @items ||= [] |
|
115 | items << MenuItem.new(name, url, options) | |
104 | @items << MenuItem.new(name, url, options) |
|
|||
105 | end |
|
116 | end | |
106 |
|
117 | |||
107 | def items |
|
118 | def items | |
108 | @items |
|
119 | @items ||= [] | |
109 | end |
|
120 | end | |
110 | end |
|
121 | end | |
111 |
|
122 | |||
112 | class MenuItem |
|
123 | class MenuItem | |
|
124 | include GLoc | |||
113 | attr_reader :name, :url, :param, :condition, :caption, :html_options |
|
125 | attr_reader :name, :url, :param, :condition, :caption, :html_options | |
114 |
|
126 | |||
115 | def initialize(name, url, options) |
|
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 | @name = name |
|
130 | @name = name | |
117 | @url = url |
|
131 | @url = url | |
118 | @condition = options[:if] |
|
132 | @condition = options[:if] | |
119 | @param = options[:param] || :id |
|
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 | @html_options = options[:html] || {} |
|
135 | @html_options = options[:html] || {} | |
122 | end |
|
136 | end | |
123 | end |
|
137 | end |
@@ -10,7 +10,17 h4, .wiki h3 {font-size: 12px;padding: 2px 10px 1px 0px;margin-bottom: 5px; bord | |||||
10 | #wrapper {background: white;} |
|
10 | #wrapper {background: white;} | |
11 |
|
11 | |||
12 | #top-menu {background: #2C4056;color: #fff;height:1.5em; padding: 2px 6px 0px 6px;} |
|
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 | #top-menu a {color: #fff; padding-right: 4px;} |
|
21 | #top-menu a {color: #fff; padding-right: 4px;} | |
|
22 | #top-menu #loggedas { float: right; margin-right: 0.5em; color: #fff; } | |||
|
23 | ||||
14 | #account {float:right;} |
|
24 | #account {float:right;} | |
15 |
|
25 | |||
16 | #header {height:5.3em;margin:0;background-color:#507AAA;color:#f8f8f8; padding: 4px 8px 0px 6px; position:relative;} |
|
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