]> git.openstreetmap.org Git - rails.git/commitdiff
Marge all the changeset list methods together into one.
authorTom Hughes <tom@compton.nu>
Sun, 7 Jun 2009 16:59:58 +0000 (16:59 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 7 Jun 2009 16:59:58 +0000 (16:59 +0000)
app/controllers/changeset_controller.rb
app/views/changeset/_changeset_paging_nav.rhtml
app/views/changeset/list.rhtml
app/views/changeset/list.rxml
app/views/changeset/list_bbox.rhtml [deleted file]
app/views/changeset/list_bbox.rxml [deleted file]
app/views/changeset/list_user.rhtml [deleted file]
app/views/changeset/list_user.rxml [deleted file]
config/locales/en.yml
config/routes.rb
test/functional/changeset_controller_test.rb

index 8d029aae50d10078483c9ba9961ff7cb1566f5d5..3af1f3ab9e03b1fac3e336e67d75928887b839a1 100644 (file)
@@ -256,77 +256,50 @@ class ChangesetController < ApplicationController
   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 (changesets) belonging to a user
-  def list_user
-    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)
+    if params[:display_name]
+      user = User.find_by_display_name(params[:display_name], :conditions => { :visible => true })
+
+      if user 
+        if user.data_public? or user == @user
+          conditions = cond_merge conditions, ['user_id = ?', user.id]
+        else
+          conditions = cond_merge conditions, ['false']
+        end
+      elsif params[:format] == 'rhtml'
+        @not_found_user = params[:display_name]
+        render :template => 'user/no_such_user', :status => :not_found
       end
-    else
-      @not_found_user = params[:display_name]
-      render :template => 'user/no_such_user', :status => :not_found
     end
-  end
-  
-  ##
-  # list changesets in a bbox
-  def list_bbox
-    # 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'])
-    elsif params['format'] == "rxml"
-      raise OSM::APIBadUserInput.new("Bounding box must be supplied for the RSS feed")
+
+    if params[:bbox]
+      bbox = params[:bbox]
+    elsif params[:minlon] and params[:minlat] and params[:maxlon] and params[:maxlat]
+      bbox = params[:minlon] + ',' + params[:minlat] + ',' + params[:maxlon] + ',' + params[:maxlat]
+    end
+
+    if bbox
+      conditions = cond_merge conditions, conditions_bbox(bbox)
+      bbox = BoundingBox.from_s(bbox)
+      bbox_link = "<a href='#{url_for(:controller => "site", :action => "index", :minlon => bbox.min_lon, :minlat => bbox.min_lat, :maxlon => bbox.max_lon, :maxlat => bbox.max_lat, :box => "yes")}'>#{bbox.to_s}</a>"
+    end
+
+    if user and bbox
+      @description = t 'changeset.list.description_user_bbox', :user => user.display_name, :bbox => bbox_link
+    elsif user
+      @description = t 'changeset.list.description_user', :user => user.display_name
+    elsif bbox
+      @description = t 'changeset.list.description_bbox', :bbox => bbox_link
     else
-      #TODO: fix bugs in location determination for history tab (and other tabs) then uncomment this redirect
-      #redirect_to :action => 'list'
-      
-      # For now just render immediately, and skip the db
-      render
-      return
+      @description = t 'changeset.list.description'
     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
   #------------------------------------------------------------
   # utility functions below.
index b8ac1a65fca39f394c5aaf7762ed9e3013535437..94edfc31ed1f673aceba4fe62a5c50431fb8b449 100644 (file)
@@ -1,3 +1,4 @@
+<p>
 <% current_page = @edit_pages.current_page %>
 
 <%= t'changeset.changeset_paging_nav.showing_page' %> 
@@ -16,3 +17,4 @@ if @edit_pages.page_count > 1
 <%
 end
 %>
+</p>
index affe10cc635dfb4dc385b742d105581225fabd49..fba45be502e31baeeda3d93179029226d070811e 100644 (file)
@@ -1,13 +1,12 @@
-<h1><%= t'changeset.list.recent_changes' %></h1>
-<p><%= t'changeset.list.recently_edited_changesets' %></p>
+<h1><%= t'changeset.list.title' %></h1>
+<p><%= @description %></p>
 
-<%= render :partial => 'changesets' %>
+<%= render :partial => 'changeset_paging_nav' %>
+<%= render :partial => 'changesets', :locals => { :showusername => !params.has_key?(:display_name) } %>
+<%= render :partial => 'changeset_paging_nav' %>
 
-<p><%= t'changeset.list.for_more_changesets' %></p>
-<br>
-
-<%= rss_link_to :action => 'list_rss' %>
+<%= rss_link_to params.merge({ :format => 'rxml' }) %>
 
 <% content_for :head do %>
