From 76c1b4ce0a50e207a7ffaf2cbb808bdc4034308b Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Mon, 4 Nov 2013 08:47:30 -0600 Subject: [PATCH] vrfs-774: integrating results with UI --- ruby/lib/jam_ruby/models/search.rb | 2 +- ruby/lib/jam_ruby/models/user.rb | 6 +- web/app/assets/javascripts/findMusician.js | 73 +++++++++---------- web/app/controllers/api_search_controller.rb | 10 ++- web/app/controllers/api_users_controller.rb | 3 +- web/app/views/api_users/index.rabl | 8 +- .../views/clients/_musician_filter.html.erb | 8 +- web/app/views/clients/_musicians.html.erb | 49 ++++++++++++- web/app/views/clients/index.html.erb | 7 ++ 9 files changed, 117 insertions(+), 49 deletions(-) diff --git a/ruby/lib/jam_ruby/models/search.rb b/ruby/lib/jam_ruby/models/search.rb index 377b9fb32..877d1a634 100644 --- a/ruby/lib/jam_ruby/models/search.rb +++ b/ruby/lib/jam_ruby/models/search.rb @@ -13,7 +13,7 @@ module JamRuby def self.order_param(params) ordering = params[:orderby] - ordering.blank? ? ORDERING_KEYS[0] : ordering + ordering.blank? ? ORDERING_KEYS[0] : ORDERING_KEYS.detect { |oo| oo.to_s == ordering } end # performs a site-white search diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index 21b933553..ee9a1ceca 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -13,6 +13,8 @@ module JamRuby after_save :check_lat_lng + PARAM_SEARCH_MUSICIAN = :search_m + attr_accessible :first_name, :last_name, :email, :city, :password, :password_confirmation, :state, :country, :birth_date, :subscribe_email, :terms_of_service, :original_fpfile, :cropped_fpfile, :cropped_s3_path, :photo_url, :crop_selection, :lat, :lng # updating_password corresponds to a lost_password @@ -935,7 +937,7 @@ module JamRuby case ordering = Search.order_param(params) when :plays when :followed - rel = rel.select("COUNT(follows) AS fcount, users.id") + rel = rel.select("COUNT(follows) AS fcount, users.*") rel = rel.joins("LEFT JOIN users_followers AS follows ON follows.user_id = users.id") rel = rel.group("users.id") rel = rel.order("COUNT(follows) DESC") @@ -944,7 +946,7 @@ module JamRuby perpage = params[:per_page] || 20 page = [params[:page].to_i, 1].max rel = rel.paginate(:page => page, :per_page => perpage) - # puts rel.to_sql + rel.includes([:instruments]) rel end diff --git a/web/app/assets/javascripts/findMusician.js b/web/app/assets/javascripts/findMusician.js index 03852dc25..cd0982d4d 100644 --- a/web/app/assets/javascripts/findMusician.js +++ b/web/app/assets/javascripts/findMusician.js @@ -7,6 +7,7 @@ var logger = context.JK.logger; var musicians = {}; var musicianList; + var instrument_logo_map = context.JK.getInstrumentIconMap24(); function removeSpinner() { $(' 0) { + if (typeof orderby != 'undefined' && orderby.length > 0) { queryString += "orderby=" + orderby + '&'; } // instrument filter var instrument = $('.instrument-list').val(); - if (instruments !== null && instruments.length() > 0) { - queryString += "instrument=" + instrument; + if (typeof instrument != 'undefined' && !(instrument === '')) { + queryString += "instrument=" + instrument + '&'; } // distance filter - var query_param = $('#musician-query-distance').val(); + var query_param = $('#musician_query_distance').val(); if (query_param !== null && query_param.length > 0) { - var matches = query_param.match(/(\d)/); - if (0 < matches.length()) { + var matches = query_param.match(/(\d+)/); + if (0 < matches.length) { var distance = matches[0]; - query_param = $('#musician-query-center').val(); - if (query_param !== null && query_param.length > 0) { - matches = query_param.match(/\\d{5}(-\\d{4})?/); - if (0 < matches.length()) { - var zip = matches[0]; - queryString += "zip=" + query_param + '&'; - queryString += "distance=" + query_param + '&'; - } - } + queryString += "distance=" + distance + '&'; } } loadMusicians(queryString); @@ -77,29 +70,38 @@ var $noMusiciansFound = $('#musicians-none-found'); if(musicianList.length == 0) { $noMusiciansFound.show(); + musicians = []; } else { $noMusiciansFound.hide(); + musicians = musicianList; + renderMusicians(); } - - startMusicianLatencyChecks(musicianList); - context.JK.GA.trackFindMusicians(musicianList.length); } /** - * Render a single musician line into the table. - * It will be inserted at the appropriate place according to the - * sortScore in musicianLatency. + * Render a list of musicians */ - function renderMusician(musicianId) { - // store musician in the appropriate bucket and increment category counts - var musician = musicians[musicianId]; - - refreshDisplay(); + function renderMusicians() { + var ii, len; + var mTemplate = $('#template-find-musician-row').html(); + var mVals, mm, renderings=''; + var instrument_html; + for (ii=0, len=musicians.length; ii < len; ii++) { + mm = musicians[ii]; + mVals = { + avatar_url: context.JK.resolveAvatarUrl(mm.photo_url), + profile_url: "/#/profile/" + mm.id, + musician_name: mm.name, + musician_location: mm.city + ', ' + mm.state, + instruments: instrument_html + }; + renderings += context.JK.fillTemplate(mTemplate, mVals); + } + $('#musician-filter-results').append(renderings); } function beforeShow(data) { - context.JK.InstrumentSelectorHelper.render('#find-musician-instrument'); } function afterShow(data) { @@ -123,33 +125,28 @@ search(); } }); - $('#btn-refresh').on("click", search); + $('#btn-refresh-musicians').on("click", search); } /** - * Initialize, providing an instance of the MusicianLatency class. + * Initialize, */ - function initialize(latency) { + function initialize() { var screenBindings = { 'beforeShow': beforeShow, 'afterShow': afterShow }; - app.bindScreen('findMusician', screenBindings); - - musicianList = new context.JK.MusicianList(app); + app.bindScreen('musicians', screenBindings); events(); } this.initialize = initialize; - this.renderMusician = renderMusician; + this.renderMusicians = renderMusicians; this.afterShow = afterShow; - // Following exposed for easier testing. - this.setMusician = setMusician; this.clearResults = clearResults; - this.getCategoryEnum = getCategoryEnum; return this; }; diff --git a/web/app/controllers/api_search_controller.rb b/web/app/controllers/api_search_controller.rb index 40e01637b..bca395dfc 100644 --- a/web/app/controllers/api_search_controller.rb +++ b/web/app/controllers/api_search_controller.rb @@ -6,6 +6,14 @@ class ApiSearchController < ApiController respond_to :json def index - @search = Search.search(params[:query], current_user.id) + if 1 == params[User::PARAM_SEARCH_MUSICIAN].to_i + logger.debug("*** params = #{params.inspect}") + query = params.clone + query[:remote_ip] = request.remote_ip + @search = User.musician_search(query, current_user) + respond_with @users, responder: ApiResponder, :status => 200 + else + @search = Search.search(params[:query], current_user.id) + end end end diff --git a/web/app/controllers/api_users_controller.rb b/web/app/controllers/api_users_controller.rb index 427a2647a..eb4de1f85 100644 --- a/web/app/controllers/api_users_controller.rb +++ b/web/app/controllers/api_users_controller.rb @@ -14,7 +14,8 @@ class ApiUsersController < ApiController respond_to :json def index - if 1 == params[:musicians].to_i + if 1 == params[User::PARAM_SEARCH_MUSICIAN].to_i + logger.debug("*** params = #{params.inspect}") query = params.clone query[:remote_ip] = request.remote_ip @users = User.musician_search(query, current_user) diff --git a/web/app/views/api_users/index.rabl b/web/app/views/api_users/index.rabl index 7d9b57db6..fff72aa1b 100644 --- a/web/app/views/api_users/index.rabl +++ b/web/app/views/api_users/index.rabl @@ -1,4 +1,10 @@ collection @users # do not retrieve all child collections when showing a list of users -attributes :id, :first_name, :last_name, :name, :city, :state, :country, :email, :online, :musician, :photo_url, :biography \ No newline at end of file +attributes :id, :first_name, :last_name, :name, :city, :state, :country, :email, :online, :musician, :photo_url, :biography + +if 1 == params[User::PARAM_SEARCH_MUSICIAN].to_i + child :instruments do + attributes :id + end +end diff --git a/web/app/views/clients/_musician_filter.html.erb b/web/app/views/clients/_musician_filter.html.erb index ec1606d96..fd1ddee37 100644 --- a/web/app/views/clients/_musician_filter.html.erb +++ b/web/app/views/clients/_musician_filter.html.erb @@ -5,18 +5,18 @@
<%= select_tag(:instrument, - options_for_select(['Select Instrument', ''].concat(JamRuby::Instrument.all.collect { |ii| [ii.description, ii.id] })), + options_for_select([['Select Instrument', '']].concat(JamRuby::Instrument.all.collect { |ii| [ii.description, ii.id] })), {:class => 'instrument-list'} ) %>
Within
- - miles of + + miles from <%= current_user.current_city(request.remote_ip) %>
diff --git a/web/app/views/clients/_musicians.html.erb b/web/app/views/clients/_musicians.html.erb index 51b5956aa..6bd5b4bed 100644 --- a/web/app/views/clients/_musicians.html.erb +++ b/web/app/views/clients/_musicians.html.erb @@ -15,7 +15,7 @@
-
+
@@ -26,3 +26,50 @@
+ + + diff --git a/web/app/views/clients/index.html.erb b/web/app/views/clients/index.html.erb index 3099cb3a2..bf3d07b8b 100644 --- a/web/app/views/clients/index.html.erb +++ b/web/app/views/clients/index.html.erb @@ -143,6 +143,13 @@ } findSessionScreen.initialize(sessionLatency); + var findMusicianScreen = new JK.FindMusicianScreen(JK.app); + findMusicianScreen.initialize(); + /*if (!("jamClient" in window)) { + var findMusicianScreen = new JK.FindMusicianScreen(JK.app); + findMusicianScreen.initialize(); + }*/ + var sessionScreen = new JK.SessionScreen(JK.app); sessionScreen.initialize(); var sessionSettingsDialog = new JK.SessionSettingsDialog(JK.app, sessionScreen);