Add 'history' tab + Move 'recent changes' changeset list to re-use the same _changeset.rhtml partial

This commit is contained in:
Harry Wood 2009-03-23 16:39:59 +00:00
parent 231bdf66cd
commit afe8dd51ec
12 changed files with 182 additions and 41 deletions

View file

@ -7,9 +7,7 @@ class BrowseController < ApplicationController
def start def start
end end
def index
@changesets = Changeset.find(:all, :order => "closed_at DESC", :conditions => ['closed_at < ?', DateTime.now], :limit=> 20)
end
def relation def relation
begin begin

View file

@ -238,6 +238,7 @@ class ChangesetController < ApplicationController
conditions = cond_merge conditions, conditions_user(params['user']) conditions = cond_merge conditions, conditions_user(params['user'])
conditions = cond_merge conditions, conditions_time(params['time']) conditions = cond_merge conditions, conditions_time(params['time'])
conditions = cond_merge conditions, conditions_open(params['open']) conditions = cond_merge conditions, conditions_open(params['open'])
conditions = cond_merge conditions, conditions_closed(params['closed'])
# create the results document # create the results document
results = OSM::API.new.get_xml_doc results = OSM::API.new.get_xml_doc
@ -291,21 +292,71 @@ class ChangesetController < ApplicationController
render ex.render_opts render ex.render_opts
end end
## ##
# list edits belonging to a user # list edits (open changesets) in reverse chronological order
def list 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]]) 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, @edit_pages, @edits = paginate(:changesets,
:include => [:user, :changeset_tags], :include => [:user, :changeset_tags],
:conditions => ["changesets.user_id = ? AND min_lat IS NOT NULL", user.id], :conditions => conditions,
:order => "changesets.created_at DESC", :order => "changesets.created_at DESC",
:per_page => 20) :per_page => 20)
@action = 'list'
@display_name = user.display_name @display_name = user.display_name
# FIXME needs rescues in here # FIXME needs rescues in here
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 = 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 private
#------------------------------------------------------------ #------------------------------------------------------------
# utility functions below. # utility functions below.
@ -317,7 +368,7 @@ private
if a and b if a and b
a_str = a.shift a_str = a.shift
b_str = b.shift b_str = b.shift
return [ a_str + " and " + b_str ] + a + b return [ a_str + " AND " + b_str ] + a + b
elsif a elsif a
return a return a
else b else b
@ -366,7 +417,7 @@ private
end end
## ##
# restrict changes to those during a particular time period # restrict changes to those closed during a particular time period
def conditions_time(time) def conditions_time(time)
unless time.nil? unless time.nil?
# if there is a range, i.e: comma separated, then the first is # if there is a range, i.e: comma separated, then the first is
@ -394,15 +445,28 @@ private
end end
## ##
# restrict changes to those which are open # 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
# at the moment this code assumes we're only interested in open # hit the maximum number of changes then it counts as no longer open.
# changesets and gives no facility to query closed changesets. this # if parameter 'open' is nill then open and closed changsets are returned
# would be reasonably simple to implement if anyone actually wants
# it?
def conditions_open(open) def conditions_open(open)
return open.nil? ? nil : ['closed_at >= ? and num_changes <= ?', return open.nil? ? nil : ['closed_at >= ? and num_changes <= ?',
DateTime.now, Changeset::MAX_ELEMENTS] DateTime.now, Changeset::MAX_ELEMENTS]
end 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 end

View file

@ -2,18 +2,24 @@ class ExportController < ApplicationController
def start def start
end end
#When the user clicks 'Export' we redirect to a URL which generates the export download
def finish def finish
bbox = BoundingBox.new(params[:minlon], params[:minlat], params[:maxlon], params[:maxlat]) bbox = BoundingBox.new(params[:minlon], params[:minlat], params[:maxlon], params[:maxlat])
format = params[:format] format = params[:format]
if format == "osm" if format == "osm"
#redirect to API map get
redirect_to "http://api.openstreetmap.org/api/#{API_VERSION}/map?bbox=#{bbox}" redirect_to "http://api.openstreetmap.org/api/#{API_VERSION}/map?bbox=#{bbox}"
elsif format == "mapnik" elsif format == "mapnik"
#redirect to a special 'export' cgi script
format = params[:mapnik_format] format = params[:mapnik_format]
scale = params[:mapnik_scale] scale = params[:mapnik_scale]
redirect_to "http://tile.openstreetmap.org/cgi-bin/export?bbox=#{bbox}&scale=#{scale}&format=#{format}" redirect_to "http://tile.openstreetmap.org/cgi-bin/export?bbox=#{bbox}&scale=#{scale}&format=#{format}"
elsif format == "osmarender" elsif format == "osmarender"
#redirect to the t@h 'MapOf' service
format = params[:osmarender_format] format = params[:osmarender_format]
zoom = params[:osmarender_zoom].to_i zoom = params[:osmarender_zoom].to_i
width = bbox.slippy_width(zoom).to_i width = bbox.slippy_width(zoom).to_i

