From: Tom Hughes Date: Wed, 28 Jul 2010 20:30:55 +0000 (+0100) Subject: Merge branch 'master' into openstreetbugs X-Git-Tag: live~5096^2~204 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/52395b3cdf4d3cfae95730158edeeccf3d062a8e?hp=72984673067a37a1ea687709a33b18263f850633 Merge branch 'master' into openstreetbugs --- diff --git a/app/controllers/browse_controller.rb b/app/controllers/browse_controller.rb index 9aec1060a..2962c6836 100644 --- a/app/controllers/browse_controller.rb +++ b/app/controllers/browse_controller.rb @@ -77,4 +77,13 @@ class BrowseController < ApplicationController rescue ActiveRecord::RecordNotFound render :action => "not_found", :status => :not_found end + + def bug + @type = "bug" + @bug = MapBug.find(params[:id]) + @next = MapBug.find(:first, :order => "id ASC", :conditions => [ "status != 'hidden' AND id > :id", { :id => @bug.id }] ) + @prev = MapBug.find(:first, :order => "id DESC", :conditions => [ "status != 'hidden' AND id < :id", { :id => @bug.id }] ) + rescue ActiveRecord::RecordNotFound + render :action => "not_found", :status => :not_found + end end diff --git a/app/controllers/map_bugs_controller.rb b/app/controllers/map_bugs_controller.rb new file mode 100644 index 000000000..41881cfb7 --- /dev/null +++ b/app/controllers/map_bugs_controller.rb @@ -0,0 +1,317 @@ +class MapBugsController < ApplicationController + + layout 'site', :only => [:my_bugs] + + before_filter :check_api_readable + before_filter :authorize_web, :only => [:add_bug, :close_bug, :edit_bug, :delete, :my_bugs] + before_filter :check_api_writable, :only => [:add_bug, :close_bug, :edit_bug, :delete] + before_filter :require_moderator, :only => [:delete] + before_filter :set_locale, :only => [:my_bugs] + after_filter :compress_output + around_filter :api_call_handle_error, :api_call_timeout + + # Help methods for checking boundary sanity and area size + include MapBoundary + + def get_bugs + + # Figure out the bbox + bbox = params['bbox'] + + if bbox and bbox.count(',') == 3 + bbox = bbox.split(',') + @min_lon, @min_lat, @max_lon, @max_lat = sanitise_boundaries(bbox) + else + #Fallback to old style, this is deprecated and should not be used + raise OSM::APIBadUserInput.new("No l was given") unless params['l'] + raise OSM::APIBadUserInput.new("No r was given") unless params['r'] + raise OSM::APIBadUserInput.new("No b was given") unless params['b'] + raise OSM::APIBadUserInput.new("No t was given") unless params['t'] + + @min_lon = params['l'].to_f + @max_lon = params['r'].to_f + @min_lat = params['b'].to_f + @max_lat = params['t'].to_f + end + limit = getLimit + conditions = closedCondition + + check_boundaries(@min_lon, @min_lat, @max_lon, @max_lat, :false) + + @bugs = MapBug.find_by_area_no_quadtile(@min_lat, @min_lon, @max_lat, @max_lon, :include => :map_bug_comment, :order => "last_changed DESC", :limit => limit, :conditions => conditions) + + respond_to do |format| + format.html {render :template => 'map_bugs/get_bugs.js', :content_type => "text/javascript"} + format.rss {render :template => 'map_bugs/get_bugs.rss'} + format.js + format.xml {render :template => 'map_bugs/get_bugs.xml'} + 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]}}) } +# format.gpx {render :template => 'map_bugs/get_bugs.gpx'} + end + end + + def add_bug + raise OSM::APIBadUserInput.new("No lat was given") unless params['lat'] + raise OSM::APIBadUserInput.new("No lon was given") unless params['lon'] + raise OSM::APIBadUserInput.new("No text was given") unless params['text'] + + lon = params['lon'].to_f + lat = params['lat'].to_f + comment = params['text'] + + name = "NoName"; + name = params['name'] if params['name']; + + #Include in a transaction to ensure that there is always a map_bug_comment for every map_bug + MapBug.transaction do + @bug = MapBug.create_bug(lat, lon) + + + #TODO: move this into a helper function + begin + url = "http://nominatim.openstreetmap.org/reverse?lat=" + lat.to_s + "&lon=" + lon.to_s + "&zoom=16" + response = REXML::Document.new(Net::HTTP.get(URI.parse(url))) + + if result = response.get_text("reversegeocode/result") + @bug.nearby_place = result.to_s + else + @bug.nearby_place = "unknown" + end + rescue Exception => err + @bug.nearby_place = "unknown" + end + + @bug.save; + add_comment(@bug, comment, name,"opened"); + end + + render_ok + end + + def edit_bug + raise OSM::APIBadUserInput.new("No id was given") unless params['id'] + raise OSM::APIBadUserInput.new("No text was given") unless params['text'] + + name = "NoName"; + name = params['name'] if params['name']; + + id = params['id'].to_i + + bug = MapBug.find_by_id(id); + raise OSM::APINotFoundError unless bug + raise OSM::APIAlreadyDeletedError unless bug.visible + + MapBug.transaction do + bug_comment = add_comment(bug, params['text'], name,"commented"); + end + + render_ok + end + + def close_bug + raise OSM::APIBadUserInput.new("No id was given") unless params['id'] + + id = params['id'].to_i + name = "NoName"; + name = params['name'] if params['name']; + + bug = MapBug.find_by_id(id); + raise OSM::APINotFoundError unless bug + raise OSM::APIAlreadyDeletedError unless bug.visible + + MapBug.transaction do + bug.close_bug; + add_comment(bug,:nil,name,"closed") + end + + render_ok + end + + + def rss + + # Figure out the bbox + bbox = params['bbox'] + + if bbox and bbox.count(',') == 3 + bbox = bbox.split(',') + @min_lon, @min_lat, @max_lon, @max_lat = sanitise_boundaries(bbox) + else + @min_lon = -180.0 + @min_lat = -90.0 + @max_lon = 180.0 + @max_lat = 90.0 + end + limit = getLimit + conditions = closedCondition + conditions = cond_merge conditions, [OSM.sql_for_area_no_quadtile(@min_lat, @min_lon, @max_lat, @max_lon)] + + check_boundaries(@min_lon, @min_lat, @max_lon, @max_lat, :false) + + @comments = MapBugComment.find(:all, :limit => limit, :order => "date_created DESC", :joins => :map_bug, :include => :map_bug, :conditions => conditions); + render :template => 'map_bugs/rss.rss' + end + + def gpx_bugs + request.format = :xml + get_bugs + end + + def read + @bug = MapBug.find(params['id']) + raise OSM::APINotFoundError unless @bug + raise OSM::APIAlreadyDeletedError unless @bug.visible + + respond_to do |format| + format.rss + format.xml + format.json { render :json => @bug.to_json(:methods => [:lat, :lon], :only => [:id, :status, :date_created], :include => { :map_bug_comment => { :only => [:commenter_name, :date_created, :comment]}}) } + end + end + + def delete + bug = MapBug.find(params['id']) + raise OSM::APINotFoundError unless @bug + raise OSM::APIAlreadyDeletedError unless @bug.visible + MapBug.transaction do + bug.status = "hidden"; + bug.save + add_comment(bug,:nil,name,"hidden") + end + + render :text => "ok\n", :content_type => "text/html" + end + + def search + raise OSM::APIBadUserInput.new("No query string was given") unless params['q'] + limit = getLimit + conditions = closedCondition + conditions = cond_merge conditions, ['map_bug_comment.comment ~ ?', params['q']] + + #TODO: There should be a better way to do this. CloseConditions are ignored at the moment + + bugs2 = MapBug.find(:all, :limit => limit, :order => "last_changed DESC", :joins => :map_bug_comment, :include => :map_bug_comment, + :conditions => conditions) + @bugs = bugs2.uniq + respond_to do |format| + format.html {render :template => 'map_bugs/get_bugs.js', :content_type => "text/javascript"} + format.rss {render :template => 'map_bugs/get_bugs.rss'} + format.js + format.xml {render :template => 'map_bugs/get_bugs.xml'} + 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]}}) } +# format.gpx {render :template => 'map_bugs/get_bugs.gpx'} + end + end + + def my_bugs + + if params[:display_name] + @user2 = User.find_by_display_name(params[:display_name], :conditions => { :visible => true }) + + if @user2 + if @user2.data_public? or @user2 == @user + conditions = ['map_bug_comment.commenter_id = ?', @user2.id] + else + conditions = ['false'] + end + else #if request.format == :html + @title = t 'user.no_such_user.title' + @not_found_user = params[:display_name] + render :template => 'user/no_such_user', :status => :not_found + return + end + end + + if @user2 + user_link = render_to_string :partial => "user", :object => @user2 + end + + @title = t 'bugs.user.title_user', :user => @user2.display_name + @heading = t 'bugs.user.heading_user', :user => @user2.display_name + @description = t 'bugs.user.description_user', :user => user_link + + @page = (params[:page] || 1).to_i + @page_size = 10 + + @bugs = MapBug.find(:all, + :include => [:map_bug_comment, {:map_bug_comment => :user}], + :joins => :map_bug_comment, + :order => "last_changed DESC", + :conditions => conditions, + :offset => (@page - 1) * @page_size, + :limit => @page_size).uniq + + end + +private + #------------------------------------------------------------ + # utility functions below. + #------------------------------------------------------------ + + ## + # merge two conditions + # TODO: this is a copy from changeset_controler.rb and should be factored out to share + def cond_merge(a, b) + if a and b + a_str = a.shift + b_str = b.shift + return [ a_str + " AND " + b_str ] + a + b + elsif a + return a + else b + return b + end + end + + + + def render_ok + output_js = :false + output_js = :true if params['format'] == "js" + + if output_js == :true + render :text => "osbResponse();", :content_type => "text/javascript" + else + render :text => "ok " + @bug.id.to_s + "\n", :content_type => "text/html" if @bug + render :text => "ok\n", :content_type => "text/html" unless @bug + end + end + + def getLimit + limit = 100; + limit = params['limit'] if ((params['limit']) && (params['limit'].to_i < 10000) && (params['limit'].to_i > 0)) + return limit + end + + def closedCondition + closed_since = 7 unless params['closed'] + closed_since = params['closed'].to_i if params['closed'] + + if closed_since < 0 + conditions = ["status != 'hidden'"] + elsif closed_since > 0 + conditions = ["((status = 'open') OR ((status = 'closed' ) AND (date_closed > '" + (Time.now - closed_since.days).to_s + "')))"] + else + conditions = ["status = 'open'"] + end + + return conditions + end + + def add_comment(bug, comment, name,event) + t = Time.now.getutc + bug_comment = bug.map_bug_comment.create(:date_created => t, :visible => true, :event => event); + bug_comment.comment = comment unless comment == :nil + if @user + bug_comment.commenter_id = @user.id + bug_comment.commenter_name = @user.display_name + else + bug_comment.commenter_ip = request.remote_ip + bug_comment.commenter_name = name + " (a)" + end + bug_comment.save; + bug.last_changed = t + bug.save + end + +end diff --git a/app/models/map_bug.rb b/app/models/map_bug.rb new file mode 100644 index 000000000..0effe38dd --- /dev/null +++ b/app/models/map_bug.rb @@ -0,0 +1,57 @@ +class MapBug < ActiveRecord::Base + include GeoRecord + + set_table_name 'map_bugs' + + validates_presence_of :id, :on => :update + validates_uniqueness_of :id + validates_numericality_of :latitude, :only_integer => true + validates_numericality_of :longitude, :only_integer => true + validates_presence_of :date_created + validates_presence_of :last_changed + validates_prensence_of :date_closed if :status == "closed" + validates_inclusion_of :status, :in => [ "open", "closed", "hidden" ] + + has_many :map_bug_comment, :foreign_key => :bug_id, :order => :date_created, :conditions => "visible = true and comment is not null" + + + def self.create_bug(lat, lon) + bug = MapBug.new(:lat => lat, :lon => lon); + raise OSM::APIBadUserInput.new("The node is outside this world") unless bug.in_world? + bug.date_created = Time.now.getutc + bug.last_changed = Time.now.getutc + bug.status = "open"; + return bug; + end + + def close_bug + self.status = "closed" + close_time = Time.now.getutc + self.last_changed = close_time + self.date_closed = close_time + + self.save; + end + + def flatten_comment ( separator_char, upto_timestamp = :nil) + resp = "" + comment_no = 1 + self.map_bug_comment.each do |comment| + next if upto_timestamp != :nil and comment.date_created > upto_timestamp + 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 + + def visible + return status != "hidden" + end + +end diff --git a/app/models/map_bug_comment.rb b/app/models/map_bug_comment.rb new file mode 100644 index 000000000..166e3fb42 --- /dev/null +++ b/app/models/map_bug_comment.rb @@ -0,0 +1,15 @@ +class MapBugComment < ActiveRecord::Base + + set_table_name 'map_bug_comment' + + belongs_to :map_bug, :foreign_key => 'bug_id' + belongs_to :user, :foreign_key => 'commenter_id' + + validates_inclusion_of :event, :in => [ "opened", "closed", "reopened", "commented", "hidden" ] + + validates_presence_of :id, :on => :update + validates_uniqueness_of :id + validates_presence_of :visible + validates_presence_of :date_created + +end diff --git a/app/views/browse/_map.html.erb b/app/views/browse/_map.html.erb index f41deff95..0b7f76f23 100644 --- a/app/views/browse/_map.html.erb +++ b/app/views/browse/_map.html.erb @@ -38,6 +38,14 @@ $("area_larger_map").href = '/?minlon='+minlon+'&minlat='+minlat+'&maxlon='+maxlon+'&maxlat='+maxlat+'&box=yes'; $("area_larger_map").innerHTML = "<%= t 'browse.map.larger.area' %>"; + <% else if map.instance_of? MapBug %> + $("loading").innerHTML = ""; + var centre = new OpenLayers.LonLat(<%= map.lon %>, <%= map.lat %>); + var zoom = 16; + setMapCenter(centre, zoom); + marker = addMarkerToMap(centre); + $("area_larger_map").href = '/?mlon=<%= map.lon %>&mlat=<%=map.lat %>'; + $("area_larger_map").innerHTML = "<%= t 'browse.map.larger.area' %>"; <% else %> var obj_type = "<%= map.class.name.downcase %>"; var obj_id = <%= map.id %>; @@ -64,7 +72,7 @@ $("small_map").style.display = "none"; } }); - <% end %> + <% end end %> } window.onload = init; diff --git a/app/views/browse/bug.html.erb b/app/views/browse/bug.html.erb new file mode 100644 index 000000000..5c65b3e41 --- /dev/null +++ b/app/views/browse/bug.html.erb @@ -0,0 +1,87 @@ + + + + + + + + <%= render :partial => "map", :object => @bug %> + +
+

+ <% if @bug.status == "closed" %> + <%= image_tag("closed_bug_marker.png", :alt => 'closed') %> + <%= t'browse.bug.closed_title', :bug_name => @bug.id %> + <% else %> + <%= image_tag("open_bug_marker.png", :alt => 'open') %> + <%= t'browse.bug.open_title', :bug_name => @bug.id %> + <% end %> +

+
+ <%= render :partial => "navigation" %> +
+ + + + + + + + + + + <% if @bug.status == "closed" %> + + + + + <% end %> + + + <% if @bug.map_bug_comment[0].user.nil? %> + + <% else %> + + <% end %> + + + + + + + + + + + +
<%= t 'browse.bug.created_at' %><%= l @bug.date_created %>
<%= t 'browse.bug.edited_at' %><%= l @bug.last_changed %>
<%= t 'browse.bug.closed_at' %><%= l @bug.date_closed %>
<%= t 'browse.bug.opened_by' %> <%= @bug.map_bug_comment[0].commenter_name %> <%= link_to h(@bug.map_bug_comment[0].user.display_name), :controller => "user", :action => "view", :display_name => @bug.map_bug_comment[0].user.display_name %>
<%= t 'browse.bug.description' %><%= h(@bug.map_bug_comment[0].comment) %>
<%= t 'browse.node_details.coordinates' %>
<%= link_to ("#{number_with_delimiter(@bug.lat)}, #{number_with_delimiter(@bug.lon)}"), {:controller => 'site', :action => 'index', :lat => h(@bug.lat), :lon => h(@bug.lon), :zoom => "18"} %>
+ +
+ + <%if @bug.map_bug_comment.length > 1 %> + + + + + + <% @bug.map_bug_comment[1..-1].each do |bug_comment| %> + + + + + + + <% end %> +
<%= t 'browse.bug.comment_by' %> <%= t 'browse.bug.comment' %> <%= t 'browse.bug.date' %>
+ <% if bug_comment.user.nil? %> + <%= bug_comment.commenter_name %> + <% else %> + <%= link_to h(bug_comment.user.display_name), :controller => "user", :action => "view", :display_name => bug_comment.user.display_name %> + <% end %> + <%= h(bug_comment.comment) %> <%= l bug_comment.date_created %>
+ + <% end %> + +
+ +
\ No newline at end of file diff --git a/app/views/map_bugs/_bugs_paging_nav.html.erb b/app/views/map_bugs/_bugs_paging_nav.html.erb new file mode 100644 index 000000000..3de179008 --- /dev/null +++ b/app/views/map_bugs/_bugs_paging_nav.html.erb @@ -0,0 +1,17 @@ +

