]> git.openstreetmap.org Git - rails.git/commitdiff
Use some rails magic to avoid having to duplicate all the changeset
authorTom Hughes <tom@compton.nu>
Sun, 7 Jun 2009 11:24:11 +0000 (11:24 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 7 Jun 2009 11:24:11 +0000 (11:24 +0000)
list controller methods for the RSS feeds.

app/controllers/changeset_controller.rb
app/views/changeset/list.rxml [moved from app/views/changeset/list_rss.rxml with 99% similarity]
app/views/changeset/list_bbox.rxml [moved from app/views/changeset/list_bbox_rss.rxml with 99% similarity]
app/views/changeset/list_user.rxml [moved from app/views/changeset/list_user_rss.rxml with 99% similarity]
app/views/layouts/site.rxml [new file with mode: 0644]
config/routes.rb

index 3d5c8dd4bf1ebd7d278d0ec595466fbe15b48c94..8d029aae50d10078483c9ba9961ff7cb1566f5d5 100644 (file)
@@ -1,7 +1,7 @@
 # The ChangesetController is the RESTful interface to Changeset objects
 
 class ChangesetController < ApplicationController
 # The ChangesetController is the RESTful interface to Changeset objects
 
 class ChangesetController < ApplicationController
-  layout 'site', :except => [ :list_rss, :list_user_rss, :list_bbox_rss ]
+  layout 'site'
   require 'xml/libxml'
 
   before_filter :authorize_web, :only => [:list, :list_user, :list_bbox]
   require 'xml/libxml'
 
   before_filter :authorize_web, :only => [:list, :list_user, :list_bbox]
@@ -255,35 +255,20 @@ class ChangesetController < ApplicationController
   # list edits (open changesets) in reverse chronological order
   def list
     conditions = conditions_nonempty
   # list edits (open changesets) in reverse chronological order
   def list
     conditions = conditions_nonempty
-    
-    
-   # @changesets = Changeset.find(:all, :order => "closed_at DESC", :conditions => ['closed_at < ?', DateTime.now], :limit=> 20)
-   
-   
-   #@edit_pages, @edits = paginate(:changesets,
-   #                                :include => [:user, :changeset_tags],
-   #                                :conditions => conditions,
-   #                                :order => "changesets.created_at DESC",
-   #                                :per_page => 20)
-   #
-    
-   @edits =  Changeset.find(:all,
-                                   :order => "changesets.created_at DESC",
-                                   :conditions => conditions,
-                                   :limit => 20)
-    
-  end
 
 
-  ##
-  # list edits (open changesets) in reverse chronological order
-  def list_rss
-    conditions = conditions_nonempty
+    # @changesets = Changeset.find(:all, :order => "closed_at DESC", :conditions => ['closed_at < ?', DateTime.now], :limit=> 20)
+
+    #@edit_pages, @edits = paginate(:changesets,
+    #                                :include => [:user, :changeset_tags],
+    #                                :conditions => conditions,
+    #                                :order => "changesets.created_at DESC",
+    #                                :per_page => 20)
+    #
 
     @edits =  Changeset.find(:all,
                              :order => "changesets.created_at DESC",
                              :conditions => conditions,
                              :limit => 20)
 
     @edits =  Changeset.find(:all,
                              :order => "changesets.created_at DESC",
                              :conditions => conditions,
                              :limit => 20)
-    
   end
   
   ##
   end
   
   ##
@@ -310,31 +295,6 @@ class ChangesetController < ApplicationController
       render :template => 'user/no_such_user', :status => :not_found
     end
   end
       render :template => 'user/no_such_user', :status => :not_found
     end
   end
-
-  ##
-  # list edits (changesets) belonging to a user
-  def list_user_rss
-    user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
-    
-    if user
-      @display_name = user.display_name
-      if not user.data_public? and @user != user
-        @edits = nil
-        render
-      else
-        conditions = cond_merge conditions, ['user_id = ?', user.id]
-        conditions = cond_merge conditions, conditions_nonempty
-        @edit_pages, @edits = paginate(:changesets,
-                                        :include => [:user, :changeset_tags],
-                                        :conditions => conditions,
-                                        :order => "changesets.created_at DESC",
-                                        :per_page => 20)
-      end
-    else
-      @not_found_user = params[:display_name]
-      render :template => 'user/no_such_user', :status => :not_found
-    end
-  end
   
   ##
   # list changesets in a bbox
   
   ##
   # list changesets in a bbox
@@ -344,6 +304,8 @@ class ChangesetController < ApplicationController
        bbox = params['bbox']
     elsif params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat']
        bbox = h(params['minlon']) + ',' + h(params['minlat']) + ',' + h(params['maxlon']) + ',' + h(params['maxlat'])
        bbox = params['bbox']
     elsif params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat']
        bbox = h(params['minlon']) + ',' + h(params['minlat']) + ',' + h(params['maxlon']) + ',' + h(params['maxlat'])
+    elsif params['format'] == "rxml"
+      raise OSM::APIBadUserInput.new("Bounding box must be supplied for the RSS feed")
     else
       #TODO: fix bugs in location determination for history tab (and other tabs) then uncomment this redirect
       #redirect_to :action => 'list'
     else
       #TODO: fix bugs in location determination for history tab (and other tabs) then uncomment this redirect
       #redirect_to :action => 'list'
@@ -364,30 +326,6 @@ class ChangesetController < ApplicationController
                                    
     @bbox = sanitise_boundaries(bbox.split(/,/)) unless bbox==nil
   end
                                    
     @bbox = sanitise_boundaries(bbox.split(/,/)) unless bbox==nil
   end
-
-  ##
-  # list changesets in a bbox
-  def list_bbox_rss
-    # support 'bbox' param or alternatively 'minlon', 'minlat' etc       
-    if params['bbox']
-       bbox = params['bbox']
-    elsif params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat']
-       bbox = h(params['minlon']) + ',' + h(params['minlat']) + ',' + h(params['maxlon']) + ',' + h(params['maxlat'])
-    else
-      raise OSM::APIBadUserInput.new("Bounding box must be supplied for /history/rss")
-    end
-       
-    conditions = conditions_bbox(bbox);
-    conditions = cond_merge conditions, conditions_nonempty
-    
-    @edit_pages, @edits = paginate(:changesets,
-                                   :include => [:user, :changeset_tags],
-                                   :conditions => conditions,
-                                   :order => "changesets.created_at DESC",
-                                   :per_page => 20)
-                                   
-    @bbox = sanitise_boundaries(bbox.split(/,/)) unless bbox==nil
-  end
   
 private
   #------------------------------------------------------------
   
 private
   #------------------------------------------------------------
similarity index 99%
rename from app/views/changeset/list_rss.rxml
rename to app/views/changeset/list.rxml
index a22d834ea396e9c74945e13e96d43cf2e7b4b1c9..95e10e8fb1c6a61ff8a81831d4acc37168b3ff66 100644 (file)
@@ -1,5 +1,3 @@
-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.rss("version" => "2.0", 
         "xmlns:geo" => "http://www.w3.org/2003/01/geo/wgs84_pos#",
         "xmlns:georss" => "http://www.georss.org/georss") do
@@ -48,4 +46,3 @@ xml.rss("version" => "2.0",
     end
   end
 end
     end
   end
 end
-
similarity index 99%
rename from app/views/changeset/list_bbox_rss.rxml
rename to app/views/changeset/list_bbox.rxml
index 73e705fe129a9a7bd519caab69aa2c1c08da6420..172523cba39f656fc8b12fcc28fef1097d67352b 100644 (file)
@@ -1,5 +1,3 @@
-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.rss("version" => "2.0", 
         "xmlns:geo" => "http://www.w3.org/2003/01/geo/wgs84_pos#",
         "xmlns:georss" => "http://www.georss.org/georss") do
@@ -48,4 +46,3 @@ xml.rss("version" => "2.0",
     end
   end
 end
     end
   end
 end
-
similarity index 99%
rename from app/views/changeset/list_user_rss.rxml
rename to app/views/changeset/list_user.rxml
index 4db0bd5159209be41129c6641553b7f96f3b5bca..ed6c6459d2b2046e79bf6f7196049bab26ff0f44 100644 (file)
@@ -1,5 +1,3 @@
-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.rss("version" => "2.0", 
         "xmlns:geo" => "http://www.w3.org/2003/01/geo/wgs84_pos#",
         "xmlns:georss" => "http://www.georss.org/georss") do
@@ -48,4 +46,3 @@ xml.rss("version" => "2.0",
     end
   end
 end
     end
   end
 end
-
diff --git a/app/views/layouts/site.rxml b/app/views/layouts/site.rxml
new file mode 100644 (file)
index 0000000..90198e8
--- /dev/null
@@ -0,0 +1,2 @@
+xml.instruct!
+xml << yield
index aead14cf94c943c1e12133017db16b2380ed12f8..1b5d483c6c686e9b8f91f833b8cddd79421a4dc6 100644 (file)
@@ -82,15 +82,15 @@ ActionController::Routing::Routes.draw do |map|
   map.connect '/browse/relation/:id', :controller => 'browse', :action => 'relation', :id => /\d+/
   map.connect '/browse/relation/:id/history', :controller => 'browse', :action => 'relation_history', :id => /\d+/
   map.connect '/browse/changeset/:id', :controller => 'browse', :action => 'changeset', :id => /\d+/
   map.connect '/browse/relation/:id', :controller => 'browse', :action => 'relation', :id => /\d+/
   map.connect '/browse/relation/:id/history', :controller => 'browse', :action => 'relation_history', :id => /\d+/
   map.connect '/browse/changeset/:id', :controller => 'browse', :action => 'changeset', :id => /\d+/
-  map.connect '/browse/changesets', :controller => 'changeset', :action => 'list'
-  map.connect '/browse/changesets/rss', :controller => 'changeset', :action => 'list_rss'
+  map.connect '/browse/changesets', :controller => 'changeset', :action => 'list', :format => 'rhtml'
+  map.connect '/browse/changesets/rss', :controller => 'changeset', :action => 'list', :format => 'rxml'
   
   # web site
   map.root :controller => 'site', :action => 'index'
   map.connect '/', :controller => 'site', :action => 'index'
   map.connect '/edit', :controller => 'site', :action => 'edit'
   
   # web site
   map.root :controller => 'site', :action => 'index'
   map.connect '/', :controller => 'site', :action => 'index'
   map.connect '/edit', :controller => 'site', :action => 'edit'
-  map.connect '/history', :controller => 'changeset', :action => 'list_bbox'
-  map.connect '/history/rss', :controller => 'changeset', :action => 'list_bbox_rss'
+  map.connect '/history', :controller => 'changeset', :action => 'list_bbox', :format => 'rhtml'
+  map.connect '/history/rss', :controller => 'changeset', :action => 'list_bbox', :format => 'rxml'
   map.connect '/export', :controller => 'site', :action => 'export'
   map.connect '/login', :controller => 'user', :action => 'login'
   map.connect '/logout', :controller => 'user', :action => 'logout'
   map.connect '/export', :controller => 'site', :action => 'export'
   map.connect '/login', :controller => 'user', :action => 'login'
   map.connect '/logout', :controller => 'user', :action => 'logout'
@@ -144,8 +144,8 @@ ActionController::Routing::Routes.draw do |map|
 
   # user pages
   map.connect '/user/:display_name', :controller => 'user', :action => 'view'
 
   # user pages
   map.connect '/user/:display_name', :controller => 'user', :action => 'view'
-  map.connect '/user/:display_name/edits', :controller => 'changeset', :action => 'list_user'
-  map.connect '/user/:display_name/edits/rss', :controller => 'changeset', :action => 'list_user_rss'
+  map.connect '/user/:display_name/edits', :controller => 'changeset', :action => 'list_user', :format => 'rhtml'
+  map.connect '/user/:display_name/edits/rss', :controller => 'changeset', :action => 'list_user', :format => 'rxml'
   map.connect '/user/:display_name/make_friend', :controller => 'user', :action => 'make_friend'
   map.connect '/user/:display_name/remove_friend', :controller => 'user', :action => 'remove_friend'
   map.connect '/user/:display_name/diary', :controller => 'diary_entry', :action => 'list'
   map.connect '/user/:display_name/make_friend', :controller => 'user', :action => 'make_friend'
   map.connect '/user/:display_name/remove_friend', :controller => 'user', :action => 'remove_friend'
   map.connect '/user/:display_name/diary', :controller => 'diary_entry', :action => 'list'