]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/map_bugs_controller.rb
Allow for different formats to the getBugs call
[rails.git] / app / controllers / map_bugs_controller.rb
index d3a62f553d3706db9f8927993e692fa0b6f25535..5064f088693160a51c6f0d8a7db59dd2135478bc 100644 (file)
@@ -1,6 +1,7 @@
 class MapBugsController < ApplicationController
 
   before_filter :check_api_readable
+  before_filter :authorize_web, :only => [:add_bug, :close_bug, :edit_bug]
   before_filter :check_api_writable, :only => [:add_bug, :close_bug, :edit_bug]
   after_filter :compress_output
   around_filter :api_call_handle_error, :api_call_timeout
@@ -29,15 +30,15 @@ class MapBugsController < ApplicationController
       return
     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 = ""
-       
-       bugs.each do |bug|
-         resp += "putAJAXMarker(" + bug.id.to_s + ", " + bug.lon.to_s + ", " + bug.lat.to_s + " , '" + bug.text + "'," + (bug.status=="open"?"0":"1") + ");\n"
+       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.gpx {render :text => "Rendering GPX"}
        end
-
-       render :text => resp, :content_type => "text/javascript"
   end
 
   def add_bug
@@ -49,7 +50,9 @@ class MapBugsController < ApplicationController
        lat = params['lat'].to_f
        comment = params['text']
 
-    bug = MapBug.create_bug(lat, lon, comment) 
+    bug = MapBug.create_bug(lat, lon)
+       bug.save;
+       add_comment(bug, comment);
  
        render_ok
   end
@@ -61,9 +64,8 @@ class MapBugsController < ApplicationController
        id = params['id'].to_i
 
        bug = MapBug.find_by_id(id);
-    bug.text += "<hr /> " + params['text']
-    bug.last_changed = Time.now.getutc;
-    bug.save;
+
+       bug_comment = add_comment(bug, params['text']);
 
        render_ok
   end
@@ -92,11 +94,28 @@ class MapBugsController < ApplicationController
   end
 
   def rss
-       ##TODO: needs to be implemented
+       request.format = :rss
+       get_bugs
   end
 
   def gpx_bugs
-       ##TODO: needs to be implemented
+       request.format = :xml
+       get_bugs
+  end
+
+  def add_comment(bug, comment) 
+    t = Time.now.getutc 
+    bug_comment = bug.map_bug_comment.create(:date_created => t, :visible => true, :comment => comment);  
+    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 = "anonymous (a)"
+    end
+    bug_comment.save; 
+    bug.last_changed = t 
+    bug.save 
   end
 
 end