diff options
author | Go MAEDA <maeda@farend.jp> | 2019-02-18 14:56:19 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2019-02-18 14:56:19 +0000 |
commit | b68dcfc930399bffdeef154f666d5e516c7680ae (patch) | |
tree | baff4b32b46056ede371b42b690b0d5115111819 /app/controllers/auto_completes_controller.rb | |
parent | b41c5c89d482225b1252dfcd7d700c505f2afc03 (diff) | |
download | redmine-b68dcfc930399bffdeef154f666d5e516c7680ae.tar.gz redmine-b68dcfc930399bffdeef154f666d5e516c7680ae.zip |
Issues autocomplete should response with content type json and not html (#30818).
Patch by Marius BALTEANU.
git-svn-id: http://svn.redmine.org/redmine/trunk@17881 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/auto_completes_controller.rb')
-rw-r--r-- | app/controllers/auto_completes_controller.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb index 293ac201e..2d707f929 100644 --- a/app/controllers/auto_completes_controller.rb +++ b/app/controllers/auto_completes_controller.rb @@ -19,7 +19,7 @@ class AutoCompletesController < ApplicationController before_action :find_project def issues - @issues = [] + issues = [] q = (params[:q] || params[:term]).to_s.strip status = params[:status].to_s issue_id = params[:issue_id].to_s @@ -32,13 +32,14 @@ class AutoCompletesController < ApplicationController scope = scope.where.not(:id => issue_id.to_i) end if q.match(/\A#?(\d+)\z/) - @issues << scope.find_by_id($1.to_i) + issues << scope.find_by_id($1.to_i) end - @issues += scope.like(q).order(:id => :desc).limit(10).to_a - @issues.compact! + issues += scope.like(q).order(:id => :desc).limit(10).to_a + issues.compact! end - render :layout => false + + render :json => format_issues_json(issues) end private @@ -50,4 +51,13 @@ class AutoCompletesController < ApplicationController rescue ActiveRecord::RecordNotFound render_404 end + + def format_issues_json(issues) + issues.map {|issue| { + 'id' => issue.id, + 'label' => "#{issue.tracker} ##{issue.id}: #{issue.subject.to_s.truncate(60)}", + 'value' => issue.id + } + } + end end |