From a8b12bcb520230b9cc25abd2d7346d746c49874d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 12 Dec 2010 16:04:28 +0000 Subject: [PATCH] Autocomplete issue relations on subject (#3170). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4502 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/auto_completes_controller.rb | 5 +++-- app/views/issue_relations/_form.rhtml | 4 +++- public/javascripts/application.js | 14 ++++++++++++++ public/stylesheets/application.css | 1 + test/functional/auto_completes_controller_test.rb | 14 ++++++++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb index 1438106f6..a3ed88e36 100644 --- a/app/controllers/auto_completes_controller.rb +++ b/app/controllers/auto_completes_controller.rb @@ -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 diff --git a/app/views/issue_relations/_form.rhtml b/app/views/issue_relations/_form.rhtml index 0de386306..fdf0582ff 100644 --- a/app/views/issue_relations/_form.rhtml +++ b/app/views/issue_relations/_form.rhtml @@ -1,7 +1,9 @@ <%= error_messages_for 'relation' %>

<%= 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 %> +

+<%= javascript_tag "observeRelatedIssueField('#{auto_complete_issues_path(:id => @issue, :project_id => @project) }')" %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 8f6c51828..486623459 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -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(){ diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 8055c8796..7a253c879 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -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; } diff --git a/test/functional/auto_completes_controller_test.rb b/test/functional/auto_completes_controller_test.rb index 25e75fc4b..697436b6e 100644 --- a/test/functional/auto_completes_controller_test.rb +++ b/test/functional/auto_completes_controller_test.rb @@ -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