-<%= auto_discovery_link_tag :atom, :controller => 'changeset', :action => 'list_rss' %>
+<%= auto_discovery_link_tag :atom, params.merge({ :format => 'rxml' }) %>
 <% end %>
index 95e10e8fb1c6a61ff8a81831d4acc37168b3ff66..f97516e61550cea0e759f8a3c6c0cea8226bc8ca 100644 (file)
@@ -2,18 +2,17 @@ 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 t('changeset.list_rss.title')
-    xml.description t('changeset.list_rss.description')
-    xml.link url_for(:controller => "browse", :action => "changesets", :only_path => false)
+    xml.title t('changeset.list.title')
+    xml.description @description
+    xml.link url_for(params.merge({ :only_path => false }))
     xml.image do
       xml.url "http://www.openstreetmap.org/images/mag_map-rss2.0.png"
       xml.title "OpenStreetMap"
       xml.width "100"
       xml.height "100"
-      xml.link url_for(:controller => "browse", :action => "changesets", :only_path => false)
+      xml.link url_for(params.merge({ :only_path => false }))
     end
 
-
     for changeset in @edits
       xml.item do
         xml.title t('browse.changeset.title') + " " + h(changeset.id)
diff --git a/app/views/changeset/list_bbox.rhtml b/app/views/changeset/list_bbox.rhtml
deleted file mode 100644 (file)
index ef774e3..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-<h1><%= t'changeset.list_bbox.history' %></h1>
-<%
-if @bbox!=nil
-       minlon = @bbox[0] 
-       minlat = @bbox[1] 
-       maxlon = @bbox[2]
-       maxlat = @bbox[3] 
-
-       %>
-<p>
-<%= t'changeset.list_bbox.changesets_within_the_area' %> 
-      (<a href='/?minlon=<%= minlon %>&minlat=<%= minlat %>&maxlon=<%= maxlon %>&maxlat=<%= maxlat %>&box=yes' title='<%= t'changeset.list_bbox.show_area_box' %>'><%= format("%0.3f",minlon) -%>,<%= format("%0.3f",minlat) -%>,<%= format("%0.3f",maxlon) -%>,<%= format("%0.3f",maxlat) -%></a>) 
-
-</p>
-
-<%     if @edits.nil? or @edits.empty? %>
-<p><b><%= t'changeset.list_bbox.no_changesets' %></b></p>
-<%     else %>
-
-<%= render :partial => 'changeset_paging_nav' %>
-<%= render :partial => 'changesets' %>
-<%= render :partial => 'changeset_paging_nav' %>
-
-<p><%= t'changeset.list_bbox.all_changes_everywhere' , :recent_changes_link => link_to(t('changeset.list_bbox.recent_changes'), :controller => "browse", :action => "changesets") %> </p>
-
-<%
-       end
-
-else 
-       #bbox is nil. happens if the user surfs to this page directly.
-%>
-
-<p><%= t'changeset.list_bbox.no_area_specified' %></p>
-<p><%= t'changeset.list_bbox.first_use_view', :view_tab_link => '<a href="/" title="' + t('changeset.list_bbox.view_the_map') + '">' + t('changeset.list_bbox.view_tab') + '</a>' %></p>
-<p><%= t'changeset.list_bbox.alternatively_view', :recent_changes_link => link_to(t('changeset.list_bbox.recent_changes'), :controller => "browse", :action => "changesets") %></p>
-
-<%
-end
-%>
-<br>
-
-<% if @bbox %>
-  <%= rss_link_to :action => 'list_bbox_rss', :bbox => @bbox.join(",") %>
-<% end %>
-
-
-<% if @bbox %>
-  <% content_for :head do %>
-    <%= auto_discovery_link_tag :atom, :controller => 'changeset', :action => 'list_bbox_rss', :bbox => @bbox.join(",") %>
-  <% end %>
-<% end %>
diff --git a/app/views/changeset/list_bbox.rxml b/app/views/changeset/list_bbox.rxml
deleted file mode 100644 (file)
index 172523c..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-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 t('changeset.list_bbox_rss.title', :bbox => @bbox.join(","))
-    xml.description t('changeset.list_bbox_rss.description', :bbox => @bbox.join(","))
-    xml.link url_for(:controller => "history", :bbox => @bbox.join(","), :only_path => false)
-    xml.image do
-      xml.url "http://www.openstreetmap.org/images/mag_map-rss2.0.png"
-      xml.title "OpenStreetMap"
-      xml.width "100"
-      xml.height "100"
-      xml.link url_for(:controller => "history", :bbox => @bbox.join(","), :only_path => false)
-    end
-
-
-    for changeset in @edits
-      xml.item do
-        xml.title t('browse.changeset.title') + " " + h(changeset.id)
-        xml.link url_for(:controller => 'browse', :action => "changeset", :id => changeset.id, :only_path => false)
-        xml.guid url_for(:controller => 'browse', :action => "changeset", :id => changeset.id, :only_path => false)
-        if changeset.user.data_public?
-          xml.author changeset.user.display_name
-        end
-        if changeset.tags['comment']
-          xml.description changeset.tags['comment']
-        end
-        xml.pubDate changeset.created_at.to_s(:rfc822)
-        if changeset.user.data_public?
-          xml.comments url_for(:controller => "message", :action => "new", :id => changeset.user.id, :only_path => false)
-        end
-
-        unless changeset.min_lat.nil?
-          minlon = changeset.min_lon/GeoRecord::SCALE.to_f
-          minlat = changeset.min_lat/GeoRecord::SCALE.to_f
-          maxlon = changeset.max_lon/GeoRecord::SCALE.to_f
-          maxlat = changeset.max_lat/GeoRecord::SCALE.to_f
-
-          # See http://georss.org/Encodings#Geometry
-          lower_corner = "#{minlat} #{minlon}"
-          upper_corner = "#{maxlat} #{maxlon}"
-
-          xml.georss :box, lower_corner + " " + upper_corner
-        end
-      end
-    end
-  end
-end
diff --git a/app/views/changeset/list_user.rhtml b/app/views/changeset/list_user.rhtml
deleted file mode 100644 (file)
index 6f246f9..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<h1><%= t'changeset.list_user.edits_by_username', :username_link => link_to(h(@display_name), {:controller=>'user', :action=>'view', :display_name=>@display_name}) %></h1>
-
-<% if not @edits or @edits.empty? %>
-<p><b><%= t'changeset.list_user.no_visible_edits_by', :name => h(@display_name) %>.</b></p>
-<% else %>
-<%= render :partial => 'changeset_paging_nav' %>
-<%= render :partial => 'changesets', :locals => {:showusername => false} %>
-<%= render :partial => 'changeset_paging_nav' %>
-<% end %>
-
-<p><%= t'changeset.list_user.for_all_changes', :recent_changes_link => link_to(t('changeset.list_user.recent_changes'), :controller => "browse", :action => "changesets") %></p>
-<br>
-
-<%= rss_link_to :action => 'list_user_rss' %>
-
-<% content_for :head do %>
-<%= auto_discovery_link_tag :atom, :controller => 'changeset', :action => 'list_user_rss' %>
-<% end %>
diff --git a/app/views/changeset/list_user.rxml b/app/views/changeset/list_user.rxml
deleted file mode 100644 (file)
index ed6c645..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-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 t('changeset.list_user_rss.title', :user => @display_name)
-    xml.description t('changeset.list_user_rss.description', :user => @display_name)
-    xml.link url_for(:controller => "user", :action => "edits", :id => @display_name, :only_path => false)
-    xml.image do
-      xml.url "http://www.openstreetmap.org/images/mag_map-rss2.0.png"
-      xml.title "OpenStreetMap"
-      xml.width "100"
-      xml.height "100"
-      xml.link url_for(:controller => "user", :action => "edits", :id => @display_name, :only_path => false)
-    end
-
-
-    for changeset in @edits
-      xml.item do
-        xml.title t('browse.changeset.title') + " " + h(changeset.id)
-        xml.link url_for(:controller => 'browse', :action => "changeset", :id => changeset.id, :only_path => false)
-        xml.guid url_for(:controller => 'browse', :action => "changeset", :id => changeset.id, :only_path => false)
-        if changeset.user.data_public?
-          xml.author changeset.user.display_name
-        end
-        if changeset.tags['comment']
-          xml.description changeset.tags['comment']
-        end
-        xml.pubDate changeset.created_at.to_s(:rfc822)
-        if changeset.user.data_public?
-          xml.comments url_for(:controller => "message", :action => "new", :id => changeset.user.id, :only_path => false)
-        end
-
-        unless changeset.min_lat.nil?
-          minlon = changeset.min_lon/GeoRecord::SCALE.to_f
-          minlat = changeset.min_lat/GeoRecord::SCALE.to_f
-          maxlon = changeset.max_lon/GeoRecord::SCALE.to_f
-          maxlat = changeset.max_lat/GeoRecord::SCALE.to_f
-
-          # See http://georss.org/Encodings#Geometry
-          lower_corner = "#{minlat} #{minlon}"
-          upper_corner = "#{maxlat} #{maxlon}"
-
-          xml.georss :box, lower_corner + " " + upper_corner
-        end
-      end
-    end
-  end
-end
index a4b0f352cc5954df2b336f8bb7348e446dddc679..d46245ad18ed7e5b4f8fe3f550a60a1600c40907 100644 (file)
@@ -217,36 +217,12 @@ en:
       user: "User"
       comment: "Comment"
       area: "Area"
