# Lists visible projects
def index
+ # try to redirect to the requested menu item
+ if params[:jump] && redirect_to_menu_item(params[:jump])
+ return
+ end
+
scope = Project.visible.sorted
respond_to do |format|
text = @project.try(:name) || l(:label_jump_to_a_project)
trigger = content_tag('span', text, :class => 'drdn-trigger')
q = text_field_tag('q', '', :id => 'projects-quick-search', :class => 'autocomplete', :data => {:automcomplete_url => projects_path(:format => 'js')})
+ all = link_to(l(:label_project_all), projects_path(:jump => current_menu_item), :class => (@project.nil? && controller.class.main_menu ? 'selected' : nil))
content = content_tag('div',
content_tag('div', q, :class => 'quick-search') +
- content_tag('div', render_projects_for_jump_box(projects, @project), :class => 'drdn-items selection'),
+ content_tag('div', render_projects_for_jump_box(projects, @project), :class => 'drdn-items projects selection') +
+ content_tag('div', all, :class => 'drdn-items all-projects selection'),
:class => 'drdn-content'
)
<% s = @projects.any? ? render_projects_for_jump_box(@projects) : content_tag('span', l(:label_no_data)) %>
-$('#project-jump .drdn-items').html('<%= escape_javascript s %>');
+$('#project-jump .drdn-items.projects').html('<%= escape_javascript s %>');
menu_items[controller_name.to_sym][:default]
end
+ # Redirects user to the menu item
+ # Returns false if user is not authorized
+ def redirect_to_menu_item(name)
+ redirect_to_project_menu_item(nil, name)
+ 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}
+ menu = project.nil? ? :application_menu : :project_menu
+ item = Redmine::MenuManager.items(menu).detect {|i| i.name.to_s == name.to_s}
if item && item.allowed?(User.current, project)
- redirect_to({item.param => project}.merge(item.url))
+ url = item.url
+ url = {item.param => project}.merge(url) if project
+ redirect_to url
return true
end
false
.drdn-content .autocomplete {box-sizing: border-box; width:100% !important; height:28px;}
.drdn-content .autocomplete:focus {border-color:#5ad;}
.drdn-items {max-height:400px; overflow:auto;}
-.quick-search + .drdn-items {border-top:1px solid #ccc;}
+div + .drdn-items {border-top:1px solid #ccc;}
.drdn-items>* {
display:block;
border:1px solid #fff;
assert_select_error /Identifier cannot be blank/
end
+ def test_jump_without_project_id_should_redirect_to_active_tab
+ get :index, :jump => 'issues'
+ assert_redirected_to '/issues'
+ end
+
+ def test_jump_should_not_redirect_to_unknown_tab
+ get :index, :jump => 'foobar'
+ assert_response :success
+ end
+
def test_jump_should_redirect_to_active_tab
get :show, :id => 1, :jump => 'issues'
assert_redirected_to '/projects/ecookbook/issues'