* teacher profile pgae

This commit is contained in:
Seth Call 2016-03-21 15:39:15 -05:00
parent b3e2943599
commit 5c14d283ab
5 changed files with 428 additions and 60 deletions

253
admin/app/admin/teachers.rb Normal file
View File

@ -0,0 +1,253 @@
ActiveAdmin.register JamRuby::Teacher, :as => 'Teachers' do
menu :label => 'Teacher', :parent => 'JamClass'
config.sort_order = 'created_at desc'
config.batch_actions = false
config.per_page = 100
config.paginate = true
index do
column "Name" do |teacher|
link_to teacher.user.name, "#{Rails.application.config.external_root_url}/client#/profile/teacher/#{teacher.user.id}"
end
column "Email" do |teacher|
teacher.user.email
end
column "Location" do |teacher|
teacher.user.location(country = true)
end
column "Profile %" do |teacher|
div do
span do
"#{teacher.pct_complete[:pct]}%"
end
br
span do
link_to "Detail", admin_teacher_path(teacher.id)
end
end
end
column "Background Check" do |teacher|
div do
if teacher.background_check_at
span do
teacher.background_check_at.to_date
end
span do
br
end
span do
link_to(mark_background_check_admin_teacher_path(teacher.id), {confirm: "Mark as background checked?"}) do
"mark as checked"
end
end
else
span do
'NOT DONE'
end
span do
br
end
span 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
span do
'YES'
end
else
span do
'NO'
end
span do
br
end
span do
link_to("mark as checked", mark_session_ready_admin_teacher_path(teacher.id), {confirm: "Mark as ready for session?"})
end
end
end
end
column "Top Teacher" do |teacher|
div do
if teacher.top_rated
span do
'YES'
end
span do
br
end
span do
link_to("mark not top", mark_not_top_admin_teacher_path(teacher.id), {confirm: "Mark as not top rated?"})
end
else
span do
'NO'
end
span do
br
end
span do
link_to("mark as top", mark_top_admin_teacher_path(teacher.id), {confirm: "Mark as top rated?"})
end
end
end
end
end
show do
attributes_table do
row "Name" do |teacher|
link_to teacher.user.name, "#{Rails.application.config.external_root_url}/client#/profile/teacher/#{teacher.user.id}"
end
row "Email" do |teacher|
teacher.user.email
end
row "Location" do |teacher|
teacher.user.location(country = true)
end
row "Profile %" do |teacher|
div do
span do
"#{teacher.pct_complete[:pct]}%"
end
br
br
div do
h5 do "Completed Sections" end
teacher.pct_complete.each do |k, v|
if k != :pct && v
div do
k
end
end
end
br
br
h5 do "Uncompleted Sections" end
teacher.pct_complete.each do |k, v|
if k != :pct && !v
div do
k
end
end
end
end
end
end
row "Background Check" do |teacher|
div do
if teacher.background_check_at
span do
teacher.background_check_at.to_date
end
span do
br
end
span do
link_to(mark_background_check_admin_teacher_path(teacher.id), {confirm: "Mark as background checked?"}) do
"mark as checked"
end
end
else
span do
'NOT DONE'
end
span do
br
end
span do
link_to("mark as checked", mark_background_check_admin_teacher_path(teacher.id), {confirm: "Mark as background checked?"})
end
end
end
end
row "Session Ready" do |teacher|
div do
if teacher.ready_for_session
span do
'YES'
end
else
span do
'NO'
end
span do
br
end
span do
link_to("mark as checked", mark_session_ready_admin_teacher_path(teacher.id), {confirm: "Mark as ready for session?"})
end
end
end
end
row "Top Teacher" do |teacher|
div do
if teacher.top_rated
span do
'YES'
end
span do
br
end
span do
link_to("mark not top", mark_not_top_admin_teacher_path(teacher.id), {confirm: "Mark as not top rated?"})
end
else
span do
'NO'
end
span do
br
end
span do
link_to("mark as top", mark_top_admin_teacher_path(teacher.id), {confirm: "Mark as top rated?"})
end
end
end
end
end
end
member_action :mark_background_check, :method => :get do
resource.mark_background_checked
redirect_to :back
end
member_action :mark_session_ready, :method => :get do
resource.mark_session_ready
redirect_to :back
end
member_action :mark_top, :method => :get do
resource.mark_top_rated
redirect_to :back
end
member_action :mark_not_top, :method => :get do
resource.mark_not_top_rated
redirect_to :back
end
end

View File

@ -339,3 +339,4 @@ acapella_rename.sql
jamblaster_pairing_active.sql
email_blacklist.sql
jamblaster_connection.sql
teacher_progression.sql

View File

@ -0,0 +1,3 @@
ALTER TABLE teachers ADD COLUMN background_check_at TIMESTAMP WITHOUT TIME ZONE;
ALTER TABLE teachers ADD COLUMN ready_for_session BOOLEAN NOT NULL DEFAULT FALSE;
ALTER TABLE teachers ADD COLUMN top_rated BOOLEAN NOT NULL DEFAULT FALSE;

View File

@ -22,6 +22,8 @@ module JamRuby
validates :years_teaching, :presence => true, :if => :validate_introduction
validates :years_playing, :presence => true, :if => :validate_introduction
validates :teaches_test_drive, inclusion: {in: [true, false]}, :if => :validate_pricing
validates :top_rated, inclusion: {in: [true, false]}
validates :ready_for_session, inclusion: {in: [true, false]}
validates :test_drives_per_week, numericality: {only_integer: true, minimum: 2, maximum: 10}, :if => :validate_pricing
validates :instruments, :length => {minimum: 1, message: "At least one instrument or subject is required"}, if: :validate_basics, unless: ->(teacher) { teacher.subjects.length>0 }
validates :subjects, :length => {minimum: 1, message: "At least one instrument or subject is required"}, if: :validate_basics, unless: ->(teacher) { teacher.instruments.length>0 }
@ -32,7 +34,7 @@ module JamRuby
validate :offer_duration, :if => :validate_pricing
validate :teaches_ages, :if => :validate_basics
default_scope { includes(:genres) }
default_scope { includes(:genres).order('created_at desc') }
def self.index(user, params = {})
@ -254,5 +256,113 @@ module JamRuby
def recent_reviews
reviews.order('created_at desc').limit(20)
end
def mark_background_checked
self.background_check_at = Time.now
self.save!
end
def mark_session_ready
self.ready_for_session = true
self.save!
end
def mark_top_rated
self.top_rated = true
self.save!
end
def mark_not_top_rated
self.top_rated = false
self.save!
end
def has_experiences_teaching?
experiences_teaching.count > 0
end
def has_experiences_education?
experiences_education.count > 0
end
def has_experiences_award?
experiences_award.count > 0
end
def has_stripe_billing?
false
end
def has_instruments_or_subject?
instruments.count > 0 || subjects.count > 0
end
def has_genres?
genres.count > 0
end
def has_languages?
languages.count > 0
end
def teaches_ages_specified?
(!teaches_age_lower.nil? && teaches_age_lower > 0) || (!teaches_age_upper.nil? && teaches_age_upper > 0)
end
def teaching_level_specified?
teaches_beginner || teaches_intermediate || teaches_advanced
end
def has_pricing_specified?
specified = false
durations_allowed = []
[30, 45, 60, 90, 120].each do |i|
durations_allowed << i if self["lesson_duration_#{i}"]
end
durations_allowed.each do |i|
if self["price_per_lesson_#{i}_cents"] || self["price_per_month_#{i}_cents"]
specified = true
break
end
end
specified
end
def has_name_specified?
!user.anonymous?
end
# how complete is their profile?
def pct_complete
@part_complete ||= {
name_specified: has_name_specified?,
experiences_teaching: has_experiences_teaching?,
experiences_education: has_experiences_education?,
experiences_award: has_experiences_award?,
has_stripe_account: has_stripe_billing?,
has_teacher_bio: !biography.nil?,
intro_video: !introductory_video.nil?,
years_teaching: years_teaching > 0,
years_playing: years_playing > 0,
instruments_or_subject: has_instruments_or_subject?,
genres: genres.count > 0,
languages: languages.count > 0,
teaches_ages_specified: teaches_ages_specified?,
teaching_level_specified: teaching_level_specified?,
has_pricing_specified: has_pricing_specified?
}
done = 0
@part_complete.each do |k, v|
if v
done += 1
end
end
complete = 100.0 * done.to_f / parts.length.to_f
@part_complete[:pct] = complete.round
@part_complete
end
end
end

View File

@ -349,11 +349,12 @@ module JamRuby
end
end
def location
def location(country = false)
loc = self.city.blank? ? '' : self.city
loc = loc.blank? ? self.state : "#{loc}, #{self.state}" unless self.state.blank?
#loc = loc.blank? ? self.country : "#{loc}, #{self.country}" unless self.country.blank?
# XXX WHY IS COUNTRY COMMENTED OUT?
if country
loc = loc.blank? ? self.country : "#{loc}, #{self.country}" unless self.country.blank?
end
loc
end