load_context.rb 1.17 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1 2 3 4 5
module Notes
  class LoadContext < BaseContext
    def execute
      target_type = params[:target_type]
      target_id   = params[:target_id]
6
      after_id    = params[:after_id]
7
      before_id   = params[:before_id]
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
8 9 10


      @notes = case target_type
11 12
               when "commit"
                 project.commit_notes(project.commit(target_id)).fresh.limit(20)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
13
               when "issue"
14
                 project.issues.find(target_id).notes.inc_author.fresh.limit(20)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
15
               when "merge_request"
16 17 18 19 20
                 project.merge_requests.find(target_id).notes.inc_author.fresh.limit(20)
               when "snippet"
                 project.snippets.find(target_id).notes.fresh
               when "wall"
                 # this is the only case, where the order is DESC
21
                 project.common_notes.order("created_at DESC, id DESC").limit(50)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
22
               when "wiki"
23
                 project.wiki_notes.limit(20)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
24 25
               end

26 27
      @notes = if after_id
                 @notes.where("id > ?", after_id)
28 29 30
               elsif before_id
                 @notes.where("id < ?", before_id)
               else
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
31 32 33 34 35
                 @notes
               end
    end
  end
end