View file

@ -1,16 +0,0 @@
<h2><%= @changesets.length %> Recently Closed Changesets</h2>
<ul id="recently_changed">
<% @changesets.each do |changeset|
if changeset.user.data_public?
user = changeset.user.display_name
else
user = "(anonymous)"
end
cmt = changeset.tags_as_hash['comment'].to_s
cmt = "(no comment)" if cmt.length == 0
text = "#{changeset.id} by #{user} - #{cmt}"
%>
<li><%= link_to h(text), :action => "changeset", :id => changeset.id %></li>
<% end %>
</ul>

View file

@ -8,9 +8,19 @@
<% if changeset.closed_at > DateTime.now %> (still editing) <% if changeset.closed_at > DateTime.now %> (still editing)
<% else %><%= changeset.closed_at.strftime("%d %b %Y %H:%M") %><% end %> <% else %><%= changeset.closed_at.strftime("%d %b %Y %H:%M") %><% end %>
<%if showusername==true %>
<td class="<%= cl %>">
<% if changeset.user.data_public? %>
<%= link_to h(changeset.user.display_name), :controller => "user", :action => "view", :display_name => changeset.user.display_name %>
<% else %>
<i>annon</i>
<% end %>
<% end %>
<td class="<%= cl %>"> <td class="<%= cl %>">
<% if changeset.tags['comment'] %> <% if changeset.tags['comment'] %>
<%= changeset.tags['comment'] %> <%= h(changeset.tags['comment']) %>
<% else %> <% else %>
(none) (none)
<% end %> <% end %>

View file

@ -7,6 +7,12 @@ if (current_page.first_item < current_page.last_item) # if more than 1 changeset
end %> end %>
of <%= @edit_pages.item_count %>) 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) } %> if @edit_pages.page_count > 1
<% end %> 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
%>

View file

@ -1,15 +1,19 @@
<h1>Edits by <%= link_to(@display_name, {:controller=>'user', :action=>'view', :display_name=>@display_name}) %></h1> <h1>Recent Changes</h1>
<%= render :partial => 'changeset_paging_nav' %>
Recently closed changesets:
<table id="keyvalue" cellpadding="3"> <table id="keyvalue" cellpadding="3">
<tr> <tr>
<th>ID</th> <th>ID</th>
<th>Saved at</th> <th>Saved at</th>
<th>User</th>
<th>Comment</th> <th>Comment</th>
<th>Area</th> <th>Area</th>
<th></th> <th></th>
</tr> </tr>
<%= render :partial => 'changeset', :collection => @edits unless @edits.nil? %> <%= render :partial => 'changeset', :locals => {:showusername => true}, :collection => @edits unless @edits.nil? %>
</table> </table>
<%= render :partial => 'changeset_paging_nav' %> <p>
For more changesets, select a user and view their edits, or see the editing 'history' of a specific area.
</p>
<br>

View file

@ -0,0 +1,50 @@
<h1>History</h1>
<%
if @bbox!=nil
lon1 = @bbox[0]
lat1 = @bbox[1]
lon2 = @bbox[2]
lat2 = @bbox[3]
%>
<p>
Changsets within the area:
(<a href='/?lat=<%= lat1 %>&lon=<%= lon1 %>&zoom=14'><%= format("%0.3f",lat1) -%>,<%= format("%0.3f",lon1) -%></a>) to
(<a href='/?lat=<%= lat2 %>&lon=<%= lon2 %>&zoom=14'><%= format("%0.3f",lat2) -%>,<%= format("%0.3f",lon2) -%></a>)
</p>
<% if @edits.nil? or @edits.empty? %>
<p><b>No changesets</b></p>
<% else %>
<%= render :partial => 'changeset_paging_nav' %>
<table id="keyvalue" cellpadding="3">
<tr>
<th>ID</th>
<th>Saved at</th>
<th>User</th>
<th>Comment</th>
<th>Area</th>
<th></th>
</tr>
<%= render :partial => 'changeset', :locals => {:showusername => true}, :collection => @edits unless @edits.nil? %>
</table>
<%= render :partial => 'changeset_paging_nav' %>
<%
end
else
#bbox is nil. happens if the user surfs to this page directly.
%>
<p>No area specified</p>
<p>First use the <a href="/" title="view the map">view tab</a> to pan and zoom to an area of interest, then click the history tab</p>
<%
end
%>
<br>
<br>

