##// END OF EJS Templates
Jump to the current tab when using the project quick-jump combo (#2364)....
Jean-Philippe Lang -
r2208:2355324d73e2
parent child
Show More
@@ -84,6 +84,11 class ProjectsController < ApplicationController
84
84
85 # Show @project
85 # Show @project
86 def show
86 def show
87 if params[:jump]
88 # try to redirect to the requested menu item
89 redirect_to_project_menu_item(@project, params[:jump]) && return
90 end
91
87 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
92 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
88 @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current))
93 @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current))
89 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
94 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
@@ -3,10 +3,10
3 <option selected="selected"><%= l(:label_jump_to_a_project) %></option>
3 <option selected="selected"><%= l(:label_jump_to_a_project) %></option>
4 <option disabled="disabled">---</option>
4 <option disabled="disabled">---</option>
5 <% user_projects_by_root.keys.sort.each do |root| %>
5 <% user_projects_by_root.keys.sort.each do |root| %>
6 <%= content_tag('option', h(root.name), :value => url_for(:controller => 'projects', :action => 'show', :id => root)) %>
6 <%= content_tag('option', h(root.name), :value => url_for(:controller => 'projects', :action => 'show', :id => root, :jump => current_menu_item)) %>
7 <% user_projects_by_root[root].sort.each do |project| %>
7 <% user_projects_by_root[root].sort.each do |project| %>
8 <% next if project == root %>
8 <% next if project == root %>
9 <%= content_tag('option', ('&#187; ' + h(project.name)), :value => url_for(:controller => 'projects', :action => 'show', :id => project)) %>
9 <%= content_tag('option', ('&#187; ' + h(project.name)), :value => url_for(:controller => 'projects', :action => 'show', :id => project, :jump => current_menu_item)) %>
10 <% end %>
10 <% end %>
11 <% end %>
11 <% end %>
12 </select>
12 </select>
@@ -52,8 +52,19 module Redmine
52
52
53 # Returns the menu item name according to the current action
53 # Returns the menu item name according to the current action
54 def current_menu_item
54 def current_menu_item
55 menu_items[controller_name.to_sym][:actions][action_name.to_sym] ||
55 @current_menu_item ||= menu_items[controller_name.to_sym][:actions][action_name.to_sym] ||
56 menu_items[controller_name.to_sym][:default]
56 menu_items[controller_name.to_sym][:default]
57 end
58
59 # Redirects user to the menu item of the given project
60 # Returns false if user is not authorized
61 def redirect_to_project_menu_item(project, name)
62 item = Redmine::MenuManager.items(:project_menu).detect {|i| i.name.to_s == name.to_s}
63 if item && User.current.allowed_to?(item.url, project) && (item.condition.nil? || item.condition.call(project))
64 redirect_to({item.param => project}.merge(item.url))
65 return true
66 end
67 false
57 end
68 end
58 end
69 end
59
70
@@ -287,6 +287,23 class ProjectsControllerTest < Test::Unit::TestCase
287 assert Project.find(1).active?
287 assert Project.find(1).active?
288 end
288 end
289
289
290 def test_jump_should_redirect_to_active_tab
291 get :show, :id => 1, :jump => 'issues'
292 assert_redirected_to 'projects/ecookbook/issues'
293 end
294
295 def test_jump_should_not_redirect_to_inactive_tab
296 get :show, :id => 3, :jump => 'documents'
297 assert_response :success
298 assert_template 'show'
299 end
300
301 def test_jump_should_not_redirect_to_unknown_tab
302 get :show, :id => 3, :jump => 'foobar'
303 assert_response :success
304 assert_template 'show'
305 end
306
290 def test_project_menu
307 def test_project_menu
291 assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do
308 assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do
292 Redmine::MenuManager.map :project_menu do |menu|
309 Redmine::MenuManager.map :project_menu do |menu|
General Comments 0
You need to be logged in to leave comments. Login now