1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-02-10 04:35:24 +00:00

Filter parent task issues in auto complete by open/closed status depending on the subtask status (#24877).

Patch by Marius BALTEANU.

git-svn-id: http://svn.redmine.org/redmine/trunk@16243 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2017-01-21 09:59:12 +00:00
parent 402d739146
commit 4abc3179f5
3 changed files with 31 additions and 1 deletions

View File

@ -21,11 +21,20 @@ class AutoCompletesController < ApplicationController
def issues
@issues = []
q = (params[:q] || params[:term]).to_s.strip
status = params[:status].to_s
issue_id = params[:issue_id].to_s
if q.present?
scope = Issue.cross_project_scope(@project, params[:scope]).visible
if status.present?
scope = scope.open(status == 'o')
end
if issue_id.present?
scope = scope.where("#{Issue.table_name}.id <> ?", issue_id.to_i)
end
if q.match(/\A#?(\d+)\z/)
@issues << scope.find_by_id($1.to_i)
end
@issues += scope.where("LOWER(#{Issue.table_name}.subject) LIKE LOWER(?)", "%#{q}%").order("#{Issue.table_name}.id DESC").limit(10).to_a
@issues.compact!
end

View File

@ -47,7 +47,7 @@
<div class="splitcontentright">
<% if @issue.safe_attribute? 'parent_issue_id' %>
<p id="parent_issue"><%= f.text_field :parent_issue_id, :size => 10, :required => @issue.required_attribute?('parent_issue_id') %></p>
<%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @issue.project, :scope => Setting.cross_project_subtasks)}')" %>
<%= 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', :issue_id => @issue.id)}')" %>
<% end %>
<% if @issue.safe_attribute? 'start_date' %>

View File

@ -81,4 +81,25 @@ class AutoCompletesControllerTest < Redmine::ControllerTest
assert_equal 13, issue['value']
assert_equal 'Bug #13: Subproject issue two', issue['label']
end
def test_auto_complete_with_status_o_should_return_open_issues_only
get :issues, :project_id => 'ecookbook', :q => 'issue', :status => 'o'
assert_response :success
assert_include "Issue due today", response.body
assert_not_include "closed", response.body
end
def test_auto_complete_with_status_c_should_return_closed_issues_only
get :issues, :project_id => 'ecookbook', :q => 'issue', :status => 'c'
assert_response :success
assert_include "closed", response.body
assert_not_include "Issue due today", response.body
end
def test_auto_complete_with_issue_id_should_not_return_that_issue
get :issues, :project_id => 'ecookbook', :q => 'issue', :issue_id => '12'
assert_response :success
assert_include "issue", response.body
assert_not_include "Bug #12: Closed issue on a locked version", response.body
end
end