The following menus can now be extended by plugins: top_menu, account_menu, application_menu (empty by default).
Sligth layout change: links in the top menu are now li elements. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1137 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
93ef8b7f77
commit
c5d998528f
|
@ -32,14 +32,6 @@ module ApplicationHelper
|
||||||
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
|
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_signin
|
|
||||||
link_to l(:label_login), { :controller => 'account', :action => 'login' }, :class => 'signin'
|
|
||||||
end
|
|
||||||
|
|
||||||
def link_to_signout
|
|
||||||
link_to l(:label_logout), { :controller => 'account', :action => 'logout' }, :class => 'logout'
|
|
||||||
end
|
|
||||||
|
|
||||||
# Display a link to user's account page
|
# Display a link to user's account page
|
||||||
def link_to_user(user)
|
def link_to_user(user)
|
||||||
user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
|
user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
|
||||||
|
|
|
@ -21,20 +21,10 @@
|
||||||
<div id="wrapper">
|
<div id="wrapper">
|
||||||
<div id="top-menu">
|
<div id="top-menu">
|
||||||
<div id="account">
|
<div id="account">
|
||||||
<% if User.current.logged? %>
|
<%= render_menu :account_menu -%>
|
||||||
<%=l(:label_logged_as)%> <%= User.current.login %> -
|
|
||||||
<%= link_to l(:label_my_account), { :controller => 'my', :action => 'account' }, :class => 'myaccount' %>
|
|
||||||
<%= link_to_signout %>
|
|
||||||
<% else %>
|
|
||||||
<%= link_to_signin %>
|
|
||||||
<%= link_to(l(:label_register), { :controller => 'account',:action => 'register' }, :class => 'register') if Setting.self_registration? %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
<%= link_to l(:label_home), home_url, :class => 'home' %>
|
<%= content_tag('div', "#{l(:label_logged_as)} #{User.current.login}", :id => 'loggedas') if User.current.logged? %>
|
||||||
<%= link_to l(:label_my_page), { :controller => 'my', :action => 'page'}, :class => 'mypage' if User.current.logged? %>
|
<%= render_menu :top_menu -%>
|
||||||
<%= link_to l(:label_project_plural), { :controller => 'projects' }, :class => 'projects' %>
|
|
||||||
<%= link_to l(:label_administration), { :controller => 'admin' }, :class => 'admin' if User.current.admin? %>
|
|
||||||
<%= link_to l(:label_help), Redmine::Info.help_url, :class => 'help' %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="header">
|
<div id="header">
|
||||||
|
|
|
@ -7,6 +7,8 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
# Keep in mind you can assign values other than :controller and :action
|
# Keep in mind you can assign values other than :controller and :action
|
||||||
|
|
||||||
map.home '', :controller => 'welcome'
|
map.home '', :controller => 'welcome'
|
||||||
|
map.signin 'login', :controller => 'account', :action => 'login'
|
||||||
|
map.signout 'logout', :controller => 'account', :action => 'logout'
|
||||||
|
|
||||||
map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil
|
map.connect 'wiki/:id/:page/:action', :controller => 'wiki', :page => nil
|
||||||
map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
|
map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
|
||||||
|
|
|
@ -88,23 +88,41 @@ Redmine::AccessControl.map do |map|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Project menu configuration
|
Redmine::MenuManager.map :top_menu do |menu|
|
||||||
|
menu.push :home, :home_url, :html => { :class => 'home' }
|
||||||
|
menu.push :my_page, { :controller => 'my', :action => 'page' }, :html => { :class => 'mypage' }, :if => Proc.new { User.current.logged? }
|
||||||
|
menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural, :html => { :class => 'projects' }
|
||||||
|
menu.push :administration, { :controller => 'admin', :action => 'index' }, :html => { :class => 'admin' }, :if => Proc.new { User.current.admin? }
|
||||||
|
menu.push :help, Redmine::Info.help_url, :html => { :class => 'help' }
|
||||||
|
end
|
||||||
|
|
||||||
|
Redmine::MenuManager.map :account_menu do |menu|
|
||||||
|
menu.push :login, :signin_url, :html => { :class => 'login' }, :if => Proc.new { !User.current.logged? }
|
||||||
|
menu.push :register, { :controller => 'account', :action => 'register' }, :html => { :class => 'register' }, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
|
||||||
|
menu.push :my_account, { :controller => 'my', :action => 'account' }, :html => { :class => 'myaccount' }, :if => Proc.new { User.current.logged? }
|
||||||
|
menu.push :logout, :signout_url, :html => { :class => 'logout' }, :if => Proc.new { User.current.logged? }
|
||||||
|
end
|
||||||
|
|
||||||
|
Redmine::MenuManager.map :application_menu do |menu|
|
||||||
|
# Empty
|
||||||
|
end
|
||||||
|
|
||||||
Redmine::MenuManager.map :project_menu do |menu|
|
Redmine::MenuManager.map :project_menu do |menu|
|
||||||
menu.push :overview, { :controller => 'projects', :action => 'show' }, :caption => :label_overview
|
menu.push :overview, { :controller => 'projects', :action => 'show' }
|
||||||
menu.push :activity, { :controller => 'projects', :action => 'activity' }, :caption => :label_activity
|
menu.push :activity, { :controller => 'projects', :action => 'activity' }
|
||||||
menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' },
|
menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' },
|
||||||
:if => Proc.new { |p| p.versions.any? }, :caption => :label_roadmap
|
:if => Proc.new { |p| p.versions.any? }
|
||||||
menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
|
menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
|
||||||
menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new,
|
menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new,
|
||||||
:html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
|
:html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
|
||||||
menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
|
menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
|
||||||
menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
|
menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
|
||||||
menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil },
|
menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil },
|
||||||
:if => Proc.new { |p| p.wiki && !p.wiki.new_record? }, :caption => :label_wiki
|
:if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
|
||||||
menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
|
menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
|
||||||
:if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
|
:if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
|
||||||
menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_attachment_plural
|
menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_attachment_plural
|
||||||
menu.push :repository, { :controller => 'repositories', :action => 'show' },
|
menu.push :repository, { :controller => 'repositories', :action => 'show' },
|
||||||
:if => Proc.new { |p| p.repository && !p.repository.new_record? }, :caption => :label_repository
|
:if => Proc.new { |p| p.repository && !p.repository.new_record? }
|
||||||
menu.push :settings, { :controller => 'projects', :action => 'settings' }, :caption => :label_settings
|
menu.push :settings, { :controller => 'projects', :action => 'settings' }
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,16 +61,28 @@ module Redmine
|
||||||
@controller.current_menu_item
|
@controller.current_menu_item
|
||||||
end
|
end
|
||||||
|
|
||||||
# Renders the application main menu as a ul element
|
# Renders the application main menu
|
||||||
def render_main_menu(project)
|
def render_main_menu(project)
|
||||||
|
render_menu((project && !project.new_record?) ? :project_menu : :application_menu, project)
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_menu(menu, project=nil)
|
||||||
links = []
|
links = []
|
||||||
Redmine::MenuManager.allowed_items(:project_menu, User.current, project).each do |item|
|
Redmine::MenuManager.allowed_items(menu, User.current, project).each do |item|
|
||||||
unless item.condition && !item.condition.call(project)
|
unless item.condition && !item.condition.call(project)
|
||||||
|
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
|
||||||
|
#url = (project && item.url.is_a?(Hash)) ? {item.param => project}.merge(item.url) : (item.url.is_a?(Symbol) ? send(item.url) : item.url)
|
||||||
links << content_tag('li',
|
links << content_tag('li',
|
||||||
link_to(l(item.caption), {item.param => project}.merge(item.url),
|
link_to(l(item.caption), url, (current_menu_item == item.name ? item.html_options.merge(:class => 'selected') : item.html_options)))
|
||||||
(current_menu_item == item.name ? item.html_options.merge(:class => 'selected') : item.html_options)))
|
|
||||||
end
|
end
|
||||||
end if project && !project.new_record?
|
end
|
||||||
links.empty? ? nil : content_tag('ul', links.join("\n"))
|
links.empty? ? nil : content_tag('ul', links.join("\n"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -89,35 +101,37 @@ module Redmine
|
||||||
end
|
end
|
||||||
|
|
||||||
def allowed_items(menu_name, user, project)
|
def allowed_items(menu_name, user, project)
|
||||||
items(menu_name).select {|item| user && user.allowed_to?(item.url, project)}
|
project ? items(menu_name).select {|item| user && user.allowed_to?(item.url, project)} : items(menu_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Mapper
|
class Mapper
|
||||||
# Adds an item at the end of the menu. Available options:
|
# Adds an item at the end of the menu. Available options:
|
||||||
# * param: the parameter name that is used for the project id (default is :id)
|
# * param: the parameter name that is used for the project id (default is :id)
|
||||||
# * condition: a proc that is called before rendering the item, the item is displayed only if it returns true
|
# * if: a proc that is called before rendering the item, the item is displayed only if it returns true
|
||||||
# * caption: the localized string key that is used as the item label
|
# * caption: the localized string key that is used as the item label
|
||||||
# * html_options: a hash of html options that are passed to link_to
|
# * html_options: a hash of html options that are passed to link_to
|
||||||
def push(name, url, options={})
|
def push(name, url, options={})
|
||||||
@items ||= []
|
items << MenuItem.new(name, url, options)
|
||||||
@items << MenuItem.new(name, url, options)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def items
|
def items
|
||||||
@items
|
@items ||= []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class MenuItem
|
class MenuItem
|
||||||
|
include GLoc
|
||||||
attr_reader :name, :url, :param, :condition, :caption, :html_options
|
attr_reader :name, :url, :param, :condition, :caption, :html_options
|
||||||
|
|
||||||
def initialize(name, url, options)
|
def initialize(name, url, options)
|
||||||
|
raise "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
|
||||||
|
raise "Invalid option :html for menu item '#{name}'" if options[:html] && !options[:html].is_a?(Hash)
|
||||||
@name = name
|
@name = name
|
||||||
@url = url
|
@url = url
|
||||||
@condition = options[:if]
|
@condition = options[:if]
|
||||||
@param = options[:param] || :id
|
@param = options[:param] || :id
|
||||||
@caption = options[:caption] || name.to_s.humanize
|
@caption = options[:caption] || (l_has_string?("label_#{name}".to_sym) ? "label_#{name}".to_sym : name.to_s.humanize)
|
||||||
@html_options = options[:html] || {}
|
@html_options = options[:html] || {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,17 @@ h4, .wiki h3 {font-size: 12px;padding: 2px 10px 1px 0px;margin-bottom: 5px; bord
|
||||||
#wrapper {background: white;}
|
#wrapper {background: white;}
|
||||||
|
|
||||||
#top-menu {background: #2C4056;color: #fff;height:1.5em; padding: 2px 6px 0px 6px;}
|
#top-menu {background: #2C4056;color: #fff;height:1.5em; padding: 2px 6px 0px 6px;}
|
||||||
|
#top-menu ul {margin: 0; padding: 0;}
|
||||||
|
#top-menu li {
|
||||||
|
float:left;
|
||||||
|
list-style-type:none;
|
||||||
|
margin: 0px 0px 0px 0px;
|
||||||
|
padding: 0px 0px 0px 0px;
|
||||||
|
white-space:nowrap;
|
||||||
|
}
|
||||||
#top-menu a {color: #fff; padding-right: 4px;}
|
#top-menu a {color: #fff; padding-right: 4px;}
|
||||||
|
#top-menu #loggedas { float: right; margin-right: 0.5em; color: #fff; }
|
||||||
|
|
||||||
#account {float:right;}
|
#account {float:right;}
|
||||||
|
|
||||||
#header {height:5.3em;margin:0;background-color:#507AAA;color:#f8f8f8; padding: 4px 8px 0px 6px; position:relative;}
|
#header {height:5.3em;margin:0;background-color:#507AAA;color:#f8f8f8; padding: 4px 8px 0px 6px; position:relative;}
|
||||||
|
|
Loading…
Reference in New Issue