X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/1df4ad819cb5151d1bdd7bb98cf4833d219bd09d..ebd109c946d71b3ccc616ea3966e56ae019638d7:/app/controllers/trace_controller.rb?ds=inline
diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb
index 99f11d546..f8ce29aba 100644
--- a/app/controllers/trace_controller.rb
+++ b/app/controllers/trace_controller.rb
@@ -15,13 +15,19 @@ class TraceController < ApplicationController
before_filter :offline_redirect, :only => [:create, :edit, :delete, :data, :api_data, :api_create]
around_filter :api_call_handle_error, :only => [:api_details, :api_data, :api_create]
+ caches_action :list, :unless => :logged_in?, :layout => false
+ caches_action :view, :layout => false
+ caches_action :georss, :layout => true
+ cache_sweeper :trace_sweeper, :only => [:create, :edit, :delete, :api_create]
+ cache_sweeper :tracetag_sweeper, :only => [:create, :edit, :delete, :api_create]
+
# Counts and selects pages of GPX traces for various criteria (by user, tags, public etc.).
# target_user - if set, specifies the user to fetch traces for. if not set will fetch all traces
def list(target_user = nil, action = "list")
# from display name, pick up user id if one user's traces only
display_name = params[:display_name]
if target_user.nil? and !display_name.blank?
- target_user = User.find(:first, :conditions => [ "visible = ? and display_name = ?", true, display_name])
+ target_user = User.find(:first, :conditions => { :status => ["active", "confirmed"], :display_name => display_name })
if target_user.nil?
@title = t'trace.no_such_user.title'
@not_found_user = display_name
@@ -75,11 +81,15 @@ class TraceController < ApplicationController
conditions[0] += " AND gpx_files.visible = ?"
conditions << true
- @trace_pages, @traces = paginate(:traces,
- :include => [:user, :tags],
- :conditions => conditions,
- :order => "gpx_files.timestamp DESC",
- :per_page => 20)
+ @page = (params[:page] || 1).to_i
+ @page_size = 20
+
+ @traces = Trace.find(:all,
+ :include => [:user, :tags],
+ :conditions => conditions,
+ :order => "gpx_files.timestamp DESC",
+ :offset => (@page - 1) * @page_size,
+ :limit => @page_size)
# put together SET of tags across traces, for related links
tagset = Hash.new
@@ -96,20 +106,11 @@ class TraceController < ApplicationController
@action = action
@display_name = target_user.display_name if target_user
@all_tags = tagset.values
+ @trace = Trace.new(:visibility => default_visibility) if @user
end
def mine
- # Load the preference of whether the user set the trace public the last time
- @trace = Trace.new
- visibility = @user.preferences.find(:first, :conditions => {:k => "gps.trace.visibility"})
- if visibility
- @trace.visibility = visibility.v
- elsif @user.preferences.find(:first, :conditions => {:k => "gps.trace.public", :v => "default"}).nil?
- @trace.visibility = "private"
- else
- @trace.visibility = "public"
- end
- list(@user, "mine")
+ redirect_to :action => :list, :display_name => @user.display_name
end
def view
@@ -232,7 +233,7 @@ class TraceController < ApplicationController
rss = OSM::GeoRSS.new
traces.each do |trace|
- rss.add(trace.latitude, trace.longitude, trace.name, trace.user.display_name, url_for({:controller => 'trace', :action => 'view', :id => trace.id, :display_name => trace.user.display_name}), " 'icon', :id => trace.id, :user_login => trace.user.display_name})}'> GPX file with #{trace.size} points from #{trace.user.display_name}", trace.timestamp)
+ rss.add(trace.latitude, trace.longitude, trace.name, trace.user.display_name, url_for({:controller => 'trace', :action => 'view', :id => trace.id, :display_name => trace.user.display_name}), " 'icon', :id => trace.id, :display_name => trace.user.display_name})}'> GPX file with #{trace.size} points from #{trace.user.display_name}", trace.timestamp)
end
render :text => rss.to_s, :content_type => "application/rss+xml"
@@ -398,4 +399,16 @@ private
redirect_to :action => :offline if OSM_STATUS == :gpx_offline
end
+ def default_visibility
+ visibility = @user.preferences.find(:first, :conditions => {:k => "gps.trace.visibility"})
+
+ if visibility
+ visibility.v
+ elsif @user.preferences.find(:first, :conditions => {:k => "gps.trace.public", :v => "default"}).nil?
+ "private"
+ else
+ "public"
+ end
+ end
+
end