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
25 limit = params['limit'] if ((params['limit']) && (params['limit'].to_i < 10000) && (params['limit'].to_i > 0))
28 # check boundary is sane and area within defined
29 # see /config/application.yml
31 check_boundaries(min_lon, min_lat, max_lon, max_lat)
32 rescue Exception => err
33 report_error(err.message)
37 @bugs = MapBug.find_by_area(min_lat, min_lon, max_lat, max_lon, :order => "last_changed DESC", :limit => limit, :conditions => "status != 'hidden'")
39 respond_to do |format|
40 format.html {render :template => 'map_bugs/get_bugs.js', :content_type => "text/javascript"}
41 format.rss {render :template => 'map_bugs/get_bugs.rss'}
43 format.xml {render :template => 'map_bugs/get_bugs.xml'}
44 format.json { render :json => @bugs.to_json(:methods => [:lat, :lon], :only => [:id, :status, :date_created], :include => { :map_bug_comment => { :only => [:commenter_name, :date_created, :comment]}}) }
45 #format.gpx {render :text => "Rendering GPX"}
50 raise OSM::APIBadUserInput.new("No lat was given") unless params['lat']
51 raise OSM::APIBadUserInput.new("No lon was given") unless params['lon']
52 raise OSM::APIBadUserInput.new("No text was given") unless params['text']
54 lon = params['lon'].to_f
55 lat = params['lat'].to_f
56 comment = params['text']
59 name = params['name'] if params['name'];
61 bug = MapBug.create_bug(lat, lon)
63 add_comment(bug, comment, name);
69 raise OSM::APIBadUserInput.new("No id was given") unless params['id']
70 raise OSM::APIBadUserInput.new("No text was given") unless params['text']
73 name = params['name'] if params['name'];
75 id = params['id'].to_i
77 bug = MapBug.find_by_id(id);
79 bug_comment = add_comment(bug, params['text'], name);
85 raise OSM::APIBadUserInput.new("No id was given") unless params['id']
87 id = params['id'].to_i
89 bug = MapBug.find_by_id(id);
97 output_js = :true if params['format'] == "js"
100 render :text => "osbResponse();", :content_type => "text/javascript"
102 render :text => "ok\n", :content_type => "text/html"
108 request.format = :rss
113 request.format = :xml
117 def add_comment(bug, comment, name)
119 bug_comment = bug.map_bug_comment.create(:date_created => t, :visible => true, :comment => comment);
121 bug_comment.commenter_id = @user.id
122 bug_comment.commenter_name = @user.display_name
124 bug_comment.commenter_ip = request.remote_ip
125 bug_comment.commenter_name = name + " (a)"