From: Thomas Wood Date: Fri, 19 Jun 2009 22:53:16 +0000 (+0000) Subject: merge 15807:16012 from rails_port X-Git-Tag: live~6819^2~17 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/ff03138a978406b431da71aba64941d87b509098?hp=98a86836d27cead19b4024427ee33beed66cdb48 merge 15807:16012 from rails_port --- diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index ca42751d3..d7f3d39c8 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -255,79 +255,54 @@ class ChangesetController < ApplicationController # 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 (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 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 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']) + + 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 = "#{bbox.to_s}" + end + + @title = t 'changeset.list.title' + + 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. diff --git a/app/views/changeset/_changeset.html.erb b/app/views/changeset/_changeset.html.erb index 8ac433415..f8f00addb 100644 --- a/app/views/changeset/_changeset.html.erb +++ b/app/views/changeset/_changeset.html.erb @@ -14,7 +14,7 @@ <%if showusername %> <% if changeset.user.data_public? %> - <%= link_to h(changeset.user.display_name), :controller => "changeset", :action => "list_user", :display_name => changeset.user.display_name %> + <%= link_to h(changeset.user.display_name), :controller => "changeset", :action => "list", :display_name => changeset.user.display_name %> <% else %> <%= t'changeset.changeset.anonymous' %> <% end %> @@ -25,7 +25,7 @@ <% if changeset.tags['comment'] %> <%= h(changeset.tags['comment']) %> <% else %> - <%= t'changeset.changeset.no_comment' %> + <%= t'changeset.changeset.no_comment' %> <% end %> diff --git a/app/views/changeset/_changeset_paging_nav.html.erb b/app/views/changeset/_changeset_paging_nav.html.erb index b8ac1a65f..94edfc31e 100644 --- a/app/views/changeset/_changeset_paging_nav.html.erb +++ b/app/views/changeset/_changeset_paging_nav.html.erb @@ -1,3 +1,4 @@ +

<% current_page = @edit_pages.current_page %> <%= t'changeset.changeset_paging_nav.showing_page' %> @@ -16,3 +17,4 @@ if @edit_pages.page_count > 1 <% end %> +

diff --git a/app/views/changeset/list.html.erb b/app/views/changeset/list.html.erb index cfe4afd3f..d2112ac73 100644 --- a/app/views/changeset/list.html.erb +++ b/app/views/changeset/list.html.erb @@ -1,7 +1,12 @@ -

<%= t'changeset.list.recent_changes' %>

-

<%= t'changeset.list.recently_edited_changesets' %>

+

<%= @title %>

+

<%= @description %>

-<%= render :partial => 'changesets' %> +<%= render :partial => 'changeset_paging_nav' %> +<%= render :partial => 'changesets', :locals => { :showusername => !params.has_key?(:display_name) } %> +<%= render :partial => 'changeset_paging_nav' %> -

<%= t'changeset.list.for_more_changesets' %>

