]> source.dussan.org Git - redmine.git/commitdiff
Use the main menu for project related actions that support cross-project display.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 19 Nov 2016 10:30:02 +0000 (10:30 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 19 Nov 2016 10:30:02 +0000 (10:30 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@15983 e93f8b46-1217-0410-a6f0-8f06a7374b81

23 files changed:
app/controllers/account_controller.rb
app/controllers/admin_controller.rb
app/controllers/auth_sources_controller.rb
app/controllers/custom_field_enumerations_controller.rb
app/controllers/custom_fields_controller.rb
app/controllers/email_addresses_controller.rb
app/controllers/enumerations_controller.rb
app/controllers/groups_controller.rb
app/controllers/issue_statuses_controller.rb
app/controllers/my_controller.rb
app/controllers/principal_memberships_controller.rb
app/controllers/projects_controller.rb
app/controllers/roles_controller.rb
app/controllers/settings_controller.rb
app/controllers/trackers_controller.rb
app/controllers/users_controller.rb
app/controllers/welcome_controller.rb
app/controllers/workflows_controller.rb
app/helpers/projects_helper.rb
lib/redmine.rb
lib/redmine/menu_manager.rb
test/functional/issues_controller_test.rb
test/integration/lib/redmine/menu_manager_test.rb

index 0dc1e9811ab91eabf76d7f6720e4fa70c8755b9a..ece857a22456bacc9a941b4be4cfcc9b85653c0e 100644 (file)
@@ -19,6 +19,8 @@ class AccountController < ApplicationController
   helper :custom_fields
   include CustomFieldsHelper
 
+  self.main_menu = false
+
   # prevents login action to be filtered by check_if_login_required application scope filter
   skip_before_action :check_if_login_required, :check_password_change
 
index 9842ec0e1678e20e7554e3b363490fc30025d034..6a3a09bf1e38023360feb93998955a3a46ed5fee 100644 (file)
@@ -17,6 +17,7 @@
 
 class AdminController < ApplicationController
   layout 'admin'
+  self.main_menu = false
   menu_item :projects, :only => :projects
   menu_item :plugins, :only => :plugins
   menu_item :info, :only => :info
index d6dd588967d02797a235eb186756a72495e629dc..a6d9158c6e7f584cb3a0a200c7f868d85cc178f5 100644 (file)
@@ -17,6 +17,7 @@
 
 class AuthSourcesController < ApplicationController
   layout 'admin'
+  self.main_menu = false
   menu_item :ldap_authentication
 
   before_action :require_admin
index f141d0d8a370ba4833899761ae332fd5cd54473d..f20269b31f16fbb6626d8e571438fe1858518eb8 100644 (file)
@@ -17,6 +17,7 @@
 
 class CustomFieldEnumerationsController < ApplicationController
   layout 'admin'
+  self.main_menu = false
 
   before_action :require_admin
   before_action :find_custom_field
index 57cb731426fa2cb05e32afa06096a80a2af0fe9a..26e9b044d15c13c882d081e2e7674e4dd62fef22 100644 (file)
@@ -17,6 +17,7 @@
 
 class CustomFieldsController < ApplicationController
   layout 'admin'
+  self.main_menu = false
 
   before_action :require_admin
   before_action :build_new_custom_field, :only => [:new, :create]
index 2fb6b29782e6bd9f40257465abd221e37a26acca..cbb301955a192086329fe609d06a93187e17de11 100644 (file)
@@ -16,6 +16,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 class EmailAddressesController < ApplicationController
+  self.main_menu = false
   before_action :find_user, :require_admin_or_current_user
   before_action :find_email_address, :only => [:update, :destroy]
   require_sudo_mode :create, :update, :destroy
index e3ae6698677bfa84ca5c67d6cb8da87250685b66..f89662082b55b6d9fbb5b56da2714d16e0ed6731 100644 (file)
@@ -17,6 +17,7 @@
 
 class EnumerationsController < ApplicationController
   layout 'admin'
+  self.main_menu = false
 
   before_action :require_admin, :except => :index
   before_action :require_admin_or_api_request, :only => :index
index 52a1242b8cb0e7555bd3356747a64df9177c6c7d..68ecbaa55dc82a6abba2cbef76442fe1081fa75a 100644 (file)
@@ -17,6 +17,7 @@
 
 class GroupsController < ApplicationController
   layout 'admin'
+  self.main_menu = false
 
   before_action :require_admin
   before_action :find_group, :except => [:index, :new, :create]
index efd2d1c44ca7e3f604ae89e0489bc86c5ce733bc..54248d819c216ee4ed0141956b406fb3fcc5010c 100644 (file)
@@ -17,6 +17,7 @@
 
 class IssueStatusesController < ApplicationController
   layout 'admin'
+  self.main_menu = false
 
   before_action :require_admin, :except => :index
   before_action :require_admin_or_api_request, :only => :index
index 5cf677a2d8cc47b4cc92e7987386c838492dcd1a..be1c3c36dcddf4b56996a8b914c56847553a1393 100644 (file)
@@ -16,6 +16,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 class MyController < ApplicationController
+  self.main_menu = false
   before_action :require_login
   # let user change user's password when user has to
   skip_before_action :check_password_change, :only => :password
index 0ac150d7138f2784b6cb8f0938130c82ee179787..b03460b5475c805fd094a610909a11ac7c53390f 100644 (file)
@@ -17,6 +17,7 @@
 
 class PrincipalMembershipsController < ApplicationController
   layout 'admin'
+  self.main_menu = false
 
   before_action :require_admin
   before_action :find_principal, :only => [:new, :create]
index ba7483c38cf26741a9300cb63b599257f65e14d1..98fc23f5fe739d20c0e5d9708c7da5650fb75507 100644 (file)
@@ -18,6 +18,7 @@
 class ProjectsController < ApplicationController
   menu_item :overview
   menu_item :settings, :only => :settings
+  menu_item :projects, :only => [:index, :new,  :create]
 
   before_action :find_project, :except => [ :index, :list, :new, :create, :copy ]
   before_action :authorize, :except => [ :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy]
index c33eff57830b10b5f49988ab591d10285f1febdd..a09455949869a161be49eb4c775a0a59af0e689c 100644 (file)
@@ -17,6 +17,7 @@
 
 class RolesController < ApplicationController
   layout 'admin'
+  self.main_menu = false
 
   before_action :require_admin, :except => [:index, :show]
   before_action :require_admin_or_api_request, :only => [:index, :show]
index fd9cd04c8cd15f2e93378a233e81e5cdbb101fa5..6b7e51874bc01449c651ea96af70349ab558e034 100644 (file)
@@ -17,6 +17,7 @@
 
 class SettingsController < ApplicationController
   layout 'admin'
+  self.main_menu = false
   menu_item :plugins, :only => :plugin
 
   helper :queries
index 363bd40d8fe5321e932869f91869f973593b12c2..5bae880d14552916aca6d715ddb8f2f7a22851a4 100644 (file)
@@ -17,6 +17,7 @@
 
 class TrackersController < ApplicationController
   layout 'admin'
+  self.main_menu = false
 
   before_action :require_admin, :except => :index
   before_action :require_admin_or_api_request, :only => :index
index 51f6af6bbdde88ca2c03915f367b29282a53fdaa..ca1e5e49a0a751900f4dec3a14f6af978e299597 100644 (file)
@@ -17,6 +17,7 @@
 
 class UsersController < ApplicationController
   layout 'admin'
+  self.main_menu = false
 
   before_action :require_admin, :except => :show
   before_action :find_user, :only => [:show, :edit, :update, :destroy]
index fe06d873f302de5ddd01716a7994c88a0288a865..783045eec250425589b1e33f9c91c200f98d4063 100644 (file)
@@ -16,6 +16,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 class WelcomeController < ApplicationController
+  self.main_menu = false
 
   def index
     @news = News.latest User.current
index 9fc3767251781beb9a32901e0321736b3b93bbab..e825171bf0b093e4a7f4504b48a9d18a2b7cfdbf 100644 (file)
@@ -17,6 +17,7 @@
 
 class WorkflowsController < ApplicationController
   layout 'admin'
+  self.main_menu = false
 
   before_action :require_admin
 
index 63218e1d34192bbe387730b50d0b324b3df48374..e8115205bc39ffe74f819238dfbcb547cce78c17 100644 (file)
@@ -48,18 +48,11 @@ module ProjectsHelper
   end
 
   def render_project_action_links
-    links = []
+    links = "".html_safe
     if User.current.allowed_to?(:add_project, nil, :global => true)
       links << link_to(l(:label_project_new), new_project_path, :class => 'icon icon-add')
     end
-    if User.current.allowed_to?(:view_issues, nil, :global => true)
-      links << link_to(l(:label_issue_view_all), issues_path)
-    end
-    if User.current.allowed_to?(:view_time_entries, nil, :global => true)
-      links << link_to(l(:label_overall_spent_time), time_entries_path)
-    end
-    links << link_to(l(:label_overall_activity), activity_path)
-    links.join(" | ").html_safe
+    links
   end
 
   # Renders the projects index
index 193d5d1a3009635ede6382df578d5a2fb804b9fb..4ad182046a3c0d7ebe40fed659d999752803e30c 100644 (file)
@@ -203,7 +203,21 @@ Redmine::MenuManager.map :account_menu do |menu|
 end
 
 Redmine::MenuManager.map :application_menu do |menu|
-  # Empty
+  menu.push :projects, {:controller => 'projects', :action => 'index'},
+    :permission => nil,
+    :caption => :label_project_plural
+  menu.push :activity, {:controller => 'activities', :action => 'index'}
+  menu.push :issues,   {:controller => 'issues', :action => 'index'},
+    :if => Proc.new {User.current.allowed_to?(:view_issues, nil, :global => true)},
+    :caption => :label_issue_plural
+  menu.push :time_entries, {:controller => 'timelog', :action => 'index'},
+    :if => Proc.new {User.current.allowed_to?(:view_time_entries, nil, :global => true)},
+    :caption => :label_spent_time
+  menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :caption => :label_gantt
+  menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :caption => :label_calendar
+
+  menu.push :news, {:controller => 'news', :action => 'index'},
+    :caption => :label_news_plural
 end
 
 Redmine::MenuManager.map :admin_menu do |menu|
index 3d19edce7f4542a093b1b741384b3e3b8fdb1a6d..9f90f681a1c916ba76d375245d4e843d3ce536e9 100644 (file)
@@ -22,6 +22,9 @@ module Redmine
 
     module MenuController
       def self.included(base)
+        base.class_attribute :main_menu
+        base.main_menu = true
+
         base.extend(ClassMethods)
       end
 
@@ -51,6 +54,14 @@ module Redmine
         self.class.menu_items
       end
 
+      def current_menu(project)
+        if project && !project.new_record?
+          :project_menu
+        elsif self.class.main_menu
+          :application_menu
+        end
+      end
+
       # Returns the menu item name according to the current action
       def current_menu_item
         @current_menu_item ||= menu_items[controller_name.to_sym][:actions][action_name.to_sym] ||
@@ -77,12 +88,14 @@ module Redmine
 
       # Renders the application main menu
       def render_main_menu(project)
-        render_menu((project && !project.new_record?) ? :project_menu : :application_menu, project)
+        if menu_name = controller.current_menu(project)
+          render_menu(menu_name, project)
+        end
       end
 
       def display_main_menu?(project)
-        menu_name = project && !project.new_record? ? :project_menu : :application_menu
-        Redmine::MenuManager.items(menu_name).children.present?
+        menu_name = controller.current_menu(project)
+        menu_name.present? && Redmine::MenuManager.items(menu_name).children.present?
       end
 
       def render_menu(menu, project=nil)
index 3e6113f38f6c378ed33ae064f2ab6470dae680ac..5426679c1c4f90823a0f26ba268edb4de9bce820 100644 (file)
@@ -2594,7 +2594,7 @@ class IssuesControllerTest < Redmine::ControllerTest
                     :subject => ''}
     assert_response :success
     # no project menu
-    assert_select '#main-menu', 0
+    assert_select '#main-menu a.overview', 0
   end
 
   def test_post_create_should_send_a_notification
index 516872c4c7a2b137072e494c2e8a866bd6a96306..26d8680e8ba03307a55ac1d1f4336a2f3820aaec 100644 (file)
@@ -63,4 +63,17 @@ class MenuManagerTest < Redmine::IntegrationTest
       end
     end
   end
+
+  def test_main_menu_should_select_projects_tab_on_project_list
+    get '/projects'
+    assert_select '#main-menu' do
+      assert_select 'a.projects'
+      assert_select 'a.projects.selected'
+    end
+  end
+
+  def test_main_menu_should_not_show_up_on_account
+    get '/login'
+    assert_select '#main-menu', 0
+  end
 end