* wip on score export

This commit is contained in:
Seth Call 2014-07-26 14:18:17 -05:00
parent c13bbb95c0
commit 2dd6153ed8
4 changed files with 137 additions and 25 deletions

View File

@ -0,0 +1,68 @@
ActiveAdmin.register_page "Score Exports" do
menu :parent => 'Score'
page_action :create_csv, :method => :post do
puts params.inspect
start_time = params[:score_exports][:start]
end_time = params[:score_exports][:end]
if start_time.blank?
start_time = '1900-01-01'
end
start_time = "DATE '#{start_time}'"
if end_time.blank?
end_time = 'NOW()'
else
end_time = "DATE '#{end_time}'"
end
@users = User.find(:all)
Fetching all user details and assigned on @users
csv_string = CSV.generate do |csv|
Using CSV class generate method to create csv file
csv << ["Id", "Name", "Email","Role"]
Creating header of CSV file
@users.each do |user|
csv << [user.id, user.name, user.name, user.role]
end
Retrieving each rows and assigning on csv_string variable.
send_data csv_string,
:type => 'text/csv; charset=iso-8859-1; header=present',
:disposition => "attachment;
filename=users.csv"
render 'hi'
# redirect_to admin_bootstrap_path, :notice => "Server created. If you start a job worker (bundle exec rake all_jobs in /web), it should update your icecast config."
end
content :title => "Score Exports" do
semantic_form_for :score_exports, :url => admin_score_exports_create_csv_path, :builder => ActiveAdmin::FormBuilder do |f|
f.inputs do
f.input :start, :as => :datepicker
f.input :end, :as => :datepicker
end
f.buttons
end
#panel "Upaid Registrations" do
# table_for Registration.unpaid.limit(10).order('created_at desc') do
# column "Registration" do |registration|
# link_to registration.id, admin_registration_path(registration)
# end
# column :user
# column :tour
# column "Payment" do |registration|
# status_tag((registration.paid? ? "Received" : "Pending"), (registration.paid? ? :ok : :warning))
# end
# end
#end
end
end

View File

@ -4,34 +4,72 @@ ActiveAdmin.register JamRuby::ScoreHistory, :as => 'Score History' do
config.batch_actions = false
config.clear_action_items!
config.filters = true
config.per_page = 10
filter :score
filter :score_dt
filter :from_user_id, as: :string
filter :from_latency_tester_id
filter :from_isp
filter :from_country
filter :from_region
filter :from_city
filter :from_postal
filter :from_latitude
filter :from_latitude
filter :from_longitude
filter :to_user_id, as: :string
filter :to_latency_tester_id
filter :to_isp
filter :to_country
filter :to_region
filter :to_city
filter :to_postal
filter :to_latitude
filter :to_latitude
filter :to_longitude
before_filter only: :index do
@per_page = 1_000_000 if request.format == 'text/csv'
end
index do
column :score
column :score_dt
column "Score", :score
column "When", :score_dt
column "From User", :from_user_id do |score|
link_to score.from_user, admin_user_path(score.from_user) if score.from_user_id
end
column "From Latency Tester", :from_latency_tester_id do |score|
link_to score.from_latency_tester_id, admin_latency_testers_path if score.from_latency_tester_id
end
column "From IP", :from_addr do |score|
IPAddr.new(score.from_addr, Socket::AF_INET).to_s if score.from_addr
end
column "From ISP", :from_isp
column "From Country", :from_country
column "From Region", :from_region
column "From City", :from_city
column "From Postal", :from_postal
column "From Lat", :from_latitude
column "From Long", :from_longitude
column "From Client", :from_client_id
column :from_client_id
column :from_user_id
column :from_latency_tester_id
column :from_addr
column :from_isp
column :from_country
column :from_region
column :from_city
column :from_postal
column :from_latitude
column :from_longitude
column :to_client_id
column :to_user_id
column :to_latency_tester_id
column :to_addr
column :to_isp
column :to_country
column :to_region
column :to_city
column :to_postal
column :to_latitude
column :to_longitude
column "To User", :to_user_id do |score|
link_to score.to_user, admin_user_path(score.to_user) if score.to_user_id
end
column "To Latency Tester", :to_latency_tester_id do |score|
link_to score.to_latency_tester_id, admin_latency_testers_path if score.to_latency_tester_id
end
column "To IP", :to_addr do |score|
IPAddr.new(score.to_addr, Socket::AF_INET).to_s if score.to_addr
end
column "To ISP", :to_isp
column "To Country", :to_country
column "To Region", :to_region
column "To City", :to_city
column "To Postal", :to_postal
column "To Lat", :to_latitude
column "To Long", :to_longitude
column "To Client", :to_client_id
end
end

View File

@ -4,6 +4,9 @@ module JamRuby
self.table_name = 'score_histories'
belongs_to :from_user, class_name: 'JamRuby::User', foreign_key: 'from_user_id'
belongs_to :to_user, class_name: 'JamRuby::User', foreign_key: 'to_user_id'
def self.migrate_scores
generic_state = GenericState.singleton

View File

@ -116,6 +116,9 @@ module JamRuby
# diagnostics
has_many :diagnostics, :class_name => "JamRuby::Diagnostic"
# score history
has_many :from_score_histories, :class_name => "JamRuby::ScoreHistory", foreign_key: 'from_user_id'
has_many :to_score_histories, :class_name => "JamRuby::ScoreHistory", foreign_key: 'to_user_id'
# This causes the authenticate method to be generated (among other stuff)
#has_secure_password