API 0.4: User rename, view trace links, tag filter summary / see all link, traces testing

This commit is contained in:
Dan Moore 2007-03-29 22:14:39 +00:00
parent 11279ebfe9
commit 2709027882
11 changed files with 129 additions and 74 deletions

View file

@ -6,7 +6,7 @@ class TraceController < ApplicationController
# target_user - if set, specifies the user to fetch traces for. if not set will fetch all traces # 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 # paging_action - the action that will be linked back to from view
def list (target_user = nil, paging_action = 'list') 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 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 # from display name, pick up user id if one user's traces only
@ -40,8 +40,9 @@ class TraceController < ApplicationController
opt[:order] = 'timestamp DESC' opt[:order] = 'timestamp DESC'
if params[:tag] if params[:tag]
@tag = params[:tag]
conditions[0] += " AND gpx_file_tags.tag = ?" conditions[0] += " AND gpx_file_tags.tag = ?"
conditions << params[:tag]; conditions << @tag;
end end
opt[:conditions] = conditions opt[:conditions] = conditions
@ -103,11 +104,15 @@ class TraceController < ApplicationController
@trace.inserted = false @trace.inserted = false
@trace.user_id = @user.id @trace.user_id = @user.id
@trace.timestamp = Time.now @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 if @trace.save
logger.info("id is #{@trace.id}") 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." 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 end
redirect_to :action => 'mine' redirect_to :action => 'mine'

View file

@ -2,6 +2,8 @@ class UserController < ApplicationController
layout 'site' layout 'site'
before_filter :authorize, :only => :preferences before_filter :authorize, :only => :preferences
before_filter :authorize_web, :only => :rename
def save def save
@user = User.new(params[:user]) @user = User.new(params[:user])
@ -15,6 +17,21 @@ class UserController < ApplicationController
render :action => 'new' render :action => 'new'
end end
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 def lost_password
if params['user']['email'] if params['user']['email']

View file

@ -1,6 +1,10 @@
class Trace < ActiveRecord::Base class Trace < ActiveRecord::Base
set_table_name 'gpx_files' 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 belongs_to :user
has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :destroy has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :destroy
@ -10,44 +14,44 @@ class Trace < ActiveRecord::Base
tt.tag = tag tt.tag = tag
tt tt
} }
end end
def large_picture= (data) def large_picture= (data)
f = File.new(large_picture_name, "wb") f = File.new(large_picture_name, "wb")
f.syswrite(data) f.syswrite(data)
f.close f.close
end end
def icon_picture= (data) def icon_picture= (data)
f = File.new(icon_picture_name, "wb") f = File.new(icon_picture_name, "wb")
f.syswrite(data) f.syswrite(data)
f.close f.close
end end
def large_picture def large_picture
f = File.new(large_picture_name, "rb") f = File.new(large_picture_name, "rb")
logger.info "large picture file: '#{f.path}', bytes: #{File.size(f.path)}" logger.info "large picture file: '#{f.path}', bytes: #{File.size(f.path)}"
data = f.sysread(File.size(f.path)) data = f.sysread(File.size(f.path))
logger.info "have read data, bytes: '#{data.length}'" logger.info "have read data, bytes: '#{data.length}'"
f.close f.close
data data
end end
def icon_picture def icon_picture
f = File.new(icon_picture_name, "rb") f = File.new(icon_picture_name, "rb")
logger.info "icon picture file: '#{f.path}'" logger.info "icon picture file: '#{f.path}'"
data = f.sysread(File.size(f.path)) data = f.sysread(File.size(f.path))
f.close f.close
data data
end end
# FIXME change to permanent filestore area # FIXME change to permanent filestore area
def large_picture_name def large_picture_name
"/tmp/#{id}.gif" "/tmp/#{id}.gif"
end end
# FIXME change to permanent filestore area # FIXME change to permanent filestore area
def icon_picture_name def icon_picture_name
"/tmp/#{id}_icon.gif" "/tmp/#{id}_icon.gif"
end end
end end

View file

@ -4,10 +4,10 @@ class User < ActiveRecord::Base
has_many :traces has_many :traces
validates_confirmation_of :pass_crypt, :message => 'Password must match the confirmation password' 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_uniqueness_of :email
validates_length_of :pass_crypt, :minimum => 8 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 validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
def set_defaults def set_defaults
@ -18,12 +18,12 @@ class User < ActiveRecord::Base
def pass_crypt=(str) def pass_crypt=(str)
write_attribute("pass_crypt", Digest::MD5.hexdigest(str)) write_attribute("pass_crypt", Digest::MD5.hexdigest(str))
end end
def pass_crypt_confirmation=(str) def pass_crypt_confirmation=(str)
write_attribute("pass_crypt_confirm", Digest::MD5.hexdigest(str)) write_attribute("pass_crypt_confirm", Digest::MD5.hexdigest(str))
end end
def self.authenticate(email, passwd) def self.authenticate(email, passwd)
find(:first, :conditions => [ "email = ? AND pass_crypt = ?", email, Digest::MD5.hexdigest(passwd)]) find(:first, :conditions => [ "email = ? AND pass_crypt = ?", email, Digest::MD5.hexdigest(passwd)])
end end