+ +<% if @page > 1 %> +<%= link_to t('changeset.changeset_paging_nav.previous'), params.merge({ :page => @page - 1 }) %> +<% else %> +<%= t('changeset.changeset_paging_nav.previous') %> +<% end %> + +| <%= t('changeset.changeset_paging_nav.showing_page', :page => @page) %> | + +<% if @bugs.size < @page_size %> +<%= t('changeset.changeset_paging_nav.next') %> +<% else %> +<%= link_to t('changeset.changeset_paging_nav.next'), params.merge({ :page => @page + 1 }) %> +<% end %> + +

diff --git a/app/views/map_bugs/_user.html.erb b/app/views/map_bugs/_user.html.erb new file mode 100644 index 000000000..0e9507650 --- /dev/null +++ b/app/views/map_bugs/_user.html.erb @@ -0,0 +1 @@ +<%= link_to user.display_name, :controller => "user", :action => "view", :display_name => user.display_name %> diff --git a/app/views/map_bugs/get_bugs.gpx.builder b/app/views/map_bugs/get_bugs.gpx.builder new file mode 100644 index 000000000..be7e9cf7a --- /dev/null +++ b/app/views/map_bugs/get_bugs.gpx.builder @@ -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("
") + end + xml.extension do + if bug.status = "open" + xml.closed "0" + else + xml.closed "1" + end + xml.id bug.id + end + end + end +end diff --git a/app/views/map_bugs/get_bugs.js.erb b/app/views/map_bugs/get_bugs.js.erb new file mode 100644 index 000000000..5bc9aafda --- /dev/null +++ b/app/views/map_bugs/get_bugs.js.erb @@ -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 %> , '<%= escape_javascript(bug.flatten_comment("
")) %>', <%= (bug.status=="open"?"0":"1") %> ); + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/map_bugs/get_bugs.rss.builder b/app/views/map_bugs/get_bugs.rss.builder new file mode 100644 index 000000000..a8ae98dc8 --- /dev/null +++ b/app/views/map_bugs/get_bugs.rss.builder @@ -0,0 +1,34 @@ +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 t('bugs.rss.description_area', :min_lat => @min_lat, :min_lon => @min_lon, :max_lat => @max_lat, :max_lon => @max_lon ) + xml.link url_for(:controller => "site", :action => "index", :only_path => false) + + for bug in @bugs + xml.item do + if bug.status == "closed" + xml.title t('bugs.rss.closed', :place => bug.nearby_place) + else if bug.map_bug_comment.length > 1 + xml.title t('bugs.rss.comment', :place => bug.nearby_place) + else + xml.title t('bugs.rss.new', :place => bug.nearby_place) + end end + + xml.link url_for(:controller => "browse", :action => "bug", :id => bug.id, :only_path => false) + xml.guid url_for(:controller => "browse", :action => "bug", :id => bug.id, :only_path => false) + xml.description htmlize(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 diff --git a/app/views/map_bugs/get_bugs.xml.builder b/app/views/map_bugs/get_bugs.xml.builder new file mode 100644 index 000000000..a594506cd --- /dev/null +++ b/app/views/map_bugs/get_bugs.xml.builder @@ -0,0 +1,29 @@ +xml.instruct! + +xml.bugs do + for bug in @bugs + xml.bug("lon" => bug.lon, "lat" => bug.lat) do + xml.id bug.id + xml.date_created bug.date_created + xml.nearby bug.nearby_place + xml.status bug.status + if bug.status == "closed" + xml.date_closed bug.date_closed + end + xml.comments do + for comment in bug.map_bug_comment + xml.comment do + xml.date comment.date_created + if !comment.commenter_id.nil? + xml.uid comment.commenter_id + xml.user comment.user.display_name + else + xml.user comment.commenter_name + end + xml.text comment.comment + end + end + end + end + end +end diff --git a/app/views/map_bugs/my_bugs.html.erb b/app/views/map_bugs/my_bugs.html.erb new file mode 100644 index 000000000..97e570060 --- /dev/null +++ b/app/views/map_bugs/my_bugs.html.erb @@ -0,0 +1,45 @@ +

<%= @heading %>

+

<%= @description %>

+ +<%= render :partial => 'bugs_paging_nav' %> + + + + + + + + + + + + +<% @bugs.each do |bug| %> +<% if bug.map_bug_comment[0].user == @user2 %> + +<% else %> + +<% end %> + + + + <% if bug.map_bug_comment[0].user.nil? %> + + <% else %> + + <% end %> + + + + +<% end %> +
<%= t'bugs.user.id' %><%= t'changeset.changesets.user' %><%= t'changeset.changesets.comment' %><%= t'changeset.changesets.saved_at' %><%= t'bugs.user.last_changed' %>
+ <% if bug.status == "closed" %> + <%= image_tag("closed_bug_marker.png", :alt => 'closed') %> + <% else %> + <%= image_tag("open_bug_marker.png", :alt => 'open') %> + <% end %> + <%= link_to bug.id.to_s, :controller => "browse", :action => "bug", :id => bug.id %> <%= bug.map_bug_comment[0].commenter_name %> <%= link_to h(bug.map_bug_comment[0].user.display_name), :controller => "user", :action => "view", :display_name => bug.map_bug_comment[0].user.display_name %> <%= htmlize bug.map_bug_comment[0].comment %> <%= l bug.date_created %><%= l bug.last_changed %>
+ + +<%= render :partial => 'bugs_paging_nav' %> diff --git a/app/views/map_bugs/read.rss.builder b/app/views/map_bugs/read.rss.builder new file mode 100644 index 000000000..501ed6bf8 --- /dev/null +++ b/app/views/map_bugs/read.rss.builder @@ -0,0 +1,32 @@ +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 t('bugs.rss.description_item',:id => @bug.id) + xml.link url_for(:controller => "site", :action => "index", :only_path => false) + + xml.item do + if @bug.status == "closed" + xml.title t('bugs.rss.closed', :place => @bug.nearby_place) + else if @bug.map_bug_comment.length > 1 + xml.title t('bugs.rss.comment', :place => @bug.nearby_place) + else + xml.title t('bugs.rss.new', :place => @bug.nearby_place) + end end + + xml.link url_for(:controller => "browse", :action => "bug", :id => @bug.id, :only_path => false) + xml.guid url_for(:controller => "map_bugs", :action => "read", :id => @bug.id, :only_path => false) + xml.description htmlize(@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 diff --git a/app/views/map_bugs/read.xml.builder b/app/views/map_bugs/read.xml.builder new file mode 100644 index 000000000..f9d7ddaa1 --- /dev/null +++ b/app/views/map_bugs/read.xml.builder @@ -0,0 +1,25 @@ +xml.instruct! + +xml.bug("lon" => @bug.lon, "lat" => @bug.lat) do + xml.id @bug.id + xml.date_created @bug.date_created + xml.nearby @bug.nearby_place + xml.status @bug.status + if @bug.status == "closed" + xml.date_closed @bug.date_closed + end + xml.comments do + for comment in @bug.map_bug_comment + xml.comment do + xml.date comment.date_created + if !comment.commenter_id.nil? + xml.uid comment.commenter_id + xml.user comment.user.display_name + else + xml.user comment.commenter_name + end + xml.text comment.comment + end + end + end +end diff --git a/app/views/map_bugs/rss.rss.builder b/app/views/map_bugs/rss.rss.builder new file mode 100644 index 000000000..a6487a024 --- /dev/null +++ b/app/views/map_bugs/rss.rss.builder @@ -0,0 +1,49 @@ +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 t('bugs.rss.description_area', :min_lat => @min_lat, :min_lon => @min_lon, :max_lat => @max_lat, :max_lon => @max_lon ) + xml.link url_for(:controller => "site", :action => "index", :only_path => false) + + for comment in @comments + xml.item do + if comment.event == "closed" + xml.title t('bugs.rss.closed', :place => comment.map_bug.nearby_place) + else if comment.event == "commented" + xml.title t('bugs.rss.comment', :place => comment.map_bug.nearby_place) + else if comment.event == "opened" + xml.title t('bugs.rss.new', :place => comment.map_bug.nearby_place) + else + xml.title "unknown event" + end end end + + xml.link url_for(:controller => "browse", :action => "bug", :id => comment.map_bug.id, :only_path => false) + xml.guid url_for(:controller => "browse", :action => "bug", :id => comment.map_bug.id, :only_path => false) + + description_text = "" + if (comment.event == "commented") and (not comment.nil?) + description_text += " Comment:
" + description_text += htmlize(comment.comment) + description_text += "
" + end + description_text += " Full bug report:
" + description_text += comment.map_bug.flatten_comment("
", comment.date_created) + xml.description description_text + + if (comment.user.nil?) + xml.author comment.commenter_name + else + xml.author comment.user.display_name + end + + xml.pubDate comment.date_created.to_s(:rfc822) + xml.geo :lat, comment.map_bug.lat + xml.geo :long, comment.map_bug.lon + xml.georss :point, "#{comment.map_bug.lat} #{comment.map_bug.lon}" + end + end + end +end diff --git a/app/views/site/index.html.erb b/app/views/site/index.html.erb index 636e6929c..9098c1a88 100644 --- a/app/views/site/index.html.erb +++ b/app/views/site/index.html.erb @@ -19,7 +19,8 @@
@@ -110,8 +111,11 @@ else end %> -<%= javascript_include_tag '/openlayers/OpenLayers.js' %> + + + <%= javascript_include_tag '/openlayers/OpenStreetMap.js' %> +<%= javascript_include_tag 'openstreetbugs.js' %> <%= javascript_include_tag 'map.js' %>