Class: Hubstats::UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/hubstats/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/hubstats/users_controller.rb', line 6

def index 
  if params[:query] ## For select 2.
    @users = Hubstats::User.where("login LIKE ?", "%#{params[:query]}%").order("login ASC")
  elsif params[:id] ## 
    @users = Hubstats::User.where(id: params[:id].split(",")).order("login ASC")
  else
    @users = Hubstats::User.only_active.with_all_metrics(@timespan).with_id(params[:users]).custom_order(params[:order]).paginate(:page => params[:page], :per_page => 15)
  end
  
  respond_to do |format|
    format.html # index.html.erb
    format.json { render :json => @users}
  end
end

#showObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/hubstats/users_controller.rb', line 21

def show
  @user = Hubstats::User.where(login: params[:id]).first
  @pull_requests = Hubstats::PullRequest.belonging_to_user(@user.id).updated_since(@timespan).order("updated_at DESC").limit(20)
  @comments = Hubstats::Comment.belonging_to_user(@user.id).created_since(@timespan).order("created_at DESC").limit(20)
  @review = Hubstats::User.pulls_reviewed_count(@timespan).where(login: params[:id]).first
  @pull_count = Hubstats::PullRequest.belonging_to_user(@user.id).updated_since(@timespan).count(:all)
  #@deploy_count = Hubstats::Deploy.belonging_to_user(@user.id).deployed_since(@timespan).count(:all)
  @comment_count = Hubstats::Comment.belonging_to_user(@user.id).created_since(@timespan).count(:all)
  @stats = {
    pull_count: Hubstats::PullRequest.belonging_to_user(@user.id).merged_since(@timespan).count(:all),
    #deploy_count: Hubstats::Deploy.belonginging_to_user(@user.id).deployed_since(@timespan).count(:all),
    comment_count: @comment_count,
    review_count: @review ? @review.reviews_count : 0,
    avg_additions: Hubstats::PullRequest.merged_since(@timespan).belonging_to_user(@user.id).average(:additions).to_i,
    avg_deletions: Hubstats::PullRequest.merged_since(@timespan).belonging_to_user(@user.id).average(:deletions).to_i,
    net_additions: Hubstats::PullRequest.merged_since(@timespan).belonging_to_user(@user.id).sum(:additions).to_i -
      Hubstats::PullRequest.merged_since(@timespan).belonging_to_user(@user.id).sum(:deletions).to_i
  }
end