summaryrefslogtreecommitdiff
path: root/app/controllers/concerns/global_milestones.rb
blob: 3e4c0e63601d4296333a7327c7973ed4af5b661a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module GlobalMilestones
  extend ActiveSupport::Concern

  def milestones
    epoch = DateTime.parse('1970-01-01')
    @milestones = MilestonesFinder.new.execute(@projects, params)
    @milestones = GlobalMilestone.build_collection(@milestones)
    @milestones = @milestones.sort_by { |x| x.due_date.nil? ? epoch : x.due_date }
    @milestones = Kaminari.paginate_array(@milestones).page(params[:page]).per(ApplicationController::PER_PAGE)
  end

  def milestone
    milestones = Milestone.of_projects(@projects).where(title: params[:title])

    if milestones.present?
      @milestone = GlobalMilestone.new(params[:title], milestones)
    else
      render_404
    end
  end
end