Merge and fix
This commit is contained in:
parent
3f994e3993
commit
4f08f6acad
|
|
@ -59,7 +59,7 @@ module JamRuby
|
|||
# has_many :plays, :class_name => "JamRuby::PlayablePlay", :foreign_key => :jam_track_id, :dependent => :destroy
|
||||
# VRFS-2916 jam_tracks.id is varchar: ADD
|
||||
has_many :plays, :class_name => "JamRuby::PlayablePlay", :as => :playable, :dependent => :destroy
|
||||
|
||||
|
||||
accepts_nested_attributes_for :jam_track_tracks, allow_destroy: true
|
||||
accepts_nested_attributes_for :jam_track_tap_ins, allow_destroy: true
|
||||
|
||||
|
|
@ -102,7 +102,15 @@ module JamRuby
|
|||
page = options[:page].to_i
|
||||
per_page = options[:per_page].to_i
|
||||
|
||||
|
||||
if per_page == 0
|
||||
# try and see if limit was specified
|
||||
limit = options[:limit]
|
||||
limit ||= 20
|
||||
limit = limit.to_i
|
||||
else
|
||||
limit = per_page
|
||||
end
|
||||
|
||||
start = (page -1 )* per_page
|
||||
limit = per_page
|
||||
else
|
||||
|
|
|
|||
|
|
@ -739,7 +739,7 @@
|
|||
}
|
||||
|
||||
function SessionOpenMetronome(bpm, click, meter, mode){
|
||||
console.log("Setting metronome BPM: ", bpm)
|
||||
logger.debug("Setting metronome BPM: ", bpm)
|
||||
metronomeActive =true
|
||||
metronomeBPM = bpm
|
||||
metronomeSound = click
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
};
|
||||
|
||||
context.JK.AVAILABILITY_US = "United States";
|
||||
context.JK.MASTER_TRACK = "Master";
|
||||
|
||||
context.JK.EVENTS = {
|
||||
DIALOG_CLOSED : 'dialog_closed',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,242 @@
|
|||
$ = jQuery
|
||||
context = window
|
||||
context.JK ||= {}
|
||||
|
||||
context.JK.JamTrackScreen=class JamTrackScreen
|
||||
LIMIT = 10
|
||||
instrument_logo_map = context.JK.getInstrumentIconMap24()
|
||||
|
||||
constructor: (@app) ->
|
||||
@logger = context.JK.logger
|
||||
@screen = null
|
||||
@content = null
|
||||
@scroller = null
|
||||
@genre = null
|
||||
@artist = null
|
||||
@instrument = null
|
||||
@availability = null
|
||||
@nextPager = null
|
||||
@noMoreJamtracks = null
|
||||
@currentPage = 0
|
||||
@next = null
|
||||
@currentQuery = this.defaultQuery()
|
||||
@expanded = false
|
||||
|
||||
beforeShow:(data) =>
|
||||
this.setFilterFromURL()
|
||||
this.refresh()
|
||||
|
||||
afterShow:(data) =>
|
||||
|
||||
events:() =>
|
||||
@genre.on 'change', this.search
|
||||
@artist.on 'change', this.search
|
||||
@instrument.on 'change', this.search
|
||||
@availability.on 'change', this.search
|
||||
|
||||
clearResults:() =>
|
||||
@currentPage = 0
|
||||
@content.empty()
|
||||
@noMoreJamtracks.hide()
|
||||
@next = null
|
||||
|
||||
setFilterFromURL:() =>
|
||||
# Grab parms from URL for artist, instrument, and availability
|
||||
parms=this.getParams()
|
||||
|
||||
if(parms.artist?)
|
||||
@artist.val(parms.artist)
|
||||
if(parms.instrument?)
|
||||
@instrument.val(parms.instrument)
|
||||
if(parms.availability?)
|
||||
@availability.val(parms.availability)
|
||||
window.history.replaceState({}, "", "/client#/jamtrack")
|
||||
|
||||
getParams:() =>
|
||||
params = {}
|
||||
q = window.location.href.split("?")[1]
|
||||
if q?
|
||||
q = q.split('#')[0]
|
||||
raw_vars = q.split("&")
|
||||
for v in raw_vars
|
||||
[key, val] = v.split("=")
|
||||
params[key] = decodeURIComponent(val)
|
||||
ms
|
||||
params
|
||||
|
||||
refresh:() =>
|
||||
@currentQuery = this.buildQuery()
|
||||
that = this
|
||||
rest.getJamtracks(@currentQuery).done((response) ->
|
||||
that.clearResults()
|
||||
that.handleJamtrackResponse(response)
|
||||
).fail (jqXHR) ->
|
||||
that.clearResults()
|
||||
that.noMoreJamtracks.show()
|
||||
that.app.notifyServerError jqXHR, 'Jamtrack Unavailable'
|
||||
|
||||
search:() =>
|
||||
this.refresh()
|
||||
false
|
||||
|
||||
defaultQuery:() =>
|
||||
query =
|
||||
per_page: LIMIT
|
||||
page: @currentPage+1
|
||||
if @next
|
||||
query.since = @next
|
||||
query
|
||||
|
||||
buildQuery:() =>
|
||||
@currentQuery = this.defaultQuery()
|
||||
# genre filter
|
||||
# var genres = @screen.find('#jamtrack_genre').val()
|
||||
# if (genres !== undefined) {
|
||||
# @currentQuery.genre = genres
|
||||
# }
|
||||
# instrument filter
|
||||
|
||||
instrument = @instrument.val()
|
||||
if instrument?
|
||||
@currentQuery.instrument = instrument
|
||||
|
||||
# artist filter
|
||||
art = @artist.val()
|
||||
if art?
|
||||
@currentQuery.artist = art
|
||||
|
||||
# availability filter
|
||||
availability = @availability.val()
|
||||
if availability?
|
||||
@currentQuery.availability = availability
|
||||
@currentQuery
|
||||
|
||||
handleJamtrackResponse:(response) =>
|
||||
@next = response.next
|
||||
this.renderJamtracks(response)
|
||||
if response.next == null
|
||||
# if we less results than asked for, end searching
|
||||
@scroller.infinitescroll 'pause'
|
||||
if @currentPage == 0 and response.jamtracks.length == 0
|
||||
@content.append '<div class=\'no-jamtracks-msg\'>There\'s no jamtracks.</div>'
|
||||
if @currentPage > 0
|
||||
@noMoreJamtracks.show()
|
||||
# there are bugs with infinitescroll not removing the 'loading'.
|
||||
# it's most noticeable at the end of the list, so whack all such entries
|
||||
$('.infinite-scroll-loader').remove()
|
||||
else
|
||||
@currentPage++
|
||||
this.buildQuery()
|
||||
this.registerInfiniteScroll()
|
||||
|
||||
|
||||
registerInfiniteScroll:() =>
|
||||
@scroller.infinitescroll {
|
||||
behavior: 'local'
|
||||
navSelector: '#jamtrackScreen .btn-next-pager'
|
||||
nextSelector: '#jamtrackScreen .btn-next-pager'
|
||||
binder: @scroller
|
||||
dataType: 'json'
|
||||
appendCallback: false
|
||||
prefill: false
|
||||
bufferPx: 100
|
||||
loading:
|
||||
msg: $('<div class="infinite-scroll-loader">Loading ...</div>')
|
||||
img: '/assets/shared/spinner.gif'
|
||||
path: (page) ->
|
||||
'/api/jamtracks?' + $.param(this.buildQuery())
|
||||
|
||||
}, (json, opts) ->
|
||||
this.handleJamtrackResponse(json)
|
||||
@scroller.infinitescroll 'resume'
|
||||
|
||||
playJamtrack:(e) =>
|
||||
e.preventDefault()
|
||||
|
||||
addToCartJamtrack:(e) =>
|
||||
e.preventDefault()
|
||||
params = id: $(e.target).attr('data-jamtrack-id')
|
||||
rest.addJamtrackToShoppingCart(params).done((response) ->
|
||||
context.location = '/client#/shoppingCart'
|
||||
).fail @app.ajaxError
|
||||
|
||||
licenseUSWhy:(e) =>
|
||||
e.preventDefault()
|
||||
@app.layout.showDialog 'jamtrack-availability-dialog'
|
||||
|
||||
registerEvents:() =>
|
||||
@screen.find('.jamtrack-detail-btn').on 'click', this.showJamtrackDescription
|
||||
@screen.find('.play-button').on 'click', this.playJamtrack
|
||||
@screen.find('.jamtrack-add-cart').on 'click', this.addToCartJamtrack
|
||||
@screen.find('.license-us-why').on 'click', this.licenseUSWhy
|
||||
@screen.find('.jamtrack-detail-btn').on 'click', this.toggleExpanded
|
||||
|
||||
renderJamtracks:(data) =>
|
||||
that = this
|
||||
for jamtrack in data.jamtracks
|
||||
for track in jamtrack.tracks
|
||||
continue if track.track_type=='Master'
|
||||
inst = '../assets/content/icon_instrument_default24.png'
|
||||
if track.instrument.id in instrument_logo_map
|
||||
inst = instrument_logo_map[track.instrument.id].asset
|
||||
track.instrument_url = inst
|
||||
track.instrument_desc = track.instrument.description
|
||||
if track.part != ''
|
||||
track.instrument_desc += ' (' + track.part + ')'
|
||||
|
||||
options =
|
||||
jamtrack: jamtrack
|
||||
expanded: that.expanded
|
||||
|
||||
@jamtrackItem = $(context._.template($('#template-jamtrack').html(), options, variable: 'data'))
|
||||
that.renderJamtrack(@jamtrackItem)
|
||||
this.registerEvents()
|
||||
|
||||
showJamtrackDescription:(e) =>
|
||||
e.preventDefault()
|
||||
@description = $(e.target).parent('.detail-arrow').next()
|
||||
if @description.css('display') == 'none'
|
||||
@description.show()
|
||||
else
|
||||
@description.hide()
|
||||
|
||||
toggleExpanded:() =>
|
||||
this.expanded = !this.expanded
|
||||
this.refresh()
|
||||
|
||||
renderJamtrack:(jamtrack) =>
|
||||
@content.append jamtrack
|
||||
|
||||
initialize:() =>
|
||||
screenBindings =
|
||||
'beforeShow': this.beforeShow
|
||||
'afterShow': this.afterShow
|
||||
@app.bindScreen 'jamtrack', screenBindings
|
||||
@screen = $('#jamtrack-find-form')
|
||||
@scroller = @screen.find('.content-body-scroller')
|
||||
@content = @screen.find('.jamtrack-content')
|
||||
@genre = @screen.find('#jamtrack_genre')
|
||||
@artist = @screen.find('#jamtrack_artist')
|
||||
@instrument = @screen.find('#jamtrack_instrument')
|
||||
@availability = @screen.find('#jamtrack_availability')
|
||||
@nextPager = @screen.find('a.btn-next-pager')
|
||||
@noMoreJamtracks = @screen.find('.end-of-jamtrack-list')
|
||||
if @screen.length == 0
|
||||
throw new Error('@screen must be specified')
|
||||
if @scroller.length == 0
|
||||
throw new Error('@scroller must be specified')
|
||||
if @content.length == 0
|
||||
throw new Error('@content must be specified')
|
||||
if @noMoreJamtracks.length == 0
|
||||
throw new Error('@noMoreJamtracks must be specified')
|
||||
#if(@genre.length == 0) throw new Error("@genre must be specified")
|
||||
|
||||
if @artist.length == 0
|
||||
throw new Error('@artist must be specified')
|
||||
if @instrument.length == 0
|
||||
throw new Error('@instrument must be specified')
|
||||
if @availability.length == 0
|
||||
throw new Error('@availability must be specified')
|
||||
this.events()
|
||||
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
a.btn-next-pager href="/api/jamtracks?page=1" Next
|
||||
.end-of-jamtrack-list.end-of-list="No more Jamtracks"
|
||||
|
||||
script type='text/template' id='template-jamtrack'
|
||||
script#template-jamtrack type='text/template'
|
||||
.jamtrack-record jamtrack-id="{{data.jamtrack.id}}"
|
||||
.top_bar
|
||||
.jamtrack-detail.jamtrack-header JAMTRACK
|
||||
|
|
@ -74,7 +74,7 @@ script type='text/template' id='template-jamtrack'
|
|||
/ | Tracks in This Recording:
|
||||
="{% counter = 0 %}"
|
||||
="{% _.each(data.jamtrack.tracks, function(track) { %}"
|
||||
="{% if(track.track_type == 'Master') return; %}"
|
||||
="{% if(track.track_type == JK.MASTER_TRACK) return; %}"
|
||||
.track-instrument href="{{track.url_44}}"
|
||||
.instrument-image
|
||||
img src="/assets/shared/play_button.png" width=24 height=24
|
||||
|
|
|
|||
|
|
@ -574,7 +574,7 @@ describe "Checkout", :js => true, :type => :feature, :capybara_feature => true d
|
|||
it "for anonymous user" do
|
||||
visit "/client#/jamtrack"
|
||||
find('h1', text: 'jamtracks')
|
||||
find('a', text: 'What is a JamTrack?')
|
||||
#find('a', text: 'What is a JamTrack?')
|
||||
|
||||
find("a.jamtrack-add-cart[data-jamtrack-id=\"#{jamtrack_acdc_backinblack.id}\"]").trigger(:click)
|
||||
find('h1', text: 'shopping cart')
|
||||
|
|
@ -673,7 +673,7 @@ describe "Checkout", :js => true, :type => :feature, :capybara_feature => true d
|
|||
it "for existing user" do
|
||||
fast_signin(user, "/client#/jamtrack")
|
||||
find('h1', text: 'jamtracks')
|
||||
find('a', text: 'What is a JamTrack?')
|
||||
#find('a', text: 'What is a JamTrack?')
|
||||
|
||||
find("a.jamtrack-add-cart[data-jamtrack-id=\"#{jamtrack_acdc_backinblack.id}\"]").trigger(:click)
|
||||
find('h1', text: 'shopping cart')
|
||||
|
|
|
|||
Loading…
Reference in New Issue