From a7be00c8f9eb7d9348155f350bddbbe2623b2822 Mon Sep 17 00:00:00 2001 From: Anthony Davis Date: Tue, 7 Jan 2014 16:32:16 -0600 Subject: [PATCH 1/4] VRFS-923 --- web/spec/support/utilities.rb | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/web/spec/support/utilities.rb b/web/spec/support/utilities.rb index f755a6e48..a4578efa4 100644 --- a/web/spec/support/utilities.rb +++ b/web/spec/support/utilities.rb @@ -29,39 +29,18 @@ def cookie_jar Capybara.current_session.driver.browser.current_session.instance_variable_get(:@rack_mock_session).cookie_jar end -#these S3 functions copied from ruby/spec/support/utilities.rb -JAMKAZAM_TESTING_BUCKET = 'jamkazam-testing' # cuz i'm not comfortable using aws_bucket accessor directly - -def app_config - klass = Class.new do - def aws_bucket - JAMKAZAM_TESTING_BUCKET - end - - def aws_access_key_id - 'AKIAJESQY24TOT542UHQ' - end - - def aws_secret_access_key - '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' - end - end - - return klass.new -end +#see also ruby/spec/support/utilities.rb +JAMKAZAM_TESTING_BUCKET = 'jamkazam-testing' #at least, this is the name given in jam-ruby def wipe_s3_test_bucket - test_config = app_config - s3 = AWS::S3.new(:access_key_id => test_config.aws_access_key_id, - :secret_access_key => test_config.aws_secret_access_key) + s3 = AWS::S3.new(:access_key_id => Rails.application.config.aws_access_key_id, + :secret_access_key => Rails.application.config.aws_secret_access_key) test_bucket = s3.buckets[JAMKAZAM_TESTING_BUCKET] - if test_bucket.name == JAMKAZAM_TESTING_BUCKET puts "Web - Pretending to delete all contents of #{test_bucket.name}" #test_bucket.delete_all end end -# --end of S3 methods copied from ruby/spec/support/utilities.rb def sign_in(user) From 473cb69f6d6a438dfad7616463769a20e31e9fc1 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 7 Jan 2014 23:30:23 +0000 Subject: [PATCH 2/4] * VRFS-972 - profile.js changes --- web/app/assets/javascripts/band_setup.js | 57 +- web/app/assets/javascripts/createSession.js | 59 +- web/app/assets/javascripts/fakeJamClient.js | 8 +- web/app/assets/javascripts/friendSelector.js | 44 +- web/app/assets/javascripts/jam_rest.js | 116 +++- web/app/assets/javascripts/profile.js | 524 +++++++++--------- .../stylesheets/client/profile.css.scss | 4 + web/app/views/clients/_band_setup.html.erb | 2 +- web/app/views/clients/_createSession.html.erb | 2 +- web/app/views/clients/_profile.html.erb | 6 +- web/spec/features/bands_spec.rb | 2 - 11 files changed, 467 insertions(+), 357 deletions(-) diff --git a/web/app/assets/javascripts/band_setup.js b/web/app/assets/javascripts/band_setup.js index 5752a35e4..8bb64150e 100644 --- a/web/app/assets/javascripts/band_setup.js +++ b/web/app/assets/javascripts/band_setup.js @@ -62,6 +62,11 @@ $("#band-setup-step-1").show(); $("#band-setup-step-2").hide(); + + $('#band-invitee-input') + .unbind('blur') + .attr("placeholder", "Looking up friends...") + .prop('disabled', true) } function resetGenres() { @@ -290,25 +295,34 @@ // TODO: this is repeated in createSession.js function loadFriends() { - var friends = rest.getFriends({ id: context.JK.currentUserId }); - $.each(friends, function() { - userNames.push(this.name); - userIds.push(this.id); - userPhotoUrls.push(this.photo_url); - }); + rest.getFriends({ id: context.JK.currentUserId }) + .done(function(friends) { + $.each(friends, function() { + userNames.push(this.name); + userIds.push(this.id); + userPhotoUrls.push(this.photo_url); + }); - var autoCompleteOptions = { - lookup: { suggestions: userNames, data: userIds }, - onSelect: addInvitation - }; - if (!autoComplete) { - autoComplete = $('#band-invitee-input').autocomplete(autoCompleteOptions); - } - else { - autoComplete.setOptions(autoCompleteOptions); - } + var autoCompleteOptions = { + lookup: { suggestions: userNames, data: userIds }, + onSelect: addInvitation + }; - $(".autocomplete").width("150px"); + $('#band-invitee-input').attr("placeholder", "Type a friend\'s name").prop('disabled', false); + + if (!autoComplete) { + autoComplete = $('#band-invitee-input').autocomplete(autoCompleteOptions); + } + else { + autoComplete.setOptions(autoCompleteOptions); + } + + $(".autocomplete").width("150px"); + }) + .fail(function() { + $('#band-invitee-input').attr("placeholder", "Unable to lookup friends"); + app.ajaxError(arguments) + }); } function loadGenres(selectedGenres) { @@ -455,14 +469,7 @@ $('#selected-band-invitees').on("click", ".invitation a", removeInvitation); // friend input focus - $('#band-invitee-input').focus(function() { - $(this).val(''); - }); - - // friend input blur - $('#band-invitee-input').blur(function() { - $(this).val('Type a friend\'s name'); - }); + $('#band-invitee-input').focus(function() { $(this).val(''); }); $('#btn-band-setup-cancel').click(function() { resetForm(); diff --git a/web/app/assets/javascripts/createSession.js b/web/app/assets/javascripts/createSession.js index 3856af5d1..6a6f1a9dc 100644 --- a/web/app/assets/javascripts/createSession.js +++ b/web/app/assets/javascripts/createSession.js @@ -28,25 +28,34 @@ function afterShow(data) { friendSelectorDialog.setCallback(friendSelectorCallback); - var friends = rest.getFriends({ id: context.JK.currentUserId }); - $.each(friends, function() { - userNames.push(this.name); - userIds.push(this.id); - userPhotoUrls.push(this.photo_url); - }); + var friends = rest.getFriends({ id: context.JK.currentUserId }) + .done(function(friends) { + $.each(friends, function() { + userNames.push(this.name); + userIds.push(this.id); + userPhotoUrls.push(this.photo_url); + }); - var autoCompleteOptions = { - lookup: { suggestions: userNames, data: userIds }, - onSelect: addInvitation - }; - if (!autoComplete) { - autoComplete = $('#friend-input').autocomplete(autoCompleteOptions); - } - else { - autoComplete.setOptions(autoCompleteOptions); - } + var autoCompleteOptions = { + lookup: { suggestions: userNames, data: userIds }, + onSelect: addInvitation + }; - $(".autocomplete").width("150px"); + $('#friend-input').attr("placeholder", "Type a friend\'s name").prop('disabled', false); + + if (!autoComplete) { + autoComplete = $('#friend-input').autocomplete(autoCompleteOptions); + } + else { + autoComplete.setOptions(autoCompleteOptions); + } + + $(".autocomplete").width("150px"); + }) + .fail(function() { + $('#friend-input').attr("placeholder", "Unable to lookup friends"); + app.ajaxError(arguments); + }); } function friendSelectorCallback(newSelections) { @@ -101,6 +110,11 @@ var fan_chat = sessionSettings.hasOwnProperty('fan_chat') ? sessionSettings.fan_chat : false; $('#fan-chat-option-' + fan_chat).iCheck('check').attr('checked', 'checked'); } + + $('#friend-input') + .unbind('blur') + .attr("placeholder", "Looking up friends...") + .prop('disabled', true) // Should easily be able to grab other items out of sessionSettings and put them into the appropriate ui elements. } @@ -267,6 +281,7 @@ } function events() { + $('#create-session-form').on('submit', submitForm); $('#btn-create-session').on("click", submitForm); $('#selected-friends').on("click", ".invitation a", removeInvitation); $('#musician-access').change(toggleMusicianAccess); @@ -288,15 +303,7 @@ invitationDialog.showFacebookDialog(); }); - // friend input focus - $('#friend-input').focus(function() { - $(this).val(''); - }); - - // friend input blur - $('#friend-input').blur(function() { - $(this).val('Type a friend\'s name'); - }); + $('#friend-input').focus(function() { $(this).val(''); }) } function toggleMusicianAccess() { diff --git a/web/app/assets/javascripts/fakeJamClient.js b/web/app/assets/javascripts/fakeJamClient.js index b79a32516..6adcc1c96 100644 --- a/web/app/assets/javascripts/fakeJamClient.js +++ b/web/app/assets/javascripts/fakeJamClient.js @@ -308,7 +308,9 @@ function SessionStartRecording() {} function SessionStopPlay() {} function SessionStopRecording() {} - + function isSessionTrackPlaying() { return false; } + function SessionCurrrentPlayPosMs() { return 0; } + function SessionGetTracksPlayDurationMs() { return 0; } function SessionGetDeviceLatency() { return 10.0; } function SessionGetMasterLocalMix() { @@ -641,6 +643,10 @@ this.SessionStartRecording = SessionStartRecording; this.SessionStopPlay = SessionStopPlay; this.SessionStopRecording = SessionStopRecording; + this.isSessionTrackPlaying = isSessionTrackPlaying; + this.SessionCurrrentPlayPosMs = SessionCurrrentPlayPosMs; + this.SessionGetTracksPlayDurationMs = SessionGetTracksPlayDurationMs; + this.SetVURefreshRate = SetVURefreshRate; this.SessionGetMasterLocalMix = SessionGetMasterLocalMix; this.SessionSetMasterLocalMix = SessionSetMasterLocalMix; diff --git a/web/app/assets/javascripts/friendSelector.js b/web/app/assets/javascripts/friendSelector.js index a2ac8c721..ce3aac5eb 100644 --- a/web/app/assets/javascripts/friendSelector.js +++ b/web/app/assets/javascripts/friendSelector.js @@ -18,31 +18,33 @@ $('#friend-selector-list').empty(); var template = $('#template-friend-selection').html(); - var friends = rest.getFriends({ id: context.JK.currentUserId }); - $.each(friends, function(index, val) { - var id = val.id; - var isSelected = selectedIds[id]; + var friends = rest.getFriends({ id: context.JK.currentUserId }) + .done(function(friends) { + $.each(friends, function(index, val) { + var id = val.id; + var isSelected = selectedIds[id]; - var html = context.JK.fillTemplate(template, { - userId: id, - css_class: isSelected ? 'selected' : '', - userName: val.name, - avatar_url: context.JK.resolveAvatarUrl(val.photo_url), - status: "", - status_img_url: "", - check_mark_display: isSelected ? "block" : "none", - status_img_display: "none" - }); + var html = context.JK.fillTemplate(template, { + userId: id, + css_class: isSelected ? 'selected' : '', + userName: val.name, + avatar_url: context.JK.resolveAvatarUrl(val.photo_url), + status: "", + status_img_url: "", + check_mark_display: isSelected ? "block" : "none", + status_img_display: "none" + }); - $('#friend-selector-list').append(html); + $('#friend-selector-list').append(html); - // disable row click if it was chosen on parent screen - if (!isSelected) { - $('#friend-selector-list tr[user-id="' + id + '"]').click(function() { - updateSelectionList(id, val.name, $(this), $(this).find('img[user-id="' + id + '"]')); + // disable row click if it was chosen on parent screen + if (!isSelected) { + $('#friend-selector-list tr[user-id="' + id + '"]').click(function() { + updateSelectionList(id, val.name, $(this), $(this).find('img[user-id="' + id + '"]')); + }); + } }); - } - }); + }).fail(app.ajaxError); } function updateSelectionList(id, name, tr, img) { diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index 056c49845..556512a40 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -93,7 +93,7 @@ band_id: bandId, user_id: userId }; - + return $.ajax({ type: "POST", dataType: "json", @@ -313,25 +313,113 @@ } function getFriends(options) { - var friends = []; var id = getId(options); - $.ajax({ + return $.ajax({ type: "GET", - async: false, url: '/api/users/' + id + '/friends', dataType: 'json' - }).done(function(response) { - friends = response; }); - return friends; } + function removeFriend(options) { + var id = getId(options); + var friendId = options["friend_id"]; + + return $.ajax({ + type: "DELETE", + dataType: "json", + url: "/api/users/" + id + "/friends/" + friendId, + processData: false + }); + } + + function addFollowing(options) { + var id = getId(options); + + return $.ajax({ + type: "POST", + dataType: "json", + contentType: 'application/json', + url: "/api/users/" + id + "/followings", + data: JSON.stringify(options), + processData: false + }); + } + + function removeFollowing(options) { + var id = getId(options); + + return $.ajax({ + type: "DELETE", + dataType: "json", + contentType: 'application/json', + url: "/api/users/" + id + "/followings", + data: JSON.stringify(options), + processData: false + }); + } + + function getFollowings(options) { + var userId = getId(options); + + // FOLLOWINGS (USERS) + return $.ajax({ + type: "GET", + dataType: "json", + url: "/api/users/" + userId + "/followings", + processData:false + }); + } + + function getFollowers(options) { + var userId = getId(options); + return $.ajax({ + type: "GET", + dataType: "json", + url: "/api/users/" + userId + "/followers", + processData:false + }); + } + + function getBandFollowings(options) { + var userId = getId(options); + + // FOLLOWINGS (BANDS) + return $.ajax({ + type: "GET", + dataType: "json", + url: "/api/users/" + userId + "/band_followings", + processData:false + }); + } + + function getBandFollowing(options) { + var id = getId(options); + var bandId = options["band_id"]; + return $.ajax({ + type: "GET", + dataType: "json", + url: "/api/users/" + id + "/band_followings/" + bandId, + processData: false + }); + } + + function getBands(options) { + var userId = getId(options); + + return $.ajax({ + type: "GET", + dataType: "json", + url: "/api/users/" + userId + "/bands", + processData:false + }); + } function getMusicianFollowers(userId) { } function getBandFollowers(bandId) { - + } function getClientDownloads(options) { @@ -358,6 +446,10 @@ if(!id) { id = context.JK.currentUserId; } + else { + delete options["id"]; + } + return id; } @@ -604,6 +696,14 @@ this.deleteAvatar = deleteAvatar; this.getFilepickerPolicy = getFilepickerPolicy; this.getFriends = getFriends; + this.removeFriend = removeFriend; + this.addFollowing = addFollowing; + this.removeFollowing = removeFollowing; + this.getFollowings = getFollowings; + this.getFollowers = getFollowers; + this.getBandFollowings = getBandFollowings; + this.getBandFollowing = getBandFollowing; + this.getBands = getBands; this.updateSession = updateSession; this.getSession = getSession; this.getClientDownloads = getClientDownloads; diff --git a/web/app/assets/javascripts/profile.js b/web/app/assets/javascripts/profile.js index 967c51839..e0d281fe6 100644 --- a/web/app/assets/javascripts/profile.js +++ b/web/app/assets/javascripts/profile.js @@ -7,7 +7,10 @@ var logger = context.JK.logger; var userId; var user = null; + var userDefer = null; var rest = context.JK.Rest(); + var decrementedFriendCountOnce = false; + var sentFriendRequest = false; var instrument_logo_map = context.JK.getInstrumentIconMap24(); @@ -25,7 +28,6 @@ function beforeShow(data) { userId = data.id; - user = null; } function afterShow(data) { @@ -47,23 +49,30 @@ } function initUser() { - if (user === null) { - rest.getUserDetail({"id": userId}) - .done(function(response) { - user = response; - events(); - renderActive(); - }) - .fail(app.ajaxError); - } - return user; + user = null; + decrementedFriendCountOnce = false; + sentFriendRequest = false; + userDefer = rest.getUserDetail({id: userId}) + .done(function(response) { + user = response; + configureUserType(); + renderActive(); + }) + .fail(function(jqXHR) { + if(jqXHR.status >= 500) { + fetchUserNetworkOrServerFailure(); + } + else if(jqXHR.status == 404) { + fetchUserGone(); + } + else { + app.ajaxError(arguments); + } + }); } function isMusician() { - if (user) { - return user.musician === true; - } - return false; + return user.musician; } function isCurrentUser() { @@ -77,13 +86,9 @@ $('#profile-instruments').show(); $('#profile-session-stats').show(); $('#profile-recording-stats').show(); - // $('#profile-following-stats').hide(); // $('#profile-favorites-stats').hide(); - - $('#btn-add-friend').show(); $('.profile-social-left').show(); - $('#profile-type-label').text('musician'); $('#profile-location-label').text('Location'); } @@ -93,112 +98,117 @@ $('#profile-instruments').hide(); $('#profile-session-stats').hide(); $('#profile-recording-stats').hide(); - // $('#profile-following-stats').show(); // $('#profile-favorites-stats').show(); - - $('#btn-add-friend').hide(); $('.profile-social-left').hide(); - $('#profile-type-label').text('fan'); $('#profile-location-label').text('Presence'); } if (isCurrentUser()) { $('#btn-profile-edit').show(); + $('#btn-add-friend').hide(); + $('#btn-follow-user').hide(); } else { + configureFriendFollowersControls(); + $('#btn-profile-edit').hide(); + $('#btn-add-friend').show(); + $('#btn-follow-user').show(); } } + function configureFriendFollowersControls() { + // wire up Add Friend click + configureFriendButton(); + + // wire up Follow click + configureFollowingButton(); + } + /****************** MAIN PORTION OF SCREEN *****************/ // events for main screen function events() { - configureUserType(); + // wire up panel clicks -- these need to check deferred because they can't be hidden when in an invalid state + $('#profile-about-link').click(function(){ renderTabDeferred(renderAbout)}); + $('#profile-history-link').click(function(){ renderTabDeferred(renderHistory)}); + $('#profile-bands-link').click(function(){ renderTabDeferred(renderBands)}); + $('#profile-social-link').click(function(){ renderTabDeferred(renderSocial)}); + $('#profile-favorites-link').click(function(){ renderTabDeferred(renderFavorites)}); - // wire up panel clicks - $('#profile-about-link').click(renderAbout); - $('#profile-history-link').click(renderHistory); - $('#profile-bands-link').click(renderBands); - $('#profile-social-link').click(renderSocial); - $('#profile-favorites-link').click(renderFavorites); + // this doesn't need deferred because it's only shown when valid + $('#btn-add-friend').click(handleFriendChange); + $('#btn-follow-user').click(handleFollowingChange); + } - // wire up buttons if you're not viewing your own profile - if (!isCurrentUser()) { - // wire up Add Friend click - configureFriendButton(isFriend()); + function handleFriendChange(evt) { + if(isFriend()) { + removeFriend(evt); + } + else { + sendFriendRequest(evt); + } + } - // wire up Follow click - configureFollowingButton(isFollowing()); + function handleFollowingChange(evt) { + if (isFollowing()) { + removeFollowing(false, userId); } else { - $('#btn-add-friend').hide(); - $('#btn-follow-user').hide(); + addFollowing(); } } function sendFriendRequest(evt) { evt.stopPropagation(); + setFriend(true); // TODO: you aren't a friend yet. just a request to be one really there are 3 states here. + sentFriendRequest = true; context.JK.sendFriendRequest(app, userId, friendRequestCallback); } function removeFriend(evt) { evt.stopPropagation(); - var url = "/api/users/" + context.JK.currentUserId + "/friends/" + userId; - $.ajax({ - type: "DELETE", - dataType: "json", - url: url, - processData: false, - success: function(response) { - renderActive(); // refresh stats - configureFriendButton(false); - }, - error: app.ajaxError - }); + rest.removeFriend({friend_id: userId}) + .done(function() { + updateFriendCount(-1); + setFriend(false); + configureFriendButton(); + }) + .fail(app.ajaxError); } function isFriend() { - return user ? user.is_friend : false; + return user.is_friend; + } + + function setFriend(isFriend) { + user.is_friend = isFriend; } function friendRequestCallback() { - configureFriendButton(true); + configureFriendButton(); } - function configureFriendButton(friend) { - $('#btn-add-friend').unbind("click"); - - if (friend) { + function configureFriendButton() { + if (isFriend()) { $('#btn-add-friend').text('REMOVE FRIEND'); - $('#btn-add-friend').click(removeFriend); } else { $('#btn-add-friend').text('ADD FRIEND'); - $('#btn-add-friend').click(sendFriendRequest); } } function addFollowing() { - var newFollowing = {}; - newFollowing.user_id = userId; - var url = "/api/users/" + context.JK.currentUserId + "/followings"; - $.ajax({ - type: "POST", - dataType: "json", - contentType: 'application/json', - url: url, - data: JSON.stringify(newFollowing), - processData: false, - success: function(response) { - renderActive(); // refresh stats - configureFollowingButton(true); - }, - error: app.ajaxError - }); + rest.addFollowing({user_id: userId}) + .done(function() { + updateFollowingCount(1); + setFollowing(true); + configureFollowingButton(); + }) + .fail(app.ajaxError); } function removeFollowing(isBand, id) { @@ -211,43 +221,36 @@ following.band_id = id; } - var url = "/api/users/" + context.JK.currentUserId + "/followings"; - $.ajax({ - type: "DELETE", - dataType: "json", - contentType: 'application/json', - url: url, - data: JSON.stringify(following), - processData: false, - success: function(response) { - renderActive(); // refresh stats + rest.removeFollowing(following) + .done(function() { if (!isBand) { - configureFollowingButton(false); + updateFollowingCount(-1); + setFollowing(false); + configureFollowingButton(); } else { + updateBandFollowingCount(id, -1); // refresh stats configureBandFollowingButton(false, id); } - }, - error: app.ajaxError - }); + }) + .fail(app.ajaxError); } function isFollowing() { - return user ? user.is_following : false; + return user.is_following; } - function configureFollowingButton(following) { - $('#btn-follow-user').unbind("click"); + function setFollowing(isFollowing) { + user.is_following = isFollowing; + } - if (following) { + function configureFollowingButton() { + + if (isFollowing()) { $('#btn-follow-user').text('STOP FOLLOWING'); - $('#btn-follow-user').click(function() { - removeFollowing(false, userId); - }); } else { $('#btn-follow-user').text('FOLLOW'); - $('#btn-follow-user').click(addFollowing); } } @@ -274,6 +277,17 @@ } } + function renderTabDeferred(tabRenderer) { + userDefer + .done(function() { + tabRenderer(); + }) + .fail(function() { + // try again + initUser(); + }) + } + /****************** ABOUT TAB *****************/ function renderAbout() { $('#profile-instruments').empty(); @@ -293,62 +307,57 @@ function bindAbout() { $('#profile-instruments').empty(); - if (user !== null) { - // name - $('#profile-username').html(user.name); + // name + $('#profile-username').html(user.name); - // avatar - $('#profile-avatar').attr('src', context.JK.resolveAvatarUrl(user.photo_url)); + // avatar + $('#profile-avatar').attr('src', context.JK.resolveAvatarUrl(user.photo_url)); - // instruments - if (user.instruments) { - for (var i=0; i < user.instruments.length; i++) { - var instrument = user.instruments[i]; - var description = instrument.instrument_id; - var proficiency = instrument.proficiency_level; - var instrument_icon_url = context.JK.getInstrumentIcon45(description); + // instruments + if (user.instruments) { + for (var i=0; i < user.instruments.length; i++) { + var instrument = user.instruments[i]; + var description = instrument.instrument_id; + var proficiency = instrument.proficiency_level; + var instrument_icon_url = context.JK.getInstrumentIcon45(description); - // add instrument info to layout - var template = $('#template-profile-instruments').html(); - var instrumentHtml = context.JK.fillTemplate(template, { - instrument_logo_url: instrument_icon_url, - instrument_description: description, - proficiency_level: proficiencyDescriptionMap[proficiency], - proficiency_level_css: proficiencyCssMap[proficiency] - }); + // add instrument info to layout + var template = $('#template-profile-instruments').html(); + var instrumentHtml = context.JK.fillTemplate(template, { + instrument_logo_url: instrument_icon_url, + instrument_description: description, + proficiency_level: proficiencyDescriptionMap[proficiency], + proficiency_level_css: proficiencyCssMap[proficiency] + }); - $('#profile-instruments').append(instrumentHtml); - } + $('#profile-instruments').append(instrumentHtml); } - - // location - $('#profile-location').html(user.location); - - // stats - var text = user.friend_count > 1 || user.friend_count === 0 ? " Friends" : " Friend"; - $('#profile-friend-stats').html(user.friend_count + text); - - text = user.follower_count > 1 || user.follower_count === 0 ? " Followers" : " Follower"; - $('#profile-follower-stats').html(user.follower_count + text); - - if (isMusician()) { - text = user.session_count > 1 || user.session_count === 0 ? " Sessions" : " Session"; - $('#profile-session-stats').html(user.session_count + text); - - text = user.recording_count > 1 || user.recording_count === 0 ? " Recordings" : " Recording"; - $('#profile-recording-stats').html(user.recording_count + text); - } else { - text = " Following"; - $('#profile-following-stats').html(user.following_count + text); - text = user.favorite_count > 1 || user.favorite_count === 0 ? " Favorites" : " Favorite"; - $('#profile-favorite-stats').html(user.favorite_count + text); - } - - $('#profile-biography').html(user.biography); } - else { - logger.debug("No user found with userId = " + userId); + + // location + $('#profile-location').html(user.location); + + // stats + var text = user.friend_count > 1 || user.friend_count === 0 ? " Friends" : " Friend"; + $('#profile-friend-stats').html('' + user.friend_count + '' + text); + + text = user.follower_count > 1 || user.follower_count === 0 ? " Followers" : " Follower"; + $('#profile-follower-stats').html('' + user.follower_count + '' + text); + + if (isMusician()) { + text = user.session_count > 1 || user.session_count === 0 ? " Sessions" : " Session"; + $('#profile-session-stats').html(user.session_count + text); + + text = user.recording_count > 1 || user.recording_count === 0 ? " Recordings" : " Recording"; + $('#profile-recording-stats').html(user.recording_count + text); + } else { + text = " Following"; + $('#profile-following-stats').html(user.following_count + text); + text = user.favorite_count > 1 || user.favorite_count === 0 ? " Favorites" : " Favorite"; + $('#profile-favorite-stats').html(user.favorite_count + text); } + + $('#profile-biography').html(user.biography); } /****************** SOCIAL TAB *****************/ @@ -378,39 +387,25 @@ function bindSocial() { if (isMusician()) { // FRIENDS - var url = "/api/users/" + userId + "/friends"; - $.ajax({ - type: "GET", - dataType: "json", - url: url, - async: false, - processData:false, - success: function(response) { - $.each(response, function(index, val) { - var template = $('#template-profile-social').html(); - var friendHtml = context.JK.fillTemplate(template, { - avatar_url: context.JK.resolveAvatarUrl(val.photo_url), - userName: val.name, - location: val.location, - type: "Friends" - }); + rest.getFriends({id:userId}) + .done(function(response) { + $.each(response, function(index, val) { + var template = $('#template-profile-social').html(); + var friendHtml = context.JK.fillTemplate(template, { + avatar_url: context.JK.resolveAvatarUrl(val.photo_url), + userName: val.name, + location: val.location, + type: "Friends" + }); - $('#profile-social-friends').append(friendHtml); - }); - }, - error: app.ajaxError - }); + $('#profile-social-friends').append(friendHtml); + }); + }) + .fail(app.ajaxError) } - // FOLLOWINGS (USERS) - url = "/api/users/" + userId + "/followings"; - $.ajax({ - type: "GET", - dataType: "json", - url: url, - async: false, - processData:false, - success: function(response) { + rest.getFollowings({id: userId}) + .done(function(response) { $.each(response, function(index, val) { var template = $('#template-profile-social').html(); var followingHtml = context.JK.fillTemplate(template, { @@ -421,19 +416,11 @@ $('#profile-social-followings').append(followingHtml); }); - }, - error: app.ajaxError - }); + }) + .fail(app.ajaxError); - // FOLLOWINGS (BANDS) - url = "/api/users/" + userId + "/band_followings"; - $.ajax({ - type: "GET", - dataType: "json", - url: url, - async: false, - processData:false, - success: function(response) { + rest.getBandFollowings({id: userId}) + .done(function(response) { $.each(response, function(index, val) { var template = $('#template-profile-social').html(); var followingHtml = context.JK.fillTemplate(template, { @@ -444,19 +431,11 @@ $('#profile-social-followings').append(followingHtml); }); - }, - error: app.ajaxError - }); + }) + .fail(app.ajaxError); - // FOLLOWERS - url = "/api/users/" + userId + "/followers"; - $.ajax({ - type: "GET", - dataType: "json", - url: url, - async: false, - processData:false, - success: function(response) { + rest.getFollowers({id: userId}) + .done(function(response) { $.each(response, function(index, val) { var template = $('#template-profile-social').html(); var followerHtml = context.JK.fillTemplate(template, { @@ -467,9 +446,9 @@ $('#profile-social-followers').append(followerHtml); }); - }, - error: app.ajaxError - }); + }) + .fail(app.ajaxError); + } /****************** HISTORY TAB *****************/ @@ -507,34 +486,28 @@ } function bindBands() { - var url = "/api/users/" + userId + "/bands"; - $.ajax({ - type: "GET", - dataType: "json", - url: url, - async: false, - processData:false, - success: function(response) { - if ( (!response || response.length === 0) && isCurrentUser()) { + + rest.getBands({id:userId}) + .done(function(response) { + if ( (!response || response.length === 0) && isCurrentUser()) { var noBandHtml = $('#template-no-bands').html(); - $("#profile-bands").append(noBandHtml); - } + $("#profile-bands").html(noBandHtml); + } + else { + addMoreBandsLink(); - else { - addMoreBandsLink(); - - $.each(response, function(index, val) { + $.each(response, function(index, val) { // build band member HTML var musicianHtml = ''; - if ("musicians" in val) { + if (val.musicians) { for (var i=0; i < val.musicians.length; i++) { var musician = val.musicians[i]; var instrumentLogoHtml = ''; - if ("instruments" in musician) { + if (musician.instruments) { for (var j=0; j < musician.instruments.length; j++) { var instrument = musician.instruments[j]; - var inst = '../assets/content/icon_instrument_default24.png'; + var inst = '/assets/content/icon_instrument_default24.png'; if (instrument.instrument_id in instrument_logo_map) { inst = instrument_logo_map[instrument.instrument_id]; } @@ -545,7 +518,7 @@ var musicianTemplate = $('#template-musician-info').html(); musicianHtml += context.JK.fillTemplate(musicianTemplate, { avatar_url: context.JK.resolveAvatarUrl(musician.photo_url), - profile_url: "/#/profile/" + musician.id, + profile_url: "/client#/profile/" + musician.id, musician_name: musician.name, instruments: instrumentLogoHtml }); @@ -555,7 +528,7 @@ var bandHtml = context.JK.fillTemplate(template, { bandId: val.id, biography: val.biography, - band_url: "/#/bandProfile/" + val.id, + band_url: "/client#/bandProfile/" + val.id, avatar_url: context.JK.resolveBandAvatarUrl(val.logo_url), name: val.name, location: val.location, @@ -569,15 +542,22 @@ $('#profile-bands').append(bandHtml); // wire up Band Follow button click handler - var following = isFollowingBand(val.id); - configureBandFollowingButton(following, val.id); - }); + // XXX; we should return if you are following the band in the rabl, so we don't + // have to hit the server per band shown + rest.getBandFollowing({band_id: val.id}) + .done(function(response) { + var alreadyFollowing = response.id !== undefined; + configureBandFollowingButton(alreadyFollowing, val.id); + }); + }); + + if(response.length >= 3) { + addMoreBandsLink(); + } + } + }) + .fail(app.ajaxError); - addMoreBandsLink(); - } - }, - error: app.ajaxError - }); } function addMoreBandsLink() { @@ -601,53 +581,38 @@ return formattedGenres; } + function updateFriendCount(value) { + if(!decrementedFriendCountOnce && !sentFriendRequest) { + decrementedFriendCountOnce = true; + var friendCount = $('#profile-friend-stats span.friend-count'); + friendCount.text(value + parseInt(friendCount.text())); + } + } + + function updateFollowingCount(value) { + var followingCount = $('#profile-follower-stats span.follower-count'); + followingCount.text(value + parseInt(followingCount.text())); + } + + function updateBandFollowingCount(bandId, value) { + var bandFollowing = $('div[band-id="' + bandId + '"].profile-bands span.follower-count'); + bandFollowing.text(value + parseInt(bandFollowing.text())); + } + function addBandFollowing(evt) { evt.stopPropagation(); var bandId = $(this).parent().parent().attr('band-id'); var newFollowing = {}; newFollowing.band_id = bandId; - logger.debug("Following band " + bandId); - var url = "/api/users/" + context.JK.currentUserId + "/followings"; - $.ajax({ - type: "POST", - dataType: "json", - contentType: 'application/json', - url: url, - data: JSON.stringify(newFollowing), - processData: false, - success: function(response) { + rest.addFollowing(newFollowing) + .done(function(response) { logger.debug("following band " + bandId); - renderBands(); // refresh stats + updateBandFollowingCount(bandId, 1); // increase counter configureBandFollowingButton(true, bandId); - }, - error: app.ajaxError - }); - } - - function isFollowingBand(bandId) { - var alreadyFollowing = false; - - var url = "/api/users/" + context.JK.currentUserId + "/band_followings/" + bandId; - $.ajax({ - type: "GET", - dataType: "json", - url: url, - async: false, - processData: false, - success: function(response) { - if (response.id !== undefined) { - alreadyFollowing = true; - } - else { - alreadyFollowing = false; - } - }, - error: app.ajaxError - }); - - return alreadyFollowing; + }) + .fail(app.ajaxError); } function configureBandFollowingButton(following, bandId) { @@ -656,8 +621,10 @@ if (following) { $btnFollowBand.text('UN-FOLLOW'); - $btnFollowBand.click(function() { + $btnFollowBand.click(function(evt) { removeFollowing(true, bandId); + evt.stopPropagation(); + return false; }); } else { @@ -680,6 +647,23 @@ bindFavorites(); } + + function fetchUserGone() { + app.notify({ + title: "User Deleted", + text: "The user you are looking for is gone", + icon_url: "/assets/content/icon_alert_big.png" + }) + } + + function fetchUserNetworkOrServerFailure() { + app.notify({ + title: "Unable to communicate with server", + text: "Please try again later", + icon_url: "/assets/content/icon_alert_big.png" + }) + } + function bindFavorites() { } @@ -689,6 +673,8 @@ 'afterShow': afterShow }; app.bindScreen('profile', screenBindings); + + events(); } this.initialize = initialize; diff --git a/web/app/assets/stylesheets/client/profile.css.scss b/web/app/assets/stylesheets/client/profile.css.scss index f2ec34e60..5e766429d 100644 --- a/web/app/assets/stylesheets/client/profile.css.scss +++ b/web/app/assets/stylesheets/client/profile.css.scss @@ -254,3 +254,7 @@ padding:3px; vertical-align:middle; } + +#btn-add-friend { + display:none; +} \ No newline at end of file diff --git a/web/app/views/clients/_band_setup.html.erb b/web/app/views/clients/_band_setup.html.erb index 6cc1b644e..2f66f7eb9 100644 --- a/web/app/views/clients/_band_setup.html.erb +++ b/web/app/views/clients/_band_setup.html.erb @@ -80,7 +80,7 @@
- +


If your bandmates are not on JamKazam yet, use any of the options below to invite them to join the service.

diff --git a/web/app/views/clients/_createSession.html.erb b/web/app/views/clients/_createSession.html.erb index 114bcaf86..abacce414 100644 --- a/web/app/views/clients/_createSession.html.erb +++ b/web/app/views/clients/_createSession.html.erb @@ -98,7 +98,7 @@
- +
diff --git a/web/app/views/clients/_profile.html.erb b/web/app/views/clients/_profile.html.erb index 5a276fa1e..1b1ae6e66 100644 --- a/web/app/views/clients/_profile.html.erb +++ b/web/app/views/clients/_profile.html.erb @@ -130,9 +130,9 @@ {location}

{genres}


- {follower_count}   - {recording_count}   - {session_count}  + {follower_count}   + {recording_count}   + {session_count} 

{biography}

diff --git a/web/spec/features/bands_spec.rb b/web/spec/features/bands_spec.rb index 898df6a02..4343af2ba 100644 --- a/web/spec/features/bands_spec.rb +++ b/web/spec/features/bands_spec.rb @@ -21,9 +21,7 @@ describe "Bands", :js => true, :type => :feature, :capybara_feature => true do sign_in_poltergeist(user) wait_until_curtain_gone find('div.homecard.profile').trigger(:click) - wait_for_ajax find('#profile-bands-link').trigger(:click) - wait_for_ajax find('#band-setup-link').trigger(:click) expect(page).to have_selector('#band-setup-title') end From c92dd66f2464a6e2edcd825292cca7a7aede8fcf Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 7 Jan 2014 23:32:08 +0000 Subject: [PATCH 3/4] * moving icecast to bottom --- db/manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/manifest b/db/manifest index 5357d4913..6ab5685bc 100755 --- a/db/manifest +++ b/db/manifest @@ -81,7 +81,7 @@ notification_band_invite.sql band_photo_filepicker.sql bands_geocoding.sql store_s3_filenames.sql -icecast.sql discardable_recorded_tracks.sql music_sessions_have_claimed_recording.sql discardable_recorded_tracks2.sql +icecast.sql From e91dbc13881f3c752bed0024f8bd6453d564fdb6 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Wed, 8 Jan 2014 00:44:56 +0000 Subject: [PATCH 4/4] * removing async:trues in code (because it's default), to make it easier to find async:false --- web/app/assets/javascripts/findBand.js | 1 - web/app/assets/javascripts/findMusician.js | 1 - web/app/assets/javascripts/findSession.js | 1 - 3 files changed, 3 deletions(-) diff --git a/web/app/assets/javascripts/findBand.js b/web/app/assets/javascripts/findBand.js index 2475521d6..9b138d09d 100644 --- a/web/app/assets/javascripts/findBand.js +++ b/web/app/assets/javascripts/findBand.js @@ -18,7 +18,6 @@ $.ajax({ type: "GET", url: "/api/search.json?" + queryString, - async: true, success: afterLoadBands, error: app.ajaxError }); diff --git a/web/app/assets/javascripts/findMusician.js b/web/app/assets/javascripts/findMusician.js index 7363ed50f..16742bafe 100644 --- a/web/app/assets/javascripts/findMusician.js +++ b/web/app/assets/javascripts/findMusician.js @@ -18,7 +18,6 @@ $.ajax({ type: "GET", url: "/api/search.json?" + queryString, - async: true, success: afterLoadMusicians, error: app.ajaxError }); diff --git a/web/app/assets/javascripts/findSession.js b/web/app/assets/javascripts/findSession.js index bc063cc73..9c96cbe80 100644 --- a/web/app/assets/javascripts/findSession.js +++ b/web/app/assets/javascripts/findSession.js @@ -45,7 +45,6 @@ $.ajax({ type: "GET", url: "/api/sessions?" + queryString, - async: true, success: afterLoadSessions, complete: removeSpinner, error: app.ajaxError