]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/changeset_controller.rb
Generate correct URLs for changeset feeds
[rails.git] / app / controllers / changeset_controller.rb
index f6d35b440f386f67c77674060db1d7465312a852..5c42013546fe6c84773c811f749e7c208809d7e0 100644 (file)
@@ -196,14 +196,19 @@ class ChangesetController < ApplicationController
   ##
   # query changesets by bounding box, time, user or open/closed status.
   def query
+    # find any bounding box
+    if params['bbox']
+      bbox = BoundingBox.from_bbox_params(params)
+    end
+
     # create the conditions that the user asked for. some or all of
     # these may be nil.
     changesets = Changeset.scoped
-    changesets, bbox = conditions_bbox(changesets, params)
-    changesets       = conditions_user(changesets, params['user'], params['display_name'])
-    changesets       = conditions_time(changesets, params['time'])
-    changesets       = conditions_open(changesets, params['open'])
-    changesets       = conditions_closed(changesets, params['closed'])
+    changesets = conditions_bbox(changesets, bbox)
+    changesets = conditions_user(changesets, params['user'], params['display_name'])
+    changesets = conditions_time(changesets, params['time'])
+    changesets = conditions_open(changesets, params['open'])
+    changesets = conditions_closed(changesets, params['closed'])
 
     # create the results document
     results = OSM::API.new.get_xml_doc
@@ -241,8 +246,6 @@ class ChangesetController < ApplicationController
     end
   end
 
-  
-  
   ##
   # list edits (open changesets) in reverse chronological order
   def list
@@ -264,12 +267,18 @@ class ChangesetController < ApplicationController
           @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
-      
-      changesets, bbox = conditions_bbox(changesets, params)
+
+      if params[:bbox]
+        bbox = BoundingBox.from_bbox_params(params)
+      elsif params[:minlon] and params[:minlat] and params[:maxlon] and params[:maxlat]
+        bbox = BoundingBox.from_lon_lat_params(params)
+      end
 
       if bbox
+        changesets = conditions_bbox(changesets, bbox)
         bbox_link = render_to_string :partial => "bbox", :object => bbox
       end
       
@@ -302,6 +311,14 @@ class ChangesetController < ApplicationController
       
       @edits = changesets.order("changesets.created_at DESC").offset((@page - 1) * @page_size).limit(@page_size).preload(:user, :changeset_tags)
     end
+
+    render :action => :list
+  end
+
+  ##
+  # list edits as an atom feed
+  def feed
+    list
   end
 
 private
@@ -313,21 +330,15 @@ private
   # if a bounding box was specified do some sanity checks.
   # restrict changesets to those enclosed by a bounding box
   # we need to return both the changesets and the bounding box
-  def conditions_bbox(changesets, params)
-    if params[:bbox]
-      bbox = BoundingBox.from_bbox_params(params)
-    elsif params[:minlon] and params[:minlat] and params[:maxlon] and params[:maxlat]
-      bbox = BoundingBox.from_lon_lat_params(params)
-    end
+  def conditions_bbox(changesets, bbox)
     if  bbox
       bbox.check_boundaries
       bbox = bbox.to_scaled
       return changesets.where("min_lon < ? and max_lon > ? and min_lat < ? and max_lat > ?",
                               bbox.max_lon.to_i, bbox.min_lon.to_i,
-                              bbox.max_lat.to_i, bbox.min_lat.to_i),
-                              bbox
+                              bbox.max_lat.to_i, bbox.min_lat.to_i)
     else
-      return changesets, bbox
+      return changesets
     end
   end