BigW Consortium Gitlab

milestones_controller.rb 1.05 KB
Newer Older
1
class Dashboard::MilestonesController < Dashboard::ApplicationController
2
  before_action :load_projects
Douwe Maan committed
3 4 5 6 7 8 9 10

  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
11
    @dashboard_milestones = Kaminari.paginate_array(@dashboard_milestones).page(params[:page]).per(PER_PAGE)
Douwe Maan committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  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