]> source.dussan.org Git - redmine.git/commitdiff
Jump to the current tab when using the project quick-jump combo (#2364).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 30 Dec 2008 14:24:51 +0000 (14:24 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 30 Dec 2008 14:24:51 +0000 (14:24 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2210 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/projects_controller.rb
app/views/layouts/_project_selector.rhtml
lib/redmine/menu_manager.rb
test/functional/projects_controller_test.rb

index 8fd79533feb47c43985bc8e76607ff1d05b18f60..0f0805262d0d8bc29da8a9bad9005e6e765a280a 100644 (file)
@@ -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")
index 7a2803534e2f2379f9988a89421fb81f35a23a90..d8e2a72c9484e3fa89cbb9b25911783f8361e037 100644 (file)
@@ -3,10 +3,10 @@
 <option selected="selected"><%= l(:label_jump_to_a_project) %></option>
 <option disabled="disabled">---</option>
 <% 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', ('&#187; ' + h(project.name)), :value => url_for(:controller => 'projects', :action => 'show', :id => project)) %>
+        <%= content_tag('option', ('&#187; ' + h(project.name)), :value => url_for(:controller => 'projects', :action => 'show', :id => project, :jump => current_menu_item)) %>
     <% end %>
 <% end %>
 </select>
index f8fc5dd8d9234051ea4c00cc44f16c092507c12f..7a89a32b9b653598085402496830f5659f080eb5 100644 (file)
@@ -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
     
index a8f8ecb76f1fdec8f100b26bb2686848768fd93f..8737b3c59582d501be3da7866a2619c530441e07 100644 (file)
@@ -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|