Autocomplete issue relations on subject (#3170).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4502 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2010-12-12 16:04:28 +00:00
parent 758f2f0a4e
commit a8b12bcb52
5 changed files with 35 additions and 3 deletions

View File

@ -4,11 +4,12 @@ class AutoCompletesController < ApplicationController
def issues
@issues = []
q = params[:q].to_s
query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues
if q.match(/^\d+$/)
@issues << @project.issues.visible.find_by_id(q.to_i)
@issues << query.visible.find_by_id(q.to_i)
end
unless q.blank?
@issues += @project.issues.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
@issues += query.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
end
render :layout => false
end

View File

@ -1,7 +1,9 @@
<%= error_messages_for 'relation' %>
<p><%= f.select :relation_type, collection_for_relation_type_select, {}, :onchange => "setPredecessorFieldsVisibility();" %>
<%= l(:label_issue) %> #<%= f.text_field :issue_to_id, :size => 6 %>
<%= l(:label_issue) %> #<%= f.text_field :issue_to_id, :size => 10 %>
<div id="related_issue_candidates" class="autocomplete"></div>
<%= javascript_tag "observeRelatedIssueField('#{auto_complete_issues_path(:id => @issue, :project_id => @project) }')" %>
<span id="predecessor_fields" style="display:none;">
<%= l(:field_delay) %>: <%= f.text_field :delay, :size => 3 %> <%= l(:label_day_plural) %>
</span>

View File

@ -218,6 +218,20 @@ function observeParentIssueField(url) {
}});
}
function observeRelatedIssueField(url) {
new Ajax.Autocompleter('relation_issue_to_id',
'related_issue_candidates',
url,
{ minChars: 3,
frequency: 0.5,
paramName: 'q',
updateElement: function(value) {
document.getElementById('relation_issue_to_id').value = value.id;
},
parameters: 'scope=all'
});
}
/* shows and hides ajax indicator */
Ajax.Responders.register({
onCreate: function(){

View File

@ -663,6 +663,7 @@ div.autocomplete ul li span.informal {
}
#parent_issue_candidates ul li {width: 500px;}
#related_issue_candidates ul li {width: 500px;}
/***** Diff *****/
.diff_out { background: #fcc; }

View File

@ -17,4 +17,18 @@ class AutoCompletesControllerTest < ActionController::TestCase
assert assigns(:issues).include?(Issue.find(13))
end
def test_auto_complete_with_scope_all_and_cross_project_relations
Setting.cross_project_issue_relations = '1'
get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all'
assert_response :success
assert_not_nil assigns(:issues)
assert assigns(:issues).include?(Issue.find(13))
end
def test_auto_complete_with_scope_all_without_cross_project_relations
Setting.cross_project_issue_relations = '0'
get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all'
assert_response :success
assert_equal [nil], assigns(:issues)
end
end