From 0bb635cf5d89e065fbd3dbd32e9063582e0b10ee Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 11 Aug 2015 05:49:48 -0500 Subject: [PATCH] * wip --- db/manifest | 3 +- db/up/jam_track_searchability.sql | 6 + ruby/lib/jam_ruby/models/jam_track.rb | 7 + ruby/lib/jam_ruby/models/search.rb | 3 +- ruby/spec/jam_ruby/models/jam_track_spec.rb | 19 ++ web/Gemfile | 1 + .../javascripts/jamtrack_landing.js.coffee | 3 +- .../assets/javascripts/react-components.js | 5 +- .../JamTrackLandingScreen.js.jsx.coffee | 139 +++++++++ .../JamTrackSearchScreen.js.jsx.coffee | 78 +++++ web/app/assets/stylesheets/client/client.css | 1 + .../client/jamtrackSearch.css.scss | 274 ++++++++++++++++++ .../react-components/ReactSelect.css.scss | 10 + .../views/clients/_jamtrack_landing.html.slim | 31 +- .../views/clients/_jamtrack_search.html.slim | 8 + web/app/views/clients/_session.html.slim | 167 ----------- web/app/views/clients/_session2.html.slim | 49 ++++ web/app/views/clients/index.html.erb | 2 +- 18 files changed, 604 insertions(+), 202 deletions(-) create mode 100644 db/up/jam_track_searchability.sql create mode 100644 web/app/assets/javascripts/react-components/JamTrackLandingScreen.js.jsx.coffee create mode 100644 web/app/assets/javascripts/react-components/JamTrackSearchScreen.js.jsx.coffee create mode 100644 web/app/assets/stylesheets/client/jamtrackSearch.css.scss create mode 100644 web/app/assets/stylesheets/client/react-components/ReactSelect.css.scss create mode 100644 web/app/views/clients/_jamtrack_search.html.slim diff --git a/db/manifest b/db/manifest index f7212acc1..9b059151a 100755 --- a/db/manifest +++ b/db/manifest @@ -299,4 +299,5 @@ enhance_band_profile.sql alter_band_profile_rate_defaults.sql repair_band_profile.sql jam_track_onboarding_enhancements.sql -jam_track_name_drop_unique.sql \ No newline at end of file +jam_track_name_drop_unique.sql +jam_track_searchability.sql \ No newline at end of file diff --git a/db/up/jam_track_searchability.sql b/db/up/jam_track_searchability.sql new file mode 100644 index 000000000..fbdaf9776 --- /dev/null +++ b/db/up/jam_track_searchability.sql @@ -0,0 +1,6 @@ +ALTER TABLE jam_tracks ADD COLUMN search_tsv tsvector; +CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE +ON jam_tracks FOR EACH ROW EXECUTE PROCEDURE +tsvector_update_trigger(search_tsv, 'public.jamenglish', original_artist, name, additional_info); +CREATE INDEX jam_track_search_tsv_index ON jam_tracks USING gin(search_tsv); +UPDATE jam_tracks SET original_artist=original_artist, name=name, additional_info=additional_info; diff --git a/ruby/lib/jam_ruby/models/jam_track.rb b/ruby/lib/jam_ruby/models/jam_track.rb index 244cbc6f1..4cbd829c8 100644 --- a/ruby/lib/jam_ruby/models/jam_track.rb +++ b/ruby/lib/jam_ruby/models/jam_track.rb @@ -252,6 +252,13 @@ module JamRuby query = query.where("jam_track_rights.user_id = ?", user.id) end + if options[:search] + tsquery = Search.create_tsquery(options[:search]) + if tsquery + query = query.where("(search_tsv @@ to_tsquery('jamenglish', ?))", tsquery) + end + end + if options[:artist].present? query = query.where("original_artist=?", options[:artist]) end diff --git a/ruby/lib/jam_ruby/models/search.rb b/ruby/lib/jam_ruby/models/search.rb index d1a4d13ea..2cdc9d4ba 100644 --- a/ruby/lib/jam_ruby/models/search.rb +++ b/ruby/lib/jam_ruby/models/search.rb @@ -83,7 +83,7 @@ module JamRuby @search_type = :musicians User.musicians end - @results = rel.where("(name_tsv @@ to_tsquery('jamenglish', ?))", tsquery).limit(10) + @results = rel.where("(name_c @@ to_tsquery('jamenglish', ?))", tsquery).limit(10) @results end @@ -139,6 +139,7 @@ module JamRuby args = args + ":*" args end + def order_param(params, keys=M_ORDERING_KEYS) ordering = params[:orderby] ordering.blank? ? keys[0] : keys.detect { |oo| oo.to_s == ordering } diff --git a/ruby/spec/jam_ruby/models/jam_track_spec.rb b/ruby/spec/jam_ruby/models/jam_track_spec.rb index c1aecf71d..674f3fedb 100644 --- a/ruby/spec/jam_ruby/models/jam_track_spec.rb +++ b/ruby/spec/jam_ruby/models/jam_track_spec.rb @@ -215,6 +215,25 @@ describe JamTrack do query.size.should == 1 query[0].should eq(jam_track1) end + + it "full text search" do + jam_track1 = FactoryGirl.create(:jam_track_with_tracks, name: 'Take a Chance On Me', original_artist: 'ABBA') + jam_track2 = FactoryGirl.create(:jam_track_with_tracks, name: 'Nothing Chance', original_artist: 'ABBA') + + query, pager = JamTrack.index({search: 'Take'}, user) + query.size.should == 1 + query[0].should eq(jam_track1) + + query, pager = JamTrack.index({search: 'ABB'}, user) + query.size.should == 2 + + query, pager = JamTrack.index({search: 'Chance'}, user) + query.size.should == 2 + + query, pager = JamTrack.index({search: 'Chan'}, user) + query.size.should == 2 + + end end describe "validations" do diff --git a/web/Gemfile b/web/Gemfile index 35c68d23c..031ebd08b 100644 --- a/web/Gemfile +++ b/web/Gemfile @@ -97,6 +97,7 @@ gem 'react-rails', '~> 1.0' source 'https://rails-assets.org' do gem 'rails-assets-reflux' gem 'rails-assets-classnames' + gem 'rails-assets-react-select' end #group :development, :production do diff --git a/web/app/assets/javascripts/jamtrack_landing.js.coffee b/web/app/assets/javascripts/jamtrack_landing.js.coffee index 5198a1f64..3a694daf9 100644 --- a/web/app/assets/javascripts/jamtrack_landing.js.coffee +++ b/web/app/assets/javascripts/jamtrack_landing.js.coffee @@ -17,7 +17,8 @@ context.JK.JamTrackLanding = class JamTrackLanding screenBindings = 'beforeShow': @beforeShow 'afterShow': @afterShow - @app.bindScreen('jamtrackLanding', screenBindings) + + #@app.bindScreen('jamtrackLanding', screenBindings) @screen = $('#jamtrackLanding') @noFreeJamTrack = @screen.find('.no-free-jamtrack') @freeJamTrack = @screen.find('.free-jamtrack') diff --git a/web/app/assets/javascripts/react-components.js b/web/app/assets/javascripts/react-components.js index a3f79c86e..348d88b96 100644 --- a/web/app/assets/javascripts/react-components.js +++ b/web/app/assets/javascripts/react-components.js @@ -1,3 +1,5 @@ +//= require react-input-autosize +//= require react-select //= require_directory ./react-components/helpers //= require_directory ./react-components/actions //= require ./react-components/stores/AppStore @@ -13,4 +15,5 @@ //= require_directory ./react-components/stores //= require_directory ./react-components/mixins //= require_directory ./react-components -//= require_directory ./react-components/landing \ No newline at end of file + +//= require_directory ./react-components/landing diff --git a/web/app/assets/javascripts/react-components/JamTrackLandingScreen.js.jsx.coffee b/web/app/assets/javascripts/react-components/JamTrackLandingScreen.js.jsx.coffee new file mode 100644 index 000000000..c821f4e26 --- /dev/null +++ b/web/app/assets/javascripts/react-components/JamTrackLandingScreen.js.jsx.coffee @@ -0,0 +1,139 @@ +context = window +MIX_MODES = context.JK.MIX_MODES + + +@JamTrackLandingScreen = React.createClass({ + + mixins: [Reflux.listenTo(@AppStore,"onAppInit")] + + getInitialState: () -> + {user: null} + + render: () -> + + howTo = null + if @state.user?.free_jamtrack + howTo = + `
+ For a limited time, get one JamTrack free. Search JamTracks below, add one to your shopping cart, and we'll make it free during the checkout process. +
` + else + howTo = + `
+ + To play with your JamTracks, open a JamTrack while in a session in the JamKazam app. Or visit the JamTracks Section of your account. + +
` + + `
+
+
+

my jamtracks

+
+ {howTo} +
+

search jamtracks

+
+ +
+

what are jamtracks?

+
+
+ JamTracks are the best way to play along with your favorite music! Unlike traditional backing tracks, JamTracks are professionally mastered, complete multitrack recordings, with fully isolated tracks for each part of the master mix. Used with the free JamKazam app & Internet service, you can: +
+
    +
  • Solo just the part you want to play in order to hear and learn it
  • +
  • Mute just the part you want to play and play along with the rest
  • +
  • Make audio recordings and share them via Facebook or URL
  • +
  • Make video recordings and share them via YouTube
  • +
  • And even go online to play with others in real time -- for example, you can play the electric guitar lead, while someone else plays the bass, and all other parts play from the recorded tracks in your session
  • +
+ + + +
+
+ +
+
` + + + componentDidMount: () -> + logger.debug("componentDidMount") + + + afterShow: (data) -> + + if context.JK.currentUserId + @app.user().done(@onUser) + else + @onUser({free_jamtrack: gon.global.one_free_jamtrack_per_user}) + + beforeShow: () -> + @setState({user: null}) + + onUser:(user) -> + @setState({user: user}) + + # Get artist names and build links + @rest.getJamTrackArtists({group_artist: true, per_page:100}) + .done(this.buildArtistLinks) + .fail(this.handleFailure) + + # Bind links to action that will open the jam_tracks list view filtered to given artist_name: + # artist_name + @bindArtistLinks() + + + buildArtistLinks:(response) -> + # Get artist names and build links + @logger.debug("buildArtist links response", response) + + artists = response.artists + $("#band_list>li:not('#no_bands_found')").remove() + if artists.length==0 + @noBandsFound.removeClass("hidden") + else + @noBandsFound.addClass("hidden") + + # client#/jamtrack + for artist in artists + artistLink = "#{artist.original_artist} (#{artist.song_count})" + @bandList.append("
  • #{artistLink}
  • ") + + + # We don't want to do a full page load if this is clicked on here: + bindArtistLinks:() -> + that=this + @bandList.on "click", "a.artist-link", (event)-> + context.location="client#/jamtrackBrowse" + if window.history.replaceState # ie9 proofing + window.history.replaceState({}, "", this.href) + event.preventDefault() + + + onAppInit: (@app) -> + + logger.debug("ON APP INI") + + @rest = context.JK.Rest() + @client = context.jamClient + @logger = context.JK.logger + @screen = null + @noFreeJamTrack = null + @freeJamTrack = null + @bandList = null + @noBandsFound = null + + screenBindings = + 'beforeShow': @beforeShow + 'afterShow': @afterShow + + @app.bindScreen('jamtrackLanding', screenBindings) + + @screen = $('#jamtrackLanding') + @noFreeJamTrack = @screen.find('.no-free-jamtrack') + @freeJamTrack = @screen.find('.free-jamtrack') + @bandList = @screen.find('#band_list') + @noBandsFound = @screen.find('#no_bands_found') +}) \ No newline at end of file diff --git a/web/app/assets/javascripts/react-components/JamTrackSearchScreen.js.jsx.coffee b/web/app/assets/javascripts/react-components/JamTrackSearchScreen.js.jsx.coffee new file mode 100644 index 000000000..b44cb385f --- /dev/null +++ b/web/app/assets/javascripts/react-components/JamTrackSearchScreen.js.jsx.coffee @@ -0,0 +1,78 @@ +context = window +MIX_MODES = context.JK.MIX_MODES + + +@JamTrackSearchScreen = React.createClass({ + + mixins: [Reflux.listenTo(@AppStore,"onAppInit")] + + LIMIT: 10 + instrument_logo_map: context.JK.getInstrumentIconMap24() + + + getInitialState: () -> + {search: null, type: 'user-input'} + + logChange: (val) -> + @logger.debug("CHANGE #{val}") + render: () -> + + options = [ + { value: 'one', label: 'One' }, + { value: 'two', label: 'Two' } + ]; + + `
    +
    +