From 897e83fd73fb1da6ad9caa4afe3ba1288ba8f619 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 6 Nov 2013 04:16:47 -0600 Subject: [PATCH] vrfs-774: added pagination support; fixed some layout issues --- ruby/lib/jam_ruby/models/search.rb | 17 +++-- ruby/lib/jam_ruby/models/user.rb | 2 + web/app/assets/javascripts/findMusician.js | 43 ++++++++--- web/app/views/api_search/index.rabl | 11 ++- .../views/clients/_musician_filter.html.erb | 2 +- web/app/views/clients/_musicians.html.erb | 72 ++++++++++--------- web/app/views/clients/index.html.erb | 4 -- 7 files changed, 94 insertions(+), 57 deletions(-) diff --git a/ruby/lib/jam_ruby/models/search.rb b/ruby/lib/jam_ruby/models/search.rb index d120ef97a..fe651c3e6 100644 --- a/ruby/lib/jam_ruby/models/search.rb +++ b/ruby/lib/jam_ruby/models/search.rb @@ -1,12 +1,13 @@ module JamRuby # not a active_record model; just a search result class Search - attr_accessor :bands, :musicians, :fans, :recordings, :friends, :search_type, :user_mappings + attr_accessor :bands, :musicians, :fans, :recordings, :friends, :search_type + attr_accessor :user_mappings, :page_num, :page_count PARAM_MUSICIAN = :search_m LIMIT = 10 - M_PER_PAGE = 20 + M_PER_PAGE = 4 M_ORDER_FOLLOWS = ['Most Followed', :followed] M_ORDER_PLAYS = ['Most Plays', :plays] @@ -37,14 +38,17 @@ module JamRuby if current_user.lat.nil? if params[:remote_ip] if geo = MaxMindGeo.ip_lookup(params[:remote_ip]) - latlng = [geo.lat, geo.lng] + latlng = [geo.lat, geo.lng] if geo.lat && geo.lng end end else latlng = [current_user.lat, current_user.lng] end distance = location_distance || 50 - rel = rel.within(distance, :origin => latlng) unless latlng.blank? + unless latlng.blank? + rel = rel.where(['lat IS NOT NULL AND lng IS NOT NULL']) + .within(distance, :origin => latlng) + end end sel_str = 'users.*' @@ -71,7 +75,9 @@ module JamRuby rel = rel.paginate(:page => page, :per_page => perpage) rel.includes([:instruments, :followings, :friends]) - Search.new.musician_results_for_user(rel.all, current_user) + srch = Search.new + srch.page_num, srch.page_count = page, rel.all.total_pages + srch.musician_results_for_user(rel.all, current_user) end # performs a site-white search @@ -175,6 +181,7 @@ module JamRuby rel = rel.joins("LEFT JOIN friendships AS friends ON friends.friend_id = '#{user.id}'") rel = rel.where(["users.id IN (#{mids}) AND friends.user_id = users.id"]) rel.all.each { |val| @user_mappings[val.uid] << RESULT_FRIEND } + else @user_mappings = {} end diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index b2e8e01be..3f1f4195b 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -18,6 +18,8 @@ module JamRuby # updating_password corresponds to a lost_password attr_accessor :updating_password, :updating_email, :updated_email, :update_email_confirmation_url, :administratively_created, :current_password, :setting_password, :confirm_current_password, :updating_avatar, :updating_progression_field + attr_accessor :search_followings + # authorizations (for facebook, etc -- omniauth) has_many :user_authorizations, :class_name => "JamRuby::UserAuthorization" diff --git a/web/app/assets/javascripts/findMusician.js b/web/app/assets/javascripts/findMusician.js index a258eebc4..4e3cc2305 100644 --- a/web/app/assets/javascripts/findMusician.js +++ b/web/app/assets/javascripts/findMusician.js @@ -8,6 +8,8 @@ var musicians = {}; var musicianList; var instrument_logo_map = context.JK.getInstrumentIconMap24(); + var did_show_musician_page = false; + var page_num=1, page_count=0; function removeSpinner() { $('= $(this)[0].scrollHeight) { + logger.debug("*** scrolling: page_num="+page_num.toString()+" page_count="+page_count.toString()); + if (page_num < page_count) { + page_num += 1; + search(); + } + } + }); } /** diff --git a/web/app/views/api_search/index.rabl b/web/app/views/api_search/index.rabl index 75fda0833..e8a1b0f28 100644 --- a/web/app/views/api_search/index.rabl +++ b/web/app/views/api_search/index.rabl @@ -7,6 +7,15 @@ unless @search.bands.nil? || @search.bands.size == 0 end unless @search.musicians.nil? || @search.musicians.size == 0 + + node :city do |user| + current_user.try(:location) + end + + node :page_count do |foo| + @search.page_count + end + child(:musicians => :musicians) { attributes :id, :first_name, :last_name, :name, :city, :state, :country, :email, :online, :musician, :photo_url, :biography @@ -15,7 +24,7 @@ unless @search.musicians.nil? || @search.musicians.size == 0 end node :is_following do |musician| - @search.is_following?(musician) + @search.is_follower?(musician) end node :is_liker do |musician| diff --git a/web/app/views/clients/_musician_filter.html.erb b/web/app/views/clients/_musician_filter.html.erb index 2ebf772bb..896a06a13 100644 --- a/web/app/views/clients/_musician_filter.html.erb +++ b/web/app/views/clients/_musician_filter.html.erb @@ -19,7 +19,7 @@
-
miles from <%= current_user.current_city(request.remote_ip) %>
+
miles of <%= current_user.current_city(request.remote_ip) %>
REFRESH diff --git a/web/app/views/clients/_musicians.html.erb b/web/app/views/clients/_musicians.html.erb index a012164ce..659d82ad7 100644 --- a/web/app/views/clients/_musicians.html.erb +++ b/web/app/views/clients/_musicians.html.erb @@ -2,48 +2,50 @@
-
- <%= image_tag "content/icon_musicians.png", {:height => 19, :width => 19} %> -
+
+ <%= image_tag "content/icon_musicians.png", {:height => 19, :width => 19} %> +
-

musicians

- <%= render "screen_navigation" %> +

musicians

+ <%= render "screen_navigation" %>
-
- <%= render :partial => "musician_filter" %> -
-
-
-
-
-
+
+ <%= render :partial => "musician_filter" %> +
+
+
+
+
+
- There are no musicians found. + There are no musicians found.
diff --git a/web/app/views/clients/index.html.erb b/web/app/views/clients/index.html.erb index bf3d07b8b..556447f6e 100644 --- a/web/app/views/clients/index.html.erb +++ b/web/app/views/clients/index.html.erb @@ -145,10 +145,6 @@ 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();