##// END OF EJS Templates
Highlight the current item of the main menu....
Jean-Philippe Lang -
r1062:0faa4568a0ab
parent child
Show More
@@ -19,6 +19,9 class ApplicationController < ActionController::Base
19 before_filter :user_setup, :check_if_login_required, :set_localization
19 before_filter :user_setup, :check_if_login_required, :set_localization
20 filter_parameter_logging :password
20 filter_parameter_logging :password
21
21
22 include Redmine::MenuManager::MenuController
23 helper Redmine::MenuManager::MenuHelper
24
22 REDMINE_SUPPORTED_SCM.each do |scm|
25 REDMINE_SUPPORTED_SCM.each do |scm|
23 require_dependency "repository/#{scm.underscore}"
26 require_dependency "repository/#{scm.underscore}"
24 end
27 end
@@ -17,6 +17,7
17
17
18 class IssueCategoriesController < ApplicationController
18 class IssueCategoriesController < ApplicationController
19 layout 'base'
19 layout 'base'
20 menu_item :settings
20 before_filter :find_project, :authorize
21 before_filter :find_project, :authorize
21
22
22 verify :method => :post, :only => :destroy
23 verify :method => :post, :only => :destroy
@@ -17,6 +17,7
17
17
18 class MessagesController < ApplicationController
18 class MessagesController < ApplicationController
19 layout 'base'
19 layout 'base'
20 menu_item :boards
20 before_filter :find_board, :only => :new
21 before_filter :find_board, :only => :new
21 before_filter :find_message, :except => :new
22 before_filter :find_message, :except => :new
22 before_filter :authorize
23 before_filter :authorize
@@ -17,6 +17,13
17
17
18 class ProjectsController < ApplicationController
18 class ProjectsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 menu_item :overview
21 menu_item :activity, :only => :activity
22 menu_item :roadmap, :only => :roadmap
23 menu_item :files, :only => [:list_files, :add_file]
24 menu_item :settings, :only => :settings
25 menu_item :issues, :only => [:add_issue, :bulk_edit_issues, :changelog, :move_issues]
26
20 before_filter :find_project, :except => [ :index, :list, :add ]
27 before_filter :find_project, :except => [ :index, :list, :add ]
21 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
28 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
22 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
29 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
@@ -17,6 +17,7
17
17
18 class QueriesController < ApplicationController
18 class QueriesController < ApplicationController
19 layout 'base'
19 layout 'base'
20 menu_item :issues
20 before_filter :find_project, :authorize
21 before_filter :find_project, :authorize
21
22
22 def index
23 def index
@@ -17,6 +17,7
17
17
18 class ReportsController < ApplicationController
18 class ReportsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 menu_item :issues
20 before_filter :find_project, :authorize
21 before_filter :find_project, :authorize
21
22
22 def issue_report
23 def issue_report
@@ -24,6 +24,7 end
24
24
25 class RepositoriesController < ApplicationController
25 class RepositoriesController < ApplicationController
26 layout 'base'
26 layout 'base'
27 menu_item :repository
27 before_filter :find_repository, :except => :edit
28 before_filter :find_repository, :except => :edit
28 before_filter :find_project, :only => :edit
29 before_filter :find_project, :only => :edit
29 before_filter :authorize
30 before_filter :authorize
@@ -16,7 +16,8
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class TimelogController < ApplicationController
18 class TimelogController < ApplicationController
19 layout 'base'
19 layout 'base'
20 menu_item :issues
20 before_filter :find_project, :authorize
21 before_filter :find_project, :authorize
21
22
22 helper :sort
23 helper :sort
@@ -17,6 +17,7
17
17
18 class VersionsController < ApplicationController
18 class VersionsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 menu_item :roadmap
20 before_filter :find_project, :authorize
21 before_filter :find_project, :authorize
21
22
22 cache_sweeper :version_sweeper, :only => [ :edit, :destroy ]
23 cache_sweeper :version_sweeper, :only => [ :edit, :destroy ]
@@ -17,6 +17,7
17
17
18 class WikisController < ApplicationController
18 class WikisController < ApplicationController
19 layout 'base'
19 layout 'base'
20 menu_item :settings
20 before_filter :find_project, :authorize
21 before_filter :find_project, :authorize
21
22
22 # Create or update a project's wiki
23 # Create or update a project's wiki
@@ -49,13 +49,7
49 <h1><%= h(@project ? @project.name : Setting.app_title) %></h1>
49 <h1><%= h(@project ? @project.name : Setting.app_title) %></h1>
50
50
51 <div id="main-menu">
51 <div id="main-menu">
52 <ul>
52 <%= render_main_menu(@project) %>
53 <% Redmine::MenuManager.allowed_items(:project_menu, User.current, @project).each do |item| %>
54 <% unless item.condition && !item.condition.call(@project) %>
55 <li><%= link_to l(item.name), {item.param => @project}.merge(item.url) %></li>
56 <% end %>
57 <% end if @project && !@project.new_record? %>
58 </ul>
59 </div>
53 </div>
60 </div>
54 </div>
61
55
@@ -91,15 +91,18 end
91
91
92 # Project menu configuration
92 # Project menu configuration
93 Redmine::MenuManager.map :project_menu do |menu|
93 Redmine::MenuManager.map :project_menu do |menu|
94 menu.push :label_overview, :controller => 'projects', :action => 'show'
94 menu.push :overview, { :controller => 'projects', :action => 'show' }, :caption => :label_overview
95 menu.push :label_activity, :controller => 'projects', :action => 'activity'
95 menu.push :activity, { :controller => 'projects', :action => 'activity' }, :caption => :label_activity
96 menu.push :label_roadmap, :controller => 'projects', :action => 'roadmap'
96 menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' }, :caption => :label_roadmap
97 menu.push :label_issue_plural, { :controller => 'issues', :action => 'index' }, :param => :project_id
97 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
98 menu.push :label_news_plural, { :controller => 'news', :action => 'index' }, :param => :project_id
98 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
99 menu.push :label_document_plural, { :controller => 'documents', :action => 'index' }, :param => :project_id
99 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
100 menu.push :label_wiki, { :controller => 'wiki', :action => 'index', :page => nil }, :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
100 menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil },
101 menu.push :label_board_plural, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, :if => Proc.new { |p| p.boards.any? }
101 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }, :caption => :label_wiki
102 menu.push :label_attachment_plural, :controller => 'projects', :action => 'list_files'
102 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
103 menu.push :label_repository, { :controller => 'repositories', :action => 'show' }, :if => Proc.new { |p| p.repository && !p.repository.new_record? }
103 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
104 menu.push :label_settings, :controller => 'projects', :action => 'settings'
104 menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_attachment_plural
105 menu.push :repository, { :controller => 'repositories', :action => 'show' },
106 :if => Proc.new { |p| p.repository && !p.repository.new_record? }, :caption => :label_repository
107 menu.push :settings, { :controller => 'projects', :action => 'settings' }, :caption => :label_settings
105 end
108 end
@@ -17,6 +17,63
17
17
18 module Redmine
18 module Redmine
19 module MenuManager
19 module MenuManager
20 module MenuController
21 def self.included(base)
22 base.extend(ClassMethods)
23 end
24
25 module ClassMethods
26 @@menu_items = Hash.new {|hash, key| hash[key] = {:default => key, :actions => {}}}
27 mattr_accessor :menu_items
28
29 # Set the menu item name for a controller or specific actions
30 # Examples:
31 # * menu_item :tickets # => sets the menu name to :tickets for the whole controller
32 # * menu_item :tickets, :only => :list # => sets the menu name to :tickets for the 'list' action only
33 # * menu_item :tickets, :only => [:list, :show] # => sets the menu name to :tickets for 2 actions only
34 #
35 # The default menu item name for a controller is controller_name by default
36 # Eg. the default menu item name for ProjectsController is :projects
37 def menu_item(id, options = {})
38 if actions = options[:only]
39 actions = [] << actions unless actions.is_a?(Array)
40 actions.each {|a| menu_items[controller_name.to_sym][:actions][a.to_sym] = id}
41 else
42 menu_items[controller_name.to_sym][:default] = id
43 end
44 end
45 end
46
47 def menu_items
48 self.class.menu_items
49 end
50
51 # Returns the menu item name according to the current action
52 def current_menu_item
53 menu_items[controller_name.to_sym][:actions][action_name.to_sym] ||
54 menu_items[controller_name.to_sym][:default]
55 end
56 end
57
58 module MenuHelper
59 # Returns the current menu item name
60 def current_menu_item
61 @controller.current_menu_item
62 end
63
64 # Renders the application main menu as a ul element
65 def render_main_menu(project)
66 links = []
67 Redmine::MenuManager.allowed_items(:project_menu, User.current, project).each do |item|
68 unless item.condition && !item.condition.call(project)
69 links << content_tag('li',
70 link_to(l(item.caption), {item.param => project}.merge(item.url),
71 :class => (current_menu_item == item.name ? 'selected' : nil)))
72 end
73 end if project && !project.new_record?
74 links.empty? ? nil : content_tag('ul', links.join("\n"))
75 end
76 end
20
77
21 class << self
78 class << self
22 def map(menu_name)
79 def map(menu_name)
@@ -48,13 +105,14 module Redmine
48 end
105 end
49
106
50 class MenuItem
107 class MenuItem
51 attr_reader :name, :url, :param, :condition
108 attr_reader :name, :url, :param, :condition, :caption
52
109
53 def initialize(name, url, options)
110 def initialize(name, url, options)
54 @name = name
111 @name = name
55 @url = url
112 @url = url
56 @condition = options[:if]
113 @condition = options[:if]
57 @param = options[:param] || :id
114 @param = options[:param] || :id
115 @caption = options[:caption] || name.to_s.humanize
58 end
116 end
59 end
117 end
60 end
118 end
@@ -34,7 +34,7 h4, .wiki h3 {font-size: 12px;padding: 2px 10px 1px 0px;margin-bottom: 5px; bord
34 padding: 4px 4px 4px 4px;
34 padding: 4px 4px 4px 4px;
35 background: #2C4056;
35 background: #2C4056;
36 }
36 }
37 #main-menu li a:hover {background:#759FCF;}
37 #main-menu li a:hover, #main-menu li a.selected {background:#759FCF;}
38
38
39 #main {background: url(../images/mainbg.png) repeat-x; background-color:#EEEEEE;}
39 #main {background: url(../images/mainbg.png) repeat-x; background-color:#EEEEEE;}
40
40
General Comments 0
You need to be logged in to leave comments. Login now