##// END OF EJS Templates
Use the main menu for project related actions that support cross-project display....
Jean-Philippe Lang -
r15601:124a459d5585
parent child
Show More
@@ -19,6 +19,8 class AccountController < ApplicationController
19 helper :custom_fields
19 helper :custom_fields
20 include CustomFieldsHelper
20 include CustomFieldsHelper
21
21
22 self.main_menu = false
23
22 # prevents login action to be filtered by check_if_login_required application scope filter
24 # prevents login action to be filtered by check_if_login_required application scope filter
23 skip_before_action :check_if_login_required, :check_password_change
25 skip_before_action :check_if_login_required, :check_password_change
24
26
@@ -17,6 +17,7
17
17
18 class AdminController < ApplicationController
18 class AdminController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20 menu_item :projects, :only => :projects
21 menu_item :projects, :only => :projects
21 menu_item :plugins, :only => :plugins
22 menu_item :plugins, :only => :plugins
22 menu_item :info, :only => :info
23 menu_item :info, :only => :info
@@ -17,6 +17,7
17
17
18 class AuthSourcesController < ApplicationController
18 class AuthSourcesController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20 menu_item :ldap_authentication
21 menu_item :ldap_authentication
21
22
22 before_action :require_admin
23 before_action :require_admin
@@ -17,6 +17,7
17
17
18 class CustomFieldEnumerationsController < ApplicationController
18 class CustomFieldEnumerationsController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20
21
21 before_action :require_admin
22 before_action :require_admin
22 before_action :find_custom_field
23 before_action :find_custom_field
@@ -17,6 +17,7
17
17
18 class CustomFieldsController < ApplicationController
18 class CustomFieldsController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20
21
21 before_action :require_admin
22 before_action :require_admin
22 before_action :build_new_custom_field, :only => [:new, :create]
23 before_action :build_new_custom_field, :only => [:new, :create]
@@ -16,6 +16,7
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 EmailAddressesController < ApplicationController
18 class EmailAddressesController < ApplicationController
19 self.main_menu = false
19 before_action :find_user, :require_admin_or_current_user
20 before_action :find_user, :require_admin_or_current_user
20 before_action :find_email_address, :only => [:update, :destroy]
21 before_action :find_email_address, :only => [:update, :destroy]
21 require_sudo_mode :create, :update, :destroy
22 require_sudo_mode :create, :update, :destroy
@@ -17,6 +17,7
17
17
18 class EnumerationsController < ApplicationController
18 class EnumerationsController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20
21
21 before_action :require_admin, :except => :index
22 before_action :require_admin, :except => :index
22 before_action :require_admin_or_api_request, :only => :index
23 before_action :require_admin_or_api_request, :only => :index
@@ -17,6 +17,7
17
17
18 class GroupsController < ApplicationController
18 class GroupsController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20
21
21 before_action :require_admin
22 before_action :require_admin
22 before_action :find_group, :except => [:index, :new, :create]
23 before_action :find_group, :except => [:index, :new, :create]
@@ -17,6 +17,7
17
17
18 class IssueStatusesController < ApplicationController
18 class IssueStatusesController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20
21
21 before_action :require_admin, :except => :index
22 before_action :require_admin, :except => :index
22 before_action :require_admin_or_api_request, :only => :index
23 before_action :require_admin_or_api_request, :only => :index
@@ -16,6 +16,7
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 MyController < ApplicationController
18 class MyController < ApplicationController
19 self.main_menu = false
19 before_action :require_login
20 before_action :require_login
20 # let user change user's password when user has to
21 # let user change user's password when user has to
21 skip_before_action :check_password_change, :only => :password
22 skip_before_action :check_password_change, :only => :password
@@ -17,6 +17,7
17
17
18 class PrincipalMembershipsController < ApplicationController
18 class PrincipalMembershipsController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20
21
21 before_action :require_admin
22 before_action :require_admin
22 before_action :find_principal, :only => [:new, :create]
23 before_action :find_principal, :only => [:new, :create]
@@ -18,6 +18,7
18 class ProjectsController < ApplicationController
18 class ProjectsController < ApplicationController
19 menu_item :overview
19 menu_item :overview
20 menu_item :settings, :only => :settings
20 menu_item :settings, :only => :settings
21 menu_item :projects, :only => [:index, :new, :create]
21
22
22 before_action :find_project, :except => [ :index, :list, :new, :create, :copy ]
23 before_action :find_project, :except => [ :index, :list, :new, :create, :copy ]
23 before_action :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
24 before_action :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
@@ -17,6 +17,7
17
17
18 class RolesController < ApplicationController
18 class RolesController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20
21
21 before_action :require_admin, :except => [:index, :show]
22 before_action :require_admin, :except => [:index, :show]
22 before_action :require_admin_or_api_request, :only => [:index, :show]
23 before_action :require_admin_or_api_request, :only => [:index, :show]
@@ -17,6 +17,7
17
17
18 class SettingsController < ApplicationController
18 class SettingsController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20 menu_item :plugins, :only => :plugin
21 menu_item :plugins, :only => :plugin
21
22
22 helper :queries
23 helper :queries
@@ -17,6 +17,7
17
17
18 class TrackersController < ApplicationController
18 class TrackersController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20
21
21 before_action :require_admin, :except => :index
22 before_action :require_admin, :except => :index
22 before_action :require_admin_or_api_request, :only => :index
23 before_action :require_admin_or_api_request, :only => :index
@@ -17,6 +17,7
17
17
18 class UsersController < ApplicationController
18 class UsersController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20
21
21 before_action :require_admin, :except => :show
22 before_action :require_admin, :except => :show
22 before_action :find_user, :only => [:show, :edit, :update, :destroy]
23 before_action :find_user, :only => [:show, :edit, :update, :destroy]
@@ -16,6 +16,7
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 WelcomeController < ApplicationController
18 class WelcomeController < ApplicationController
19 self.main_menu = false
19
20
20 def index
21 def index
21 @news = News.latest User.current
22 @news = News.latest User.current
@@ -17,6 +17,7
17
17
18 class WorkflowsController < ApplicationController
18 class WorkflowsController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20 self.main_menu = false
20
21
21 before_action :require_admin
22 before_action :require_admin
22
23
@@ -48,18 +48,11 module ProjectsHelper
48 end
48 end
49
49
50 def render_project_action_links
50 def render_project_action_links
51 links = []
51 links = "".html_safe
52 if User.current.allowed_to?(:add_project, nil, :global => true)
52 if User.current.allowed_to?(:add_project, nil, :global => true)
53 links << link_to(l(:label_project_new), new_project_path, :class => 'icon icon-add')
53 links << link_to(l(:label_project_new), new_project_path, :class => 'icon icon-add')
54 end
54 end
55 if User.current.allowed_to?(:view_issues, nil, :global => true)
55 links
56 links << link_to(l(:label_issue_view_all), issues_path)
57 end
58 if User.current.allowed_to?(:view_time_entries, nil, :global => true)
59 links << link_to(l(:label_overall_spent_time), time_entries_path)
60 end
61 links << link_to(l(:label_overall_activity), activity_path)
62 links.join(" | ").html_safe
63 end
56 end
64
57
65 # Renders the projects index
58 # Renders the projects index
@@ -203,7 +203,21 Redmine::MenuManager.map :account_menu do |menu|
203 end
203 end
204
204
205 Redmine::MenuManager.map :application_menu do |menu|
205 Redmine::MenuManager.map :application_menu do |menu|
206 # Empty
206 menu.push :projects, {:controller => 'projects', :action => 'index'},
207 :permission => nil,
208 :caption => :label_project_plural
209 menu.push :activity, {:controller => 'activities', :action => 'index'}
210 menu.push :issues, {:controller => 'issues', :action => 'index'},
211 :if => Proc.new {User.current.allowed_to?(:view_issues, nil, :global => true)},
212 :caption => :label_issue_plural
213 menu.push :time_entries, {:controller => 'timelog', :action => 'index'},
214 :if => Proc.new {User.current.allowed_to?(:view_time_entries, nil, :global => true)},
215 :caption => :label_spent_time
216 menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :caption => :label_gantt
217 menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :caption => :label_calendar
218
219 menu.push :news, {:controller => 'news', :action => 'index'},
220 :caption => :label_news_plural
207 end
221 end
208
222
209 Redmine::MenuManager.map :admin_menu do |menu|
223 Redmine::MenuManager.map :admin_menu do |menu|
@@ -22,6 +22,9 module Redmine
22
22
23 module MenuController
23 module MenuController
24 def self.included(base)
24 def self.included(base)
25 base.class_attribute :main_menu
26 base.main_menu = true
27
25 base.extend(ClassMethods)
28 base.extend(ClassMethods)
26 end
29 end
27
30
@@ -51,6 +54,14 module Redmine
51 self.class.menu_items
54 self.class.menu_items
52 end
55 end
53
56
57 def current_menu(project)
58 if project && !project.new_record?
59 :project_menu
60 elsif self.class.main_menu
61 :application_menu
62 end
63 end
64
54 # Returns the menu item name according to the current action
65 # Returns the menu item name according to the current action
55 def current_menu_item
66 def current_menu_item
56 @current_menu_item ||= menu_items[controller_name.to_sym][:actions][action_name.to_sym] ||
67 @current_menu_item ||= menu_items[controller_name.to_sym][:actions][action_name.to_sym] ||
@@ -77,12 +88,14 module Redmine
77
88
78 # Renders the application main menu
89 # Renders the application main menu
79 def render_main_menu(project)
90 def render_main_menu(project)
80 render_menu((project && !project.new_record?) ? :project_menu : :application_menu, project)
91 if menu_name = controller.current_menu(project)
92 render_menu(menu_name, project)
93 end
81 end
94 end
82
95
83 def display_main_menu?(project)
96 def display_main_menu?(project)
84 menu_name = project && !project.new_record? ? :project_menu : :application_menu
97 menu_name = controller.current_menu(project)
85 Redmine::MenuManager.items(menu_name).children.present?
98 menu_name.present? && Redmine::MenuManager.items(menu_name).children.present?
86 end
99 end
87
100
88 def render_menu(menu, project=nil)
101 def render_menu(menu, project=nil)
@@ -2594,7 +2594,7 class IssuesControllerTest < Redmine::ControllerTest
2594 :subject => ''}
2594 :subject => ''}
2595 assert_response :success
2595 assert_response :success
2596 # no project menu
2596 # no project menu
2597 assert_select '#main-menu', 0
2597 assert_select '#main-menu a.overview', 0
2598 end
2598 end
2599
2599
2600 def test_post_create_should_send_a_notification
2600 def test_post_create_should_send_a_notification
@@ -63,4 +63,17 class MenuManagerTest < Redmine::IntegrationTest
63 end
63 end
64 end
64 end
65 end
65 end
66
67 def test_main_menu_should_select_projects_tab_on_project_list
68 get '/projects'
69 assert_select '#main-menu' do
70 assert_select 'a.projects'
71 assert_select 'a.projects.selected'
72 end
73 end
74
75 def test_main_menu_should_not_show_up_on_account
76 get '/login'
77 assert_select '#main-menu', 0
78 end
66 end
79 end
General Comments 0
You need to be logged in to leave comments. Login now