dashboard_controller.rb 2.3 KB
Newer Older
G
gitlabhq 已提交
1
class DashboardController < ApplicationController
D
Dmitriy Zaporozhets 已提交
2
  respond_to :html
D
Dmitriy Zaporozhets 已提交
3

4
  before_filter :load_projects, except: [:projects]
D
Dmitriy Zaporozhets 已提交
5
  before_filter :event_filter, only: :show
6

D
Dmitriy Zaporozhets 已提交
7
  def show
8
    @groups = current_user.authorized_groups.sort_by(&:human_name)
9
    @has_authorized_projects = @projects.count > 0
10 11
    @projects_count = @projects.count
    @projects = @projects.limit(20)
12

13
    @events = Event.in_projects(current_user.authorized_projects.pluck(:id))
14 15 16
    @events = @event_filter.apply_filter(@events)
    @events = @events.limit(20).offset(params[:offset] || 0)

R
randx 已提交
17
    @last_push = current_user.recent_push
18

R
randx 已提交
19
    respond_to do |format|
R
randx 已提交
20
      format.html
R
randx 已提交
21
      format.js
22
      format.atom { render layout: false }
R
randx 已提交
23
    end
D
Dmitriy Zaporozhets 已提交
24 25
  end

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

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

41
    @labels = current_user.authorized_projects.tags_on(:labels)
42
    @groups = current_user.authorized_groups
43 44 45

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

48
  # Get authored or assigned open merge requests
D
Dmitriy Zaporozhets 已提交
49
  def merge_requests
D
Dmitriy Zaporozhets 已提交
50
    @merge_requests = current_user.cared_merge_requests
51
    @merge_requests = FilterContext.new(@merge_requests, params).execute
D
Dmitriy Zaporozhets 已提交
52
    @merge_requests = @merge_requests.recent.page(params[:page]).per(20)
D
Dmitriy Zaporozhets 已提交
53 54
  end

55
  # Get only assigned issues
D
Dmitriy Zaporozhets 已提交
56
  def issues
D
Dmitriy Zaporozhets 已提交
57
    @issues = current_user.assigned_issues
58
    @issues = FilterContext.new(@issues, params).execute
D
Dmitriy Zaporozhets 已提交
59
    @issues = @issues.recent.page(params[:page]).per(20)
D
Dmitriy Zaporozhets 已提交
60 61 62 63
    @issues = @issues.includes(:author, :project)

    respond_to do |format|
      format.html
64
      format.atom { render layout: false }
D
Dmitriy Zaporozhets 已提交
65
    end
G
gitlabhq 已提交
66
  end
67

D
Dmitriy Zaporozhets 已提交
68 69
  protected

70
  def load_projects
71
    @projects = current_user.authorized_projects.sorted_by_activity
D
Dmitriy Zaporozhets 已提交
72
  end
G
gitlabhq 已提交
73
end