dashboard_controller.rb 2.65 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1
class DashboardController < ApplicationController
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
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
7
  before_filter :default_filter, only: [:issues, :merge_requests]

8

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

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

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

randx's avatar
randx committed
23
    @last_push = current_user.recent_push
24

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

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

skv's avatar
skv committed
44
    @projects = @projects.where(namespace_id: Group.find_by(name: params[:group])) if params[:group].present?
45
    @projects = @projects.where(visibility_level: params[:visibility_level]) if params[:visibility_level].present?
46
47
48
49
    @projects = @projects.includes(:namespace)
    @projects = @projects.tagged_with(params[:label]) if params[:label].present?
    @projects = @projects.sort(@sort = params[:sort])
    @projects = @projects.page(params[:page]).per(30)
50

51
    @labels = current_user.authorized_projects.tags_on(:labels)
52
    @groups = current_user.authorized_groups
53
54
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
55
  def merge_requests
56
    @merge_requests = FilteringService.new.execute(MergeRequest, current_user, params)
57
    @merge_requests = @merge_requests.recent.page(params[:page]).per(20)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
58
59
60
  end

  def issues
61
    @issues = FilteringService.new.execute(Issue, current_user, params)
62
    @issues = @issues.recent.page(params[:page]).per(20)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
63
64
65
66
    @issues = @issues.includes(:author, :project)

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

71
72
  protected

73
  def load_projects
74
    @projects = current_user.authorized_projects.sorted_by_activity.non_archived
75
  end
76
77
78
79
80

  def default_filter
    params[:scope] = 'assigned-to-me' if params[:scope].blank?
    params[:state] = 'opened' if params[:state].blank?
  end
gitlabhq's avatar
gitlabhq committed
81
end