VRFS-2498, VRFS-2499 : Validations.
This commit is contained in:
parent
f6111516fd
commit
d0c0c6d01e
|
|
@ -1,2 +1,2 @@
|
|||
ALTER TABLE active_music_sessions ADD COLUMN backing_track_initiator_id BIGINT;
|
||||
ALTER TABLE active_music_sessions ADD COLUMN backing_track_initiator_filename VARCHAR(1024);
|
||||
ALTER TABLE active_music_sessions ADD COLUMN backing_track_id VARCHAR(1024);
|
||||
ALTER TABLE active_music_sessions ADD COLUMN backing_track_initiator_id VARCHAR(64);
|
||||
|
|
|
|||
|
|
@ -82,6 +82,8 @@ module ValidationMessages
|
|||
MUST_BE_KNOWN_TIMEZONE = "not valid"
|
||||
JAM_TRACK_ALREADY_OPEN = 'another jam track already open'
|
||||
RECORDING_ALREADY_IN_PROGRESS = "recording being made"
|
||||
METRONOME_ALREADY_OPEN = 'another metronome already open'
|
||||
BACKING_TRACK_ALREADY_OPEN = 'another audio file already open'
|
||||
|
||||
# notification
|
||||
DIFFERENT_SOURCE_TARGET = 'can\'t be same as the sender'
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ module JamRuby
|
|||
|
||||
self.table_name = 'active_music_sessions'
|
||||
|
||||
attr_accessor :legal_terms, :max_score, :opening_jam_track, :opening_recording
|
||||
attr_accessor :legal_terms, :max_score, :opening_jam_track, :opening_recording, :opening_backing_track, :opening_metronome
|
||||
|
||||
belongs_to :claimed_recording, :class_name => "JamRuby::ClaimedRecording", :foreign_key => "claimed_recording_id", :inverse_of => :playing_sessions
|
||||
belongs_to :claimed_recording_initiator, :class_name => "JamRuby::User", :inverse_of => :playing_claimed_recordings, :foreign_key => "claimed_recording_initiator_id"
|
||||
|
|
@ -15,6 +15,9 @@ module JamRuby
|
|||
belongs_to :jam_track, :class_name => "JamRuby::JamTrack", :foreign_key => "jam_track_id", :inverse_of => :playing_sessions
|
||||
belongs_to :jam_track_initiator, :class_name => "JamRuby::User", :inverse_of => :playing_jam_tracks, :foreign_key => "jam_track_initiator_id"
|
||||
|
||||
belongs_to :backing_track_initiator, :class_name => "JamRuby::User", :inverse_of => :playing_jam_tracks, :foreign_key => "backing_track_initiator_id"
|
||||
belongs_to :metronome_initiator, :class_name => "JamRuby::User", :inverse_of => :playing_jam_tracks, :foreign_key => "metronome_initiator_id"
|
||||
|
||||
has_one :music_session, :class_name => "JamRuby::MusicSession", :foreign_key => 'music_session_id'
|
||||
has_one :mount, :class_name => "JamRuby::IcecastMount", :inverse_of => :music_session, :foreign_key => 'music_session_id'
|
||||
belongs_to :creator, :class_name => 'JamRuby::User', :foreign_key => :user_id
|
||||
|
|
@ -27,6 +30,8 @@ module JamRuby
|
|||
validate :creator_is_musician
|
||||
validate :validate_opening_recording, :if => :opening_recording
|
||||
validate :validate_opening_jam_track, :if => :opening_jam_track
|
||||
validate :validate_opening_backing_track, :if => :opening_backing_track
|
||||
validate :validate_opening_metronome, :if => :opening_metronome
|
||||
|
||||
after_create :started_session
|
||||
|
||||
|
|
@ -73,22 +78,52 @@ module JamRuby
|
|||
if is_jam_track_open?
|
||||
errors.add(:claimed_recording, ValidationMessages::JAM_TRACK_ALREADY_OPEN)
|
||||
end
|
||||
|
||||
if is_backing_track_open?
|
||||
errors.add(:claimed_recording, ValidationMessages::BACKING_TRACK_ALREADY_OPEN)
|
||||
end
|
||||
|
||||
if is_metronome_open?
|
||||
errors.add(:claimed_recording, ValidationMessages::METRONOME_ALREADY_OPEN)
|
||||
end
|
||||
end
|
||||
|
||||
def validate_opening_jam_track
|
||||
validate_other_audio(:jam_track)
|
||||
end
|
||||
|
||||
def validate_opening_backing_track
|
||||
validate_other_audio(:backing_track)
|
||||
end
|
||||
|
||||
def validate_opening_metronome
|
||||
validate_other_audio(:metronome)
|
||||
end
|
||||
|
||||
def validate_other_audio(error_key)
|
||||
# validate that there is no metronome already open in this session
|
||||
unless metronome_id_was.nil?
|
||||
errors.add(error_key, ValidationMessages::METRONOME_ALREADY_OPEN)
|
||||
end
|
||||
|
||||
# validate that there is no backing track already open in this session
|
||||
unless backing_track_id_was.nil?
|
||||
errors.add(error_key, ValidationMessages::BACKING_TRACK_ALREADY_OPEN)
|
||||
end
|
||||
|
||||
# validate that there is no jam track already open in this session
|
||||
unless jam_track_id_was.nil?
|
||||
errors.add(:jam_track, ValidationMessages::JAM_TRACK_ALREADY_OPEN)
|
||||
errors.add(error_key, ValidationMessages::JAM_TRACK_ALREADY_OPEN)
|
||||
end
|
||||
|
||||
# validate that there is no recording being made
|
||||
if is_recording?
|
||||
errors.add(:jam_track, ValidationMessages::RECORDING_ALREADY_IN_PROGRESS)
|
||||
errors.add(error_key, ValidationMessages::RECORDING_ALREADY_IN_PROGRESS)
|
||||
end
|
||||
|
||||
# validate that there is no recording being played back to the session
|
||||
if is_playing_recording?
|
||||
errors.add(:jam_track, ValidationMessages::CLAIMED_RECORDING_ALREADY_IN_PROGRESS)
|
||||
errors.add(error_key, ValidationMessages::CLAIMED_RECORDING_ALREADY_IN_PROGRESS)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -593,6 +628,14 @@ module JamRuby
|
|||
!self.jam_track.nil?
|
||||
end
|
||||
|
||||
def is_backing_track_open?
|
||||
self.backing_track_id.present?
|
||||
end
|
||||
|
||||
def is_metronome_open?
|
||||
self.metronome_id.present?
|
||||
end
|
||||
|
||||
# is this music session currently recording?
|
||||
def is_recording?
|
||||
recordings.where(:duration => nil).count > 0
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@
|
|||
<% if Rails.application.config.jam_tracks_available %>
|
||||
<li><a href="#" id="open-a-jamtrack">JamTrack</a></li>
|
||||
<% end %>
|
||||
<li><a href="#" id="open-backing-track">Audio File</a></li>
|
||||
<li><a href="#" id="open-backing-track">Audio File</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<br clear="all" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue