From: Dan Karran Date: Wed, 10 Oct 2007 19:22:16 +0000 (+0000) Subject: Reduce number of nearby people listed to the closest 5 by default, and show friends... X-Git-Tag: live~8075 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/60d8673e3027ea672f50bb12873a440d46195ff3?hp=63bd068f2ed5027485dff791ab44e31fbdaf4052 Reduce number of nearby people listed to the closest 5 by default, and show friends ahead of nearby people. --- diff --git a/app/models/user.rb b/app/models/user.rb index c4b81e7ab..e55f373b7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -72,11 +72,11 @@ class User < ActiveRecord::Base return el1 end - def nearby(radius = 50) + def nearby(radius = 50, num = 5) if self.home_lon and self.home_lat gc = OSM::GreatCircle.new(self.home_lat, self.home_lon) bounds = gc.bounds(radius) - nearby = User.find(:all, :conditions => "home_lat between #{bounds[:minlat]} and #{bounds[:maxlat]} and home_lon between #{bounds[:minlon]} and #{bounds[:maxlon]} and data_public = 1 and id != #{self.id}") + nearby = User.find(:all, :conditions => "home_lat between #{bounds[:minlat]} and #{bounds[:maxlat]} and home_lon between #{bounds[:minlon]} and #{bounds[:maxlon]} and data_public = 1 and id != #{self.id}", :limit => num) nearby.delete_if { |u| gc.distance(u.home_lat, u.home_lon) > radius } nearby.sort! { |u1,u2| gc.distance(u1.home_lat, u1.home_lon) <=> gc.distance(u2.home_lat, u2.home_lon) } else diff --git a/app/views/user/view.rhtml b/app/views/user/view.rhtml index d0600bb8d..93bed72b0 100644 --- a/app/views/user/view.rhtml +++ b/app/views/user/view.rhtml @@ -27,23 +27,8 @@ You can set your home location on your <%= link_to 'settings', :controller => 'user', :action => 'account', :display_name => @user.display_name %> page. <% end %> <% else %> - Nearby users:
- <% if @this_user.nearby.empty? %> - There are no users who admit to mapping nearby yet. - <% else %> - - <% @this_user.nearby.each do |nearby| %> - - - - - - <%end%> -
<%= link_to nearby.display_name, :controller => 'user', :action => 'view', :display_name => nearby.display_name %><%= @this_user.distance(nearby).round %>km away(<%= link_to 'send message', :controller => 'message', :action => 'new', :user_id => nearby.id %>)
- <%end%> <% if @user and @this_user.id == @user.id %> -
Your friends:
<% if @this_user.friends.empty? %> You have not added any friends yet. @@ -59,5 +44,22 @@ <%end%> <%end%> +
+ <%end%> + + Nearby users:
+ <% if @this_user.nearby.empty? %> + There are no users who admit to mapping nearby yet. + <% else %> + + <% @this_user.nearby.each do |nearby| %> + + + + + + <%end%> +
<%= link_to nearby.display_name, :controller => 'user', :action => 'view', :display_name => nearby.display_name %><%= @this_user.distance(nearby).round %>km away(<%= link_to 'send message', :controller => 'message', :action => 'new', :user_id => nearby.id %>)
<%end%> + <% end %>