dashboard_controller.rb 2.7 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 7
  before_filter :default_filter, only: [:issues, :merge_requests]

8

D
Dmitriy Zaporozhets 已提交
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)

R
randx 已提交
23
    @last_push = current_user.recent_push
24

R
randx 已提交
25
    respond_to do |format|
R
randx 已提交
26
      format.html
27
      format.json { pager_json("events/_events", @events.count) }
28
      format.atom { render layout: false }
R
randx 已提交
29
    end
D
Dmitriy Zaporozhets 已提交
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

S
skv 已提交
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

D
Dmitriy Zaporozhets 已提交
55
  def merge_requests
56
    @merge_requests = FilteringService.new.execute(MergeRequest, current_user, params)
D
Dmitriy Zaporozhets 已提交
57
    @merge_requests = @merge_requests.recent.page(params[:page]).per(20)
D
Dmitriy Zaporozhets 已提交
58 59 60
  end

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

    respond_to do |format|
      format.html
67
      format.atom { render layout: false }
D
Dmitriy Zaporozhets 已提交
68
    end
G
gitlabhq 已提交
69
  end
70

D
Dmitriy Zaporozhets 已提交
71 72
  protected

73
  def load_projects
74
    @projects = current_user.authorized_projects.sorted_by_activity.non_archived
D
Dmitriy Zaporozhets 已提交
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
G
gitlabhq 已提交
81
end