View file

@ -0,0 +1,15 @@
<h1>Edits by <%= link_to(@display_name, {:controller=>'user', :action=>'view', :display_name=>@display_name}) %></h1>
<%= render :partial => 'changeset_paging_nav' %>
<table id="keyvalue" cellpadding="3">
<tr>
<th>ID</th>
<th>Saved at</th>
<th>Comment</th>
<th>Area</th>
<th></th>
</tr>
<%= render :partial => 'changeset', :locals => {:showusername => false}, :collection => @edits unless @edits.nil? %>
</table>
<%= render :partial => 'changeset_paging_nav' %>

View file

@ -38,16 +38,19 @@
<% <%
viewclass = '' viewclass = ''
editclass = '' editclass = ''
historyclass = ''
exportclass = '' exportclass = ''
traceclass = '' traceclass = ''
viewclass = 'active' if params['controller'] == 'site' and params['action'] == 'index' viewclass = 'active' if params['controller'] == 'site' and params['action'] == 'index'
editclass = 'active' if params['controller'] == 'site' and params['action'] == 'edit' 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' exportclass = 'active' if params['controller'] == 'site' and params['action'] == 'export'
traceclass = 'active' if params['controller'] == 'trace' traceclass = 'active' if params['controller'] == 'trace'
diaryclass = 'active' if params['controller'] == 'diary_entry' diaryclass = 'active' if params['controller'] == 'diary_entry'
%> %>
<li><%= link_to 'View', {:controller => 'site', :action => 'index'}, {:id => 'viewanchor', :title => 'view maps', :class => viewclass} %></li> <li><%= link_to 'View', {:controller => 'site', :action => 'index'}, {:id => 'viewanchor', :title => 'view maps', :class => viewclass} %></li>
<li><%= link_to 'Edit', {:controller => 'site', :action => 'edit'}, {:id => 'editanchor', :title => 'edit maps', :class => editclass} %></li> <li><%= link_to 'Edit', {:controller => 'site', :action => 'edit'}, {:id => 'editanchor', :title => 'edit maps', :class => editclass} %></li>
<li><%= link_to 'History', {:controller => 'history' }, {:id => 'historyanchor', :title => 'changeset history', :class => historyclass} %></li>
<% if params['controller'] == 'site' and (params['action'] == 'index' or params['action'] == 'export') %> <% if params['controller'] == 'site' and (params['action'] == 'index' or params['action'] == 'export') %>
<li><%= link_to_remote 'Export', {:url => {:controller => 'export', :action => 'start'}}, {:id => 'exportanchor', :title => 'export map data', :class => exportclass, :href => url_for(:controller => 'site', :action => 'export')} %></li> <li><%= link_to_remote 'Export', {:url => {:controller => 'export', :action => 'start'}}, {:id => 'exportanchor', :title => 'export map data', :class => exportclass, :href => url_for(:controller => 'site', :action => 'export')} %></li>
<% else %> <% else %>

View file

@ -164,8 +164,9 @@ end
var lonlat = getMapCenter(); var lonlat = getMapCenter();
var zoom = map.getZoom(); var zoom = map.getZoom();
var layers = getMapLayers(); 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; document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers;
} }

View file

@ -5,7 +5,7 @@
<!-- Displaying user's own profile page --> <!-- Displaying user's own profile page -->
<%= link_to 'my diary', :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name %> <%= 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 '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 traces', :controller => 'trace', :action=>'mine' %>
| <%= link_to 'my settings', :controller => 'user', :action => 'account', :display_name => @user.display_name %> | <%= link_to 'my settings', :controller => 'user', :action => 'account', :display_name => @user.display_name %>
<% else %> <% else %>