def start
end
- def index
- @changesets = Changeset.find(:all, :order => "closed_at DESC", :conditions => ['closed_at < ?', DateTime.now], :limit=> 20)
- end
+
def relation
begin
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
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.
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
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
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
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
+++ /dev/null
-<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>
<% if changeset.closed_at > DateTime.now %> (still editing)
<% 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 %>">
<% if changeset.tags['comment'] %>
- <%= changeset.tags['comment'] %>
+ <%= h(changeset.tags['comment']) %>
<% else %>
(none)
<% end %>
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
+%>
-<h1>Edits by <%= link_to(@display_name, {:controller=>'user', :action=>'view', :display_name=>@display_name}) %></h1>
-<%= render :partial => 'changeset_paging_nav' %>
+<h1>Recent Changes</h1>
+Recently closed changesets:
<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', :collection => @edits unless @edits.nil? %>
+ <%= render :partial => 'changeset', :locals => {:showusername => true}, :collection => @edits unless @edits.nil? %>
</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>
--- /dev/null
+<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>
--- /dev/null
+<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' %>
<%
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'
%>
<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 'History', {:controller => 'history' }, {:id => 'historyanchor', :title => 'changeset history', :class => historyclass} %></li>
<% 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>
<% else %>
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;
}
<!-- Displaying user's own profile page -->
<%= 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 %>