From afe8dd51ece21325eea8a108515b9426764de5b2 Mon Sep 17 00:00:00 2001 From: Harry Wood Date: Mon, 23 Mar 2009 16:39:59 +0000 Subject: [PATCH] Add 'history' tab + Move 'recent changes' changeset list to re-use the same _changeset.rhtml partial --- app/controllers/browse_controller.rb | 4 +- app/controllers/changeset_controller.rb | 88 ++++++++++++++++--- app/controllers/export_controller.rb | 6 ++ app/views/browse/index.rhtml | 16 ---- app/views/changeset/_changeset.rhtml | 12 ++- .../changeset/_changeset_paging_nav.rhtml | 12 ++- app/views/changeset/list.rhtml | 12 ++- app/views/changeset/list_bbox.rhtml | 50 +++++++++++ app/views/changeset/list_user.rhtml | 15 ++++ app/views/layouts/site.rhtml | 3 + app/views/site/index.rhtml | 3 +- app/views/user/view.rhtml | 2 +- 12 files changed, 182 insertions(+), 41 deletions(-) delete mode 100644 app/views/browse/index.rhtml create mode 100644 app/views/changeset/list_bbox.rhtml create mode 100644 app/views/changeset/list_user.rhtml diff --git a/app/controllers/browse_controller.rb b/app/controllers/browse_controller.rb index 237c57ab2..10145a50a 100644 --- a/app/controllers/browse_controller.rb +++ b/app/controllers/browse_controller.rb @@ -7,9 +7,7 @@ class BrowseController < ApplicationController def start end - def index - @changesets = Changeset.find(:all, :order => "closed_at DESC", :conditions => ['closed_at < ?', DateTime.now], :limit=> 20) - end + def relation begin diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index b2ff42711..ebad59aa0 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -238,6 +238,7 @@ class ChangesetController < ApplicationController conditions = cond_merge conditions, conditions_user(params['user']) conditions = cond_merge conditions, conditions_time(params['time']) conditions = cond_merge conditions, conditions_open(params['open']) + conditions = cond_merge conditions, conditions_closed(params['closed']) # create the results document results = OSM::API.new.get_xml_doc @@ -291,21 +292,71 @@ class ChangesetController < ApplicationController render ex.render_opts end + + ## - # list edits belonging to a user + # 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 + #find user by display name user = User.find(:first, :conditions => [ "visible = ? and display_name = ?", true, params[:display_name]]) + + conditions = conditions_user(user.id); + conditions = cond_merge conditions, conditions_nonempty @edit_pages, @edits = paginate(:changesets, :include => [:user, :changeset_tags], - :conditions => ["changesets.user_id = ? AND min_lat IS NOT NULL", user.id], + :conditions => conditions, :order => "changesets.created_at DESC", :per_page => 20) - @action = 'list' @display_name = user.display_name # FIXME needs rescues in here 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 = params['minlon'] + ',' + params['minlat'] + ',' + params['maxlon'] + ',' + params['maxlat'] + 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. @@ -317,7 +368,7 @@ private if a and b a_str = a.shift b_str = b.shift - return [ a_str + " and " + b_str ] + a + b + return [ a_str + " AND " + b_str ] + a + b elsif a return a else b @@ -366,7 +417,7 @@ private end ## - # restrict changes to those during a particular time period + # restrict changes to those closed during a particular time period def conditions_time(time) unless time.nil? # if there is a range, i.e: comma separated, then the first is @@ -394,15 +445,28 @@ private end ## - # restrict changes to those which are open - # - # at the moment this code assumes we're only interested in open - # changesets and gives no facility to query closed changesets. this - # would be reasonably simple to implement if anyone actually wants - # it? + # return changesets which are open (haven't been closed yet) + # we do this by seeing if the 'closed at' time is in the future. Also if we've + # hit the maximum number of changes then it counts as no longer open. + # if parameter 'open' is nill then open and closed changsets are returned def conditions_open(open) return open.nil? ? nil : ['closed_at >= ? and num_changes <= ?', DateTime.now, Changeset::MAX_ELEMENTS] end + + ## + # query changesets which are closed + # ('closed at' time has passed or changes limit is hit) + def conditions_closed(closed) + return closed.nil? ? nil : ['closed_at < ? and num_changes > ?', + DateTime.now, Changeset::MAX_ELEMENTS] + end + ## + # eliminate empty changesets (where the bbox has not been set) + # this should be applied to all changeset list displays + def conditions_nonempty() + return ['min_lat IS NOT NULL'] + end + end diff --git a/app/controllers/export_controller.rb b/app/controllers/export_controller.rb index a773d4b72..754cc4b82 100644 --- a/app/controllers/export_controller.rb +++ b/app/controllers/export_controller.rb @@ -2,18 +2,24 @@ class ExportController < ApplicationController def start end + #When the user clicks 'Export' we redirect to a URL which generates the export download def finish bbox = BoundingBox.new(params[:minlon], params[:minlat], params[:maxlon], params[:maxlat]) format = params[:format] if format == "osm" + #redirect to API map get redirect_to "http://api.openstreetmap.org/api/#{API_VERSION}/map?bbox=#{bbox}" + elsif format == "mapnik" + #redirect to a special 'export' cgi script format = params[:mapnik_format] scale = params[:mapnik_scale] redirect_to "http://tile.openstreetmap.org/cgi-bin/export?bbox=#{bbox}&scale=#{scale}&format=#{format}" + elsif format == "osmarender" + #redirect to the t@h 'MapOf' service format = params[:osmarender_format] zoom = params[:osmarender_zoom].to_i width = bbox.slippy_width(zoom).to_i diff --git a/app/views/browse/index.rhtml b/app/views/browse/index.rhtml deleted file mode 100644 index fa7e13ac0..000000000 --- a/app/views/browse/index.rhtml +++ /dev/null @@ -1,16 +0,0 @@ -

