summaryrefslogtreecommitdiff
path: root/app/controllers/dashboard/milestones_controller.rb
blob: 33227e7f1d8bc6ec1e8e3d352a5310b685ce4814 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Dashboard::MilestonesController < ApplicationController
  before_action :load_projects

  def index
    project_milestones = case params[:state]
                         when 'all'; state
                         when 'closed'; state('closed')
                         else state('active')
                         end
    @dashboard_milestones = Milestones::GroupService.new(project_milestones).execute
    @dashboard_milestones = Kaminari.paginate_array(@dashboard_milestones).page(params[:page]).per(PER_PAGE)
  end

  def show
    project_milestones = Milestone.where(project_id: @projects).order("due_date ASC")
    @dashboard_milestone = Milestones::GroupService.new(project_milestones).milestone(title)
  end

  private

  def load_projects
    @projects = current_user.authorized_projects.sorted_by_activity.non_archived
  end

  def title
    params[:title]
  end

  def state(state = nil)
    conditions = { project_id: @projects }
    conditions.reverse_merge!(state: state) if state
    Milestone.where(conditions).order("title ASC")
  end
end