VRFS-1210 VRFS-1212 VRFS-1223 bug fixes

This commit is contained in:
Brian Smith 2014-02-24 01:10:09 -05:00
parent 1e75e2ffeb
commit ccee2e15b3
15 changed files with 286 additions and 132 deletions

View File

@ -47,55 +47,53 @@
/****************** MAIN PORTION OF SCREEN *****************/
function addFollowing(isBand, id) {
var newFollowing = {};
var newFollowing = {};
if (!isBand) {
newFollowing.user_id = id;
}
else {
newFollowing.band_id = id;
}
if (!isBand) {
newFollowing.user_id = id;
}
else {
newFollowing.band_id = id;
}
rest.addFollowing(newFollowing)
.done(function() {
if (isBand) {
var newCount = parseInt($("#band-profile-follower-stats").text()) + 1;
var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower";
$('#band-profile-follower-stats').html(newCount + text);
configureBandFollowingButton(true);
}
else {
configureMemberFollowingButton(true, id);
}
})
.fail(app.ajaxError);
rest.addFollowing(newFollowing)
.done(function() {
if (isBand) {
var newCount = parseInt($("#band-profile-follower-stats").text()) + 1;
var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower";
$('#band-profile-follower-stats').html(newCount + text);
configureBandFollowingButton(true);
}
else {
configureMemberFollowingButton(true, id);
}
renderActive();
})
.fail(app.ajaxError);
}
function removeFollowing(isBand, id) {
var following = {};
following.target_entity_id = id;
rest.removeFollowing(following)
.done(function() {
renderActive(); // refresh stats
if (isBand) {
var newCount = parseInt($("#band-profile-follower-stats").text()) - 1;
var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower";
$('#band-profile-follower-stats').html(newCount + text);
configureBandFollowingButton(false);
}
else {
configureMemberFollowingButton(false, id);
}
})
.fail(app.ajaxError);
rest.removeFollowing(id)
.done(function() {
if (isBand) {
var newCount = parseInt($("#band-profile-follower-stats").text()) - 1;
var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower";
$('#band-profile-follower-stats').html(newCount + text);
configureBandFollowingButton(false);
}
else {
configureMemberFollowingButton(false, id);
}
renderActive();
})
.fail(app.ajaxError);
}
function configureBandFollowingButton(following) {
$('#btn-follow-band').unbind("click");
if (following) {
$('#btn-follow-band').text('STOP FOLLOWING');
$('#btn-follow-band').text('UNFOLLOW');
$('#btn-follow-band').click(function() {
removeFollowing(true, bandId);
return false;
@ -121,7 +119,7 @@
$btnFollowMember.unbind("click");
if (following) {
$btnFollowMember.text('UN-FOLLOW');
$btnFollowMember.text('UNFOLLOW');
$btnFollowMember.click(function() {
removeFollowing(false, userId);
return false;

View File

@ -49,21 +49,23 @@
});
var bandHtml = context.JK.fillTemplate(template, {
avatar_url: context.JK.resolveBandAvatarUrl(response.photo_url),
name: response.name,
location: response.location,
genres: genres.join(', '),
musicians: musicianHtml,
like_count: response.liker_count,
follower_count: response.follower_count,
recording_count: response.recording_count,
session_count: response.session_count,
biography: response.biography,
profile_url: "/client#/bandProfile/" + response.id
bandId: response.id,
avatar_url: context.JK.resolveBandAvatarUrl(response.photo_url),
name: response.name,
location: response.location,
genres: genres.join(', '),
musicians: musicianHtml,
like_count: response.liker_count,
follower_count: response.follower_count,
recording_count: response.recording_count,
session_count: response.session_count,
biography: response.biography,
followAction: response.is_following ? "removeBandFollowing" : "addBandFollowing",
profile_url: "/client#/bandProfile/" + response.id
});
$(hoverSelector).append('<h2>Band Detail</h2>' + bandHtml);
toggleActionButtons();
configureActionButtons(response);
})
.fail(function(xhr) {
if(xhr.status >= 500) {
@ -78,9 +80,17 @@
});
};
function toggleActionButtons() {
function configureActionButtons(band) {
var btnFollowSelector = "#btnFollow";
// if unauthenticated or authenticated user is viewing his own profile
if (!context.JK.currentUserId) {
$("#btnFollow", hoverSelector).hide();
$(btnFollowSelector, hoverSelector).hide();
}
else {
if (band.is_following) {
$(btnFollowSelector, hoverSelector).html('UNFOLLOW');
}
}
}

View File

@ -56,13 +56,15 @@
location: response.location,
friend_count: response.friend_count,
follower_count: response.follower_count,
friendAction: response.is_friend ? "removeFanFriend" : (response.pending_friend_request ? "" : "sendFanFriendRequest"),
followAction: response.is_following ? "removeFanFollowing" : "addFanFollowing",
biography: response.biography,
followings: response.followings && response.followings.length > 0 ? followingHtml : "<tr><td>N/A</td></tr>",
profile_url: "/client#/profile/" + response.id
});
$(hoverSelector).append('<h2>Fan Detail</h2>' + fanHtml);
toggleActionButtons();
configureActionButtons(response);
})
.fail(function(xhr) {
if(xhr.status >= 500) {
@ -77,10 +79,30 @@
});
};
function toggleActionButtons() {
if (!context.JK.currentUserId) {
$("#btnFriend", hoverSelector).hide();
$("#btnFollow", hoverSelector).hide();
function configureActionButtons(user) {
var btnFriendSelector = "#btnFriend";
var btnFollowSelector = "#btnFollow";
if (!context.JK.currentUserId || context.JK.currentUserId === user.id) {
$(btnFriendSelector, hoverSelector).hide();
$(btnFollowSelector, hoverSelector).hide();
}
else {
if (user.is_friend) {
$(btnFriendSelector, hoverSelector).html('DISCONNECT');
}
if (user.is_following) {
$(btnFollowSelector, hoverSelector).html('UNFOLLOW');
$(btnFollowSelector, hoverSelector).click(function(evt) {
rest.removeFollowing(user.id);
});
}
if (user.pending_friend_request) {
$(btnFriendSelector, hoverSelector).hide();
}
}
}

View File

@ -75,13 +75,15 @@
session_count: response.session_count,
session_display: sessionDisplayStyle,
session_id: sessionId,
friendAction: response.is_friend ? "removeMusicianFriend" : (response.pending_friend_request ? "" : "sendMusicianFriendRequest"),
followAction: response.is_following ? "removeMusicianFollowing" : "addMusicianFollowing",
biography: response.biography,
followings: response.followings && response.followings.length > 0 ? followingHtml : "<tr><td>N/A</td></tr>",
profile_url: "/client#/profile/" + response.id
});
$(hoverSelector).append('<h2>Musician Detail</h2>' + musicianHtml);
toggleActionButtons();
configureActionButtons(response);
})
.fail(function(xhr) {
if(xhr.status >= 500) {
@ -96,10 +98,25 @@
});
};
function toggleActionButtons() {
if (!context.JK.currentUserId) {
$("#btnFriend", hoverSelector).hide();
$("#btnFollow", hoverSelector).hide();
function configureActionButtons(user) {
var btnFriendSelector = "#btnFriend";
var btnFollowSelector = "#btnFollow";
// if unauthenticated or authenticated user is viewing his own profile
if (!context.JK.currentUserId || context.JK.currentUserId === user.id) {
$(btnFriendSelector, hoverSelector).hide();
$(btnFollowSelector, hoverSelector).hide();
}
else {
if (user.is_friend) {
$(btnFriendSelector, hoverSelector).html('DISCONNECT');
}
if (user.is_following) {
$(btnFollowSelector, hoverSelector).html('UNFOLLOW');
}
if (user.pending_friend_request) {
$(btnFriendSelector, hoverSelector).hide();
}
}
}

View File

@ -451,7 +451,7 @@
});
}
function removeLike(options) {
function removeLike(likableId, options) {
var id = getId(options);
return $.ajax({
type: "DELETE",
@ -476,15 +476,13 @@
});
}
function removeFollowing(options) {
function removeFollowing(followableId, options) {
var id = getId(options);
return $.ajax({
type: "DELETE",
dataType: "json",
contentType: 'application/json',
url: "/api/users/" + id + "/followings",
data: JSON.stringify(options),
url: "/api/users/" + id + "/followings/" + followableId,
processData: false
});
}

View File

@ -193,10 +193,10 @@
function configureFriendButton() {
if (isFriend()) {
$('#btn-add-friend').text('REMOVE FRIEND');
$('#btn-add-friend').text('DISCONNECT');
}
else {
$('#btn-add-friend').text('ADD FRIEND');
$('#btn-add-friend').text('CONNECT');
}
}
@ -213,10 +213,7 @@
}
function removeFollowing(isBand, id) {
var following = {};
following.target_entity_id = id;
rest.removeFollowing(following)
rest.removeFollowing(id)
.done(function() {
if (!isBand) {
updateFollowingCount(-1);
@ -242,7 +239,7 @@
function configureFollowingButton() {
if (isFollowing()) {
$('#btn-follow-user').text('STOP FOLLOWING');
$('#btn-follow-user').text('UNFOLLOW');
}
else {
$('#btn-follow-user').text('FOLLOW');

View File

@ -117,23 +117,23 @@
selector = isSidebar ? '#sidebar-search-results' : '#search-results';
$(selector).append(invitationSentHtml);
// wire up button click handler if search result is not a friend or the current use
// wire up button click handler if search result is not a friend or the current user
if (isSidebar) {
var $sidebar = $('div[layout=sidebar] div[user-id=' + val.id + ']');
if (!val.is_friend && val.id !== context.JK.currentUserId) {
$sidebar.find('.btn-connect-friend').click(sendFriendRequest);
if (val.is_friend || val.pending_friend_request || val.id === context.JK.currentUserId) {
// hide the button if the search result is already a friend
$sidebar.find('.btn-connect-friend').hide();
}
else {
// hide the button if the search result is already a friend
$sidebar.find('.btn-connect-friend').hide();
$sidebar.find('.btn-connect-friend').click(sendFriendRequest);
}
}
else {
if (!val.is_friend && val.id !== context.JK.currentUserId) {
$('div[user-id=' + val.id + ']').find('.btn-connect-friend').click(sendFriendRequest);
if (val.is_friend || val.pending_friend_request || val.id === context.JK.currentUserId) {
$('div[user-id=' + val.id + ']').find('.btn-connect-friend').hide();
}
else {
$('div[user-id=' + val.id + ']').find('.btn-connect-friend').hide();
$('div[user-id=' + val.id + ']').find('.btn-connect-friend').click(sendFriendRequest);
}
}
resultDivVisibility(val, isSidebar);

View File

@ -202,7 +202,7 @@ class ApiUsersController < ApiController
end
def liking_destroy
User.delete_liking(params[:id], params[:target_entity_id])
User.delete_liking(params[:id], params[:likable_id])
respond_with responder: ApiResponder, :status => 204
end
@ -230,7 +230,7 @@ class ApiUsersController < ApiController
end
def following_destroy
User.delete_following(params[:id], params[:target_entity_id])
User.delete_following(params[:id], params[:followable_id])
respond_with responder: ApiResponder, :status => 204
end

View File

@ -23,6 +23,10 @@ if @search.musicians_text_search?
musician.friends?(current_user)
end
node :pending_friend_request do |musician|
musician.pending_friend_request?(current_user)
end
child :musician_instruments => :instruments do
attributes :instrument_id, :description, :proficiency_level, :priority
end
@ -50,6 +54,10 @@ if @search.musicians_filter_search?
@search.is_follower?(musician)
end
node :pending_friend_request do |musician|
@search.pending_friend_request?(musician)
end
node :biography do |musician|
musician.biography.nil? ? "" : musician.biography
end
@ -112,6 +120,10 @@ if @search.fans_text_search?
node :is_friend do |fan|
fan.friends?(current_user)
end
node :pending_friend_request do |musician|
@search.pending_friend_request?(musician)
end
}
end

View File

@ -5,25 +5,49 @@
<script type="text/javascript">
var rest = JK.Rest();
function addLike(bandId) {
rest.addLike({band_id: bandId})
// function addLike(bandId) {
// rest.addLike({band_id: bandId})
// .done(function(response) {
// $("#spnLikeCount", "#band-hover").html(parseInt($("#spnLikeCount", "#band-hover").text()) + 1);
// var $btnLikeSelector = $("#btnLike", "#band-hover");
// $btnLikeSelector.unbind("click");
// $btnLikeSelector.html("LIKED");
// });
// }
function addBandFollowing(bandId) {
rest.addFollowing({band_id: bandId})
.done(function(response) {
$("#spnLikeCount", "#band-hover").html(parseInt($("#spnLikeCount", "#band-hover").text()) + 1);
var $btnLikeSelector = $("#btnLike", "#band-hover");
$btnLikeSelector.unbind("click");
$btnLikeSelector.html("LIKED");
adjustBandFollowingCount(1);
var $btnFollowSelector = $("#btnFollow", "#band-hover");
$btnFollowSelector.unbind('click');
$btnFollowSelector.attr('onclick', '');
$btnFollowSelector.click(function() {
removeBandFollowing(bandId);
});
$btnFollowSelector.html("UNFOLLOW");
});
}
function addFollowing(bandId) {
rest.addFollowing({band_id: bandId})
function removeBandFollowing(bandId) {
rest.removeFollowing(bandId)
.done(function(response) {
$("#spnFollowCount", "#band-hover").html(parseInt($("#spnFollowCount", "#band-hover").text()) + 1);
var $btnFollowSelector = $("#btnFollow", "#band-hover");
$btnFollowSelector.unbind("click");
$btnFollowSelector.html("STOP FOLLOWING");
adjustBandFollowingCount(-1);
var $btnFollowSelector = $("#btnFollow", "#band-hover");
$btnFollowSelector.unbind('click');
$btnFollowSelector.attr('onclick', '');
$btnFollowSelector.click(function() {
addBandFollowing(bandId);
});
$btnFollowSelector.html("FOLLOW");
});
}
function adjustBandFollowingCount(value) {
$("#spnFollowCount", "#band-hover").text(parseInt($("#spnFollowCount", "#band-hover").text()) + value);
}
</script>
<script type="text/template" id="template-hover-band">
@ -33,7 +57,6 @@
<h3>{name}</h3>
<small>{location}<br /><strong>{genres}</strong></small><br />
<br clear="all" />
<span id="spnLikeCount">{like_count}</span> <img src="/assets/content/icon_like.png" align="absmiddle" />&nbsp;&nbsp;&nbsp;
<span id="spnFollowCount">{follower_count}</span> <img src="/assets/content/icon_followers.png" width="22" height="12" align="absmiddle" />&nbsp;&nbsp;&nbsp;
{recording_count} <img src="/assets/content/icon_recordings.png" width="12" height="13" align="absmiddle" />&nbsp;&nbsp;&nbsp;
{session_count} <img src="/assets/content/icon_session_tiny.png" width="12" height="12" align="absmiddle" />
@ -47,8 +70,8 @@
<br />
<div align="center">
<div class="left"><a href="{profile_url}" class="button-orange">PROFILE</a></div>
<div class="left"><a class="button-orange">LIKE</a></div>
<div class="left"><a class="button-orange">FOLLOW</a></div>
<div class="left" style="display:none;"><a class="button-orange">LIKE</a></div>
<div class="left"><a id="btnFollow" onclick="{followAction}('{bandId}');" class="button-orange">FOLLOW</a></div>
</div>
<br /><br />
</div>

View File

@ -5,19 +5,58 @@
<script type="text/javascript">
var rest = JK.Rest();
function addFollowing(userId) {
function addFanFollowing(userId) {
rest.addFollowing({user_id: userId})
.done(function(response) {
$("#spnFollowCount", "#fan-hover").html(parseInt($("#spnFollowCount", "#fan-hover").text()) + 1);
var $btnFollowSelector = $("#btnFollow", "#fan-hover");
$btnFollowSelector.unbind("click");
$btnFollowSelector.html("STOP FOLLOWING");
adjustFanFollowingCount(1);
var $btnFollowSelector = $("#btnFollow", "#fan-hover");
$btnFollowSelector.unbind('click');
$btnFollowSelector.attr('onclick', '');
$btnFollowSelector.click(function() {
removeFanFollowing(userId);
});
$btnFollowSelector.html("UNFOLLOW");
});
}
function sendFriendRequest(userId) {
rest.sendFriendRequest(JK.app, userId);
function removeFanFollowing(userId) {
rest.removeFollowing(userId)
.done(function(response) {
adjustFanFollowingCount(-1);
var $btnFollowSelector = $("#btnFollow", "#fan-hover");
$btnFollowSelector.unbind('click');
$btnFollowSelector.attr('onclick', '');
$btnFollowSelector.click(function() {
addFanFollowing(userId);
});
$btnFollowSelector.html("FOLLOW");
});
}
function adjustFanFollowingCount(value) {
$("#spnFollowCount", "#fan-hover").text(parseInt($("#spnFollowCount", "#fan-hover").text()) + value);
}
function sendFanFriendRequest(userId) {
rest.sendFriendRequest(JK.app, userId);
$("#btnFriend", "#fan-hover").hide();
}
function removeFanFriend(userId) {
rest.removeFriend({friend_id: userId})
.done(function() {
var $btnFriendSelector = $("#btnFriend", "#fan-hover");
$btnFriendSelector.unbind("click");
$btnFriendSelector.attr('onclick', '');
$btnFriendSelector.html("CONNECT");
$btnFriendSelector.click(function() {
sendFanFriendRequest(userId);
});
});
}
</script>
<script type="text/template" id="template-hover-fan">
@ -38,8 +77,8 @@
<br />
<div align="center">
<div class="left"><a href="{profile_url}" class="button-orange">PROFILE</a></div>
<div class="left"><a id="btnFriend" onclick="sendFriendRequest('{userId}');" class="button-orange">FRIEND</a></div>
<div class="left"><a id="btnFollow" onclick="addFollowing('{userId}');" class="button-orange">FOLLOW</a></div>
<div class="left"><a id="btnFriend" onclick="{friendAction}('{userId}');" class="button-orange">CONNECT</a></div>
<div class="left"><a id="btnFollow" onclick="{followAction}('{userId}');" class="button-orange">FOLLOW</a></div>
</div>
<br /><br />
</div>

View File

@ -5,28 +5,66 @@
<script type="text/javascript">
var rest = JK.Rest();
function addLike(userId) {
rest.addLike({user_id: userId})
.done(function(response) {
$("#spnLikeCount", "#musician-hover").html(parseInt($("#spnLikeCount", "#musician-hover").text()) + 1);
var $btnLikeSelector = $("#btnLike", "#musician-hover");
$btnLikeSelector.unbind("click");
$btnLikeSelector.html("LIKED");
});
}
// function addLike(userId) {
// rest.addLike({user_id: userId})
// .done(function(response) {
// $("#spnLikeCount", "#musician-hover").text(parseInt($("#spnLikeCount", "#musician-hover").text()) + 1);
// var $btnLikeSelector = $("#btnLike", "#musician-hover");
// $btnLikeSelector.unbind("click");
// $btnLikeSelector.html("LIKED");
// });
// }
function addFollowing(userId) {
function addMusicianFollowing(userId) {
rest.addFollowing({user_id: userId})
.done(function(response) {
$("#spnFollowCount", "#musician-hover").html(parseInt($("#spnFollowCount", "#musician-hover").text()) + 1);
var $btnFollowSelector = $("#btnFollow", "#musician-hover");
$btnFollowSelector.unbind("click");
$btnFollowSelector.html("UNFOLLOW");
adjustMusicianFollowingCount(1);
var $btnFollowSelector = $("#btnFollow", "#musician-hover");
$btnFollowSelector.unbind('click');
$btnFollowSelector.attr('onclick', '');
$btnFollowSelector.click(function() {
removeMusicianFollowing(userId);
});
$btnFollowSelector.html("UNFOLLOW");
});
}
function sendFriendRequest(userId) {
function removeMusicianFollowing(userId) {
rest.removeFollowing(userId)
.done(function(response) {
adjustMusicianFollowingCount(-1);
var $btnFollowSelector = $("#btnFollow", "#musician-hover");
$btnFollowSelector.unbind('click');
$btnFollowSelector.attr('onclick', '');
$btnFollowSelector.click(function() {
addMusicianFollowing(userId);
});
$btnFollowSelector.html("FOLLOW");
});
}
function adjustMusicianFollowingCount(value) {
$("#spnFollowCount", "#musician-hover").html(parseInt($("#spnFollowCount", "#musician-hover").html()) + value);
}
function sendMusicianFriendRequest(userId) {
rest.sendFriendRequest(JK.app, userId);
$("#btnFriend", "#musician-hover").hide();
}
function removeMusicianFriend(userId) {
rest.removeFriend({friend_id: userId})
.done(function() {
var $btnFriendSelector = $("#btnFriend", "#musician-hover");
$btnFriendSelector.unbind("click");
$btnFriendSelector.attr('onclick', '');
$btnFriendSelector.html("CONNECT");
$btnFriendSelector.click(function() {
sendMusicianFriendRequest(userId);
});
});
}
</script>
@ -54,9 +92,9 @@
<br />
<div align="center">
<div class="left"><a href="{profile_url}" class="button-orange">PROFILE</a></div>
<div class="left"><a id="btnLike" onclick="addLike('{userId}');" class="button-orange">LIKE</a></div>
<div class="left"><a id="btnFriend" onclick="sendFriendRequest('{userId}');" class="button-orange">FRIEND</a></div>
<div class="left"><a id="btnFollow" onclick="addFollowing('{userId}');" class="button-orange">FOLLOW</a></div>
<div class="left" style="display:none;"><a id="btnLike" onclick="addLike('{userId}');" class="button-orange">LIKE</a></div>
<div class="left"><a id="btnFriend" onclick="{friendAction}('{userId}');" class="button-orange">CONNECT</a></div>
<div class="left"><a id="btnFollow" onclick="{followAction}('{userId}');" class="button-orange">FOLLOW</a></div>
</div>
<br /><br />
</div>

View File

@ -53,7 +53,7 @@
<div class="w100">
<div class="recording-controls">
<% if !@music_session.music_session.nil? && !@music_session.music_session.mount.blank? %>
<a id="btnPlayPause" class="left mr20" href="#">
<a id="btnPlayPause" class="left mr20">
<%= image_tag "content/icon_playbutton.png", {:id => "imgPlayPause", :width => 20, :height => 20, :alt => ""} %>
</a>
<% end %>

View File

@ -161,7 +161,7 @@ SampleApp::Application.routes.draw do
# user likes
match '/users/:id/likings' => 'api_users#liking_index', :via => :get, :as => 'api_user_liking_index'
match '/users/:id/likings' => 'api_users#liking_create', :via => :post
match '/users/:id/likings' => 'api_users#liking_destroy', :via => :delete
match '/users/:id/likings/:likable_id' => 'api_users#liking_destroy', :via => :delete
# user followers
match '/users/:id/followers' => 'api_users#follower_index', :via => :get, :as => 'api_user_follower_index'
@ -169,7 +169,7 @@ SampleApp::Application.routes.draw do
# user followings
match '/users/:id/followings' => 'api_users#following_index', :via => :get, :as => 'api_user_following_index'
match '/users/:id/followings' => 'api_users#following_create', :via => :post
match '/users/:id/followings' => 'api_users#following_destroy', :via => :delete
match '/users/:id/followings/:followable_id' => 'api_users#following_destroy', :via => :delete
# favorites
match '/users/:id/favorites' => 'api_users#favorite_index', :via => :get, :as => 'api_favorite_index'

View File

@ -56,7 +56,7 @@ describe "User API", :type => :api do
def delete_user_like(authenticated_user, source_user, target_user)
login(authenticated_user.email, authenticated_user.password, 200, true)
delete "/api/users/#{source_user.id}/likings.json", { :target_entity_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json'
delete "/api/users/#{source_user.id}/likings/#{target_user.id}.json", "CONTENT_TYPE" => 'application/json'
return last_response
end
@ -99,7 +99,7 @@ describe "User API", :type => :api do
def delete_user_following(authenticated_user, source_user, target_user)
login(authenticated_user.email, authenticated_user.password, 200, true)
delete "/api/users/#{source_user.id}/followings.json", { :target_entity_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json'
delete "/api/users/#{source_user.id}/followings/#{target_user.id}.json", "CONTENT_TYPE" => 'application/json'
return last_response
end