Feature #9909 » 9909_default_search_scope_v2.patch
| app/controllers/search_controller.rb | ||
|---|---|---|
| 49 | 49 |
when 'my_projects' |
| 50 | 50 |
User.current.projects |
| 51 | 51 |
when 'subprojects' |
| 52 |
@project ? (@project.self_and_descendants.active.to_a) : nil
|
|
| 53 |
else
|
|
| 52 |
include_subprojects
|
|
| 53 |
when 'project'
|
|
| 54 | 54 |
@project |
| 55 |
else |
|
| 56 |
Setting.display_subprojects_issues? ? include_subprojects : @project |
|
| 55 | 57 |
end |
| 56 | 58 | |
| 57 | 59 |
@object_types = Redmine::Search.available_search_types.dup |
| ... | ... | |
| 89 | 91 |
end |
| 90 | 92 | |
| 91 | 93 |
private |
| 94 |
def include_subprojects |
|
| 95 |
@project ? (@project.self_and_descendants.active.to_a) : nil |
|
| 96 |
end |
|
| 97 | ||
| 92 | 98 |
def find_optional_project |
| 93 | 99 |
return true unless params[:id] |
| 94 | 100 |
@project = Project.find(params[:id]) |
| app/helpers/search_helper.rb | ||
|---|---|---|
| 44 | 44 |
end |
| 45 | 45 | |
| 46 | 46 |
def project_select_tag |
| 47 |
if params[:scope].present? |
|
| 48 |
scope = params[:scope].to_s |
|
| 49 |
else |
|
| 50 |
scope = Setting.display_subprojects_issues? ? 'subprojects' : 'project' |
|
| 51 |
end |
|
| 52 | ||
| 47 | 53 |
options = [[l(:label_project_all), 'all']] |
| 48 | 54 |
options << [l(:label_my_projects), 'my_projects'] unless User.current.memberships.empty? |
| 49 | 55 |
options << [l(:label_and_its_subprojects, @project.name), 'subprojects'] unless @project.nil? || @project.descendants.active.empty? |
| 50 |
options << [@project.name, ''] unless @project.nil? |
|
| 56 |
options << [@project.name, 'project'] unless @project.nil?
|
|
| 51 | 57 |
label_tag("scope", l(:description_project_scope), :class => "hidden-for-sighted") +
|
| 52 |
select_tag('scope', options_for_select(options, params[:scope].to_s)) if options.size > 1
|
|
| 58 |
select_tag('scope', options_for_select(options, scope)) if options.size > 1
|
|
| 53 | 59 |
end |
| 54 | 60 | |
| 55 | 61 |
def render_results_by_type(results_by_type) |
| ... | ... | |
| 63 | 69 |
:all_words => params[:all_words], :scope => params[:scope], t => 1) |
| 64 | 70 |
end |
| 65 | 71 |
('<ul>'.html_safe +
|
| 66 |
links.map {|link| content_tag('li', link)}.join(' ').html_safe +
|
|
| 72 |
links.map {|link| content_tag('li', link)}.join(' ').html_safe +
|
|
| 67 | 73 |
'</ul>'.html_safe) unless links.empty? |
| 68 | 74 |
end |
| 69 | 75 |
end |
| config/locales/en.yml | ||
|---|---|---|
| 411 | 411 |
setting_per_page_options: Objects per page options |
| 412 | 412 |
setting_user_format: Users display format |
| 413 | 413 |
setting_activity_days_default: Days displayed on project activity |
| 414 |
setting_display_subprojects_issues: Display subprojects issues on main projects by default
|
|
| 414 |
setting_display_subprojects_issues: Include subprojects issues on main projects by default
|
|
| 415 | 415 |
setting_enabled_scm: Enabled SCM |
| 416 | 416 |
setting_mail_handler_body_delimiters: "Truncate emails after one of these lines" |
| 417 | 417 |
setting_mail_handler_enable_regex_delimiters: "Enable regular expressions" |
| test/functional/search_controller_test.rb | ||
|---|---|---|
| 169 | 169 |
end |
| 170 | 170 |
end |
| 171 | 171 | |
| 172 |
def test_search_project_and_subprojects |
|
| 172 |
def test_search_scope_subprojects_should_search_in_project_and_subprojects
|
|
| 173 | 173 |
get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''}
|
| 174 |
assert_response :success |
|
| 175 | ||
| 176 |
assert_select '#search-results' do |
|
| 177 |
assert_select 'dt.issue', :text => /Bug #1/ |
|
| 178 |
assert_select 'dt.issue', :text => /Bug #5/ |
|
| 179 |
end |
|
| 180 |
end |
|
| 181 | ||
| 182 |
def test_search_scope_project_should_search_only_in_project |
|
| 183 |
get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'project', :all_words => ''}
|
|
| 174 | 184 |
assert_response :success |
| 175 | 185 | |
| 176 | 186 |
assert_select '#search-results' do |
| 177 | 187 |
assert_select 'dt.issue', :text => /Bug #1/ |
| 178 |
assert_select 'dt.issue', :text => /Bug #5/ |
|
| 188 |
assert_select 'dt.issue a[href="/issues/5"]', 0 |
|
| 189 |
end |
|
| 190 |
end |
|
| 191 | ||
| 192 |
def test_search_scope_with_setting_display_subprojects_issues_on_should_set_scope_to_subprojects |
|
| 193 |
with_settings :display_subprojects_issues => '1' do |
|
| 194 |
get :index, :params => {:id => 1, :q => 'recipe subproject', :all_words => ''}
|
|
| 195 |
end |
|
| 196 |
assert_response :success |
|
| 197 | ||
| 198 |
assert_select '#scope option[selected=selected][value=?]', 'subprojects', :text => 'eCookbook and its subprojects' |
|
| 199 |
end |
|
| 200 | ||
| 201 |
def test_search_with_setting_display_subprojects_issues_off_should_set_scope_to_project |
|
| 202 |
with_settings :display_subprojects_issues => '0' do |
|
| 203 |
get :index, :params => {:id => 1, :q => 'recipe subproject', :all_words => ''}
|
|
| 179 | 204 |
end |
| 205 |
assert_response :success |
|
| 206 | ||
| 207 |
assert_select '#scope option[selected=selected][value=?]', 'project', :text => 'eCookbook' |
|
| 180 | 208 |
end |
| 181 | 209 | |
| 182 | 210 |
def test_search_without_searchable_custom_fields |
| ... | ... | |
| 270 | 298 |
assert_select 'input[name=all_words]:not([checked])' |
| 271 | 299 |
assert_select '#search-results' do |
| 272 | 300 |
assert_select 'dt.issue', :text => / #3 / |
| 273 |
assert_select 'dt', 3
|
|
| 301 |
assert_select 'dt', 4
|
|
| 274 | 302 |
end |
| 275 | 303 |
end |
| 276 | 304 | |
- « Previous
- 1
- 2
- Next »