]> git.openstreetmap.org Git - rails.git/blob - app/controllers/map_bugs_controller.rb
An initial (incomplete) "proof of concept" integration of an OpenStreetBugs interface...
[rails.git] / app / controllers / map_bugs_controller.rb
1 class MapBugsController < ApplicationController
2
3   before_filter :check_api_readable
4   before_filter :check_api_writable, :only => [:add_bug, :close_bug, :edit_bug]
5   after_filter :compress_output
6   around_filter :api_call_handle_error, :api_call_timeout
7
8   # Help methods for checking boundary sanity and area size
9   include MapBoundary
10
11   def get_bugs
12
13         raise OSM::APIBadUserInput.new("No l was given") unless params['l']
14         raise OSM::APIBadUserInput.new("No r was given") unless params['r']
15         raise OSM::APIBadUserInput.new("No b was given") unless params['b']
16         raise OSM::APIBadUserInput.new("No t was given") unless params['t']
17
18         min_lon = params['l'].to_f
19         max_lon = params['r'].to_f
20         min_lat = params['b'].to_f
21         max_lat = params['t'].to_f
22         
23         # check boundary is sane and area within defined
24     # see /config/application.yml
25     begin
26       check_boundaries(min_lon, min_lat, max_lon, max_lat)
27     rescue Exception => err
28       report_error(err.message)
29       return
30     end
31
32         bugs = MapBug.find_by_area(min_lat, min_lon, max_lat, max_lon, :order => "last_changed DESC", :limit => 100, :conditions => "status != 'hidden'")
33
34         resp = ""
35         
36         bugs.each do |bug|
37           resp += "putAJAXMarker(" + bug.id.to_s + ", " + bug.lon.to_s + ", " + bug.lat.to_s + " , '" + bug.text + "'," + (bug.status=="open"?"0":"1") + ");\n"
38         end
39
40         render :text => resp, :content_type => "text/javascript"
41   end
42
43   def add_bug
44         raise OSM::APIBadUserInput.new("No lat was given") unless params['lat']
45         raise OSM::APIBadUserInput.new("No lon was given") unless params['lon']
46         raise OSM::APIBadUserInput.new("No text was given") unless params['text']
47
48         lon = params['lon'].to_f
49         lat = params['lat'].to_f
50         comment = params['text']
51
52     bug = MapBug.create_bug(lat, lon, comment)  
53  
54         render_ok
55   end
56
57   def edit_bug
58         raise OSM::APIBadUserInput.new("No id was given") unless params['id']
59         raise OSM::APIBadUserInput.new("No text was given") unless params['text']
60
61         id = params['id'].to_i
62
63         bug = MapBug.find_by_id(id);
64     bug.text += "<hr /> " + params['text']
65     bug.last_changed = Time.now.getutc;
66     bug.save;
67
68         render_ok
69   end
70
71   def close_bug
72         raise OSM::APIBadUserInput.new("No id was given") unless params['id']
73         
74         id = params['id'].to_i
75
76         bug = MapBug.find_by_id(id);
77         bug.close_bug;
78
79         render_ok
80   end 
81
82   def render_ok
83         output_js = :false
84         output_js = :true if params['format'] == "js"
85
86         if output_js == :true
87           render :text => "osbResponse();", :content_type => "text/javascript" 
88         else
89           render :text => "ok\n", :content_type => "text/html" 
90         end
91         
92   end
93
94   def rss
95         ##TODO: needs to be implemented
96   end
97
98   def gpx_bugs
99         ##TODO: needs to be implemented
100   end
101
102 end