Put the option to delete GPS traces back. Fixes #405.

This commit is contained in:
Tom Hughes 2007-08-22 18:01:23 +00:00
parent 30c20855e3
commit d274c0e3d8
4 changed files with 102 additions and 25 deletions

View file

@ -48,6 +48,8 @@ class TraceController < ApplicationController
conditions << @tag
end
conditions[0] += " AND gpx_files.visible = 1"
@trace_pages, @traces = paginate(:traces,
:include => [:user, :tags],
:conditions => conditions,
@ -82,10 +84,10 @@ class TraceController < ApplicationController
def view
@trace = Trace.find(params[:id])
@title = "Viewing trace #{@trace.name}"
unless @trace.public
if @user
render :nothing, :status => :forbidden if @trace.user.id != @user.id
end
if !@trace.visible?
render :nothing => true, :status => :not_found
elsif !@trace.public? and @trace.user.id != @user.id
render :nothing => true, :status => :forbidden
end
rescue ActiveRecord::RecordNotFound
render :nothing => true, :status => :not_found
@ -109,7 +111,7 @@ class TraceController < ApplicationController
def data
trace = Trace.find(params[:id])
if trace.public? or (@user and @user == trace.user)
if trace.visible? and (trace.public? or (@user and @user == trace.user))
send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => 'attachment')
else
render :nothing, :status => :not_found
@ -118,14 +120,42 @@ class TraceController < ApplicationController
render :nothing => true, :status => :not_found
end
def delete
trace = Trace.find(params[:id])
if @user and trace.user == @user
if request.post? and trace.visible?
trace.visible = false
trace.save
flash[:notice] = 'Track scheduled for deletion'
redirect_to :controller => 'traces', :action => 'mine'
else
render :nothing, :status => :bad_request
end
else
render :nothing, :status => :forbidden
end
rescue ActiveRecord::RecordNotFound
render :nothing => true, :status => :not_found
end
def make_public
trace = Trace.find(params[:id])
if @user and trace.user == @user and !trace.public
trace.public = true
trace.save
flash[:notice] = 'Track made public'
redirect_to :controller => 'trace', :action => 'view', :id => params[:id]
if @user and trace.user == @user
if request.post? and !trace.public?
trace.public = true
trace.save
flash[:notice] = 'Track made public'
redirect_to :controller => 'trace', :action => 'view', :id => params[:id]
else
render :nothing, :status => :bad_request
end
else
render :nothing, :status => :forbidden
end
rescue ActiveRecord::RecordNotFound
render :nothing => true, :status => :not_found
end
def georss

View file

@ -3,26 +3,54 @@
<img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :display_name => @trace.user.display_name %>">
<table border="0">
<tr><td>filename:</td><td><%= @trace.name %> (<%= link_to 'download', :controller => 'trace', :action => 'data', :id => @trace.id %>)</td></tr> <!-- TODO link to download -->
<tr><td>uploaded at:</td><td><%= @trace.timestamp %></td></tr>
<tr>
<td>Filename:</td>
<td><%= @trace.name %> (<%= link_to 'download', :controller => 'trace', :action => 'data', :id => @trace.id %>)</td>
</tr>
<tr>
<td>Uploaded at:</td>
<td><%= @trace.timestamp %></td>
</tr>
<% if @trace.inserted? %>
<tr><td>points:</td><td><%= @trace.size.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,') %></td></tr>
<tr><td>start coordinate:</td><td><%= @trace.latitude %>, <%= @trace.longitude %> (<%=link_to 'map', :controller => 'site', :action => 'index', :lat => @trace.latitude, :lon => @trace.longitude, :zoom => 14 %> / <%=link_to 'edit', :controller => 'site', :action => 'edit', :lat => @trace.latitude, :lon => @trace.longitude, :zoom => 14 %>)</td></tr>
<tr>
<td>Points:</td>
<td><%= @trace.size.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,') %></td></tr>
<tr>
<td>Start coordinate:</td>
<td><%= @trace.latitude %>, <%= @trace.longitude %> (<%=link_to 'map', :controller => 'site', :action => 'index', :lat => @trace.latitude, :lon => @trace.longitude, :zoom => 14 %> / <%=link_to 'edit', :controller => 'site', :action => 'edit', :lat => @trace.latitude, :lon => @trace.longitude, :zoom => 14 %>)</td>
</tr>
<% end %>
<tr><td>owner:</td><td><%= link_to @trace.user.display_name, {:controller => 'trace', :action => 'view', :display_name => @trace.user.display_name, :id => nil} %></td></tr>
<tr><td>description:</td><td><%= @trace.description %></td></tr>
<tr><td>tags:</td><td>
<tr>
<td>Owner:</td>
<td><%= link_to @trace.user.display_name, {:controller => 'trace', :action => 'view', :display_name => @trace.user.display_name} %></td>
</tr>
<tr>
<td>Description:</td>
<td><%= @trace.description %></td>
</tr>
<tr>
<td>Tags:</td>
<td>
<% if @trace.tags %>
<% @trace.tags.each do |tag| %>
<%= link_to tag.tag, { :controller => 'trace', :action => 'list', :tag => tag.tag, :id => nil } %>
<% end %>
<% else %>
None
<% end %>
</td></tr>
</td>
</tr>
</table>
<% unless @trace.public? %>
<br /><br />
<%= start_form_tag :controller => 'trace', :action => 'make_public', :id => @trace.id%>
<%= submit_tag 'Make this track public permanently' %>
<%= end_form_tag %>
<% end %>
<br /><br />
<table>
<tr>
<% unless @trace.public? %>
<td><%= button_to 'Make this track public permanently', :controller => 'trace', :action => 'make_public', :id => @trace.id %></td>
<% end %>
<% if @trace.user.id == @user.id %>
<td><%= button_to 'Delete this track', :controller => 'trace', :action => 'delete', :id => @trace.id %></td>
<% end %>
</tr>
</table>

View file

@ -75,6 +75,8 @@ ActionController::Routing::Routes.draw do |map|
map.connect '/traces/mine/tag/:tag', :controller => 'trace', :action => 'mine'
map.connect '/traces/mine/tag/:tag/page/:page', :controller => 'trace', :action => 'mine'
map.connect '/trace/create', :controller => 'trace', :action => 'create'
map.connect '/trace/:id/delete', :controller => 'trace', :action => 'delete'
map.connect '/trace/:id/make_public', :controller => 'trace', :action => 'make_public'
map.connect '/user/:display_name/traces', :controller => 'trace', :action => 'list'
map.connect '/user/:display_name/traces/page/:page', :controller => 'trace', :action => 'list'
map.connect '/user/:display_name/traces/rss', :controller => 'trace', :action => 'georss'

View file

@ -12,7 +12,7 @@ logger = ActiveRecord::Base.logger
while(true) do
ActiveRecord::Base.logger.info("GPX Import daemon wake @ #{Time.now}.")
Trace.find(:all, :conditions => ['inserted = ?', false]).each do |trace|
Trace.find(:all, :conditions => 'inserted = 0').each do |trace|
Signal.trap("TERM") do
terminated = true
end
@ -38,5 +38,22 @@ while(true) do
exit if terminated
end
Trace.find(:all, :conditions => 'visible = 0').each do |trace|
Signal.trap("TERM") do
terminated = true
end
begin
trace.destroy
rescue Exception => ex
logger.info ex.to_s
ex.backtrace.each {|l| logger.info l }
end
Signal.trap("TERM", "DEFAULT")
exit if terminated
end
sleep 5.minutes
end