BigW Consortium Gitlab

dashboard_controller.rb 1.52 KB
Newer Older
1
class DashboardController < Dashboard::ApplicationController
2 3 4
  include IssuesAction
  include MergeRequestsAction

5
  before_action :event_filter, only: :activity
6
  before_action :projects, only: [:issues, :merge_requests, :labels, :milestones]
7

8
  respond_to :html
9

10 11 12 13 14 15 16 17 18 19 20 21 22
  def activity
    @last_push = current_user.recent_push

    respond_to do |format|
      format.html

      format.json do
        load_events
        pager_json("events/_events", @events.count)
      end
    end
  end

23
  def labels
24 25
    labels = Label.where(project_id: @projects).select(:title, :color).uniq(:title)

26 27
    respond_to do |format|
      format.json do
28
        render json: labels
29 30 31 32 33
      end
    end
  end

  def milestones
34 35 36 37 38
    milestones = Milestone.where(project_id: @projects).active
    epoch = DateTime.parse('1970-01-01')
    grouped_milestones = GlobalMilestone.build_collection(milestones)
    grouped_milestones = grouped_milestones.sort_by { |x| x.due_date.nil? ? epoch : x.due_date }

39 40
    respond_to do |format|
      format.json do
41
        render json: grouped_milestones
42 43 44 45
      end
    end
  end

46 47
  protected

48
  def load_events
49
    projects =
50 51 52 53
      if params[:filter] == "starred"
        current_user.starred_projects
      else
        current_user.authorized_projects
54
      end
55

56
    @events = Event.in_projects(projects)
57 58 59
    @events = @event_filter.apply_filter(@events).with_associations
    @events = @events.limit(20).offset(params[:offset] || 0)
  end
60 61 62 63

  def projects
    @projects ||= current_user.authorized_projects.sorted_by_activity.non_archived
  end
gitlabhq committed
64
end