1 class MapBugsController < ApplicationController
3 before_filter :check_api_readable
4 before_filter :authorize_web, :only => [:add_bug, :close_bug, :edit_bug]
5 before_filter :check_api_writable, :only => [:add_bug, :close_bug, :edit_bug]
6 after_filter :compress_output
7 around_filter :api_call_handle_error, :api_call_timeout
9 # Help methods for checking boundary sanity and area size
14 raise OSM::APIBadUserInput.new("No l was given") unless params['l']
15 raise OSM::APIBadUserInput.new("No r was given") unless params['r']
16 raise OSM::APIBadUserInput.new("No b was given") unless params['b']
17 raise OSM::APIBadUserInput.new("No t was given") unless params['t']
19 min_lon = params['l'].to_f
20 max_lon = params['r'].to_f
21 min_lat = params['b'].to_f
22 max_lat = params['t'].to_f
24 # check boundary is sane and area within defined
25 # see /config/application.yml
27 check_boundaries(min_lon, min_lat, max_lon, max_lat)
28 rescue Exception => err
29 report_error(err.message)
33 @bugs = MapBug.find_by_area(min_lat, min_lon, max_lat, max_lon, :order => "last_changed DESC", :limit => 100, :conditions => "status != 'hidden'")
35 respond_to do |format|
36 format.html {render :template => 'map_bugs/get_bugs.js', :content_type => "text/javascript"}
37 format.rss {render :template => 'map_bugs/get_bugs.rss'}
39 format.xml {render :template => 'map_bugs/get_bugs.xml'}
40 #format.gpx {render :text => "Rendering GPX"}
45 raise OSM::APIBadUserInput.new("No lat was given") unless params['lat']
46 raise OSM::APIBadUserInput.new("No lon was given") unless params['lon']
47 raise OSM::APIBadUserInput.new("No text was given") unless params['text']
49 lon = params['lon'].to_f
50 lat = params['lat'].to_f
51 comment = params['text']
53 bug = MapBug.create_bug(lat, lon)
55 add_comment(bug, comment);
61 raise OSM::APIBadUserInput.new("No id was given") unless params['id']
62 raise OSM::APIBadUserInput.new("No text was given") unless params['text']
64 id = params['id'].to_i
66 bug = MapBug.find_by_id(id);
68 bug_comment = add_comment(bug, params['text']);
74 raise OSM::APIBadUserInput.new("No id was given") unless params['id']
76 id = params['id'].to_i
78 bug = MapBug.find_by_id(id);
86 output_js = :true if params['format'] == "js"
89 render :text => "osbResponse();", :content_type => "text/javascript"
91 render :text => "ok\n", :content_type => "text/html"
102 request.format = :xml
106 def add_comment(bug, comment)
108 bug_comment = bug.map_bug_comment.create(:date_created => t, :visible => true, :comment => comment);
110 bug_comment.commenter_id = @user.id
111 bug_comment.commenter_name = @user.display_name
113 bug_comment.commenter_ip = request.remote_ip
114 bug_comment.commenter_name = "anonymous (a)"