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'")
38 resp += "putAJAXMarker(" + bug.id.to_s + ", " + bug.lon.to_s + ", " + bug.lat.to_s;
40 bug.map_bug_comment.each do |comment|
41 resp += (comment_no == 1 ? ", '" : "<hr />")
42 resp += comment.comment if comment.comment
44 resp += comment.commenter_name if comment.commenter_name
45 resp += " " + comment.date_created.to_s + " ]"
48 resp += (comment_no == 1 ? "," : "', ") + (bug.status=="open"?"0":"1") + ");\n"
51 render :text => resp, :content_type => "text/javascript"
55 raise OSM::APIBadUserInput.new("No lat was given") unless params['lat']
56 raise OSM::APIBadUserInput.new("No lon was given") unless params['lon']
57 raise OSM::APIBadUserInput.new("No text was given") unless params['text']
59 lon = params['lon'].to_f
60 lat = params['lat'].to_f
61 comment = params['text']
63 bug = MapBug.create_bug(lat, lon)
65 add_comment(bug, comment);
71 raise OSM::APIBadUserInput.new("No id was given") unless params['id']
72 raise OSM::APIBadUserInput.new("No text was given") unless params['text']
74 id = params['id'].to_i
76 bug = MapBug.find_by_id(id);
78 bug_comment = add_comment(bug, params['text']);
84 raise OSM::APIBadUserInput.new("No id was given") unless params['id']
86 id = params['id'].to_i
88 bug = MapBug.find_by_id(id);
96 output_js = :true if params['format'] == "js"
99 render :text => "osbResponse();", :content_type => "text/javascript"
101 render :text => "ok\n", :content_type => "text/html"
107 ##TODO: needs to be implemented
111 ##TODO: needs to be implemented
114 def add_comment(bug, comment)
116 bug_comment = bug.map_bug_comment.create(:date_created => t, :visible => true, :comment => comment);
118 bug_comment.commenter_id = @user.id
119 bug_comment.commenter_name = @user.display_name
121 bug_comment.commenter_ip = request.remote_ip
122 bug_comment.commenter_name = "anonymous (a)"