VRFS-3246 : Support online presences and performance samples through sub-widget. Incremental.

This commit is contained in:
Steven Miers 2015-06-02 15:13:41 -05:00
parent bd8287b528
commit d60eff50ba
5 changed files with 139 additions and 64 deletions

View File

@ -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

View File

@ -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);

View File

@ -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 = '<option value=""></option>';
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 = '<option value=""></option>'
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(currentStep<STEPS_COUNT-1) {
// if(currentStep==SAMPLE_STEP) {
// accountProfileSamples.renderPlayer(band)
// }
$("#btn-band-setup-back").removeClass("hidden")
$("#btn-band-setup-next").removeClass("hidden").html("SAVE & NEXT")
} else {
@ -113,6 +123,7 @@
function resetForm() {
removeErrors();
accountProfileSamples.resetForm()
// name
$("#band-name").val('');
@ -260,15 +271,25 @@
}
}
function saveBand(saveFn) {
function saveBand(saveBandSuccessFn) {
unbindNavButtons()
var band = buildBand()
// Collect and store data from this sub-widget:
var performanceSampleData = accountProfileSamples.buildPlayer()
band.website=performanceSampleData.website
band.online_presences=performanceSampleData.online_presences
band.performance_samples=performanceSampleData.performance_samples
var saveBandFn = (isNewBand()) ? rest.createBand : rest.updateBand
saveBandFn(band)
.done(function (response) {
console.log("RESPONSESSSSS", response)
bandId = response.id
saveInvitations()
saveFn(band)
if(saveBandSuccessFn) {
saveBandSuccessFn(band)
}
})
.fail(function (jqXHR) {
if(jqXHR.status == 422) {
@ -317,7 +338,7 @@
currentStep=stepNum
delete data['d'];
}
}
}
resetForm();
}
@ -410,6 +431,8 @@
renderDesiredExperienceLabel($selectedInstruments)
accountProfileSamples.renderPlayer(band)
});
}
@ -654,13 +677,14 @@
return false
}
function loadBandCallback() {
return (isNewBand()) ? {} : rest.getBand(bandId)
}
function initialize(invitationDialogInstance, friendSelectorDialog) {
inviteMusiciansUtil = new JK.InviteMusiciansUtil(app)
inviteMusiciansUtil.initialize(friendSelectorDialog)
accountProfileSamples = new JK.AccountProfileSamples(JK.app, $screen)
accountProfileSamples.initialize()
friendInput = inviteMusiciansUtil.inviteBandCreate('#band-setup-invite-musicians', "<div class='left w70'>If your bandmates are already on JamKazam, start typing their names in the box below, or click the Choose Friends button to select them.</div>")
invitationDialog = invitationDialogInstance
events()

View File

@ -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

View File

@ -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);