]> git.openstreetmap.org Git - rails.git/commitdiff
can now download a trace
authorSteve Coast <steve@asklater.com>
Sat, 7 Apr 2007 17:07:03 +0000 (17:07 +0000)
committerSteve Coast <steve@asklater.com>
Sat, 7 Apr 2007 17:07:03 +0000 (17:07 +0000)
app/controllers/trace_controller.rb
app/views/trace/view.rhtml

index c3ddb5f2d8c1382edd1ad862ac3325ee999a2384..fd9e2af2532a20c3483f160bf4e15ef15ab560f2 100644 (file)
@@ -113,7 +113,15 @@ class TraceController < ApplicationController
       flash[:notice] = "Your GPX file has been uploaded and is awaiting insertion in to the database. This will usually happen within half an hour, and an email will be sent to you on completion."
       redirect_to :action => 'mine'
     else
-#      render :action => 'mine'
+      # fixme throw an error here
+      # render :action => 'mine'
+    end
+  end
+
+  def data
+    trace = Trace.find(params[:id])
+    if trace.public? or (@user and @user == trace.user)
+      send_data(File.open("/tmp/#{trace.id}.gpx",'r').read , :filename => "#{trace.id}.gpx", :type => 'text/plain', :disposition => 'inline')
     end
   end
 
@@ -134,11 +142,11 @@ class TraceController < ApplicationController
 
   def picture
     trace = Trace.find(params[:id])
-    send_data(trace.large_picture, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') if trace.public
+    send_data(trace.large_picture, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') if trace.public?
   end
 
   def icon
     trace = Trace.find(params[:id])
-    send_data(trace.icon_picture, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline') if trace.public
+    send_data(trace.icon_picture, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline') if trace.public?
   end
 end
index b5f3bf65d6e1340e8ed1275ff8ee4a0770ba5183..63b1b7e004542b4ccef21cbd7ed3ca9ca8160932 100644 (file)
@@ -3,7 +3,7 @@
 <img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :user_login => @trace.user.display_name %>">
 
 <table border="0">
-  <tr><td>filename:</td><td><%= @trace.name %></td></tr> <!-- TODO link to download -->
+  <tr><td>filename:</td><td><%= @trace.name %> (<%= link_to 'download', :controller => 'trace', :action => 'data', :id => @trace.id %>)</td></tr> <!-- TODO link to download -->
   <tr><td>uploaded at:</td><td><%= @trace.timestamp %></td></tr>
   <tr><td>points:</td><td><%= @trace.size.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,') %></td></tr>
   <tr><td>start coordinate:</td><td><%= @trace.latitude %>, <%= @trace.longitude %> (<%=link_to 'map', :controller => 'site', :action => 'index', :lat => @trace.latitude, :lon => @trace.longitude, :zooom => 6 %>)</td></tr>