From 5d68fe322a098fa7e2ebc523465545b906885716 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Fri, 27 May 2016 21:33:26 -0500 Subject: [PATCH] VRFS-4126 - update teacher rating/student ratig post session dialog --- .../jam_ruby/models/active_music_session.rb | 4 +- ruby/lib/jam_ruby/models/connection.rb | 2 +- ruby/lib/jam_ruby/models/recording.rb | 2 +- ruby/lib/jam_ruby/models/user.rb | 9 ++ web/app/assets/javascripts/jam_rest.js | 10 ++ .../RateUserDialog.js.jsx.coffee | 138 ++++++++++-------- .../stores/SessionStore.js.coffee | 28 +++- .../api_lesson_sessions_controller.rb | 18 ++- web/config/routes.rb | 1 + 9 files changed, 145 insertions(+), 67 deletions(-) diff --git a/ruby/lib/jam_ruby/models/active_music_session.rb b/ruby/lib/jam_ruby/models/active_music_session.rb index cca5d6eda..dc10df5d1 100644 --- a/ruby/lib/jam_ruby/models/active_music_session.rb +++ b/ruby/lib/jam_ruby/models/active_music_session.rb @@ -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) diff --git a/ruby/lib/jam_ruby/models/connection.rb b/ruby/lib/jam_ruby/models/connection.rb index b8a2afdaf..5b1444fc7 100644 --- a/ruby/lib/jam_ruby/models/connection.rb +++ b/ruby/lib/jam_ruby/models/connection.rb @@ -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 diff --git a/ruby/lib/jam_ruby/models/recording.rb b/ruby/lib/jam_ruby/models/recording.rb index 67585f678..c9550ba1a 100644 --- a/ruby/lib/jam_ruby/models/recording.rb +++ b/ruby/lib/jam_ruby/models/recording.rb @@ -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| diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index 79eeaee36..91321138e 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -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 diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index 0a85887cf..1c00aac3e 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -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); diff --git a/web/app/assets/javascripts/react-components/RateUserDialog.js.jsx.coffee b/web/app/assets/javascripts/react-components/RateUserDialog.js.jsx.coffee index e460ba4b0..914859f5d 100644 --- a/web/app/assets/javascripts/react-components/RateUserDialog.js.jsx.coffee +++ b/web/app/assets/javascripts/react-components/RateUserDialog.js.jsx.coffee @@ -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 = `

Please rate this teacher based on your experience with them:

` - descriptionPrompt = `

Please help other students by explaining what you like or don’t like about this teacher:

` - choices = - `
-
- -
-
- -
-
- -
-
- -
-
- -
-
` + if !@state.willUpdate && (@state.rating_decision? && @state.rating_decision.rating?) + dialogContents = `
+ +

Would you like to update your rating/review of this teacher?

+ +
+ NO + YES +
+
` else - title = 'Rate Student' - help = `

Please rate this student based on your experience with them:

` - descriptionPrompt = `

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.

` - choices = - `
-
- -
-
- -
-
- -
-
- -
-
- -
-
` - - `
-
- - -

{title}

-
-
+ if @isRatingTeacher() + title = 'Rate Teacher' + help = `

Please rate this teacher based on your experience with them:

` + descriptionPrompt = `

Please help other students by explaining what you like or don’t like about this teacher:

` + choices = + `
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
` + else + title = 'Rate Student' + help = `

Please rate this student based on your experience with them:

` + descriptionPrompt = `

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.

` + choices = + `
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
` + dialogContents = `
{help} @@ -194,7 +208,15 @@ context = window CANCEL SUBMIT RATING
+
` + + `
+
+ + +

{title}

+ {dialogContents}
` }) \ No newline at end of file diff --git a/web/app/assets/javascripts/react-components/stores/SessionStore.js.coffee b/web/app/assets/javascripts/react-components/stores/SessionStore.js.coffee index 95ffeb0b5..f8504382a 100644 --- a/web/app/assets/javascripts/react-components/stores/SessionStore.js.coffee +++ b/web/app/assets/javascripts/react-components/stores/SessionStore.js.coffee @@ -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? diff --git a/web/app/controllers/api_lesson_sessions_controller.rb b/web/app/controllers/api_lesson_sessions_controller.rb index 8acc3ff57..22a0bf5b1 100644 --- a/web/app/controllers/api_lesson_sessions_controller.rb +++ b/web/app/controllers/api_lesson_sessions_controller.rb @@ -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 diff --git a/web/config/routes.rb b/web/config/routes.rb index c05812a9c..7ceeb0c99 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -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