diff --git a/web/app/assets/javascripts/ga.js b/web/app/assets/javascripts/ga.js index 11a96eed6..0b3ed3f27 100644 --- a/web/app/assets/javascripts/ga.js +++ b/web/app/assets/javascripts/ga.js @@ -19,6 +19,11 @@ join : "Join" }; + var sessionQualityTypes = { + good : "Good", + poor : "Poor" + }; + var invitationTypes = { email : "Email", facebook : "Facebook", @@ -83,6 +88,7 @@ audioTest : "AudioTest", sessionCount : "SessionCount", sessionMusicians : "SessionMusicians", + sessionQuality : "SessionQuality", invite : "Invite", findSession : "FindSession", friendConnect : "Connect", @@ -174,6 +180,11 @@ context.ga('send', 'event', categories.sessionMusicians, joinOrCreate); } + function trackSessionQuality(goodOrPoor) { + assertOneOf(goodOrPoor, sessionQualityTypes); + context.ga('send', 'event', categories.sessionQuality, goodOrPoor); + } + function trackServiceInvitations(invitationType, numInvited) { assertOneOf(invitationType, invitationTypes); assertNumber(numInvited); @@ -271,6 +282,7 @@ var GA = {}; GA.Categories = categories; GA.SessionCreationTypes = sessionCreationTypes; + GA.SessionQualityTypes = sessionQualityTypes; GA.InvitationTypes = invitationTypes; GA.FriendConnectTypes = friendConnectTypes; GA.RecordingActions = recordingActions; diff --git a/web/app/assets/javascripts/rateSessionDialog.js b/web/app/assets/javascripts/rateSessionDialog.js index 391425222..16bde8cf0 100644 --- a/web/app/assets/javascripts/rateSessionDialog.js +++ b/web/app/assets/javascripts/rateSessionDialog.js @@ -8,8 +8,21 @@ var dialogId = 'rate-session-dialog'; var $scopeSelector = "[layout-id='rate-session-dialog']"; + function reset() { + $('#btn-rate-session-up', $scopeSelector).removeClass('selected'); + $('#btn-rate-session-down', $scopeSelector).removeClass('selected'); + $('#txt-rate-session-comment',"[layout-id='rate-session-dialog']").val(''); + } + function showDialog() { if (context.JK.JamServer.clientID) { + // $.ajax({ + // type: "/api/participant_histories/"+context.JK.JamServer.clientID, + // url: url, + // data: { rating: getRating(), comment: getComment() } + // }).done(function (response) { + // }); + reset(); app.layout.showDialog(dialogId); return true; // false if should not show dialog } @@ -49,6 +62,7 @@ if ($('#btn-rate-session-down').hasClass('selected')) { $('#btn-rate-session-down').removeClass('selected') } + return false; }); $('#btn-rate-session-down', $scopeSelector).click(function(evt) { if ($(this).hasClass('selected')) { @@ -59,16 +73,29 @@ if ($('#btn-rate-session-up').hasClass('selected')) { $('#btn-rate-session-up').removeClass('selected') } + return false; }); $('#btn-rate-session-send', $scopeSelector).click(function(evt) { + var rr = getRating(), cc = getComment(); + if (0 == rr && 0 == cc.length) { + closeDialog(); + return false; + } var url = "/api/participant_histories/"+context.JK.JamServer.clientID+"/rating"; $.ajax({ type: "POST", url: url, data: { rating: getRating(), comment: getComment() } }).done(function (response) { + var qq = getRating(); + if (0 < qq) { + context.JK.GA.trackSessionQuality(context.JK.GA.SessionQualityTypes.good); + } else if (0 > qq){ + context.JK.GA.trackSessionQuality(context.JK.GA.SessionQualityTypes.poor); + } closeDialog(); }); + return false; }); } diff --git a/web/app/assets/javascripts/session.js b/web/app/assets/javascripts/session.js index 2819b780a..9896f9dab 100644 --- a/web/app/assets/javascripts/session.js +++ b/web/app/assets/javascripts/session.js @@ -31,6 +31,7 @@ var playbackControls = null; var promptLeave = false; var backendMixerAlertThrottleTimer = null; + var rateSessionDialog = null; var rest = context.JK.Rest(); @@ -1317,9 +1318,11 @@ } function rateSession() { - var dialog = new context.JK.RateSessionDialog(context.JK.app, bailOut); - dialog.initialize(); - if (dialog.showDialog() === false) { + if (rateSessionDialog === null) { + rateSessionDialog = new context.JK.RateSessionDialog(context.JK.app, bailOut); + rateSessionDialog.initialize(); + } + if (rateSessionDialog.showDialog() === false) { bailOut(); } return true; diff --git a/web/app/controllers/api_music_sessions_controller.rb b/web/app/controllers/api_music_sessions_controller.rb index 7c598d56e..ce47df7de 100644 --- a/web/app/controllers/api_music_sessions_controller.rb +++ b/web/app/controllers/api_music_sessions_controller.rb @@ -152,14 +152,24 @@ class ApiMusicSessionsController < ApiController def participant_rating if @history = MusicSessionUserHistory.find_by_client_id(params[:client_id]) - @history.add_rating(params[:rating], params[:comment]) - @history.save + if request.post? + @history.add_rating(params[:rating], params[:comment]) + @history.save - if @history.errors.any? - response.status = :unprocessable_entity - respond_with @history - else - render :json => {}, :status => :ok + if @history.errors.any? + response.status = :unprocessable_entity + respond_with @history + else + uu = @history.user + if (uu.first_good_music_session_at.nil?) + uu.first_good_music_session_at = Time.now + uu.save + end if uu + render :json => {}, :status => :ok + + elsif request.get? + render :json => { :should_rate_session => @history.should_rate_session? }, :status => :ok + end end else render :json => { :message => ValidationMessages::SESSION_NOT_FOUND }, :status => 404 diff --git a/web/app/views/clients/_rateSession.html.erb b/web/app/views/clients/_rateSession.html.erb index 612a76d9a..fa87832f5 100644 --- a/web/app/views/clients/_rateSession.html.erb +++ b/web/app/views/clients/_rateSession.html.erb @@ -1,18 +1,17 @@ -
-
- -
-

please rate your session

-
-
-
-       -

- -

- SEND FEEDBACK   NOT NOW, THANKS -
-
- +
+ +
+ <%= image_tag "shared/icon_session.png", {:height => 19, :width => 19, :class => "content-icon"} %> +

please rate your session

+
+
+       +

+ +

+ SEND FEEDBACK   NOT NOW, THANKS +
+
+
diff --git a/web/config/routes.rb b/web/config/routes.rb index aa10f42ff..5e59b6c4d 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -168,6 +168,7 @@ SampleApp::Application.routes.draw do match '/sessions/:id/claimed_recording/:claimed_recording_id/stop' => 'api_music_sessions#claimed_recording_stop', :via => :post match '/participant_histories/:client_id/rating' => 'api_music_sessions#participant_rating', :via => :post + match '/participant_histories/:client_id' => 'api_music_sessions#participant_rating', :via => :get # genres match '/genres' => 'api_genres#index', :via => :get