From 2355324d73e26f224e2b13b21249f181314b289f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 30 Dec 2008 14:24:51 +0000 Subject: [PATCH] Jump to the current tab when using the project quick-jump combo (#2364). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2210 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/projects_controller.rb | 5 +++++ app/views/layouts/_project_selector.rhtml | 4 ++-- lib/redmine/menu_manager.rb | 15 +++++++++++++-- test/functional/projects_controller_test.rb | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 8fd79533f..0f0805262 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -84,6 +84,11 @@ class ProjectsController < ApplicationController # Show @project def show + if params[:jump] + # try to redirect to the requested menu item + redirect_to_project_menu_item(@project, params[:jump]) && return + end + @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current)) @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") diff --git a/app/views/layouts/_project_selector.rhtml b/app/views/layouts/_project_selector.rhtml index 7a2803534..d8e2a72c9 100644 --- a/app/views/layouts/_project_selector.rhtml +++ b/app/views/layouts/_project_selector.rhtml @@ -3,10 +3,10 @@ <% user_projects_by_root.keys.sort.each do |root| %> - <%= content_tag('option', h(root.name), :value => url_for(:controller => 'projects', :action => 'show', :id => root)) %> + <%= content_tag('option', h(root.name), :value => url_for(:controller => 'projects', :action => 'show', :id => root, :jump => current_menu_item)) %> <% user_projects_by_root[root].sort.each do |project| %> <% next if project == root %> - <%= content_tag('option', ('» ' + h(project.name)), :value => url_for(:controller => 'projects', :action => 'show', :id => project)) %> + <%= content_tag('option', ('» ' + h(project.name)), :value => url_for(:controller => 'projects', :action => 'show', :id => project, :jump => current_menu_item)) %> <% end %> <% end %> diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb index f8fc5dd8d..7a89a32b9 100644 --- a/lib/redmine/menu_manager.rb +++ b/lib/redmine/menu_manager.rb @@ -52,8 +52,19 @@ module Redmine # 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] + @current_menu_item ||= menu_items[controller_name.to_sym][:actions][action_name.to_sym] || + menu_items[controller_name.to_sym][:default] + end + + # Redirects user to the menu item of the given project + # Returns false if user is not authorized + def redirect_to_project_menu_item(project, name) + item = Redmine::MenuManager.items(:project_menu).detect {|i| i.name.to_s == name.to_s} + if item && User.current.allowed_to?(item.url, project) && (item.condition.nil? || item.condition.call(project)) + redirect_to({item.param => project}.merge(item.url)) + return true + end + false end end diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index a8f8ecb76..8737b3c59 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -287,6 +287,23 @@ class ProjectsControllerTest < Test::Unit::TestCase assert Project.find(1).active? end + def test_jump_should_redirect_to_active_tab + get :show, :id => 1, :jump => 'issues' + assert_redirected_to 'projects/ecookbook/issues' + end + + def test_jump_should_not_redirect_to_inactive_tab + get :show, :id => 3, :jump => 'documents' + assert_response :success + assert_template 'show' + end + + def test_jump_should_not_redirect_to_unknown_tab + get :show, :id => 3, :jump => 'foobar' + assert_response :success + assert_template 'show' + end + def test_project_menu assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do Redmine::MenuManager.map :project_menu do |menu| -- 2.39.5