Commit c12a4555 authored by Fabian Rodriguez's avatar Fabian Rodriguez

fix #2645

  * refactor a bit #weekly_user_stats
  * pass 0 instead of "" to i18n
  * use the first week if none is provided
parent bbbdd875
......@@ -30,20 +30,15 @@ class AdminsController < ApplicationController
end
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_by_week = Hash.new{ |h,k| h[k] = [] }
@created_users.find_each do |u|
unless u.nil?
@created_users_by_week[u.created_at.beginning_of_week.strftime("%Y-%m-%d")].push("#{u.username}")
end
end
unless(params[:week]).nil?
# @segment = "#{@created_users_by_week[(params[:week])]}"
@counter = "#{@created_users_by_week[(params[:week])].count}"
else
@counter = ""
week = u.created_at.beginning_of_week.strftime("%Y-%m-%d")
@created_users_by_week[week] << u.username
end
@selected_week = params[:week] || @created_users_by_week.keys.first
@counter = @created_users_by_week[@selected_week].count
end
def stats
......
.span-24
= render :partial => 'admins/admin_bar'
= render partial: 'admins/admin_bar'
%br
%br
.span-24.last
%h2
= t('.current_server', :date => Time.now.to_date)
= t('.current_server', date: Time.now.to_date)
= form_tag('/admins/weekly_user_stats', :method => 'get') do
= select_tag(:week, options_for_select(@created_users_by_week.keys))
= form_tag('/admins/weekly_user_stats', method: 'get') do
= select_tag(:week, options_for_select(@created_users_by_week.keys), selected: @selected_week)
= submit_tag t('admins.stats.go')
= t('.amount_of', :count => @counter)
= t('.amount_of', count: @counter)
%br
- @created_users_by_week[(params[:week])].each do |m|
- @created_users_by_week[@selected_week].each do |m|
= link_to m, "/u/#{m}"
%br
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment