]> git.openstreetmap.org Git - rails.git/blob - app/models/trace.rb
Made way controller return text/xml instead of text/html. Fixes #450
[rails.git] / app / models / trace.rb
1 class Trace < ActiveRecord::Base
2   set_table_name 'gpx_files'
3
4   validates_presence_of :user_id, :name, :public, :description, :timestamp
5 #  validates_numericality_of :latitude, :longitude
6   validates_inclusion_of :inserted, :in => [ true, false]
7   
8   belongs_to :user
9   has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :destroy
10   has_many :points, :class_name => 'Tracepoint', :foreign_key => 'gpx_id', :dependent => :destroy
11
12   def tagstring=(s)
13     self.tags = s.split().collect {|tag|
14       tt = Tracetag.new
15       tt.tag = tag
16       tt
17     }
18   end
19   
20   def large_picture= (data)
21     f = File.new(large_picture_name, "wb")
22     f.syswrite(data)
23     f.close
24   end
25   
26   def icon_picture= (data)
27     f = File.new(icon_picture_name, "wb")
28     f.syswrite(data)
29     f.close
30   end
31
32   def large_picture
33     f = File.new(large_picture_name, "rb")
34     logger.info "large picture file: '#{f.path}', bytes: #{File.size(f.path)}"
35     data = f.sysread(File.size(f.path))
36     logger.info "have read data, bytes: '#{data.length}'"
37     f.close
38     data
39   end
40   
41   def icon_picture
42     f = File.new(icon_picture_name, "rb")
43     logger.info "icon picture file: '#{f.path}'"
44     data = f.sysread(File.size(f.path))
45     f.close
46     data
47   end
48   
49   # FIXME change to permanent filestore area
50   def large_picture_name
51     "/home/osm/icons/#{id}.gif"
52   end
53
54   # FIXME change to permanent filestore area
55   def icon_picture_name
56     "/home/osm/icons/#{id}_icon.gif"
57   end
58
59   def to_xml_node
60     el1 = XML::Node.new 'gpx_file'
61     el1['id'] = self.id.to_s
62     el1['name'] = self.name.to_s
63     el1['lat'] = self.latitude.to_s
64     el1['lon'] = self.longitude.to_s
65     el1['user'] = self.user.display_name
66     el1['public'] = self.public.to_s
67     el1['pending'] = (!self.inserted).to_s
68     el1['timestamp'] = self.timestamp.xmlschema
69     return el1
70   end
71 end