VRFS-4126 - update teacher rating/student ratig post session dialog

This commit is contained in:
Seth Call 2016-05-27 21:33:26 -05:00
parent 9d160bfd7c
commit 5d68fe322a
9 changed files with 145 additions and 67 deletions

View File

@ -767,8 +767,8 @@ module JamRuby
feed.active = true
feed.save
GoogleAnalyticsEvent.track_session_duration(self)
GoogleAnalyticsEvent.track_band_real_session(self)
#GoogleAnalyticsEvent.track_session_duration(self)
#GoogleAnalyticsEvent.track_band_real_session(self)
end
def open_jam_track(user, jam_track)

View File

@ -162,7 +162,7 @@ module JamRuby
self.connected? &&
self.as_musician? &&
0 < (count = self.music_session.connected_participant_count)
GoogleAnalyticsEvent.report_session_participant(count)
#GoogleAnalyticsEvent.report_session_participant(count)
end
true
end

View File

@ -224,7 +224,7 @@ module JamRuby
recording.video = record_video
if recording.save
GoogleAnalyticsEvent.report_band_recording(recording.band)
#GoogleAnalyticsEvent.report_band_recording(recording.band)
# make quick mixes *before* the audio/video tracks, because this will give them precedence in list_uploads
music_session.users.uniq.each do |user|

View File

@ -199,6 +199,7 @@ module JamRuby
has_many :jam_track_session, :class_name => "JamRuby::JamTrackSession"
has_many :taken_lessons, :class_name => "JamRuby::LessonSession", inverse_of: :user, foreign_key: :user_id
has_many :taught_lessons, :class_name => "JamRuby::LessonSession", inverse_of: :teacher, foreign_key: :teacher_id
belongs_to :school, :class_name => "JamRuby::School", inverse_of: :students
has_one :owned_school, :class_name => "JamRuby::School", inverse_of: :user
@ -1925,6 +1926,14 @@ module JamRuby
lesson_purchases.where('lesson_package_type_id in (?)', LessonPackageType.test_drive_package_ids).where('created_at > ?', APP_CONFIG.test_drive_wait_period_year.years.ago).count == 0
end
def lessons_with_teacher(teacher)
taken_lessons.where(teacher_id: teacher.id)
end
def lessons_with_student(student)
taught_lessons.where(user_id: student.id)
end
def has_test_drives?
remaining_test_drives > 0
end

View File

@ -2514,6 +2514,15 @@
})
}
function ratingDecision(options) {
return $.ajax({
type: "GET",
url: '/api/lesson_sessions/rating_decision?' + $.param(options),
dataType: "json",
contentType: 'application/json'
})
}
function initialize() {
return self;
}
@ -2739,6 +2748,7 @@
this.lessonStartTime = lessonStartTime;
this.createReview = createReview;
this.askSearchHelp = askSearchHelp;
this.ratingDecision = ratingDecision;
return this;
};
})(window,jQuery);

View File

@ -29,9 +29,14 @@ context = window
logger.debug("RateUserDialog.beforeShow", args.d1)
parsed = @parseId(args.d1)
@setState({student: null, teacher: null, type: parsed.type, id: parsed.id, rating: null})
@setState({rating_decision: null, type: parsed.type, id: parsed.id, rating: null, willUpdate: false, description:''})
rest.getUserDetail({id: parsed.id}).done((response) => @userLookupDone(response)).fail((jqXHR) => @userLookupFail(jqXHR))
as_student = parsed.type == 'teacher'
rest.ratingDecision({
as_student: as_student,
teacher_id: parsed.id,
student_id: parsed.id
}).done((response) => @userLookupDone(response)).fail((jqXHR) => @userLookupFail(jqXHR))
afterHide: () ->
@ -42,10 +47,10 @@ context = window
@state.type == 'student'
userLookupDone: (response) ->
if @isRatingTeacher()
@setState({teacher: response})
else
@setState({student: response})
value = response.rating?.rating
if value?
@setState({rating: value, description: response.rating?.description})
@setState({rating_decision: response})
userLookupFail: (jqXHR) ->
@app.ajaxError(jqXHR, null, null)
@ -123,62 +128,71 @@ context = window
@app.ajaxError(jqXHR, null, null)
disabled: () ->
!@state.rating? || (!@state.teacher? && !@state.student?)
!@state.rating? || (!@state.rating_decision?)
willUpdate: (e) ->
e.preventDefault()
@setState({willUpdate: true})
render: () ->
submitClasses = classNames({'button-orange': true, disabled: @disabled()})
if @isRatingTeacher()
title = 'Rate Teacher'
help = `<h2>Please rate this teacher based on your experience with them:</h2>`
descriptionPrompt = `<h2>Please help other students by explaining what you like or dont like about this teacher:</h2>`
choices =
`<div className="choices">
<div className="field">
<input type="radio" name="rating" value="5"/><label>Great teacher</label>
</div>
<div className="field">
<input type="radio" name="rating" value="4"/><label>Good teacher</label>
</div>
<div className="field">
<input type="radio" name="rating" value="3"/><label>Average teacher</label>
</div>
<div className="field">
<input type="radio" name="rating" value="2"/><label>Poor teacher</label>
</div>
<div className="field">
<input type="radio" name="rating" value="1"/><label>Terrible teacher</label>
</div>
</div>`
if !@state.willUpdate && (@state.rating_decision? && @state.rating_decision.rating?)
dialogContents = `<div className="dialog-inner">
<h2>Would you like to update your rating/review of this teacher?</h2>
<div className="actions">
<a onClick={this.doCancel} className="button-grey">NO</a>
<a onClick={this.willUpdate} className={submitClasses}>YES</a>
</div>
</div>`
else
title = 'Rate Student'
help = `<h2>Please rate this student based on your experience with them:</h2>`
descriptionPrompt = `<h2>Please tell us if you have problems with this student in the form of tardiness, abusiveness, or other inappropriate behaviors. We will not share this information with other teachers or students, but we may use aggregate negative feedback on a student from multiple teachers to block the student from our lesson marketplace.</h2>`
choices =
`<div className="choices">
<div className="field">
<input type="radio" name="rating" value="5"/><label>Great student</label>
</div>
<div className="field">
<input type="radio" name="rating" value="4"/><label>Good student</label>
</div>
<div className="field">
<input type="radio" name="rating" value="3"/><label>Average student</label>
</div>
<div className="field">
<input type="radio" name="rating" value="2"/><label>Poor student</label>
</div>
<div className="field">
<input type="radio" name="rating" value="1"/><label>Terrible student</label>
</div>
</div>`
`<div>
<div className="content-head">
<img className="content-icon" src="/assets/content/icon_add.png" height={19} width={19}/>
<h1>{title}</h1>
</div>
<div className="dialog-inner">
if @isRatingTeacher()
title = 'Rate Teacher'
help = `<h2>Please rate this teacher based on your experience with them:</h2>`
descriptionPrompt = `<h2>Please help other students by explaining what you like or dont like about this teacher:</h2>`
choices =
`<div className="choices">
<div className="field">
<input type="radio" name="rating" value="5"/><label>Great teacher</label>
</div>
<div className="field">
<input type="radio" name="rating" value="4"/><label>Good teacher</label>
</div>
<div className="field">
<input type="radio" name="rating" value="3"/><label>Average teacher</label>
</div>
<div className="field">
<input type="radio" name="rating" value="2"/><label>Poor teacher</label>
</div>
<div className="field">
<input type="radio" name="rating" value="1"/><label>Terrible teacher</label>
</div>
</div>`
else
title = 'Rate Student'
help = `<h2>Please rate this student based on your experience with them:</h2>`
descriptionPrompt = `<h2>Please tell us if you have problems with this student in the form of tardiness, abusiveness, or other inappropriate behaviors. We will not share this information with other teachers or students, but we may use aggregate negative feedback on a student from multiple teachers to block the student from our lesson marketplace.</h2>`
choices =
`<div className="choices">
<div className="field">
<input type="radio" name="rating" value="5"/><label>Great student</label>
</div>
<div className="field">
<input type="radio" name="rating" value="4"/><label>Good student</label>
</div>
<div className="field">
<input type="radio" name="rating" value="3"/><label>Average student</label>
</div>
<div className="field">
<input type="radio" name="rating" value="2"/><label>Poor student</label>
</div>
<div className="field">
<input type="radio" name="rating" value="1"/><label>Terrible student</label>
</div>
</div>`
dialogContents = `<div className="dialog-inner">
{help}
@ -194,7 +208,15 @@ context = window
<a onClick={this.doCancel} className="button-grey">CANCEL</a>
<a onClick={this.doRating} className={submitClasses}>SUBMIT RATING</a>
</div>
</div>`
`<div>
<div className="content-head">
<img className="content-icon" src="/assets/content/icon_add.png" height={19} width={19}/>
<h1>{title}</h1>
</div>
{dialogContents}
</div>`
})

View File

@ -1076,10 +1076,30 @@ ConfigureTracksActions = @ConfigureTracksActions
if @currentSession?.lesson_session?
if context.JK.currentUserId == @currentSession.lesson_session.teacher_id
@app.layout.showDialog('rate-user-dialog', {d1: 'student_' + @currentSession.lesson_session.student_id})
else
@app.layout.showDialog('rate-user-dialog', {d1: 'teacher_' + @currentSession.lesson_session.teacher_id})
isTeacher = context.JK.currentUserId == @currentSession.lesson_session.teacher_id
tempSession = @currentSession
rest.ratingDecision({
as_student: !isTeacher,
teacher_id: @currentSession.lesson_session.teacher_id,
student_id: @currentSession.lesson_session.teacher_id
}).done(((decision) =>
showDialog = !decision.rating || showDialog = decision.lesson_count % 6 == 0
if showDialog
if isTeacher
@app.layout.showDialog('rate-user-dialog', {d1: 'student_' + tempSession.lesson_session.student_id})
else
@app.layout.showDialog('rate-user-dialog', {d1: 'teacher_' + tempSession.lesson_session.teacher_id})
else
unless @rateSessionDialog?
@rateSessionDialog = new context.JK.RateSessionDialog(context.JK.app);
@rateSessionDialog.initialize();
@rateSessionDialog.showDialog();
))
else
unless @rateSessionDialog?

View File

@ -1,7 +1,7 @@
class ApiLessonSessionsController < ApiController
before_filter :api_signed_in_user
before_filter :lookup_lesson, except: [:index, :uncollectable]
before_filter :lookup_lesson, except: [:index, :uncollectable, :rating_decision]
before_filter :is_teacher, only: [:accept]
before_filter :is_student, only: []
respond_to :json
@ -141,6 +141,22 @@ class ApiLessonSessionsController < ApiController
end
def rating_decision
if params[:as_student]
teacher = User.find(params[:teacher_id])
lessons = current_user.lessons_with_teacher(teacher)
rating = current_user.teacher_rating(teacher.teacher).first
else
student = User.find(params[:student_id])
lessons = teacher.lessons_with_student(student)
rating = teacher.student_rating(student).first
end
render :json => {lesson_count: lessons.count, rating: rating}, :status => 200
end
private
def lookup_lesson

View File

@ -694,6 +694,7 @@ SampleApp::Application.routes.draw do
match '/lesson_bookings/unprocessed_or_intent' => 'api_lesson_bookings#unprocessed_or_intent', :via => :get
match '/lesson_sessions/uncollectable' => 'api_lesson_sessions#uncollectable', :via => :get
match '/lesson_sessions/rating_decision' => 'api_lesson_sessions#rating_decision', :via => :get
match '/lesson_sessions/:id' => 'api_lesson_sessions#show', :via => :get
match '/lesson_sessions/:id/update_unread_messages' => 'api_lesson_sessions#update_unread_messages', :via => :post
match '/lesson_sessions/:id/attach_recording' => 'api_lesson_sessions#attach_recording', :via => :post