* VRFS-900 - guard against 0 tracks
This commit is contained in:
commit
a3289c5d4c
|
|
@ -42,7 +42,7 @@ module ValidationMessages
|
|||
|
||||
#connection
|
||||
|
||||
SELECT_AT_LEAST_ONE = "Please select at least one track"
|
||||
SELECT_AT_LEAST_ONE = "Please select at least one track" # DO NOT CHANGE THIS TEXT MESSAGE UNLESS YOU CHANGE createSession.js.erb, which is looking for it
|
||||
FAN_CAN_NOT_JOIN_AS_MUSICIAN = "A fan can not join a music session as a musician"
|
||||
MUSIC_SESSION_MUST_BE_SPECIFIED = "A music session must be specified"
|
||||
INVITE_REQUIRED = "You must be invited to join this session"
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ module JamRuby
|
|||
private
|
||||
def require_at_least_one_track_when_in_session
|
||||
if tracks.count == 0
|
||||
errors.add(:genres, ValidationMessages::SELECT_AT_LEAST_ONE)
|
||||
errors.add(:tracks, ValidationMessages::SELECT_AT_LEAST_ONE)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ module JamRuby
|
|||
class MusicSession < ActiveRecord::Base
|
||||
self.primary_key = 'id'
|
||||
|
||||
attr_accessor :legal_terms, :skip_genre_validation
|
||||
attr_accessor :legal_terms, :skip_genre_validation, :max_score
|
||||
attr_accessible :creator, :description, :musician_access, :approval_required, :fan_chat, :fan_access, :genres
|
||||
|
||||
belongs_to :creator, :inverse_of => :music_sessions, :class_name => "JamRuby::User", :foreign_key => "user_id"
|
||||
|
|
@ -43,6 +43,15 @@ module JamRuby
|
|||
|
||||
#default_scope :select => "*, 0 as score"
|
||||
|
||||
def attributes
|
||||
super.merge('max_score' => self.max_score)
|
||||
end
|
||||
|
||||
def max_score
|
||||
nil unless has_attribute?(:max_score)
|
||||
read_attribute(:max_score).to_i
|
||||
end
|
||||
|
||||
before_create :create_uuid
|
||||
def create_uuid
|
||||
#self.id = SecureRandom.uuid
|
||||
|
|
@ -197,7 +206,7 @@ module JamRuby
|
|||
locidispid = connection.locidispid
|
||||
|
||||
query = MusicSession
|
||||
.select("music_sessions.*, max(coalesce(scores.score, 99)) as max_score")
|
||||
.select("music_sessions.*, max(coalesce(current_scores.score, 99)) as max_score")
|
||||
.joins(
|
||||
%Q{
|
||||
INNER JOIN
|
||||
|
|
@ -209,11 +218,11 @@ module JamRuby
|
|||
.joins(
|
||||
%Q{
|
||||
LEFT OUTER JOIN
|
||||
scores
|
||||
current_scores
|
||||
ON
|
||||
scores.alocidispid = connections.locidispid
|
||||
current_scores.alocidispid = connections.locidispid
|
||||
AND
|
||||
scores.blocidispid = #{locidispid}
|
||||
current_scores.blocidispid = #{locidispid}
|
||||
}
|
||||
)
|
||||
.joins(
|
||||
|
|
|
|||
|
|
@ -123,6 +123,16 @@
|
|||
return;
|
||||
}
|
||||
|
||||
// if for some reason there are 0 tracks, show FTUE
|
||||
var tracks = context.JK.TrackHelpers.getUserTracks(context.jamClient);
|
||||
if(tracks.length == 0) {
|
||||
logger.error("we should never have 0 tracks and have gotten this far. Launch FTUE is the best we can do right now")
|
||||
// If user hasn't completed FTUE - do so now.
|
||||
app.afterFtue = function() { submitForm(evt); };
|
||||
app.layout.startNewFtue();
|
||||
return;
|
||||
}
|
||||
|
||||
var isValid = validateForm();
|
||||
if (!isValid) {
|
||||
// app.notify({
|
||||
|
|
@ -155,7 +165,7 @@
|
|||
// top instrument in the user's profile.
|
||||
// 2. Otherwise, use the tracks from the last created session.
|
||||
// Defaulting to 1st instrument in profile always at the moment.
|
||||
data.tracks = context.JK.TrackHelpers.getUserTracks(context.jamClient);
|
||||
data.tracks = tracks;
|
||||
|
||||
var jsonData = JSON.stringify(data);
|
||||
|
||||
|
|
@ -186,9 +196,20 @@
|
|||
context.JK.GA.trackSessionMusicians(context.JK.GA.SessionCreationTypes.create);
|
||||
},
|
||||
error: function(jqXHR) {
|
||||
app.notifyServerError(jqXHR, "Unable to Create Session");
|
||||
var handled = false;
|
||||
if(jqXHR.status = 422) {
|
||||
var response = JSON.parse(jqXHR.responseText);
|
||||
if(response["errors"] && response["errors"]["tracks"] && response["errors"]["tracks"][0] == "Please select at least one track") {
|
||||
app.notifyAlert("No Inputs Configured", $('<span>You will need to reconfigure your audio device.</span>'));
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
if(!handled) {
|
||||
app.notifyServerError(jqXHR, "Unable to Create Session");
|
||||
}
|
||||
$('#btn-create-session').removeClass('button-disabled');
|
||||
$('#btn-create-session').unbind('click', false);
|
||||
|
||||
}
|
||||
});
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@
|
|||
if (jqXHR.status == 422) {
|
||||
var errors = JSON.parse(jqXHR.responseText);
|
||||
var $errors = context.JK.format_all_errors(errors);
|
||||
console.log("$errors", $errors)
|
||||
console.log("Unprocessable entity sent from server:", errors)
|
||||
this.notify({title: title, text: $errors, icon_url: "/assets/content/icon_alert_big.png"})
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -740,6 +740,7 @@
|
|||
function setNotificationInfo(message, descriptor) {
|
||||
var $notify = $('[layout="notify"]');
|
||||
$('h2', $notify).text(message.title);
|
||||
$('p', $notify).empty();
|
||||
if (message.text instanceof jQuery) {
|
||||
$('p', $notify).append(message.text)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,10 +36,8 @@
|
|||
* user's profile is used.
|
||||
*/
|
||||
getUserTracks: function(jamClient) {
|
||||
var trackIds = jamClient.SessionGetIDs();
|
||||
var localMusicTracks = [];
|
||||
var i;
|
||||
var instruments = [];
|
||||
|
||||
localMusicTracks = context.JK.TrackHelpers.getTracks(jamClient, 2);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,5 +25,9 @@
|
|||
|
||||
#notification p {
|
||||
margin-bottom:20px;
|
||||
|
||||
.error-text {
|
||||
display:inline-block;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ if !current_user
|
|||
}
|
||||
else
|
||||
|
||||
attributes :id, :description, :musician_access, :approval_required, :fan_access, :fan_chat, :band_id, :user_id, :claimed_recording_initiator_id, :track_changes_counter
|
||||
attributes :id, :description, :musician_access, :approval_required, :fan_access, :fan_chat, :band_id, :user_id, :claimed_recording_initiator_id, :track_changes_counter, :max_score
|
||||
|
||||
node :genres do |item|
|
||||
item.genres.map(&:description)
|
||||
|
|
|
|||
Loading…
Reference in New Issue