diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb index 593b31ddd2e1c56075a35a42cd8887d544a314c4..61569f33d13244f828f351e82fb1b3ce2fe4b3e9 100644 --- a/app/controllers/admins_controller.rb +++ b/app/controllers/admins_controller.rb @@ -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 diff --git a/app/views/admins/weekly_user_stats.haml b/app/views/admins/weekly_user_stats.haml index 7c65d6160330bb824c0794cf9b1a79b0adc21a0f..ee87c5397df5093c6c7ba515d9aa66056a2f1c61 100644 --- a/app/views/admins/weekly_user_stats.haml +++ b/app/views/admins/weekly_user_stats.haml @@ -1,19 +1,18 @@ - .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