]> git.openstreetmap.org Git - rails.git/blob - app/controllers/trace_controller.rb
3448b43acf42e5226fa2e3d8bd5e8117cbe06a93
[rails.git] / app / controllers / trace_controller.rb
1 class TraceController < ApplicationController
2   before_filter :authorize_web  
3   layout 'site'
4
5   def list
6     @traces = Trace.find(:all, :conditions => ['public = true'])
7   end
8
9   def mine
10     @traces = Trace.find(:all, :conditions => ['user_id = ?', @user.id])
11   end
12
13   def view
14     @trace = Trace.find(params[:id])
15     unless @trace.public
16       if @user
17         render :nothing, :status => 401 if @trace.user.id != @user.id
18       end
19     end
20   end
21
22   def create
23     filename = "/tmp/#{rand}"
24
25     File.open(filename, "w") { |f| f.write(@params['trace']['gpx_file'].read) }
26     @params['trace']['name'] = @params['trace']['gpx_file'].original_filename.gsub(/[^a-zA-Z0-9.]/, '_') # This makes sure filenames are sane
27     @params['trace'].delete('gpx_file') # let's remove the field from the hash, because there's no such field in the DB anyway.
28     @trace = Trace.new(@params['trace'])
29     @trace.inserted = false
30     @trace.user_id = @user.id
31     @trace.timestamp = Time.now
32     if @trace.save
33       logger.info("id is #{@trace.id}")
34       `mv #{filename} /tmp/#{@trace.id}.gpx`
35       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."
36     end
37
38     redirect_to :action => 'mine'
39   end
40
41   def georss
42     traces = Trace.find(:all, :conditions => ['public = true'], :order => 'timestamp DESC', :limit => 20)
43
44
45   end
46
47   def picture
48     trace = Trace.find(params[:id])
49     send_data(trace.large_picture, :filename => "#{trace.id}.gif", :type => 'image/png', :disposition => 'inline') if trace.public
50   end
51
52   def icon
53     trace = Trace.find(params[:id])
54     send_data(trace.icon_picture, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') if trace.public
55   end
56 end