Allow for different formats to the getBugs call
This is a rudimentary initial version of a GPX and a rss format for looking at bugs in an area.
This commit is contained in:
parent
eac7348ad2
commit
d0e291552e
5 changed files with 90 additions and 19 deletions
|
@ -30,25 +30,15 @@ class MapBugsController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
bugs = MapBug.find_by_area(min_lat, min_lon, max_lat, max_lon, :order => "last_changed DESC", :limit => 100, :conditions => "status != 'hidden'")
|
@bugs = MapBug.find_by_area(min_lat, min_lon, max_lat, max_lon, :order => "last_changed DESC", :limit => 100, :conditions => "status != 'hidden'")
|
||||||
|
|
||||||
resp = ""
|
respond_to do |format|
|
||||||
|
format.html {render :template => 'map_bugs/get_bugs.js', :content_type => "text/javascript"}
|
||||||
bugs.each do |bug|
|
format.rss {render :template => 'map_bugs/get_bugs.rss'}
|
||||||
resp += "putAJAXMarker(" + bug.id.to_s + ", " + bug.lon.to_s + ", " + bug.lat.to_s;
|
format.js
|
||||||
comment_no = 1
|
format.xml {render :template => 'map_bugs/get_bugs.xml'}
|
||||||
bug.map_bug_comment.each do |comment|
|
#format.gpx {render :text => "Rendering GPX"}
|
||||||
resp += (comment_no == 1 ? ", '" : "<hr />")
|
|
||||||
resp += comment.comment if comment.comment
|
|
||||||
resp += " [ "
|
|
||||||
resp += comment.commenter_name if comment.commenter_name
|
|
||||||
resp += " " + comment.date_created.to_s + " ]"
|
|
||||||
comment_no += 1
|
|
||||||
end
|
end
|
||||||
resp += (comment_no == 1 ? "," : "', ") + (bug.status=="open"?"0":"1") + ");\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
render :text => resp, :content_type => "text/javascript"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_bug
|
def add_bug
|
||||||
|
@ -104,11 +94,13 @@ class MapBugsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def rss
|
def rss
|
||||||
##TODO: needs to be implemented
|
request.format = :rss
|
||||||
|
get_bugs
|
||||||
end
|
end
|
||||||
|
|
||||||
def gpx_bugs
|
def gpx_bugs
|
||||||
##TODO: needs to be implemented
|
request.format = :xml
|
||||||
|
get_bugs
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_comment(bug, comment)
|
def add_comment(bug, comment)
|
||||||
|
|
|
@ -29,4 +29,20 @@ class MapBug < ActiveRecord::Base
|
||||||
self.save;
|
self.save;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def flatten_comment ( separator_char )
|
||||||
|
resp = ""
|
||||||
|
comment_no = 1
|
||||||
|
self.map_bug_comment.each do |comment|
|
||||||
|
resp += (comment_no == 1 ? "" : separator_char)
|
||||||
|
resp += comment.comment if comment.comment
|
||||||
|
resp += " [ "
|
||||||
|
resp += comment.commenter_name if comment.commenter_name
|
||||||
|
resp += " " + comment.date_created.to_s + " ]"
|
||||||
|
comment_no += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return resp
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
7
app/views/map_bugs/get_bugs.js.erb
Normal file
7
app/views/map_bugs/get_bugs.js.erb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<% if @bugs.empty? %>
|
||||||
|
|
||||||
|
<% else %>
|
||||||
|
<% @bugs.each do |bug| %>
|
||||||
|
putAJAXMarker(<%= bug.id.to_s %> , <%= bug.lon.to_s %> , <%= bug.lat.to_s %> , '<%= bug.flatten_comment("<hr />") %>', <%= (bug.status=="open"?"0":"1") %> );
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
33
app/views/map_bugs/get_bugs.rss.builder
Normal file
33
app/views/map_bugs/get_bugs.rss.builder
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
xml.instruct!
|
||||||
|
|
||||||
|
xml.rss("version" => "2.0",
|
||||||
|
"xmlns:geo" => "http://www.w3.org/2003/01/geo/wgs84_pos#",
|
||||||
|
"xmlns:georss" => "http://www.georss.org/georss") do
|
||||||
|
xml.channel do
|
||||||
|
xml.title "OpenStreetBugs"
|
||||||
|
xml.description "A list of bugs, reported, commented on or closed in your area"
|
||||||
|
xml.link url_for(:controller => "site", :action => "index", :only_path => false)
|
||||||
|
|
||||||
|
for bug in @bugs
|
||||||
|
xml.item do
|
||||||
|
if bug.status == "closed"
|
||||||
|
xml.title "Closed bug"
|
||||||
|
else if bug.map_bug_comment.length > 1
|
||||||
|
xml.title "Commented on bug"
|
||||||
|
else
|
||||||
|
xml.title "Created bug"
|
||||||
|
end end
|
||||||
|
|
||||||
|
xml.link url_for(:controller => "site", :action => "index", :only_path => false)
|
||||||
|
xml.description bug.flatten_comment("|")
|
||||||
|
if (!bug.map_bug_comment.empty?)
|
||||||
|
xml.author bug.map_bug_comment[-1].commenter_name
|
||||||
|
end
|
||||||
|
xml.pubDate bug.last_changed.to_s(:rfc822)
|
||||||
|
xml.geo :lat, bug.lat
|
||||||
|
xml.geo :long, bug.lon
|
||||||
|
xml.georss :point, "#{bug.lat} #{bug.lon}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
23
app/views/map_bugs/get_bugs.xml.builder
Normal file
23
app/views/map_bugs/get_bugs.xml.builder
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
xml.instruct!
|
||||||
|
|
||||||
|
|
||||||
|
xml.gpx("version" => "1.1",
|
||||||
|
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
|
||||||
|
"xsi:schemaLocation" => "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd") do
|
||||||
|
|
||||||
|
for bug in @bugs
|
||||||
|
xml.wpt("lon" => bug.lon, "lat" => bug.lat) do
|
||||||
|
xml.desc do
|
||||||
|
xml.cdata! bug.flatten_comment("<hr />")
|
||||||
|
end
|
||||||
|
xml.extension do
|
||||||
|
if bug.status = "open"
|
||||||
|
xml.closed "0"
|
||||||
|
else
|
||||||
|
xml.closed "1"
|
||||||
|
end
|
||||||
|
xml.id bug.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue