users_controller.rb 2.6 KB
Newer Older
D
Dmitriy Zaporozhets 已提交
1
class UsersController < ApplicationController
2 3
  skip_before_action :authenticate_user!
  before_action :set_user
4

D
Dmitriy Zaporozhets 已提交
5
  def show
6 7
    respond_to do |format|
      format.html
8 9 10 11 12 13

      format.atom do
        load_events
        render layout: false
      end

14 15 16 17
      format.json do
        load_events
        pager_json("events/_events", @events.count)
      end
18 19 20
    end
  end

21 22 23
  def groups
    load_groups

A
Alfredo Sumaran 已提交
24
    respond_to do |format|
25
      format.html { render 'show' }
A
Alfredo Sumaran 已提交
26 27 28 29 30 31
      format.json do
        render json: {
          html: view_to_html_string("shared/groups/_list", groups: @groups)
        }
      end
    end
32 33
  end

34
  def projects
35 36
    load_projects

A
Alfredo Sumaran 已提交
37
    respond_to do |format|
38
      format.html { render 'show' }
A
Alfredo Sumaran 已提交
39 40 41 42 43 44
      format.json do
        render json: {
          html: view_to_html_string("shared/projects/_list", projects: @projects, remote: true)
        }
      end
    end
45 46
  end

47
  def contributed
48 49
    load_contributed_projects

A
Alfredo Sumaran 已提交
50
    respond_to do |format|
51
      format.html { render 'show' }
A
Alfredo Sumaran 已提交
52 53 54 55 56 57
      format.json do
        render json: {
          html: view_to_html_string("shared/projects/_list", projects: @contributed_projects)
        }
      end
    end
58 59
  end

60
  def calendar
61
    calendar = contributions_calendar
62
    @timestamps = calendar.timestamps
63 64
    @starting_year = calendar.starting_year
    @starting_month = calendar.starting_month
65

66
    render 'calendar', layout: false
D
Dmitriy Zaporozhets 已提交
67
  end
68

69
  def calendar_activities
70 71
    @calendar_date = Date.parse(params[:date]) rescue nil
    @events = []
72

73 74
    if @calendar_date
      @events = contributions_calendar.events_by_date(@calendar_date)
75 76 77 78 79
    end

    render 'calendar_activities', layout: false
  end

80 81
  private

82
  def set_user
83 84
    @user = User.find_by_username!(params[:username])
  end
85

86
  def contributed_projects
87
    ContributedProjectsFinder.new(@user).execute(current_user)
88 89 90 91
  end

  def contributions_calendar
    @contributions_calendar ||= Gitlab::ContributionsCalendar.
92
      new(contributed_projects, @user)
93
  end
94

95 96 97
  def load_events
    # Get user activity feed for projects common for both users
    @events = @user.recent_events.
98 99 100 101 102
      merge(projects_for_current_user).
      references(:project).
      with_associations.
      limit_recent(20, params[:offset])
  end
103

104 105 106 107 108 109 110 111 112 113 114 115 116 117
  def load_projects
    @projects =
      PersonalProjectsFinder.new(@user).execute(current_user)
      .page(params[:page]).per(PER_PAGE)
  end

  def load_contributed_projects
    @contributed_projects = contributed_projects.joined(@user)
  end

  def load_groups
    @groups = @user.groups.order_id_desc
  end

118 119
  def projects_for_current_user
    ProjectsFinder.new.execute(current_user)
120
  end
D
Dmitriy Zaporozhets 已提交
121
end