Project

General

Profile

Defect #29276 » responde_with_json.patch

Marius BĂLTEANU, 2019-02-03 17:18

View differences:

app/controllers/auto_completes_controller.rb
19 19
  before_action :find_project
20 20

  
21 21
  def issues
22
    @issues = []
22
    issues = []
23 23
    q = (params[:q] || params[:term]).to_s.strip
24 24
    status = params[:status].to_s
25 25
    issue_id = params[:issue_id].to_s
......
32 32
        scope = scope.where.not(:id => issue_id.to_i)
33 33
      end
34 34
      if q.match(/\A#?(\d+)\z/)
35
        @issues << scope.find_by_id($1.to_i)
35
        issues << scope.find_by_id($1.to_i)
36 36
      end
37 37

  
38
      @issues += scope.like(q).order(:id => :desc).limit(10).to_a
39
      @issues.compact!
38
      issues += scope.like(q).order(:id => :desc).limit(10).to_a
39
      issues.compact!
40 40
    end
41
    render :layout => false
41

  
42
    render :json => format_issues_json(issues)
42 43
  end
43 44

  
44 45
  private
......
50 51
  rescue ActiveRecord::RecordNotFound
51 52
    render_404
52 53
  end
54

  
55
  def format_issues_json(issues)
56
    issues.map {|issue| {
57
      'id' => issue.id,
58
      'label' => "#{issue.tracker} ##{issue.id}: #{issue.subject.to_s.truncate(60)}",
59
      'value' => issue.id
60
      }
61
    }
62
  end
53 63
end
    (1-1/1)