-
+<%= rss_link_to params.merge({ :format => :rss }) %> + +<% content_for :head do %> +<%= auto_discovery_link_tag :atom, params.merge({ :format => :rss }) %> +<% end %> diff --git a/app/views/changeset/list.rss.builder b/app/views/changeset/list.rss.builder new file mode 100644 index 000000000..0251367fc --- /dev/null +++ b/app/views/changeset/list.rss.builder @@ -0,0 +1,47 @@ +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 @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(params.merge({ :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_bbox.html.erb b/app/views/changeset/list_bbox.html.erb deleted file mode 100644 index 87c61790c..000000000 --- a/app/views/changeset/list_bbox.html.erb +++ /dev/null @@ -1,41 +0,0 @@ -

<%= t'changeset.list_bbox.history' %>

-<% -if @bbox!=nil - minlon = @bbox[0] - minlat = @bbox[1] - maxlon = @bbox[2] - maxlat = @bbox[3] - - %> -

-<%= t'changeset.list_bbox.changesets_within_the_area' %> - ('><%= format("%0.3f",minlon) -%>,<%= format("%0.3f",minlat) -%>,<%= format("%0.3f",maxlon) -%>,<%= format("%0.3f",maxlat) -%>) - -

- -<% if @edits.nil? or @edits.empty? %> -

<%= t'changeset.list_bbox.no_changesets' %>

-<% else %> - -<%= render :partial => 'changeset_paging_nav' %> -<%= render :partial => 'changesets' %> -<%= render :partial => 'changeset_paging_nav' %> - -

<%= t'changeset.list_bbox.all_changes_everywhere' , :recent_changes_link => link_to(t('changeset.list_bbox.recent_changes'), :controller => "browse", :action => "changesets") %>

- -<% - end - -else - #bbox is nil. happens if the user surfs to this page directly. -%> - -

<%= t'changeset.list_bbox.no_area_specified' %>

-

<%= t'changeset.list_bbox.first_use_view', :view_tab_link => '' + t('changeset.list_bbox.view_tab') + '' %>

-

<%= t'changeset.list_bbox.alternatively_view', :recent_changes_link => link_to(t('changeset.list_bbox.recent_changes'), :controller => "browse", :action => "changesets") %>

- -<% -end -%> -
- diff --git a/app/views/changeset/list_user.html.erb b/app/views/changeset/list_user.html.erb deleted file mode 100644 index 7240e6027..000000000 --- a/app/views/changeset/list_user.html.erb +++ /dev/null @@ -1,13 +0,0 @@ -

<%= t'changeset.list_user.edits_by_username', :username_link => link_to(h(@display_name), {:controller=>'user', :action=>'view', :display_name=>@display_name}) %>

- -<% if not @edits or @edits.empty? %> -

<%= t'changeset.list_user.no_visible_edits_by', :name => h(@display_name) %>.

-<% else %> -<%= render :partial => 'changeset_paging_nav' %> -<%= render :partial => 'changesets', :locals => {:showusername => false} %> -<%= render :partial => 'changeset_paging_nav' %> -<% end %> - -

<%= t'changeset.list_user.for_all_changes', :recent_changes_link => link_to(t('changeset.list_user.recent_changes'), :controller => "browse", :action => "changesets") %>

-
- diff --git a/app/views/layouts/site.html.erb b/app/views/layouts/site.html.erb index 612c419c6..241bf1817 100644 --- a/app/views/layouts/site.html.erb +++ b/app/views/layouts/site.html.erb @@ -47,14 +47,14 @@ traceclass = '' viewclass = 'active' if params['controller'] == 'site' and params['action'] == 'index' editclass = 'active' if params['controller'] == 'site' and params['action'] == 'edit' - historyclass = 'active' if params['controller'] == 'changeset' and params['action'] == 'list_bbox' + historyclass = 'active' if params['controller'] == 'changeset' and params['action'] == 'list' exportclass = 'active' if params['controller'] == 'site' and params['action'] == 'export' traceclass = 'active' if params['controller'] == 'trace' diaryclass = 'active' if params['controller'] == 'diary_entry' %>
  • <%= link_to t('layouts.view'), {:controller => 'site', :action => 'index'}, {:id => 'viewanchor', :title => t('layouts.view_tooltip'), :class => viewclass} %>
  • <%= link_to t('layouts.edit'), {:controller => 'site', :action => 'edit'}, {:id => 'editanchor', :title => t('layouts.edit_tooltip'), :class => editclass} %>
  • -
  • <%= link_to t('layouts.history'), {:controller => 'changeset', :action => 'list_bbox' }, {:id => 'historyanchor', :title => t('layouts.history_tooltip'), :class => historyclass} %>
  • +
  • <%= link_to t('layouts.history'), {:controller => 'changeset', :action => 'list' }, {:id => 'historyanchor', :title => t('layouts.history_tooltip'), :class => historyclass} %>
  • <% if params['controller'] == 'site' and (params['action'] == 'index' or params['action'] == 'export') %>
  • <%= link_to_remote t('layouts.export'), {:url => {:controller => 'export', :action => 'start'}}, {:id => 'exportanchor', :title => t('layouts.export_tooltip'), :class => exportclass, :href => url_for(:controller => 'site', :action => 'export')} %>
  • <% else %> diff --git a/app/views/layouts/site.rss.builder b/app/views/layouts/site.rss.builder new file mode 100644 index 000000000..90198e8f4 --- /dev/null +++ b/app/views/layouts/site.rss.builder @@ -0,0 +1,2 @@ +xml.instruct! +xml << yield diff --git a/app/views/user/view.html.erb b/app/views/user/view.html.erb index 5fdea140f..0dbc09dd3 100644 --- a/app/views/user/view.html.erb +++ b/app/views/user/view.html.erb @@ -4,14 +4,14 @@ <%= link_to t('user.view.my diary'), :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name %> | <%= link_to t('user.view.new diary entry'), :controller => 'diary_entry', :action => 'new', :display_name => @user.display_name %> -| <%= link_to t('user.view.my edits'), :controller => 'changeset', :action => 'list_user', :display_name => @user.display_name %> +| <%= link_to t('user.view.my edits'), :controller => 'changeset', :action => 'list', :display_name => @user.display_name %> | <%= link_to t('user.view.my traces'), :controller => 'trace', :action=>'mine' %> | <%= link_to t('user.view.my settings'), :controller => 'user', :action => 'account', :display_name => @user.display_name %> <% else %> <%= link_to t('user.view.send message'), :controller => 'message', :action => 'new', :display_name => @this_user.display_name %> | <%= link_to t('user.view.diary'), :controller => 'diary_entry', :action => 'list', :display_name => @this_user.display_name %> -| <%= link_to t('user.view.edits'), :controller => 'changeset', :action => 'list_user', :display_name => @this_user.display_name %> +| <%= link_to t('user.view.edits'), :controller => 'changeset', :action => 'list', :display_name => @this_user.display_name %> | <%= link_to t('user.view.traces'), :controller => 'trace', :action => 'view', :display_name => @this_user.display_name %> | <% if @user and @user.is_friends_with?(@this_user) %> <%= link_to t('user.view.remove as friend'), :controller => 'user', :action => 'remove_friend', :display_name => @this_user.display_name %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 58ca1d431..9581d83b7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -222,27 +222,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_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" + 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 diff --git a/config/routes.rb b/config/routes.rb index 92bc493e1..afaec0403 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -83,12 +83,14 @@ ActionController::Routing::Routes.draw do |map| 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', :format => :rss # 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', :controller => 'changeset', :action => 'list' + map.connect '/history/rss', :controller => 'changeset', :action => 'list', :format => :rss map.connect '/export', :controller => 'site', :action => 'export' map.connect '/login', :controller => 'user', :action => 'login' map.connect '/logout', :controller => 'user', :action => 'logout' @@ -142,7 +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' + map.connect '/user/:display_name/edits', :controller => 'changeset', :action => 'list' + map.connect '/user/:display_name/edits/rss', :controller => 'changeset', :action => 'list', :format =>:rss 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' diff --git a/lib/bounding_box.rb b/lib/bounding_box.rb index d943768ad..30bbebb8d 100644 --- a/lib/bounding_box.rb +++ b/lib/bounding_box.rb @@ -4,7 +4,7 @@ class BoundingBox end def self.from_s(s) - BoundingBox.new(s.split(/,/)) + BoundingBox.new(*s.split(/,/)) end def min_lon diff --git a/test/functional/changeset_controller_test.rb b/test/functional/changeset_controller_test.rb index d60fe2fbc..f1ecb3cc7 100644 --- a/test/functional/changeset_controller_test.rb +++ b/test/functional/changeset_controller_test.rb @@ -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