API 0.4: User rename, view trace links, tag filter summary / see all link, traces testing
This commit is contained in:
parent
11279ebfe9
commit
2709027882
11 changed files with 129 additions and 74 deletions
|
@ -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
|
||||
# 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
|
||||
|
@ -40,8 +40,9 @@ class TraceController < ApplicationController
|
|||
|
||||
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
|
||||
|
@ -103,11 +104,15 @@ class TraceController < ApplicationController
|
|||
@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'
|
||||
|
|
|
@ -2,6 +2,8 @@ class UserController < ApplicationController
|
|||
layout 'site'
|
||||
|
||||
before_filter :authorize, :only => :preferences
|
||||
before_filter :authorize_web, :only => :rename
|
||||
|
||||
|
||||
def save
|
||||
@user = User.new(params[:user])
|
||||
|
@ -15,6 +17,21 @@ class UserController < ApplicationController
|
|||
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']
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
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
|
||||
|
||||
|
@ -10,44 +14,44 @@ class Trace < ActiveRecord::Base
|
|||
tt.tag = tag
|
||||
tt
|
||||
}
|
||||
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
|
||||
|
||||
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
|
||||
|
|
|
@ -4,10 +4,10 @@ class User < ActiveRecord::Base
|
|||
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
|
||||
|
@ -18,12 +18,12 @@ class User < ActiveRecord::Base
|
|||
|
||||
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)
|
||||
find(:first, :conditions => [ "email = ? AND pass_crypt = ?", email, Digest::MD5.hexdigest(passwd)])
|
||||
end
|
||||
|
|
|
@ -80,9 +80,7 @@
|
|||
</center>
|
||||
|
||||
</div>
|
||||
|
||||
<%= yield :optionals %>
|
||||
|
||||
<div id="cclogo">
|
||||
<center>
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
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>
|
||||
|
|
|
@ -1,17 +1,25 @@
|
|||
<% 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 %>
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
<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">
|
||||
|
|
|
@ -1,8 +1,16 @@
|
|||
<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) %>
|
||||
|
@ -17,8 +25,6 @@
|
|||
</td></tr>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<%= end_form_tag %>
|
||||
|
||||
<%= render (:partial => 'trace_paging_nav') %>
|
||||
|
|
|
@ -3,11 +3,17 @@
|
|||
<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>
|
||||
|
|
|
@ -2,7 +2,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||
|
||||
# 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
|
||||
|
||||
|
@ -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/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
|
||||
map.connect ':controller/:action/:id'
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue