Highlight the current item of the main menu.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1076 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
3e031b4243
commit
0faa4568a0
|
@ -19,6 +19,9 @@ class ApplicationController < ActionController::Base
|
||||||
before_filter :user_setup, :check_if_login_required, :set_localization
|
before_filter :user_setup, :check_if_login_required, :set_localization
|
||||||
filter_parameter_logging :password
|
filter_parameter_logging :password
|
||||||
|
|
||||||
|
include Redmine::MenuManager::MenuController
|
||||||
|
helper Redmine::MenuManager::MenuHelper
|
||||||
|
|
||||||
REDMINE_SUPPORTED_SCM.each do |scm|
|
REDMINE_SUPPORTED_SCM.each do |scm|
|
||||||
require_dependency "repository/#{scm.underscore}"
|
require_dependency "repository/#{scm.underscore}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
class IssueCategoriesController < ApplicationController
|
class IssueCategoriesController < ApplicationController
|
||||||
layout 'base'
|
layout 'base'
|
||||||
|
menu_item :settings
|
||||||
before_filter :find_project, :authorize
|
before_filter :find_project, :authorize
|
||||||
|
|
||||||
verify :method => :post, :only => :destroy
|
verify :method => :post, :only => :destroy
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
class MessagesController < ApplicationController
|
class MessagesController < ApplicationController
|
||||||
layout 'base'
|
layout 'base'
|
||||||
|
menu_item :boards
|
||||||
before_filter :find_board, :only => :new
|
before_filter :find_board, :only => :new
|
||||||
before_filter :find_message, :except => :new
|
before_filter :find_message, :except => :new
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
|
|
@ -17,6 +17,13 @@
|
||||||
|
|
||||||
class ProjectsController < ApplicationController
|
class ProjectsController < ApplicationController
|
||||||
layout 'base'
|
layout 'base'
|
||||||
|
menu_item :overview
|
||||||
|
menu_item :activity, :only => :activity
|
||||||
|
menu_item :roadmap, :only => :roadmap
|
||||||
|
menu_item :files, :only => [:list_files, :add_file]
|
||||||
|
menu_item :settings, :only => :settings
|
||||||
|
menu_item :issues, :only => [:add_issue, :bulk_edit_issues, :changelog, :move_issues]
|
||||||
|
|
||||||
before_filter :find_project, :except => [ :index, :list, :add ]
|
before_filter :find_project, :except => [ :index, :list, :add ]
|
||||||
before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
|
before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
|
||||||
before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
|
before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
class QueriesController < ApplicationController
|
class QueriesController < ApplicationController
|
||||||
layout 'base'
|
layout 'base'
|
||||||
|
menu_item :issues
|
||||||
before_filter :find_project, :authorize
|
before_filter :find_project, :authorize
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
class ReportsController < ApplicationController
|
class ReportsController < ApplicationController
|
||||||
layout 'base'
|
layout 'base'
|
||||||
|
menu_item :issues
|
||||||
before_filter :find_project, :authorize
|
before_filter :find_project, :authorize
|
||||||
|
|
||||||
def issue_report
|
def issue_report
|
||||||
|
|
|
@ -24,6 +24,7 @@ end
|
||||||
|
|
||||||
class RepositoriesController < ApplicationController
|
class RepositoriesController < ApplicationController
|
||||||
layout 'base'
|
layout 'base'
|
||||||
|
menu_item :repository
|
||||||
before_filter :find_repository, :except => :edit
|
before_filter :find_repository, :except => :edit
|
||||||
before_filter :find_project, :only => :edit
|
before_filter :find_project, :only => :edit
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
|
|
@ -16,7 +16,8 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class TimelogController < ApplicationController
|
class TimelogController < ApplicationController
|
||||||
layout 'base'
|
layout 'base'
|
||||||
|
menu_item :issues
|
||||||
before_filter :find_project, :authorize
|
before_filter :find_project, :authorize
|
||||||
|
|
||||||
helper :sort
|
helper :sort
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
class VersionsController < ApplicationController
|
class VersionsController < ApplicationController
|
||||||
layout 'base'
|
layout 'base'
|
||||||
|
menu_item :roadmap
|
||||||
before_filter :find_project, :authorize
|
before_filter :find_project, :authorize
|
||||||
|
|
||||||
cache_sweeper :version_sweeper, :only => [ :edit, :destroy ]
|
cache_sweeper :version_sweeper, :only => [ :edit, :destroy ]
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
class WikisController < ApplicationController
|
class WikisController < ApplicationController
|
||||||
layout 'base'
|
layout 'base'
|
||||||
|
menu_item :settings
|
||||||
before_filter :find_project, :authorize
|
before_filter :find_project, :authorize
|
||||||
|
|
||||||
# Create or update a project's wiki
|
# Create or update a project's wiki
|
||||||
|
|
|
@ -49,13 +49,7 @@
|
||||||
<h1><%= h(@project ? @project.name : Setting.app_title) %></h1>
|
<h1><%= h(@project ? @project.name : Setting.app_title) %></h1>
|
||||||
|
|
||||||
<div id="main-menu">
|
<div id="main-menu">
|
||||||
<ul>
|
<%= render_main_menu(@project) %>
|
||||||
<% Redmine::MenuManager.allowed_items(:project_menu, User.current, @project).each do |item| %>
|
|
||||||
<% unless item.condition && !item.condition.call(@project) %>
|
|
||||||
<li><%= link_to l(item.name), {item.param => @project}.merge(item.url) %></li>
|
|
||||||
<% end %>
|
|
||||||
<% end if @project && !@project.new_record? %>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -91,15 +91,18 @@ end
|
||||||
|
|
||||||
# Project menu configuration
|
# Project menu configuration
|
||||||
Redmine::MenuManager.map :project_menu do |menu|
|
Redmine::MenuManager.map :project_menu do |menu|
|
||||||
menu.push :label_overview, :controller => 'projects', :action => 'show'
|
menu.push :overview, { :controller => 'projects', :action => 'show' }, :caption => :label_overview
|
||||||
menu.push :label_activity, :controller => 'projects', :action => 'activity'
|
menu.push :activity, { :controller => 'projects', :action => 'activity' }, :caption => :label_activity
|
||||||
menu.push :label_roadmap, :controller => 'projects', :action => 'roadmap'
|
menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' }, :caption => :label_roadmap
|
||||||
menu.push :label_issue_plural, { :controller => 'issues', :action => 'index' }, :param => :project_id
|
menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
|
||||||
menu.push :label_news_plural, { :controller => 'news', :action => 'index' }, :param => :project_id
|
menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
|
||||||
menu.push :label_document_plural, { :controller => 'documents', :action => 'index' }, :param => :project_id
|
menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
|
||||||
menu.push :label_wiki, { :controller => 'wiki', :action => 'index', :page => nil }, :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
|
menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil },
|
||||||
menu.push :label_board_plural, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, :if => Proc.new { |p| p.boards.any? }
|
:if => Proc.new { |p| p.wiki && !p.wiki.new_record? }, :caption => :label_wiki
|
||||||
menu.push :label_attachment_plural, :controller => 'projects', :action => 'list_files'
|
menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
|
||||||
menu.push :label_repository, { :controller => 'repositories', :action => 'show' }, :if => Proc.new { |p| p.repository && !p.repository.new_record? }
|
:if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
|
||||||
menu.push :label_settings, :controller => 'projects', :action => 'settings'
|
menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_attachment_plural
|
||||||
|
menu.push :repository, { :controller => 'repositories', :action => 'show' },
|
||||||
|
:if => Proc.new { |p| p.repository && !p.repository.new_record? }, :caption => :label_repository
|
||||||
|
menu.push :settings, { :controller => 'projects', :action => 'settings' }, :caption => :label_settings
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,63 @@
|
||||||
|
|
||||||
module Redmine
|
module Redmine
|
||||||
module MenuManager
|
module MenuManager
|
||||||
|
module MenuController
|
||||||
|
def self.included(base)
|
||||||
|
base.extend(ClassMethods)
|
||||||
|
end
|
||||||
|
|
||||||
|
module ClassMethods
|
||||||
|
@@menu_items = Hash.new {|hash, key| hash[key] = {:default => key, :actions => {}}}
|
||||||
|
mattr_accessor :menu_items
|
||||||
|
|
||||||
|
# Set the menu item name for a controller or specific actions
|
||||||
|
# Examples:
|
||||||
|
# * menu_item :tickets # => sets the menu name to :tickets for the whole controller
|
||||||
|
# * menu_item :tickets, :only => :list # => sets the menu name to :tickets for the 'list' action only
|
||||||
|
# * menu_item :tickets, :only => [:list, :show] # => sets the menu name to :tickets for 2 actions only
|
||||||
|
#
|
||||||
|
# The default menu item name for a controller is controller_name by default
|
||||||
|
# Eg. the default menu item name for ProjectsController is :projects
|
||||||
|
def menu_item(id, options = {})
|
||||||
|
if actions = options[:only]
|
||||||
|
actions = [] << actions unless actions.is_a?(Array)
|
||||||
|
actions.each {|a| menu_items[controller_name.to_sym][:actions][a.to_sym] = id}
|
||||||
|
else
|
||||||
|
menu_items[controller_name.to_sym][:default] = id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def menu_items
|
||||||
|
self.class.menu_items
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the menu item name according to the current action
|
||||||
|
def current_menu_item
|
||||||
|
menu_items[controller_name.to_sym][:actions][action_name.to_sym] ||
|
||||||
|
menu_items[controller_name.to_sym][:default]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module MenuHelper
|
||||||
|
# Returns the current menu item name
|
||||||
|
def current_menu_item
|
||||||
|
@controller.current_menu_item
|
||||||
|
end
|
||||||
|
|
||||||
|
# Renders the application main menu as a ul element
|
||||||
|
def render_main_menu(project)
|
||||||
|
links = []
|
||||||
|
Redmine::MenuManager.allowed_items(:project_menu, User.current, project).each do |item|
|
||||||
|
unless item.condition && !item.condition.call(project)
|
||||||
|
links << content_tag('li',
|
||||||
|
link_to(l(item.caption), {item.param => project}.merge(item.url),
|
||||||
|
:class => (current_menu_item == item.name ? 'selected' : nil)))
|
||||||
|
end
|
||||||
|
end if project && !project.new_record?
|
||||||
|
links.empty? ? nil : content_tag('ul', links.join("\n"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def map(menu_name)
|
def map(menu_name)
|
||||||
|
@ -48,13 +105,14 @@ module Redmine
|
||||||
end
|
end
|
||||||
|
|
||||||
class MenuItem
|
class MenuItem
|
||||||
attr_reader :name, :url, :param, :condition
|
attr_reader :name, :url, :param, :condition, :caption
|
||||||
|
|
||||||
def initialize(name, url, options)
|
def initialize(name, url, options)
|
||||||
@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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,7 +34,7 @@ h4, .wiki h3 {font-size: 12px;padding: 2px 10px 1px 0px;margin-bottom: 5px; bord
|
||||||
padding: 4px 4px 4px 4px;
|
padding: 4px 4px 4px 4px;
|
||||||
background: #2C4056;
|
background: #2C4056;
|
||||||
}
|
}
|
||||||
#main-menu li a:hover {background:#759FCF;}
|
#main-menu li a:hover, #main-menu li a.selected {background:#759FCF;}
|
||||||
|
|
||||||
#main {background: url(../images/mainbg.png) repeat-x; background-color:#EEEEEE;}
|
#main {background: url(../images/mainbg.png) repeat-x; background-color:#EEEEEE;}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue