AutocompleteForRelatedIssues.patch

Patch to enable issue autocomplete on related issue field - Felix Schäfer, 2010-05-14 13:06

Download (4.2 KB)

View differences:

test/functional/issues_controller_test.rb (working copy)
1249 1249
    assert_not_nil assigns(:issues)
1250 1250
    assert assigns(:issues).include?(Issue.find(13))
1251 1251
  end
1252

  
1253
  def test_auto_complete_with_scope_all_and_cross_project_relations
1254
    Setting.cross_project_issue_relations = '1'
1255
    get :aut_complete, :project_id => 'ecookbook', :q => '13', :scope => 'all'
1256
    assert_response :success
1257
    assert_not_nil assigns(:issues)
1258
    assert assigns(:issues).include?(Issue.find(13))
1259
  end
1252 1260
  
1261
  def test_auto_complete_with_scope_all_without_cross_project_relations
1262
    get :aut_complete, :project_id => 'ecookbook', :q => '13', :scope => 'all'
1263
    assert_response :success
1264
    assert_nil assigns(:issues)
1265
  end
1266
  
1253 1267
  def test_destroy_issue_with_no_time_entries
1254 1268
    assert_nil TimeEntry.find_by_issue_id(2)
1255 1269
    @request.session[:user_id] = 2
app/controllers/issues_controller.rb (working copy)
405 405
  def auto_complete
406 406
    @issues = []
407 407
    q = params[:q].to_s
408
    query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues
408 409
    if q.match(/^\d+$/)
409
      @issues << @project.issues.visible.find_by_id(q.to_i)
410
      @issues << query.visible.find_by_id(q.to_i)
410 411
    end
411 412
    unless q.blank?
412
      @issues += @project.issues.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
413
      @issues += query.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
413 414
    end
414 415
    render :layout => false
415 416
  end
public/javascripts/application.js (working copy)
206 206
                           }});
207 207
}
208 208

  
209
function observeRelatedIssueField(url) {
210
  new Ajax.Autocompleter('relation_issue_to_id',
211
                         'related_issue_candidates',
212
                         url,
213
                         { minChars: 3,
214
                           frequency: 0.5,
215
                           paramName: 'q',
216
                           updateElement: function(value) {
217
                             document.getElementById('relation_issue_to_id').value = value.id;
218
                           },
219
                           parameters: 'scope=all'
220
                           });
221
}
222

  
209 223
/* shows and hides ajax indicator */
210 224
Ajax.Responders.register({
211 225
    onCreate: function(){
public/stylesheets/application.css (working copy)
655 655
}
656 656

  
657 657
#parent_issue_candidates ul li {width: 500px;}
658
#related_issue_candidates ul li {width: 500px;}
658 659

  
659 660
/***** Diff *****/
660 661
.diff_out { background: #fcc; }
app/views/issue_relations/_form.rhtml (working copy)
2 2

  
3 3
<p><%= f.select :relation_type, collection_for_relation_type_select, {}, :onchange => "setPredecessorFieldsVisibility();" %>
4 4
<%= l(:label_issue) %> #<%= f.text_field :issue_to_id, :size => 6 %>
5
<div id="related_issue_candidates" class="autocomplete"></div>
6
<%= javascript_tag "observeRelatedIssueField('#{url_for(:controller => :issues,
7
                                                       :action => :auto_complete,
8
                                                       :id => @issue,
9
                                                       :project_id => @project) }')" %>
5 10
<span id="predecessor_fields" style="display:none;">
6 11
<%= l(:field_delay) %>: <%= f.text_field :delay, :size => 3 %> <%= l(:label_day_plural) %>
7 12
</span>