From 12d8310dc627a1664ee35b2ddc444aa22afdf6ff Mon Sep 17 00:00:00 2001 From: Seth Call Date: Fri, 25 Mar 2016 12:08:23 -0500 Subject: [PATCH] * update teacher dump admin page and add new URL --- admin/app/admin/teachers.rb | 17 +++++++++++++---- admin/app/controllers/email_controller.rb | 15 +++++++++++++++ admin/config/routes.rb | 1 + db/manifest | 3 ++- db/up/teacher_complete.sql | 2 ++ ruby/lib/jam_ruby/models/teacher.rb | 9 +++++++++ ruby/lib/jam_ruby/models/user.rb | 7 ++++++- web/lib/tasks/users.rake | 6 ++++++ 8 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 db/up/teacher_complete.sql diff --git a/admin/app/admin/teachers.rb b/admin/app/admin/teachers.rb index df10c1b2f..34c780ab4 100644 --- a/admin/app/admin/teachers.rb +++ b/admin/app/admin/teachers.rb @@ -7,7 +7,10 @@ ActiveAdmin.register JamRuby::Teacher, :as => 'Teachers' do config.per_page = 100 config.paginate = true - scope("Default", default: true) { |scope| scope.unscoped.order("background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") } + scope("All", default: true) { |scope| scope.unscoped.order("background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") } + scope("All Sorted By Sign Up") { |scope| scope.unscoped.order("teachers.created_at DESC, background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") } + scope("50% and Session Ready" ) { |scope| scope.unscoped.where('profile_pct >= ?', 50.0).where('ready_for_session_at IS NOT NULL').order("background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") } + scope("50% and Not Session Ready" ) { |scope| scope.unscoped.where('profile_pct > ?', 50.0).where('ready_for_session_at IS NULL').order("background_check_at > '#{(Date.today - 365).to_s}}' NULLS FIRST, ready_for_session_at IS NULL DESC") } index do column "Name" do |teacher| @@ -67,11 +70,8 @@ ActiveAdmin.register JamRuby::Teacher, :as => 'Teachers' do link_to("mark as checked", mark_background_check_admin_teacher_path(teacher.id), {confirm: "Mark as background checked?"}) end end - - end end - column "Session Ready" do |teacher| div do if teacher.ready_for_session_at @@ -118,6 +118,10 @@ ActiveAdmin.register JamRuby::Teacher, :as => 'Teachers' do end end + column "Signed Up" do |teacher| + teacher.created_at.to_date + end + end show do @@ -238,6 +242,11 @@ ActiveAdmin.register JamRuby::Teacher, :as => 'Teachers' do end end + + row "Signed Up" do |teacher| + teacher.created_at.to_date + end + end end diff --git a/admin/app/controllers/email_controller.rb b/admin/app/controllers/email_controller.rb index 45af1bb2e..9644dfca1 100644 --- a/admin/app/controllers/email_controller.rb +++ b/admin/app/controllers/email_controller.rb @@ -21,4 +21,19 @@ class EmailController < ApplicationController @users = @users.select('DISTINCT users.id, email, first_name, last_name').joins(:sales => :sale_line_items).where("sale_line_items.product_type = 'JamTrack'") end end + + def dump_teachers + + if params[:code] != Rails.application.config.email_dump_code + render :text => "", :status => 404 + return + end + + headers['Content-Disposition'] = "attachment; filename=\"teacher-list.csv\"" + headers['Content-Type'] ||= 'text/csv' + + @users = User.joins(:teacher) + + render "dump_emailables.csv.erb" + end end \ No newline at end of file diff --git a/admin/config/routes.rb b/admin/config/routes.rb index 4565d26a2..7c671b018 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -30,6 +30,7 @@ JamAdmin::Application.routes.draw do match '/api/checks/latency_tester' => 'checks#check_latency_tester', :via => :get match '/api/users/emailables/:code' => 'email#dump_emailables', :via => :get + match '/api/teachers/:code' => 'email#dump_teachers', :via => :get match '/jam_tracks/top/:code' => 'jam_track#dump_top_selling', :via => :get match '/api/jam_tracks/released' => 'jam_track#dump_released', :via => :get, as: 'released_jamtracks_csv' diff --git a/db/manifest b/db/manifest index 8b5d0e349..9c07236f3 100755 --- a/db/manifest +++ b/db/manifest @@ -339,4 +339,5 @@ acapella_rename.sql jamblaster_pairing_active.sql email_blacklist.sql jamblaster_connection.sql -teacher_progression.sql \ No newline at end of file +teacher_progression.sql +teacher_complete.sql \ No newline at end of file diff --git a/db/up/teacher_complete.sql b/db/up/teacher_complete.sql new file mode 100644 index 000000000..7e67f1a20 --- /dev/null +++ b/db/up/teacher_complete.sql @@ -0,0 +1,2 @@ +ALTER TABLE teachers ADD COLUMN profile_pct NUMERIC(8,2) ; +ALTER TABLE teachers ADD COLUMN profile_pct_summary JSON; \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/teacher.rb b/ruby/lib/jam_ruby/models/teacher.rb index 904e6ef12..0daca4373 100644 --- a/ruby/lib/jam_ruby/models/teacher.rb +++ b/ruby/lib/jam_ruby/models/teacher.rb @@ -35,6 +35,15 @@ module JamRuby default_scope { includes(:genres).order('created_at desc') } + after_save :update_profile_pct + + def update_profile_pct + result = pct_complete + self.profile_pct = result[:pct] + self.profile_pct_summary = result.to_json + Teacher.where(id: id).update_all(profile_pct: self.profile_pct, profile_pct_summary: self.profile_pct_summary) + end + def self.index(user, params = {}) limit = params[:per_page] diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index d9e8b5dd5..50f350c01 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -36,7 +36,7 @@ module JamRuby acts_as_mappable - # after_save :check_lat_lng + after_save :update_teacher_pct attr_accessible :first_name, :last_name, :email, :city, :password, :password_confirmation, :state, :country, :birth_date, :subscribe_email, :terms_of_service, :original_fpfile, :cropped_fpfile, :cropped_large_fpfile, :cropped_s3_path, :cropped_large_s3_path, :photo_url, :large_photo_url, :crop_selection @@ -243,6 +243,11 @@ module JamRuby scope :musicians_geocoded, musicians.geocoded_users scope :email_opt_in, where(:subscribe_email => true) + def update_teacher_pct + if teacher + teacher.update_profile_pct + end + end def user_progression_fields @user_progression_fields ||= Set.new ["first_downloaded_client_at", "first_ran_client_at", "first_music_session_at", "first_real_music_session_at", "first_good_music_session_at", "first_certified_gear_at", "first_invited_at", "first_friended_at", "first_recording_at", "first_social_promoted_at", "first_played_jamtrack_at"] end diff --git a/web/lib/tasks/users.rake b/web/lib/tasks/users.rake index b84af130e..e64e07ba0 100644 --- a/web/lib/tasks/users.rake +++ b/web/lib/tasks/users.rake @@ -15,4 +15,10 @@ namespace :users do end end + task :update_profile_pct do |task, args| + Teacher.all.each do |teacher| + teacher.update_profile_pct + end + end + end