Patch #24877 » filter_autocomplete_issues_by_status.patch
| app/controllers/auto_completes_controller.rb | ||
|---|---|---|
| 21 | 21 |
def issues |
| 22 | 22 |
@issues = [] |
| 23 | 23 |
q = (params[:q] || params[:term]).to_s.strip |
| 24 |
status = params[:status].to_s.strip |
|
| 24 | 25 |
if q.present? |
| 25 | 26 |
scope = Issue.cross_project_scope(@project, params[:scope]).visible |
| 27 |
scope = scope.open if status == 'o' |
|
| 28 |
scope = scope.joins(:status).where("#{IssueStatus.table_name}.is_closed = 1") if status == 'c'
|
|
| 26 | 29 |
if q.match(/\A#?(\d+)\z/) |
| 27 | 30 |
@issues << scope.find_by_id($1.to_i) |
| 28 | 31 |
end |
| 32 | ||
| 29 | 33 |
@issues += scope.where("LOWER(#{Issue.table_name}.subject) LIKE LOWER(?)", "%#{q}%").order("#{Issue.table_name}.id DESC").limit(10).to_a
|
| 30 | 34 |
@issues.compact! |
| 31 | 35 |
end |
| app/views/issues/_attributes.html.erb | ||
|---|---|---|
| 47 | 47 |
<div class="splitcontentright"> |
| 48 | 48 |
<% if @issue.safe_attribute? 'parent_issue_id' %> |
| 49 | 49 |
<p id="parent_issue"><%= f.text_field :parent_issue_id, :size => 10, :required => @issue.required_attribute?('parent_issue_id') %></p>
|
| 50 |
<%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @issue.project, :scope => Setting.cross_project_subtasks)}')" %>
|
|
| 50 |
<%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @issue.project, :scope => Setting.cross_project_subtasks, :status => @issue.closed? ? 'c' : 'o')}')" %>
|
|
| 51 | 51 |
<% end %> |
| 52 | 52 | |
| 53 | 53 |
<% if @issue.safe_attribute? 'start_date' %> |
| test/functional/auto_completes_controller_test.rb | ||
|---|---|---|
| 81 | 81 |
assert_equal 13, issue['value'] |
| 82 | 82 |
assert_equal 'Bug #13: Subproject issue two', issue['label'] |
| 83 | 83 |
end |
| 84 | ||
| 85 |
def test_auto_complete_with_status_o_should_return_open_issues_only |
|
| 86 |
get :issues, :project_id => 'ecookbook', :q => 'issue', :status => 'o' |
|
| 87 |
assert_response :success |
|
| 88 |
assert_include "Issue due today", response.body |
|
| 89 |
assert_not_include "closed", response.body |
|
| 90 |
end |
|
| 91 | ||
| 92 |
def test_auto_complete_with_status_c_should_return_closed_issues_only |
|
| 93 |
get :issues, :project_id => 'ecookbook', :q => 'issue', :status => 'c' |
|
| 94 |
assert_response :success |
|
| 95 |
assert_include "closed", response.body |
|
| 96 |
assert_not_include "Issue due today", response.body |
|
| 97 |
end |
|
| 84 | 98 |
end |