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
|
# 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'
|
||||||
|
|
|
@ -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])
|
||||||
|
@ -16,6 +18,21 @@ class UserController < ApplicationController
|
||||||
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']
|
||||||
user = User.find_by_email(params['user']['email'])
|
user = User.find_by_email(params['user']['email'])
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -80,9 +80,7 @@
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= yield :optionals %>
|
<%= yield :optionals %>
|
||||||
|
|
||||||
<div id="cclogo">
|
<div id="cclogo">
|
||||||
<center>
|
<center>
|
||||||
|
|
||||||
|
|
|
@ -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">
|
||||||
|
<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>
|
</div>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -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">
|
||||||
|
|
|
@ -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') %>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue