From d60eff50ba2692a4e9c34b02c2103247e970a180 Mon Sep 17 00:00:00 2001 From: Steven Miers Date: Tue, 2 Jun 2015 15:13:41 -0500 Subject: [PATCH] VRFS-3246 : Support online presences and performance samples through sub-widget. Incremental. --- ruby/lib/jam_ruby/models/band.rb | 26 +++++- .../javascripts/accounts_profile_samples.js | 87 ++++++++++++------- web/app/assets/javascripts/band_setup.js | 82 ++++++++++------- web/app/controllers/api_bands_controller.rb | 2 + web/app/views/clients/index.html.erb | 6 +- 5 files changed, 139 insertions(+), 64 deletions(-) diff --git a/ruby/lib/jam_ruby/models/band.rb b/ruby/lib/jam_ruby/models/band.rb index a0c3a5033..6d6c6f96e 100644 --- a/ruby/lib/jam_ruby/models/band.rb +++ b/ruby/lib/jam_ruby/models/band.rb @@ -179,7 +179,7 @@ module JamRuby band = id.blank? ? Band.new : Band.find(id) # ensure user updating Band details is a Band member - unless band.new_record? || band.users.exists?(user) + unless band.new_record? || band.users.exists?(user) raise JamPermissionError, ValidationMessages::USER_NOT_BAND_MEMBER_VALIDATION_ERROR end @@ -200,12 +200,34 @@ module JamRuby end band.skip_genre_validation = true unless params[:validate_genres] - puts "SKIPPING GENRE VALIDATION: #{band.skip_genre_validation}" + + unless band.new_record? + OnlinePresence.delete_all(["player_id = ?", band.id]) + PerformanceSample.delete_all(["player_id = ?", band.id]) + end + + online_presences = params[:online_presences] + Rails.logger.info("ONLINE_PRESENCE: #{online_presences.inspect} / #{params.inspect}") + if online_presences.present? + online_presences.each do |op| + new_presence = OnlinePresence.create(band, op, false) + band.online_presences << new_presence + end + end + + performance_samples = params[:performance_samples] + if performance_samples.present? + performance_samples.each do |ps| + band.performance_samples << PerformanceSample.create(band, ps, false) + end + end + band end # helper method for creating / updating a Band def self.save(user, params) + puts "Band.save with #{user}, #{params}" band = build_band(user, params) if band.save diff --git a/web/app/assets/javascripts/accounts_profile_samples.js b/web/app/assets/javascripts/accounts_profile_samples.js index 88084449e..aebe9b51e 100644 --- a/web/app/assets/javascripts/accounts_profile_samples.js +++ b/web/app/assets/javascripts/accounts_profile_samples.js @@ -3,7 +3,10 @@ "use strict"; context.JK = context.JK || {}; - context.JK.AccountProfileSamples = function(app, parent) { + + // TODO: Add a target type, which can be band or user -- call the + // appropriate API methods. + context.JK.AccountProfileSamples = function(app, parent, loadFn, updateFn) { var $document = $(document); // used to initialize RecordingSourceValidator in site_validator.js.coffee @@ -17,11 +20,9 @@ var ui = new context.JK.UIHelper(JK.app); var target = {}; var profileUtils = context.JK.ProfileUtils; - - var $screen = $('.account-profile-samples', parent); - + var $screen = $('.profile-online-sample-controls', parent); // online presences - var $website = $screen.find('#website'); + var $website = $screen.find('#website'); var $soundCloudUsername = $screen.find('#soundcloud-username'); var $reverbNationUsername = $screen.find('#reverbnation-username'); var $bandCampUsername = $screen.find('#bandcamp-username'); @@ -44,71 +45,78 @@ function beforeShow(data) { } - function afterShow(data) { - $.when(api.getUserProfile()) - .done(function(userDetail) { - renderPresence(userDetail); - renderSamples(userDetail); + function afterShow(data) { + //$.when(api.getUserProfile()) + $.when(loadFn()) + .done(function(targetPlayer) { + if (targetPlayer && targetPlayer.keys && targetPlayer.keys.length > 0) { + renderPlayer(targetPlayer) + } }); } - function renderPresence(user) { - $website.val(user.website); + function renderPlayer(targetPlayer) { + renderPresence(targetPlayer); + renderSamples(targetPlayer); + } + + function renderPresence(targetPlayer) { + $website.val(targetPlayer.website); // SoundCloud - var presences = profileUtils.soundCloudPresences(user.online_presences); + var presences = profileUtils.soundCloudPresences(targetPlayer.online_presences); if (presences && presences.length > 0) { $soundCloudUsername.val(presences[0].username); } // ReverbNation - presences = profileUtils.reverbNationPresences(user.online_presences); + presences = profileUtils.reverbNationPresences(targetPlayer.online_presences); if (presences && presences.length > 0) { $reverbNationUsername.val(presences[0].username); } // Bandcamp - presences = profileUtils.bandCampPresences(user.online_presences); + presences = profileUtils.bandCampPresences(targetPlayer.online_presences); if (presences && presences.length > 0) { $bandCampUsername.val(presences[0].username); } // Fandalism - presences = profileUtils.fandalismPresences(user.online_presences); + presences = profileUtils.fandalismPresences(targetPlayer.online_presences); if (presences && presences.length > 0) { $fandalismUsername.val(presences[0].username); } // YouTube - presences = profileUtils.youTubePresences(user.online_presences); + presences = profileUtils.youTubePresences(targetPlayer.online_presences); if (presences && presences.length > 0) { $youTubeUsername.val(presences[0].username); } // Facebook - presences = profileUtils.facebookPresences(user.online_presences); + presences = profileUtils.facebookPresences(targetPlayer.online_presences); if (presences && presences.length > 0) { $facebookUsername.val(presences[0].username); } // Twitter - presences = profileUtils.twitterPresences(user.online_presences); + presences = profileUtils.twitterPresences(targetPlayer.online_presences); if (presences && presences.length > 0) { $twitterUsername.val(presences[0].username); } } - function renderSamples(user) { + function renderSamples(targetPlayer) { // JamKazam recordings - var samples = profileUtils.jamkazamSamples(user.performance_samples); + var samples = profileUtils.jamkazamSamples(targetPlayer.performance_samples); loadSamples(samples, 'jamkazam', $jamkazamSampleList, window.jamkazamRecordingSources); // SoundCloud recordings - samples = profileUtils.soundCloudSamples(user.performance_samples); + samples = profileUtils.soundCloudSamples(targetPlayer.performance_samples); loadSamples(samples, 'soundcloud', $soundCloudSampleList, window.soundCloudRecordingSources); // YouTube videos - samples = profileUtils.youTubeSamples(user.performance_samples); + samples = profileUtils.youTubeSamples(targetPlayer.performance_samples); loadSamples(samples, 'youtube', $youTubeSampleList, window.youTubeRecordingSources); } @@ -269,9 +277,22 @@ function handleUpdateProfile() { disableSubmits() + + var player = buildPlayer() + updateFn({ + website: player.website, + online_presences: player.online_presences, + performance_samples: player.performance_samples + }) + .done(postUpdateProfileSuccess) + .fail(postUpdateProfileFailure) + .always(enableSubmits); + } + + function buildPlayer() { // extract online presences var op = []; - var presenceTypes = profileUtils.ONLINE_PRESENCE_TYPES; + var presenceTypes = profileUtils.ONLINE_PRESENCE_TYPES; addOnlinePresence(op, $soundCloudUsername.val(), presenceTypes.SOUNDCLOUD.description); addOnlinePresence(op, $reverbNationUsername.val(), presenceTypes.REVERBNATION.description); addOnlinePresence(op, $bandCampUsername.val(), presenceTypes.BANDCAMP.description); @@ -286,15 +307,12 @@ addPerformanceSamples(ps, $jamkazamSampleList, performanceSampleTypes.JAMKAZAM.description); addPerformanceSamples(ps, $soundCloudSampleList, performanceSampleTypes.SOUNDCLOUD.description); addPerformanceSamples(ps, $youTubeSampleList, performanceSampleTypes.YOUTUBE.description); - - api.updateUser({ + + return { website: $website.val(), online_presences: op, performance_samples: ps - }) - .done(postUpdateProfileSuccess) - .fail(postUpdateProfileFailure) - .always(enableSubmits); + } } function postUpdateProfileSuccess(response) { @@ -336,7 +354,7 @@ var initialized = false; $(document).on('JAMKAZAM_READY', function(e, data) { window.JK.JamServer.get$Server().on(window.JK.EVENTS.CONNECTION_UP, function() { - if(initialized) { + if(initialized) { return; } initialized = true; @@ -439,6 +457,10 @@ } // end initializeValidators. + function resetForm() { + $("input", $screen).val("") + } + function initialize() { var screenBindings = { 'beforeShow': beforeShow, @@ -453,6 +475,9 @@ this.initialize = initialize; this.beforeShow = beforeShow; this.afterShow = afterShow; + this.buildPlayer = buildPlayer; + this.renderPlayer = renderPlayer + this.resetForm = resetForm; return this; }; })(window,jQuery); \ No newline at end of file diff --git a/web/app/assets/javascripts/band_setup.js b/web/app/assets/javascripts/band_setup.js index 9c87aca44..5e0e71222 100644 --- a/web/app/assets/javascripts/band_setup.js +++ b/web/app/assets/javascripts/band_setup.js @@ -10,32 +10,39 @@ context.JK.BandSetupScreen = function (app) { var NONE_SPECIFIED = 'None specified' - var GENRE_STEP = 1 + var GENRE_STEP = 1 + var SAMPLE_STEP = 3 + var STEPS_COUNT = 5 + var currentStep = 0 var ui = new context.JK.UIHelper(JK.app) - var logger = context.JK.logger; - var profileUtils = context.JK.ProfileUtils; - var rest = context.JK.Rest(); - var inviteMusiciansUtil = null; - var invitationDialog = null; - var autoComplete = null; - var userNames = []; - var userIds = []; - var userPhotoUrls = []; - var selectedFriendIds = {}; - var nilOptionStr = ''; - var nilOptionText = 'n/a'; - var bandId = ''; - var friendInput=null; - var bandType=null; - var bandStatus=null; - var concertCount=null; - var currentStep = 0; - var STEPS_COUNT=5; + var logger = context.JK.logger + var profileUtils = context.JK.ProfileUtils + var rest = context.JK.Rest() + var inviteMusiciansUtil = null + var invitationDialog = null + var autoComplete = null + var userNames = [] + var userIds = [] + var userPhotoUrls = [] + var selectedFriendIds = {} + var nilOptionStr = '' + var nilOptionText = 'n/a' + var bandId = '' + var friendInput=null + var bandType=null + var bandStatus=null + var concertCount=null + + var $screen=$("#band-setup") var $samples = $screen.find(".account-profile-samples") var $selectedInstruments=[] - var accountProfileSamples = null; - + + console.log("------------------------------------------") + var accountProfileSamples = new JK.AccountProfileSamples(app, $screen, loadBandCallback, rest.updateBand) + accountProfileSamples.initialize() + console.log("==========================================") + function navBack() { if (currentStep>0) { saveBand(function() { @@ -46,7 +53,7 @@ } function navCancel() { - resetForm() + resetForm() window.history.go(-1) return false } @@ -72,6 +79,9 @@ $("#btn-band-setup-back").addClass("hidden") $("#btn-band-setup-next").removeClass("hidden").html("SAVE & NEXT") } else if(currentStepIf your bandmates are already on JamKazam, start typing their names in the box below, or click the Choose Friends button to select them.") invitationDialog = invitationDialogInstance events() diff --git a/web/app/controllers/api_bands_controller.rb b/web/app/controllers/api_bands_controller.rb index 8b0c83ccd..879cb09f2 100644 --- a/web/app/controllers/api_bands_controller.rb +++ b/web/app/controllers/api_bands_controller.rb @@ -250,6 +250,7 @@ class ApiBandsController < ApiController def auth_band_member @band = Band.find(params[:id]) unless @band.users.exists? current_user + Rails.logger.info("Could not find #{current_user} in #{@band.users.inspect}") raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR end end @@ -257,6 +258,7 @@ class ApiBandsController < ApiController uid = current_user.id @band = Band.find(params[:id]) unless @band.band_musicians.detect { |bm| bm.user_id == uid && bm.admin? } + Rails.logger.info("Could not find #{current_user} in #{@band.band_musicians.inspect}") raise JamPermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR end end diff --git a/web/app/views/clients/index.html.erb b/web/app/views/clients/index.html.erb index 5e05e88d6..128a693d1 100644 --- a/web/app/views/clients/index.html.erb +++ b/web/app/views/clients/index.html.erb @@ -110,6 +110,8 @@ }; } + var api = JK.Rest() + <% if current_user %> JK.currentUserId = '<%= current_user.id %>'; JK.currentUserAvatarUrl = JK.resolveAvatarUrl('<%= current_user.photo_url %>'); @@ -165,7 +167,7 @@ var openBackingTrackDialog = new JK.OpenBackingTrackDialog(JK.app); openBackingTrackDialog.initialize(); - var configureTracksDialog = new JK.ConfigureTracksDialog(JK.app); + var configureTracksDialog = new JK.ConfigureTracksDialog(JK.app, null, api.getUserProfile, api.updateUser) configureTracksDialog.initialize(); var networkTestDialog = new JK.NetworkTestDialog(JK.app); @@ -230,7 +232,7 @@ var accountProfileInterests = new JK.AccountProfileInterests(JK.app); accountProfileInterests.initialize(); - var accountProfileSamples = new JK.AccountProfileSamples(JK.app); + var accountProfileSamples = new JK.AccountProfileSamples(JK.app, null) accountProfileSamples.initialize(); var accountAudioProfile = new JK.AccountAudioProfile(JK.app);