-    list_bbox:
-      history: "History"
-      changesets_within_the_area: "Changesets within the area:"
-      show_area_box: "show area box"
-      no_changesets: "No changesets"
-      all_changes_everywhere: "For all changes everywhere see {{recent_changes_link}}"
-      recent_changes: "Recent Changes"
-      no_area_specified: "No area specified"
-      first_use_view: "First use the {{view_tab_link}} to pan and zoom to an area of interest, then click the history tab."
-      view_the_map: "view the map"
-      view_tab: "view tab"
-      alternatively_view: "Alternatively, view all {{recent_changes_link}}"
     list:
-      recent_changes: "Recent Changes"
-      recently_edited_changesets: "Recently edited changesets:"
-      for_more_changesets: "For more changesets, select a user and view their edits, or see the editing 'history' of a specific area."
-    list_rss:
-      title: "Recent changes"
-      description: "Recently edited changesets"
-    list_bbox_rss:
-      title: "Recent changesets within {{bbox}}"
-      description: "Recently edited changesets within the area {{bbox}}"
-    list_user:
-      edits_by_username: "Edits by {{username_link}}"
-      no_visible_edits_by: "No visible edits by {{name}}."
-      for_all_changes: "For changes by all users see {{recent_changes_link}}"
-      recent_changes: "Recent Changes"
-    list_user_rss:
-      title: "Edits by {{user}}"
-      description: "Recent changesets by {{user}}"
+      title: "Changesets"
+      description: "Recent edits"
+      description_user: "Recent edits by {{user}}"
+      description_bbox: "Recent edits within {{bbox}}"
+      description_user_bbox: "Recent edits by {{user}} within {{bbox}}"
   diary_entry:
     new:
       title: New Diary Entry
index 1b5d483c6c686e9b8f91f833b8cddd79421a4dc6..68f1ad6d25b57d9ac9d67a1c6ff5fda2451bc2ac 100644 (file)
@@ -73,7 +73,7 @@ ActionController::Routing::Routes.draw do |map|
   map.connect "api/#{API_VERSION}/swf/trackpoints", :controller =>'swf', :action =>'trackpoints'
   
   # Data browsing
-  map.connect '/browse', :controller => 'changeset', :action => 'list'
+  map.connect '/browse', :controller => 'changeset', :action => 'list', :format => 'rhtml'
   map.connect '/browse/start', :controller => 'browse', :action => 'start'
   map.connect '/browse/way/:id', :controller => 'browse', :action => 'way', :id => /\d+/
   map.connect '/browse/way/:id/history', :controller => 'browse', :action => 'way_history', :id => /\d+/
@@ -89,8 +89,8 @@ ActionController::Routing::Routes.draw do |map|
   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', :format => 'rhtml'
-  map.connect '/history/rss', :controller => 'changeset', :action => 'list_bbox', :format => 'rxml'
+  map.connect '/history', :controller => 'changeset', :action => 'list', :format => 'rhtml'
+  map.connect '/history/rss', :controller => 'changeset', :action => 'list', :format => 'rxml'
   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'
-  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/edits', :controller => 'changeset', :action => 'list', :format => 'rhtml'
+  map.connect '/user/:display_name/edits/rss', :controller => 'changeset', :action => 'list', :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'
index d60fe2fbc9621344512f373f479916ee85b3942d..f1ecb3cc77c0648a737e922b360697625fe4091c 100644 (file)
@@ -1490,11 +1490,11 @@ EOF
   def test_list
     changesets = Changeset.find(:all, :order => "created_at DESC", :conditions => ['min_lat IS NOT NULL'], :limit=> 20)
     assert changesets.size <= 20
-    get :list
+    get :list, {:format => "rhtml"}
     assert_response :success
     assert_template "list"
     # Now check that all 20 (or however many were returned) changesets are in the html
-    assert_select "h1", :text => "Recent Changes", :count => 1
+    assert_select "h1", :text => "Changesets", :count => 1
     assert_select "table[id='changeset_list'] tr", :count => changesets.size + 1
     changesets.each do |changeset|
       # FIXME this test needs rewriting - test for table contents
@@ -1505,16 +1505,16 @@ EOF
   # Checks the display of the user changesets listing
   def test_list_user
     user = users(:public_user)
-    get :list_user, {:display_name => user.display_name}
+    get :list, {:format => "rhtml", :display_name => user.display_name}
     assert_response :success
-    assert_template 'list_user'
+    assert_template "list"
     ## FIXME need to add more checks to see which if edits are actually shown if your data is public
   end
   
   ##
   # Check the not found of the list user changesets
   def test_list_user_not_found
-    get :list_user, {:display_name => "Some random user"}
+    get :list, {:format => "rhtml", :display_name => "Some random user"}
     assert_response :not_found
     assert_template 'user/no_such_user'
   end