Project

General

Profile

Feature #9909 » 9909_default_search_scope_v2.patch

Marius BĂLTEANU, 2017-04-13 00:12

View differences:

app/controllers/search_controller.rb
when 'my_projects'
User.current.projects
when 'subprojects'
@project ? (@project.self_and_descendants.active.to_a) : nil
else
include_subprojects
when 'project'
@project
else
Setting.display_subprojects_issues? ? include_subprojects : @project
end
@object_types = Redmine::Search.available_search_types.dup
......
end
private
def include_subprojects
@project ? (@project.self_and_descendants.active.to_a) : nil
end
def find_optional_project
return true unless params[:id]
@project = Project.find(params[:id])
app/helpers/search_helper.rb
end
def project_select_tag
if params[:scope].present?
scope = params[:scope].to_s
else
scope = Setting.display_subprojects_issues? ? 'subprojects' : 'project'
end
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 << [@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
select_tag('scope', options_for_select(options, scope)) if options.size > 1
end
def render_results_by_type(results_by_type)
......
: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
config/locales/en.yml
setting_per_page_options: Objects per page options
setting_user_format: Users display format
setting_activity_days_default: Days displayed on project activity
setting_display_subprojects_issues: Display subprojects issues on main projects by default
setting_display_subprojects_issues: Include subprojects issues on main projects by default
setting_enabled_scm: Enabled SCM
setting_mail_handler_body_delimiters: "Truncate emails after one of these lines"
setting_mail_handler_enable_regex_delimiters: "Enable regular expressions"
test/functional/search_controller_test.rb
end
end
def test_search_project_and_subprojects
def test_search_scope_subprojects_should_search_in_project_and_subprojects
get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''}
assert_response :success
assert_select '#search-results' do
assert_select 'dt.issue', :text => /Bug #1/
assert_select 'dt.issue', :text => /Bug #5/
end
end
def test_search_scope_project_should_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', :text => /Bug #5/
assert_select 'dt.issue a[href="/issues/5"]', 0
end
end
def test_search_scope_with_setting_display_subprojects_issues_on_should_set_scope_to_subprojects
with_settings :display_subprojects_issues => '1' do
get :index, :params => {:id => 1, :q => 'recipe subproject', :all_words => ''}
end
assert_response :success
assert_select '#scope option[selected=selected][value=?]', 'subprojects', :text => 'eCookbook and its subprojects'
end
def test_search_with_setting_display_subprojects_issues_off_should_set_scope_to_project
with_settings :display_subprojects_issues => '0' do
get :index, :params => {:id => 1, :q => 'recipe subproject', :all_words => ''}
end
assert_response :success
assert_select '#scope option[selected=selected][value=?]', 'project', :text => 'eCookbook'
end
def test_search_without_searchable_custom_fields
......
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
(2-2/2)