<%= @changesets.length %> Recently Closed Changesets

- diff --git a/app/views/changeset/_changeset.rhtml b/app/views/changeset/_changeset.rhtml index 69d8933f6..67f3e72bb 100644 --- a/app/views/changeset/_changeset.rhtml +++ b/app/views/changeset/_changeset.rhtml @@ -8,9 +8,19 @@ <% if changeset.closed_at > DateTime.now %> (still editing) <% else %><%= changeset.closed_at.strftime("%d %b %Y %H:%M") %><% end %> + + <%if showusername==true %> + + <% if changeset.user.data_public? %> + <%= link_to h(changeset.user.display_name), :controller => "user", :action => "view", :display_name => changeset.user.display_name %> + <% else %> + annon + <% end %> + <% end %> + <% if changeset.tags['comment'] %> - <%= changeset.tags['comment'] %> + <%= h(changeset.tags['comment']) %> <% else %> (none) <% end %> diff --git a/app/views/changeset/_changeset_paging_nav.rhtml b/app/views/changeset/_changeset_paging_nav.rhtml index df84a3930..7be15305d 100644 --- a/app/views/changeset/_changeset_paging_nav.rhtml +++ b/app/views/changeset/_changeset_paging_nav.rhtml @@ -7,6 +7,12 @@ if (current_page.first_item < current_page.last_item) # if more than 1 changeset end %> of <%= @edit_pages.item_count %>) -<% if @edit_pages.page_count > 1 %> - | <%= pagination_links_each(@edit_pages, {}) { |n| link_to(n, :display_name => @display_name, :page => n) } %> -<% end %> +<% +if @edit_pages.page_count > 1 + bboxparam = h(params['bbox']) + bboxparam = nil if bboxparam=="" +%> + | <%= pagination_links_each(@edit_pages, {}) { |n| link_to(n, :display_name => @display_name, :bbox => bboxparam , :page => n) } %> +<% +end +%> diff --git a/app/views/changeset/list.rhtml b/app/views/changeset/list.rhtml index cea156320..0edd951ce 100644 --- a/app/views/changeset/list.rhtml +++ b/app/views/changeset/list.rhtml @@ -1,15 +1,19 @@ -

Edits by <%= link_to(@display_name, {:controller=>'user', :action=>'view', :display_name=>@display_name}) %>

-<%= render :partial => 'changeset_paging_nav' %> +

Recent Changes

+Recently closed changesets: + - <%= render :partial => 'changeset', :collection => @edits unless @edits.nil? %> + <%= render :partial => 'changeset', :locals => {:showusername => true}, :collection => @edits unless @edits.nil? %>
ID Saved atUser Comment Area
-<%= render :partial => 'changeset_paging_nav' %> +

+For more changesets, select a user and view their edits, or see the editing 'history' of a specific area. +

