Class: AdminsController

Inherits:
Admin::AdminController show all
Includes:
ApplicationHelper
Defined in:
app/controllers/admins_controller.rb

Defined Under Namespace

Classes: UserSearch

Instance Method Summary collapse

Methods included from ApplicationHelper

#all_services_connected?, #bookmarklet_code, #changelog_url, #donations_enabled?, #jquery_include_tag, #pod_name, #pod_version, #popover_with_close_html, #qrcode_uri, #service_unconnected?, #source_url, #timeago

Instance Method Details

#add_invitesObject


36
37
38
39
# File 'app/controllers/admins_controller.rb', line 36

def add_invites
  InvitationCode.find_by_token(params[:invite_code_id]).add_invites!
  redirect_to user_search_path
end

#admin_inviterObject


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/admins_controller.rb', line 22

def admin_inviter
  inviter = InvitationCode.default_inviter_or(current_user)
  email = params[:identifier]
  user = User.find_by_email(email)

  unless user
    EmailInviter.new(email, inviter).send!
    flash[:notice] = "invitation sent to #{email}"
  else
    flash[:notice]= "error sending invite to #{email}"
  end
  redirect_to user_search_path, :notice => flash[:notice]
end

#dashboardObject


6
7
8
# File 'app/controllers/admins_controller.rb', line 6

def dashboard
  gon.push(pod_version: pod_version)
end

#statsObject


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/admins_controller.rb', line 53

def stats
  @popular_tags = ActsAsTaggableOn::Tagging.joins(:tag)
                                           .limit(50)
                                           .order(Arel.sql("count(taggings.id) DESC"))
                                           .group(:tag)
                                           .count

  case params[:range]
  when "week"
    range = 1.week
    @segment = t('admins.stats.week')
  when "2weeks"
    range = 2.weeks
    @segment = t('admins.stats.2weeks')
  when "month"
    range = 1.month
    @segment = t('admins.stats.month')
  else
    range = 1.day
    @segment = t('admins.stats.daily')
  end

  [Post, Comment, AspectMembership, User].each do |model|
    create_hash(model, :range => range)
  end

  @posts_per_day = Post.where("created_at >= ?", Time.zone.today - 21.days)
                       .group(Arel.sql("DATE(created_at)"))
                       .order(Arel.sql("DATE(created_at) ASC"))
                       .count
  @most_posts_within = @posts_per_day.values.max.to_f

  @user_count = User.count

  #@posts[:new_public] = Post.where(:type => ['StatusMessage','ActivityStreams::Photo'],
  #                                 :public => true).order('created_at DESC').limit(15).all

end

#user_searchObject


10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/admins_controller.rb', line 10

def user_search
  if params[:admins_controller_user_search]
    search_params = params.require(:admins_controller_user_search)
                          .permit(:username, :email, :guid, :under13)
    @search = UserSearch.new(search_params)
    @users = @search.perform
  end

  @search ||= UserSearch.new
  @users ||= []
end

#weekly_user_statsObject


41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/admins_controller.rb', line 41

def weekly_user_stats
  @created_users_by_week = Hash.new{ |h,k| h[k] = [] }
  @created_users = User.where("username IS NOT NULL and created_at IS NOT NULL")
  @created_users.find_each do |u|
    week = u.created_at.beginning_of_week.strftime("%Y-%m-%d")
    @created_users_by_week[week] << {username: u.username, closed_account: u.person.}
  end

  @selected_week = params[:week] || @created_users_by_week.keys.last
  @counter = @created_users_by_week[@selected_week].count
end