--- /dev/null
+class AutoCompletesController < ApplicationController
+ before_filter :find_project
+
+ def issues
+ @issues = []
+ q = params[:q].to_s
+ if q.match(/^\d+$/)
+ @issues << @project.issues.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)
+ end
+ render :layout => false
+ end
+
+ private
+
+ def find_project
+ project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
+ @project = Project.find(project_id)
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+
+end
before_filter :find_issue, :only => [:show, :edit, :update]
before_filter :find_issues, :only => [:bulk_edit, :move, :perform_move, :destroy]
- before_filter :find_project, :only => [:new, :create, :update_form, :preview, :auto_complete]
+ before_filter :find_project, :only => [:new, :create, :update_form, :preview]
before_filter :authorize, :except => [:index, :changes, :preview, :context_menu]
before_filter :find_optional_project, :only => [:index, :changes]
before_filter :check_for_default_issue_status, :only => [:new, :create]
render :layout => false
end
- def auto_complete
- @issues = []
- q = params[:q].to_s
- if q.match(/^\d+$/)
- @issues << @project.issues.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)
- end
- render :layout => false
- end
-
private
def find_issue
@issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
--- /dev/null
+<ul>
+<% if @issues.any? -%>
+ <% @issues.each do |issue| -%>
+ <%= content_tag 'li', h("#{issue.tracker} ##{issue.id}: #{issue.subject}"), :id => issue.id %>
+ <% end -%>
+<% else -%>
+ <%= content_tag("li", l(:label_none), :style => 'display:none') %>
+<% end -%>
+</ul>
<% unless (@issue.new_record? && @issue.parent_issue_id.nil?) || !User.current.allowed_to?(:manage_subtasks, @project) %>
<p><%= f.text_field :parent_issue_id, :size => 10 %></p>
<div id="parent_issue_candidates" class="autocomplete"></div>
-<%= javascript_tag "observeParentIssueField('#{url_for(:controller => :issues,
- :action => :auto_complete,
- :id => @issue,
- :project_id => @project) }')" %>
+<%= javascript_tag "observeParentIssueField('#{auto_complete_issues_path(:id => @issue, :project_id => @project) }')" %>
<% end %>
<p><%= f.text_area :description,
+++ /dev/null
-<ul>
-<% if @issues.any? -%>
- <% @issues.each do |issue| -%>
- <%= content_tag 'li', h("#{issue.tracker} ##{issue.id}: #{issue.subject}"), :id => issue.id %>
- <% end -%>
-<% else -%>
- <%= content_tag("li", l(:label_none), :style => 'display:none') %>
-<% end -%>
-</ul>
end
map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move'
-
+ map.auto_complete_issues '/issues/auto_complete', :controller => 'auto_completes', :action => 'issues'
+
map.with_options :controller => 'issues' do |issues_routes|
issues_routes.with_options :conditions => {:method => :get} do |issues_views|
issues_views.connect 'issues', :action => 'index'
map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member
# Issues
map.permission :view_issues, {:projects => :roadmap,
- :issues => [:index, :changes, :show, :context_menu, :auto_complete],
+ :issues => [:index, :changes, :show, :context_menu],
+ :auto_complete => [:issues],
:versions => [:show, :status_by],
:queries => :index,
:reports => [:issue_report, :issue_report_details]}
--- /dev/null
+require File.dirname(__FILE__) + '/../test_helper'
+
+class AutoCompletesControllerTest < ActionController::TestCase
+ fixtures :all
+
+ def test_issues_should_not_be_case_sensitive
+ get :issues, :project_id => 'ecookbook', :q => 'ReCiPe'
+ assert_response :success
+ assert_not_nil assigns(:issues)
+ assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
+ end
+
+ def test_issues_should_return_issue_with_given_id
+ get :issues, :project_id => 'subproject1', :q => '13'
+ assert_response :success
+ assert_not_nil assigns(:issues)
+ assert assigns(:issues).include?(Issue.find(13))
+ end
+
+end
assert_not_nil assigns(:notes)
end
- def test_auto_complete_should_not_be_case_sensitive
- get :auto_complete, :project_id => 'ecookbook', :q => 'ReCiPe'
- assert_response :success
- assert_not_nil assigns(:issues)
- assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
- end
-
- def test_auto_complete_should_return_issue_with_given_id
- get :auto_complete, :project_id => 'subproject1', :q => '13'
- assert_response :success
- assert_not_nil assigns(:issues)
- assert assigns(:issues).include?(Issue.find(13))
- end
-
def test_destroy_issue_with_no_time_entries
assert_nil TimeEntry.find_by_issue_id(2)
@request.session[:user_id] = 2
should_route :get, "/projects/project-name/issues/gantt", :controller => 'gantts', :action => 'show', :project_id => 'project-name'
should_route :post, "/projects/project-name/issues/gantt", :controller => 'gantts', :action => 'show', :project_id => 'project-name'
- should_route :get, "/issues/auto_complete", :controller => 'issues', :action => 'auto_complete'
+ should_route :get, "/issues/auto_complete", :controller => 'auto_completes', :action => 'issues'
end
context "issue categories" do