VRFS-1577 VRFS-736

This commit is contained in:
Jonathan Kolyer 2014-05-07 01:33:27 +00:00
parent 1c6b5b78bb
commit ebe9aa1047
3 changed files with 25 additions and 14 deletions

View File

@ -17,6 +17,14 @@ module JamRuby
:class_name => "MusicSessionHistory",
:foreign_key => "music_session_id")
def self.latest_history(client_id)
self.where(:client_id => client_id)
.order('created_at DESC')
.limit(1)
.includes(:user)
.first
end
def music_session_history
@msh ||= JamRuby::MusicSessionHistory.find_by_music_session_id(self.music_session_id)
end
@ -104,10 +112,8 @@ module JamRuby
def add_rating(rval, comment='')
rval = rval.to_i
if 0 != rval
self.rating = self.rating.to_i + rval
self.rating_comment = comment
end
self.rating = rval if 0 != rval
self.rating_comment = comment
end
MIN_SESSION_DURATION_RATING = 60
@ -118,5 +124,9 @@ module JamRuby
Rails.env.development?
end
def good_rating?
0 < self.rating.to_i
end
end
end

View File

@ -7,23 +7,25 @@
var logger = context.JK.logger;
var dialogId = 'rate-session-dialog';
var $scopeSelector = "[layout-id='rate-session-dialog']";
var clientId = context.JK.JamServer.clientID;
function reset() {
clientId = context.JK.JamServer.clientID;
$('#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) {
if (clientId) {
reset();
$.ajax({
type: "GET",
url: "/api/participant_histories/"+context.JK.JamServer.clientID
url: "/api/participant_histories/"+clientId
}).done(function (response) {
if (response &&
response.hasOwnProperty('should_rate_session') &&
true==response['should_rate_session']) {
reset();
app.layout.showDialog(dialogId);
}
});
@ -81,7 +83,7 @@
closeDialog();
return false;
}
var url = "/api/participant_histories/"+context.JK.JamServer.clientID+"/rating";
var url = "/api/participant_histories/"+clientId+"/rating";
$.ajax({
type: "POST",
url: url,

View File

@ -151,7 +151,7 @@ class ApiMusicSessionsController < ApiController
end
def participant_rating
if @history = MusicSessionUserHistory.find_by_client_id(params[:client_id])
if @history = MusicSessionUserHistory.latest_history(params[:client_id])
if request.post?
@history.add_rating(params[:rating], params[:comment])
@history.save
@ -160,11 +160,10 @@ class ApiMusicSessionsController < ApiController
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
if @history.good_rating? && @history.user.first_good_music_session_at.nil?
@history.user.first_good_music_session_at = Time.now
@history.user.save
end
render :json => {}, :status => :ok
end
elsif request.get?