# target_user - if set, specifies the user to fetch traces for. if not set will fetch all traces
# paging_action - the action that will be linked back to from view
def list (target_user = nil, paging_action = 'list')
- @traces_per_page = 4
+ @traces_per_page = 20
page_index = params[:page] ? params[:page].to_i - 1 : 0 # nice 1-based page -> 0-based page index
# from display name, pick up user id if one user's traces only
opt[:order] = 'timestamp DESC'
if params[:tag]
+ @tag = params[:tag]
conditions[0] += " AND gpx_file_tags.tag = ?"
- conditions << params[:tag];
+ conditions << @tag;
end
opt[:conditions] = conditions
@trace.inserted = false
@trace.user_id = @user.id
@trace.timestamp = Time.now
+ saved_filename = "/tmp/#{@trace.id}.gpx"
+ # *nix - specific `mv #{filename} /tmp/#{@trace.id}.gpx`
+ File.rename(filename, saved_filename)
+ @trace.tmpname = saved_filename
if @trace.save
logger.info("id is #{@trace.id}")
- File.rename(filename, "/tmp/#{@trace.id}.gpx")
- # *nix - specific `mv #{filename} /tmp/#{@trace.id}.gpx`
flash[:notice] = "Your GPX file has been uploaded and is awaiting insertion in to the database. This will usually happen within half an hour, and an email will be sent to you on completion."
+ else
+ #TODO upload failure
end
redirect_to :action => 'mine'
layout 'site'
before_filter :authorize, :only => :preferences
+ before_filter :authorize_web, :only => :rename
+
def save
@user = User.new(params[:user])
render :action => 'new'
end
end
+
+ def rename
+ new_name = params['display_name']
+ if @user
+ @user.display_name = new_name
+ if @user.save
+ flash[:notice] = "User display name updated OK."
+ else
+ flash[:notice] = "Rename failed: #{ @user.errors.full_messages.join('; ') }."
+ end
+ else
+ flash[:notice] = 'not logged in'
+ end
+ redirect_to :back
+ end
def lost_password
if params['user']['email']
class Trace < ActiveRecord::Base
set_table_name 'gpx_files'
+ validates_presence_of :user_id, :name, :public, :description, :tmpname, :timestamp
+ validates_numericality_of :latitude, :longitude
+ validates_inclusion_of :inserted, :in => [ true, false]
+
belongs_to :user
has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :destroy
tt.tag = tag
tt
}
- end\r
- \r
- def large_picture= (data)\r
- f = File.new(large_picture_name, "wb")\r
- f.syswrite(data)\r
- f.close\r
- end\r
- \r
- def icon_picture= (data)\r
- f = File.new(icon_picture_name, "wb")\r
- f.syswrite(data)\r
- f.close\r
- end\r
-\r
- def large_picture\r
- f = File.new(large_picture_name, "rb")\r
- logger.info "large picture file: '#{f.path}', bytes: #{File.size(f.path)}"\r
- data = f.sysread(File.size(f.path))\r
- logger.info "have read data, bytes: '#{data.length}'"\r
- f.close\r
- data\r
- end\r
- \r
- def icon_picture\r
- f = File.new(icon_picture_name, "rb")\r
- logger.info "icon picture file: '#{f.path}'"\r
- data = f.sysread(File.size(f.path))\r
- f.close\r
- data\r
- end\r
- \r
- # FIXME change to permanent filestore area\r
- def large_picture_name\r
- "/tmp/#{id}.gif"\r
- end\r
-\r
- # FIXME change to permanent filestore area\r
- def icon_picture_name\r
- "/tmp/#{id}_icon.gif"\r
- end\r
+ end
+
+ def large_picture= (data)
+ f = File.new(large_picture_name, "wb")
+ f.syswrite(data)
+ f.close
+ end
+
+ def icon_picture= (data)
+ f = File.new(icon_picture_name, "wb")
+ f.syswrite(data)
+ f.close
+ end
+
+ def large_picture
+ f = File.new(large_picture_name, "rb")
+ logger.info "large picture file: '#{f.path}', bytes: #{File.size(f.path)}"
+ data = f.sysread(File.size(f.path))
+ logger.info "have read data, bytes: '#{data.length}'"
+ f.close
+ data
+ end
+
+ def icon_picture
+ f = File.new(icon_picture_name, "rb")
+ logger.info "icon picture file: '#{f.path}'"
+ data = f.sysread(File.size(f.path))
+ f.close
+ data
+ end
+
+ # FIXME change to permanent filestore area
+ def large_picture_name
+ "/tmp/#{id}.gif"
+ end
+
+ # FIXME change to permanent filestore area
+ def icon_picture_name
+ "/tmp/#{id}_icon.gif"
+ end
end
has_many :traces
validates_confirmation_of :pass_crypt, :message => 'Password must match the confirmation password'
- validates_uniqueness_of :display_name
+ validates_uniqueness_of :display_name, :allow_nil => true
validates_uniqueness_of :email
validates_length_of :pass_crypt, :minimum => 8
- validates_length_of :display_name, :minimum => 3
+ validates_length_of :display_name, :minimum => 3, :allow_nil => true
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
def set_defaults
def pass_crypt=(str)
write_attribute("pass_crypt", Digest::MD5.hexdigest(str))
- end
+ end
def pass_crypt_confirmation=(str)
write_attribute("pass_crypt_confirm", Digest::MD5.hexdigest(str))
- end
-
+ end
+
def self.authenticate(email, passwd) \r
find(:first, :conditions => [ "email = ? AND pass_crypt = ?", email, Digest::MD5.hexdigest(passwd)])\r
end
</center>
</div>
-
<%= yield :optionals %>
-
<div id="cclogo">
<center>
by <%= link_to trace.user.display_name, {:controller => 'trace', :action => 'list', :display_name => trace.user.display_name} %>
in
<% if trace.tags %>
- <% trace.tags.each do |tag| %>
- <%= link_to tag.tag, :controller => 'trace', :action => @paging_action, :tag => tag.tag %>
- <% end %>
+ <% trace.tags.each do |tag| %>
+ <%= link_to tag.tag, :controller => 'trace', :action => @paging_action, :tag => tag.tag %>
+ <% end %>
<% end %>
</td>
</tr>
<% content_for "optionals" do %>
<div class="optionalbox">
- <h2>Tags</h2>
+ <span class="oboxheader">Tags</span>
+ <br />
+ <br />
<% if @all_tags %>
<% @all_tags.each do |tag| %>
<%= link_to tag, :controller => 'trace', :action => @paging_action, :tag => tag %><br />
<% end %>
<% end %>
</div>
- <div class="optionalbox" >
- <h2>User</h2>
- <p>It's an optional box!!</p>
-<% if @user %>
- <%= "<p><b>...and you're logged in!</b></p>" %>
-<% end %>
- </div>
+ <% if @user %>
+ <div class="optionalbox">
+ <span class="oboxheader">User</span>
+ <br />
+ <br />
+ <form action="/user/rename" method="get" style="margin: 0px">
+ <span>Display name:</span><br />
+ <input type="text" value="<%= @user.display_name %>" maxlength="255" size="8" name="display_name"/>
+ <input type="submit" value="Save"/>
+ <input type="hidden" value="<%= request.request_uri %>" name="redirect_url"/>
+ </form>
+ </div>
+ <% end %>
<% end %>
<h1>Public GPS Traces</h1>
-<br />
-
+<% if @tag %>
+ Traces filtered by tag <b><%= @tag %></b>
+ <br/><br/>
+<% end %>
<span class="rsssmall"><a href="<%= url_for :controller => 'trace', :action => 'georss' %>"><img src="/images/RSS.gif" border="0"></a></span> |
<% if @user %>
<%= link_to 'See just your traces', {:controller => 'trace', :action => 'mine'} %>
<% else %>
<%= link_to 'login', {:controller => 'user', :action => 'login'} %> to see just your traces
<% end %>
+<% if @tag %>
+ | <%= link_to 'See all traces', {:controller => 'trace', :action => 'list'} %>
+<% end %>
-<br /><br />
+<br />
+<br />
+
<%= render (:partial => 'trace_paging_nav') %>
<table id="keyvalue" cellpadding="3">
<h1>Your GPS Traces</h1>
-<br />
+<% if @tag %>
+ Traces filtered by tag <b><%= @tag %></b>
+ <br/><br/>
+<% end %>
+<%= link_to 'See all traces', {:controller => 'trace', :action => 'list'} %>
+<% if @tag %>
+ | <%= link_to 'See all your traces', {:controller => 'trace', :action => 'mine'} %>
+<% end %>
-<%= link_to 'See all traces', {:controller => 'trace', :action => 'list'} %><br /><br />
+<br />
+<br />
<% if @user %>
<%= start_form_tag({:action => 'create'}, :multipart => true) %>
</td></tr>
</table>
-<br>
-
<%= end_form_tag %>
<%= render (:partial => 'trace_paging_nav') %>
<img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :user_login => @trace.user.display_name %>">
<table border="0">
- <tr><td>filename:</td><td><%= @trace.name %></td></tr>
+ <tr><td>filename:</td><td><%= @trace.name %></td></tr> <!-- TODO link to download -->
<tr><td>uploaded at:</td><td><%= @trace.timestamp %></td></tr>
<tr><td>points:</td><td><%= @trace.size %></td></tr>
- <tr><td>start coordinate:</td><td><%= @trace.latitude %>, <%= @trace.longitude %></td></tr>
- <tr><td>owner:</td><td><%= link_to @trace.user.display_name, {:controller => 'trace', :action => 'by_user'} %></td></tr>
+ <tr><td>start coordinate:</td><td><%= @trace.latitude %>, <%= @trace.longitude %></td></tr> <!-- TODO link to map -->
+ <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><%= @trace.tags.collect {|tag| tag.tag} %></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 %>
+ <% end %>
+ </td></tr>
</table>
# API
map.connect "api/#{API_VERSION}/node/create", :controller => 'node', :action => 'create'
- map.connect "api/#{API_VERSION}/node/:id/history", :controller => 'old_node', :action => 'history', :id => nil # TODO is this :id => nil correct? looks like it would throw away essential info - if it does check all these id => nils
+ map.connect "api/#{API_VERSION}/node/:id/history", :controller => 'old_node', :action => 'history', :id => nil
map.connect "api/#{API_VERSION}/node/:id", :controller => 'node', :action => 'rest', :id => nil
map.connect "api/#{API_VERSION}/nodes", :controller => 'node', :action => 'nodes', :id => nil
map.connect '/traces/tag/:tag', :controller => 'trace', :action => 'list', :id => nil
map.connect '/traces/tag/:tag/page/:page', :controller => 'trace', :action => 'list', :id => nil\r
+ # test pages
+ map.connect '/test/populate/:table/:from/:count', :controller => 'test', :action => 'populate'
+ map.connect '/test/populate/:table/:count', :controller => 'test', :action => 'populate', :from => 1
+
# fall through
map.connect ':controller/:action/:id'
end