diff --git a/ruby/lib/jam_ruby/models/genre.rb b/ruby/lib/jam_ruby/models/genre.rb index 91d80f755..818d37882 100644 --- a/ruby/lib/jam_ruby/models/genre.rb +++ b/ruby/lib/jam_ruby/models/genre.rb @@ -22,5 +22,12 @@ module JamRuby def to_s description end + + def self.jam_track_list + sql = "SELECT DISTINCT genre_id FROM jam_tracks WHERE genre_id IS NOT NULL" + Genre.where("genres.id IN (#{sql})") + .order('genres.description ASC') + end + end end diff --git a/ruby/lib/jam_ruby/models/instrument.rb b/ruby/lib/jam_ruby/models/instrument.rb index 1a3fa8df7..d1b2d74c2 100644 --- a/ruby/lib/jam_ruby/models/instrument.rb +++ b/ruby/lib/jam_ruby/models/instrument.rb @@ -47,6 +47,12 @@ module JamRuby return Instrument.where('instruments.popularity > 0').order('instruments.popularity DESC, instruments.description ASC') end + def self.jam_track_list + sql = "SELECT DISTINCT instrument_id FROM jam_track_tracks WHERE instrument_id IS NOT NULL" + Instrument.where("instruments.id IN (#{sql})") + .order('instruments.description ASC') + end + def icon_name MAP_ICON_NAME[self.id] end diff --git a/web/app/controllers/api_genres_controller.rb b/web/app/controllers/api_genres_controller.rb index 293552737..8a76fcc6a 100644 --- a/web/app/controllers/api_genres_controller.rb +++ b/web/app/controllers/api_genres_controller.rb @@ -3,7 +3,11 @@ class ApiGenresController < ApiController respond_to :json def index - @genres = Genre.order(:description) + if params[:jamtracks] + @genres = Genre.jam_track_list + else + @genres = Genre.order(:description) + end end def show diff --git a/web/app/controllers/api_instruments_controller.rb b/web/app/controllers/api_instruments_controller.rb index c5f10bd49..6c8c9fe63 100644 --- a/web/app/controllers/api_instruments_controller.rb +++ b/web/app/controllers/api_instruments_controller.rb @@ -3,7 +3,11 @@ class ApiInstrumentsController < ApiController respond_to :json def index - @instruments = Instrument.standard_list + if params[:jamtracks] + @instruments = Instrument.jam_track_list + else + @instruments = Instrument.standard_list + end end def show diff --git a/web/app/controllers/api_search_controller.rb b/web/app/controllers/api_search_controller.rb index 54e3ab5b0..ea6e0df65 100644 --- a/web/app/controllers/api_search_controller.rb +++ b/web/app/controllers/api_search_controller.rb @@ -66,4 +66,30 @@ class ApiSearchController < ApiController end end + def jam_tracks + if request.get? + if params[:results] + @search = JamTrackSearch.user_search_filter(current_user).search_results_page(params[:subtype]) + respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/index' + elsif params[:genres] + + elsif params[:instruments] + + else + render :json => JamTrackSearch.search_filter_json(current_user, params[:subtype]), :status => 200 + end + + elsif request.post? + sobj = JamTrackSearch.user_search_filter(current_user) + filter = params[:filter] + if filter == 'reset' + @search = sobj.reset_search_results(params[:subtype]) + else + json = JSON.parse(filter, :create_additions => false) + @search = sobj.search_results_page(params[:subtype], json, [params[:page].to_i, 1].max) + end + respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/index' + end + end + end diff --git a/web/config/routes.rb b/web/config/routes.rb index cef2252c1..f2f565125 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -496,6 +496,7 @@ SampleApp::Application.routes.draw do match '/search' => 'api_search#index', :via => :get match '/search/musicians' => 'api_search#musicians', :via => [:get, :post] match '/search/bands' => 'api_search#bands', :via => [:get, :post] + match '/search/jam_tracks' => 'api_search#jam_tracks', :via => [:get, :post] # join requests match '/join_requests/:id' => 'api_join_requests#show', :via => :get, :as => 'api_join_request_detail'