+
diff --git a/app/views/changeset/list_bbox.rhtml b/app/views/changeset/list_bbox.rhtml new file mode 100644 index 000000000..f1d8633f0 --- /dev/null +++ b/app/views/changeset/list_bbox.rhtml @@ -0,0 +1,50 @@ +

History

+<% +if @bbox!=nil + lon1 = @bbox[0] + lat1 = @bbox[1] + lon2 = @bbox[2] + lat2 = @bbox[3] + + %> +

+Changsets within the area: +(<%= format("%0.3f",lat1) -%>,<%= format("%0.3f",lon1) -%>) to +(<%= format("%0.3f",lat2) -%>,<%= format("%0.3f",lon2) -%>) +

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

No changesets

+<% else %> + +<%= render :partial => 'changeset_paging_nav' %> + + + + + + + + + + + <%= render :partial => 'changeset', :locals => {:showusername => true}, :collection => @edits unless @edits.nil? %> +
IDSaved atUserCommentArea
+ +<%= render :partial => 'changeset_paging_nav' %> + +<% + end + +else + #bbox is nil. happens if the user surfs to this page directly. +%> + +

No area specified

+

First use the view tab to pan and zoom to an area of interest, then click the history tab

+ +<% +end +%> +
+
diff --git a/app/views/changeset/list_user.rhtml b/app/views/changeset/list_user.rhtml new file mode 100644 index 000000000..a2096adef --- /dev/null +++ b/app/views/changeset/list_user.rhtml @@ -0,0 +1,15 @@ +

Edits by <%= link_to(@display_name, {:controller=>'user', :action=>'view', :display_name=>@display_name}) %>

+<%= render :partial => 'changeset_paging_nav' %> + + + + + + + + + + <%= render :partial => 'changeset', :locals => {:showusername => false}, :collection => @edits unless @edits.nil? %> +
IDSaved atCommentArea
+ +<%= render :partial => 'changeset_paging_nav' %> diff --git a/app/views/layouts/site.rhtml b/app/views/layouts/site.rhtml index cc8f7192d..49c0ae376 100644 --- a/app/views/layouts/site.rhtml +++ b/app/views/layouts/site.rhtml @@ -38,16 +38,19 @@ <% viewclass = '' editclass = '' + historyclass = '' exportclass = '' 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' 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 'View', {:controller => 'site', :action => 'index'}, {:id => 'viewanchor', :title => 'view maps', :class => viewclass} %>
  • <%= link_to 'Edit', {:controller => 'site', :action => 'edit'}, {:id => 'editanchor', :title => 'edit maps', :class => editclass} %>
  • +
  • <%= link_to 'History', {:controller => 'history' }, {:id => 'historyanchor', :title => 'changeset history', :class => historyclass} %>
  • <% if params['controller'] == 'site' and (params['action'] == 'index' or params['action'] == 'export') %>
  • <%= link_to_remote 'Export', {:url => {:controller => 'export', :action => 'start'}}, {:id => 'exportanchor', :title => 'export map data', :class => exportclass, :href => url_for(:controller => 'site', :action => 'export')} %>
  • <% else %> diff --git a/app/views/site/index.rhtml b/app/views/site/index.rhtml index 99024f176..35509f4e0 100644 --- a/app/views/site/index.rhtml +++ b/app/views/site/index.rhtml @@ -164,8 +164,9 @@ end var lonlat = getMapCenter(); var zoom = map.getZoom(); var layers = getMapLayers(); + var extents = getMapExtent(); - updatelinks(lonlat.lon, lonlat.lat, zoom, layers); + updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents); document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers; } diff --git a/app/views/user/view.rhtml b/app/views/user/view.rhtml index 4f2a168a1..d12198ca8 100644 --- a/app/views/user/view.rhtml +++ b/app/views/user/view.rhtml @@ -5,7 +5,7 @@ <%= link_to 'my diary', :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name %> | <%= link_to 'new diary entry', :controller => 'diary_entry', :action => 'new', :display_name => @user.display_name %> -| <%= link_to 'my edits', :controller => 'changeset', :action => 'list', :display_name => @user.display_name %> +| <%= link_to 'my edits', :controller => 'changeset', :action => 'list_user', :display_name => @user.display_name %> | <%= link_to 'my traces', :controller => 'trace', :action=>'mine' %> | <%= link_to 'my settings', :controller => 'user', :action => 'account', :display_name => @user.display_name %> <% else %> -- 2.43.2