dashboard_controller.rb 2.54 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1
class DashboardController < ApplicationController
2
  respond_to :html
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
3

4
  before_filter :load_projects, except: [:projects]
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
5
  before_filter :event_filter, only: :show
6

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
7
  def show
8 9 10 11
    # Fetch only 30 projects.
    # If user needs more - point to Dashboard#projects page
    @projects_limit = 30

12
    @groups = current_user.authorized_groups.sort_by(&:human_name)
13
    @has_authorized_projects = @projects.count > 0
14
    @projects_count = @projects.count
15
    @projects = @projects.limit(@projects_limit)
16

17
    @events = Event.in_projects(current_user.authorized_projects.pluck(:id))
18 19 20
    @events = @event_filter.apply_filter(@events)
    @events = @events.limit(20).offset(params[:offset] || 0)

randx's avatar
randx committed
21
    @last_push = current_user.recent_push
22

randx's avatar
randx committed
23
    respond_to do |format|
randx's avatar
randx committed
24
      format.html
25
      format.json { pager_json("events/_events", @events.count) }
26
      format.atom { render layout: false }
randx's avatar
randx committed
27
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
28 29
  end

30 31 32
  def projects
    @projects = case params[:scope]
                when 'personal' then
33
                  current_user.namespace.projects
34
                when 'joined' then
35 36 37
                  current_user.authorized_projects.joined(current_user)
                when 'owned' then
                  current_user.owned_projects
38
                else
39
                  current_user.authorized_projects
40 41 42
                end

    @projects = @projects.where(namespace_id: Group.find_by_name(params[:group])) if params[:group].present?
43
    @projects = @projects.where(visibility_level: params[:visibility_level]) if params[:visibility_level].present?
44
    @projects = @projects.includes(:namespace).sorted_by_activity
45

46
    @labels = current_user.authorized_projects.tags_on(:labels)
47
    @groups = current_user.authorized_groups
48 49 50

    @projects = @projects.tagged_with(params[:label]) if params[:label].present?
    @projects = @projects.page(params[:page]).per(30)
51 52
  end

53
  # Get authored or assigned open merge requests
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
54
  def merge_requests
55
    @merge_requests = current_user.cared_merge_requests
56
    @merge_requests = FilterContext.new(@merge_requests, params).execute
57
    @merge_requests = @merge_requests.recent.page(params[:page]).per(20)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
58 59
  end

60
  # Get only assigned issues
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
61
  def issues
62
    @issues = current_user.assigned_issues
63
    @issues = FilterContext.new(@issues, params).execute
64
    @issues = @issues.recent.page(params[:page]).per(20)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
65 66 67 68
    @issues = @issues.includes(:author, :project)

    respond_to do |format|
      format.html
69
      format.atom { render layout: false }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
70
    end
gitlabhq's avatar
gitlabhq committed
71
  end
72

73 74
  protected

75
  def load_projects
76
    @projects = current_user.authorized_projects.sorted_by_activity
77
  end
gitlabhq's avatar
gitlabhq committed
78
end