View file

@ -80,9 +80,7 @@
</center> </center>
</div> </div>
<%= yield :optionals %> <%= yield :optionals %>
<div id="cclogo"> <div id="cclogo">
<center> <center>

View file

@ -20,9 +20,9 @@
by <%= link_to trace.user.display_name, {:controller => 'trace', :action => 'list', :display_name => trace.user.display_name} %> by <%= link_to trace.user.display_name, {:controller => 'trace', :action => 'list', :display_name => trace.user.display_name} %>
in in
<% if trace.tags %> <% if trace.tags %>
<% trace.tags.each do |tag| %> <% trace.tags.each do |tag| %>
<%= link_to tag.tag, :controller => 'trace', :action => @paging_action, :tag => tag.tag %> <%= link_to tag.tag, :controller => 'trace', :action => @paging_action, :tag => tag.tag %>
<% end %> <% end %>
<% end %> <% end %>
</td> </td>
</tr> </tr>

View file

@ -1,17 +1,25 @@
<% content_for "optionals" do %> <% content_for "optionals" do %>
<div class="optionalbox"> <div class="optionalbox">
<h2>Tags</h2> <span class="oboxheader">Tags</span>
<br />
<br />
<% if @all_tags %> <% if @all_tags %>
<% @all_tags.each do |tag| %> <% @all_tags.each do |tag| %>
<%= link_to tag, :controller => 'trace', :action => @paging_action, :tag => tag %><br /> <%= link_to tag, :controller => 'trace', :action => @paging_action, :tag => tag %><br />
<% end %> <% end %>
<% end %> <% end %>
</div> </div>
<div class="optionalbox" > <% if @user %>
<h2>User</h2> <div class="optionalbox">
<p>It's an optional box!!</p> <span class="oboxheader">User</span>
<% if @user %> <br />
<%= "<p><b>...and you're logged in!</b></p>" %> <br />
<% end %> <form action="/user/rename" method="get" style="margin: 0px">
</div> <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 %> <% end %>

View file

@ -1,16 +1,23 @@
<h1>Public GPS Traces</h1> <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> | <span class="rsssmall"><a href="<%= url_for :controller => 'trace', :action => 'georss' %>"><img src="/images/RSS.gif" border="0"></a></span> |
<% if @user %> <% if @user %>
<%= link_to 'See just your traces', {:controller => 'trace', :action => 'mine'} %> <%= link_to 'See just your traces', {:controller => 'trace', :action => 'mine'} %>
<% else %> <% else %>
<%= link_to 'login', {:controller => 'user', :action => 'login'} %> to see just your traces <%= link_to 'login', {:controller => 'user', :action => 'login'} %> to see just your traces
<% end %> <% end %>
<% if @tag %>
| <%= link_to 'See all traces', {:controller => 'trace', :action => 'list'} %>
<% end %>
<br /><br /> <br />
<br />
<%= render (:partial => 'trace_paging_nav') %> <%= render (:partial => 'trace_paging_nav') %>
<table id="keyvalue" cellpadding="3"> <table id="keyvalue" cellpadding="3">

View file

@ -1,8 +1,16 @@
<h1>Your GPS Traces</h1> <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 %> <% if @user %>
<%= start_form_tag({:action => 'create'}, :multipart => true) %> <%= start_form_tag({:action => 'create'}, :multipart => true) %>
@ -17,8 +25,6 @@
</td></tr> </td></tr>
</table> </table>
<br>
<%= end_form_tag %> <%= end_form_tag %>
<%= render (:partial => 'trace_paging_nav') %> <%= render (:partial => 'trace_paging_nav') %>

View file

@ -3,11 +3,17 @@
<img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :user_login => @trace.user.display_name %>"> <img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :user_login => @trace.user.display_name %>">
<table border="0"> <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>uploaded at:</td><td><%= @trace.timestamp %></td></tr>
<tr><td>points:</td><td><%= @trace.size %></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>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 => 'by_user'} %></td></tr> <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>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> </table>

View file

@ -2,7 +2,7 @@ ActionController::Routing::Routes.draw do |map|
# API # API
map.connect "api/#{API_VERSION}/node/create", :controller => 'node', :action => 'create' 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}/node/:id", :controller => 'node', :action => 'rest', :id => nil
map.connect "api/#{API_VERSION}/nodes", :controller => 'node', :action => 'nodes', :id => nil map.connect "api/#{API_VERSION}/nodes", :controller => 'node', :action => 'nodes', :id => nil
@ -44,6 +44,10 @@ ActionController::Routing::Routes.draw do |map|
map.connect '/traces/tag/:tag', :controller => 'trace', :action => 'list', :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 map.connect '/traces/tag/:tag/page/:page', :controller => 'trace', :action => 'list', :id => nil
# 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 # fall through
map.connect ':controller/:action/:id' map.connect ':controller/:action/:id'
end end