Feature #9909 » 9909_set_default_search_scope_to_project_and_its_subprojects.patch
| app/controllers/search_controller.rb | ||
|---|---|---|
|
nil
|
||
|
when 'my_projects'
|
||
|
User.current.projects
|
||
|
when 'subprojects'
|
||
|
@project ? (@project.self_and_descendants.active.to_a) : nil
|
||
|
else
|
||
|
when 'project'
|
||
|
@project
|
||
|
else
|
||
|
@project ? (@project.self_and_descendants.active.to_a) : nil
|
||
|
end
|
||
|
@object_types = Redmine::Search.available_search_types.dup
|
||
| app/helpers/search_helper.rb | ||
|---|---|---|
|
def project_select_tag
|
||
|
options = [[l(:label_project_all), 'all']]
|
||
|
options << [l(:label_my_projects), 'my_projects'] unless User.current.memberships.empty?
|
||
|
options << [l(:label_and_its_subprojects, @project.name), 'subprojects'] unless @project.nil? || @project.descendants.active.empty?
|
||
|
options << [@project.name, ''] unless @project.nil?
|
||
|
options << [l(:label_and_its_subprojects, @project.name), ''] unless @project.nil? || @project.descendants.active.empty?
|
||
|
options << [@project.name, 'project'] unless @project.nil?
|
||
|
label_tag("scope", l(:description_project_scope), :class => "hidden-for-sighted") +
|
||
|
select_tag('scope', options_for_select(options, params[:scope].to_s)) if options.size > 1
|
||
|
end
|
||
| ... | ... | |
|
:all_words => params[:all_words], :scope => params[:scope], t => 1)
|
||
|
end
|
||
|
('<ul>'.html_safe +
|
||
|
links.map {|link| content_tag('li', link)}.join(' ').html_safe +
|
||
|
links.map {|link| content_tag('li', link)}.join(' ').html_safe +
|
||
|
'</ul>'.html_safe) unless links.empty?
|
||
|
end
|
||
|
end
|
||
| test/functional/search_controller_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_search_project_and_subprojects
|
||
|
get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''}
|
||
|
def test_search_only_in_project
|
||
|
get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'project', :all_words => ''}
|
||
|
assert_response :success
|
||
|
assert_select '#search-results' do
|
||
|
assert_select 'dt.issue', :text => /Bug #1/
|
||
|
assert_select 'dt.issue a[href="/issues/5"]', 0
|
||
|
end
|
||
|
end
|
||
|
def test_search_default_scope_should_search_in_project_and_subprojects
|
||
|
get :index, :params => {:id => 1, :q => 'recipe subproject', :all_words => ''}
|
||
|
assert_response :success
|
||
|
assert_select '#scope option[selected=selected]', :text => 'eCookbook and its subprojects'
|
||
|
assert_select '#search-results' do
|
||
|
assert_select 'dt.issue', :text => /Bug #1/
|
||
|
assert_select 'dt.issue', :text => /Bug #5/
|
||
|
end
|
||
|
end
|
||
| ... | ... | |
|
assert_select 'input[name=all_words]:not([checked])'
|
||
|
assert_select '#search-results' do
|
||
|
assert_select 'dt.issue', :text => / #3 /
|
||
|
assert_select 'dt', 3
|
||
|
assert_select 'dt', 4
|
||
|
end
|
||
|
end
|
||