API 0.4 Updates - work on traces pages + pagination, edit tab, some API testing
* traces - added some routes, replicated data access / pagination, but presentation and pending file control not complete * edit - setup so that applet can be loaded + token authorisation enabled * API - tests out ok against applet, but had to change segment-node associations * misc - gems version required upgraded to 1.2.3 (latest stable rails version), changed some find_first to find(:first... calls
This commit is contained in:
parent
e7c2d2a211
commit
d07277efba
25 changed files with 248 additions and 93 deletions
|
@ -27,7 +27,7 @@ class ApiController < ApplicationController
|
||||||
if node_ids.length > 0
|
if node_ids.length > 0
|
||||||
node_ids_sql = "(#{node_ids.join(',')})"
|
node_ids_sql = "(#{node_ids.join(',')})"
|
||||||
# get the referenced segments
|
# get the referenced segments
|
||||||
segments = Segment.find_by_sql "select * from current_segments where node_a in #{node_ids_sql} or node_b in #{node_ids_sql}"
|
segments = Segment.find_by_sql "select * from current_segments where visible = 1 and (node_a in #{node_ids_sql} or node_b in #{node_ids_sql})"
|
||||||
end
|
end
|
||||||
# see if we have nay missing nodes
|
# see if we have nay missing nodes
|
||||||
segments_nodes = segments.collect {|segment| segment.node_a }
|
segments_nodes = segments.collect {|segment| segment.node_a }
|
||||||
|
@ -49,8 +49,7 @@ class ApiController < ApplicationController
|
||||||
if segment_ids.length > 0
|
if segment_ids.length > 0
|
||||||
way_segments = WaySegment.find_all_by_segment_id(segment_ids)
|
way_segments = WaySegment.find_all_by_segment_id(segment_ids)
|
||||||
way_ids = way_segments.collect {|way_segment| way_segment.id }
|
way_ids = way_segments.collect {|way_segment| way_segment.id }
|
||||||
|
ways = Way.find(way_ids) # NB: doesn't pick up segments, tags from db until accessed via way.way_segments etc.
|
||||||
ways = Way.find(way_ids)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
nodes.each do |node|
|
nodes.each do |node|
|
||||||
|
|
|
@ -6,24 +6,31 @@ class ApplicationController < ActionController::Base
|
||||||
@user = User.find_by_token(session[:token])
|
@user = User.find_by_token(session[:token])
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorize(realm='Web Password', errormessage="Could't authenticate you")
|
def authorize(realm='Web Password', errormessage="Could't authenticate you")
|
||||||
username, passwd = get_auth_data
|
username, passwd = get_auth_data # parse from headers
|
||||||
# check if authorized
|
# authenticate per-scheme
|
||||||
# try to get user
|
if username.nil?
|
||||||
if @user = User.authenticate(username, passwd)
|
@user = nil # no authentication provided - perhaps first connect (client should retry after 401)
|
||||||
|
elsif username == 'token'
|
||||||
|
@user = User.authenticate_token(passwd) # preferred - random token for user from db, passed in basic auth
|
||||||
|
else
|
||||||
|
@user = User.authenticate(username, passwd) # basic auth
|
||||||
|
end
|
||||||
|
|
||||||
|
# handle authenticate pass/fail
|
||||||
|
if @user
|
||||||
# user exists and password is correct ... horray!
|
# user exists and password is correct ... horray!
|
||||||
if @user.methods.include? 'lastlogin'
|
if @user.methods.include? 'lastlogin' # note last login
|
||||||
# note last login
|
|
||||||
@session['lastlogin'] = user.lastlogin
|
@session['lastlogin'] = user.lastlogin
|
||||||
@user.last.login = Time.now
|
@user.last.login = Time.now
|
||||||
@user.save()
|
@user.save()
|
||||||
@session["User.id"] = @user.id
|
@session["User.id"] = @user.id
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# the user does not exist or the password was wrong
|
# no auth, the user does not exist or the password was wrong
|
||||||
@response.headers["Status"] = "Unauthorized"
|
response.headers["Status"] = "Unauthorized"
|
||||||
@response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\""
|
response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\""
|
||||||
render_text(errormessage, 401)
|
render_text(errormessage, 401) # :unauthorized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,22 +44,18 @@ class ApplicationController < ActionController::Base
|
||||||
return doc
|
return doc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# extract authorisation credentials from headers, returns user = nil if none
|
||||||
private
|
private
|
||||||
def get_auth_data
|
def get_auth_data
|
||||||
user, pass = '', ''
|
if request.env.has_key? 'X-HTTP_AUTHORIZATION' # where mod_rewrite might have put it
|
||||||
# extract authorisation credentials
|
authdata = request.env['X-HTTP_AUTHORIZATION'].to_s.split
|
||||||
if request.env.has_key? 'X-HTTP_AUTHORIZATION'
|
elsif request.env.has_key? 'HTTP_AUTHORIZATION' # regular location
|
||||||
# try to get it where mod_rewrite might have put it
|
authdata = request.env['HTTP_AUTHORIZATION'].to_s.split
|
||||||
authdata = @request.env['X-HTTP_AUTHORIZATION'].to_s.split
|
|
||||||
elsif request.env.has_key? 'HTTP_AUTHORIZATION'
|
|
||||||
# this is the regular location
|
|
||||||
authdata = @request.env['HTTP_AUTHORIZATION'].to_s.split
|
|
||||||
end
|
end
|
||||||
|
# only basic authentication supported
|
||||||
# at the moment we only support basic authentication
|
|
||||||
if authdata and authdata[0] == 'Basic'
|
if authdata and authdata[0] == 'Basic'
|
||||||
user, pass = Base64.decode64(authdata[1]).split(':')[0..1]
|
user, pass = Base64.decode64(authdata[1]).split(':')[0..1]
|
||||||
end
|
end
|
||||||
return [user, pass]
|
return [user, pass]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ class NodeController < ApplicationController
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
after_filter :compress_output
|
after_filter :compress_output
|
||||||
|
|
||||||
def create
|
def create
|
||||||
response.headers["Content-Type"] = 'application/xml'
|
response.headers["Content-Type"] = 'application/xml'
|
||||||
if request.put?
|
if request.put?
|
||||||
node = nil
|
node = nil
|
||||||
|
|
|
@ -10,7 +10,6 @@ class SegmentController < ApplicationController
|
||||||
segment = Segment.from_xml(request.raw_post, true)
|
segment = Segment.from_xml(request.raw_post, true)
|
||||||
|
|
||||||
if segment
|
if segment
|
||||||
|
|
||||||
segment.user_id = @user.id
|
segment.user_id = @user.id
|
||||||
|
|
||||||
segment.from_node = Node.find(segment.node_a.to_i)
|
segment.from_node = Node.find(segment.node_a.to_i)
|
||||||
|
|
|
@ -1,24 +1,87 @@
|
||||||
class TraceController < ApplicationController
|
class TraceController < ApplicationController
|
||||||
before_filter :authorize_web
|
before_filter :authorize_web
|
||||||
layout 'site'
|
layout 'site'
|
||||||
|
|
||||||
|
# Counts and selects pages of GPX traces for various criteria (by user, tags, public etc.).
|
||||||
|
# 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
|
||||||
|
page_index = params[:page] ? params[:page].to_i - 1 : 0 # nice 1-based page -> 0-based page index
|
||||||
|
|
||||||
def list
|
# from display name, pick up user id if one user's traces only
|
||||||
@page = params[:page].to_i
|
display_name = params[:display_name]
|
||||||
|
if target_user.nil? and display_name and display_name != ''
|
||||||
opt = Hash.new
|
target_user = User.find(:first, :conditions => [ "display_name = ?", display_name])
|
||||||
opt[:conditions] = ['public = true']
|
|
||||||
opt[:order] = 'timestamp DESC'
|
|
||||||
opt[:limit] = 20
|
|
||||||
|
|
||||||
if @page > 0
|
|
||||||
opt[:offset => 20*@page]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opt = Hash.new
|
||||||
|
opt[:include] = [:user, :tags] # load users and tags from db at same time as traces
|
||||||
|
|
||||||
|
# four main cases:
|
||||||
|
# 1 - all traces, logged in = all public traces + all user's (i.e + all mine)
|
||||||
|
# 2 - all traces, not logged in = all public traces
|
||||||
|
# 3 - user's traces, logged in as same user = all user's traces
|
||||||
|
# 4 - user's traces, not logged in as that user = all user's public traces
|
||||||
|
if target_user.nil? # all traces
|
||||||
|
if @user
|
||||||
|
conditions = ["(public = 1 OR user_id = ?)", @user.id] #1
|
||||||
|
else
|
||||||
|
conditions = ["public = 1"] #2
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if @user and @user.id == target_user.id
|
||||||
|
conditions = ["user_id = ?", @user.id] #3 (check vs user id, so no join + can't pick up non-public traces by changing name)
|
||||||
|
else
|
||||||
|
conditions = ["public = 1 AND user_id = ?", target_user.id] #4
|
||||||
|
end
|
||||||
|
end
|
||||||
|
conditions[0] += " AND users.display_name != ''" # users need to set display name before traces will be exposed
|
||||||
|
|
||||||
|
opt[:order] = 'timestamp DESC'
|
||||||
if params[:tag]
|
if params[:tag]
|
||||||
|
conditions[0] += " AND gpx_file_tags.tag = ?"
|
||||||
|
conditions << params[:tag];
|
||||||
|
end
|
||||||
|
|
||||||
|
opt[:conditions] = conditions
|
||||||
|
|
||||||
|
# count traces using all options except limit
|
||||||
|
@max_trace = Trace.count(opt)
|
||||||
|
@max_page = Integer((@max_trace + 1) / @traces_per_page)
|
||||||
|
|
||||||
|
# last step before fetch - add paging options
|
||||||
|
opt[:limit] = @traces_per_page
|
||||||
|
if page_index > 0
|
||||||
|
opt[:offset] = @traces_per_page * page_index
|
||||||
end
|
end
|
||||||
|
|
||||||
@traces = Trace.find(:all , opt)
|
@traces = Trace.find(:all , opt)
|
||||||
|
|
||||||
|
# put together SET of tags across traces, for related links
|
||||||
|
tagset = Hash.new
|
||||||
|
if @traces
|
||||||
|
@traces.each do |trace|
|
||||||
|
trace.tags.reload if params[:tag] # if searched by tag, ActiveRecord won't bring back other tags, so do explicitly here
|
||||||
|
trace.tags.each do |tag|
|
||||||
|
tagset[tag.tag] = tag.tag
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# final helper vars for view
|
||||||
|
@display_name = display_name
|
||||||
|
@all_tags = tagset.values
|
||||||
|
@paging_action = paging_action # the action that paging requests should route back to, e.g. 'list' or 'mine'
|
||||||
|
@page = page_index + 1 # nice 1-based external page numbers
|
||||||
|
end
|
||||||
|
|
||||||
|
def mine
|
||||||
|
if @user
|
||||||
|
list(@user, 'mine') unless @user.nil?
|
||||||
|
else
|
||||||
|
redirect_to :controller => 'user', :action => 'login'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def view
|
def view
|
||||||
|
@ -42,7 +105,8 @@ class TraceController < ApplicationController
|
||||||
@trace.timestamp = Time.now
|
@trace.timestamp = Time.now
|
||||||
if @trace.save
|
if @trace.save
|
||||||
logger.info("id is #{@trace.id}")
|
logger.info("id is #{@trace.id}")
|
||||||
`mv #{filename} /tmp/#{@trace.id}.gpx`
|
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."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -66,11 +130,11 @@ class TraceController < ApplicationController
|
||||||
|
|
||||||
def picture
|
def picture
|
||||||
trace = Trace.find(params[:id])
|
trace = Trace.find(params[:id])
|
||||||
send_data(trace.large_picture, :filename => "#{trace.id}.gif", :type => 'image/png', :disposition => 'inline') if trace.public
|
send_data(trace.large_picture, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') if trace.public
|
||||||
end
|
end
|
||||||
|
|
||||||
def icon
|
def icon
|
||||||
trace = Trace.find(params[:id])
|
trace = Trace.find(params[:id])
|
||||||
send_data(trace.icon_picture, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') if trace.public
|
send_data(trace.icon_picture, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline') if trace.public
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
class WayController < ApplicationController
|
class WayController < ApplicationController
|
||||||
require 'xml/libxml'
|
require 'xml/libxml'
|
||||||
|
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
after_filter :compress_output
|
after_filter :compress_output
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if request.put?
|
if request.put?
|
||||||
way = Way.from_xml(request.raw_post, true)
|
way = Way.from_xml(request.raw_post, true)
|
||||||
|
@ -32,7 +32,7 @@ class WayController < ApplicationController
|
||||||
render :nothing => true, :status => 500 # something went very wrong
|
render :nothing => true, :status => 500 # something went very wrong
|
||||||
end
|
end
|
||||||
|
|
||||||
def rest
|
def rest
|
||||||
unless Way.exists?(params[:id])
|
unless Way.exists?(params[:id])
|
||||||
render :nothing => true, :status => 404
|
render :nothing => true, :status => 404
|
||||||
return
|
return
|
||||||
|
@ -41,7 +41,7 @@ class WayController < ApplicationController
|
||||||
way = Way.find(params[:id])
|
way = Way.find(params[:id])
|
||||||
case request.method
|
case request.method
|
||||||
|
|
||||||
when :get
|
when :get
|
||||||
unless way.visible
|
unless way.visible
|
||||||
render :nothing => true, :status => 410
|
render :nothing => true, :status => 410
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class Node < ActiveRecord::Base
|
class Node < ActiveRecord::Base
|
||||||
require 'xml/libxml'
|
require 'xml/libxml'
|
||||||
set_table_name 'current_nodes'
|
set_table_name 'current_nodes'
|
||||||
|
|
||||||
|
|
||||||
validates_numericality_of :latitude
|
validates_numericality_of :latitude
|
||||||
validates_numericality_of :longitude
|
validates_numericality_of :longitude
|
||||||
|
|
|
@ -8,8 +8,9 @@ class Segment < ActiveRecord::Base
|
||||||
has_many :old_segments, :foreign_key => :id
|
has_many :old_segments, :foreign_key => :id
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
has_one :from_node, :class_name => 'Node', :foreign_key => 'id'
|
# using belongs_to :foreign_key = 'node_*', since if use has_one :foreign_key = 'id', segment preconditions? fails checking for segment id in node table
|
||||||
has_one :to_node, :class_name => 'Node', :foreign_key => 'id'
|
belongs_to :from_node, :class_name => 'Node', :foreign_key => 'node_a'
|
||||||
|
belongs_to :to_node, :class_name => 'Node', :foreign_key => 'node_b'
|
||||||
|
|
||||||
def self.from_xml(xml, create=false)
|
def self.from_xml(xml, create=false)
|
||||||
p = XML::Parser.new
|
p = XML::Parser.new
|
||||||
|
|
|
@ -10,5 +10,44 @@ class Trace < ActiveRecord::Base
|
||||||
tt.tag = tag
|
tt.tag = tag
|
||||||
tt
|
tt
|
||||||
}
|
}
|
||||||
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
|
end
|
||||||
|
|
|
@ -24,12 +24,12 @@ class User < ActiveRecord::Base
|
||||||
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([ "email = ? AND pass_crypt =?", email, Digest::MD5.hexdigest(passwd) ])
|
find(:first, :conditions => [ "email = ? AND pass_crypt = ?", email, Digest::MD5.hexdigest(passwd)])
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.authenticate_token(token)
|
def self.authenticate_token(token)
|
||||||
find_first([ "token = ? ", token])
|
find(:first, :conditions => [ "token = ? ", token])
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.make_token(length=30)
|
def self.make_token(length=30)
|
||||||
|
|
|
@ -63,11 +63,16 @@ class Way < ActiveRecord::Base
|
||||||
el1['visible'] = self.visible.to_s
|
el1['visible'] = self.visible.to_s
|
||||||
el1['timestamp'] = self.timestamp.xmlschema
|
el1['timestamp'] = self.timestamp.xmlschema
|
||||||
|
|
||||||
self.way_segments.each do |seg| # FIXME need to make sure they come back in the right order
|
# make sure segments are output in sequence_id order
|
||||||
e = XML::Node.new 'seg'
|
ordered_segments = []
|
||||||
e['id'] = seg.segment_id.to_s
|
self.way_segments.each do |seg|
|
||||||
el1 << e
|
ordered_segments[seg.sequence_id] = seg.segment_id.to_s
|
||||||
end
|
end
|
||||||
|
ordered_segments.each do |seg_id|
|
||||||
|
e = XML::Node.new 'seg'
|
||||||
|
e['id'] = seg_id
|
||||||
|
el1 << e
|
||||||
|
end
|
||||||
|
|
||||||
self.way_tags.each do |tag|
|
self.way_tags.each do |tag|
|
||||||
e = XML::Node.new 'tag'
|
e = XML::Node.new 'tag'
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<% if @flash[:notice] %>
|
<% if flash[:notice] %>
|
||||||
<div id="notice"><%= @flash[:notice] %></div>
|
<div id="notice"><%= flash[:notice] %></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= @content_for_layout %>
|
<%= yield %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -81,6 +81,8 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<%= yield :optionals %>
|
||||||
|
|
||||||
<div id="cclogo">
|
<div id="cclogo">
|
||||||
<center>
|
<center>
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<applet
|
<applet
|
||||||
code="org/openstreetmap/processing/OsmApplet.class"
|
code="org/openstreetmap/processing/OsmApplet.class"
|
||||||
archive="OSMApplet.jar, commons-codec-1.3.jar, core.jar, commons-logging.jar, commons-httpclient-3.0-rc3.jar, MinML2.jar, plugin.jar, thinlet.jar"
|
archive="OSMApplet.jar, commons-codec-1.3.jar, core.jar, commons-logging.jar, commons-httpclient-3.0-rc3.jar, MinML2.jar, thinlet.jar"
|
||||||
width="700"
|
width="700"
|
||||||
height="500"
|
height="500"
|
||||||
MAYSCRIPT="true" >
|
MAYSCRIPT="true" >
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
<param name="user" value="token">
|
<param name="user" value="token">
|
||||||
<param name="pass" value="<%= @user.token %>">
|
<param name="pass" value="<%= @user.token %>">
|
||||||
<param name="wmsurl" value="http://www.openstreetmap.org/tile/0.2/gpx?;http://www.openstreetmap.org/api/wms/0.2/landsat/?request=GetMap&layers=modis,global_mosaic&styles=&srs=EPSG:4326&FORMAT=image/jpeg">
|
<param name="wmsurl" value="http://www.openstreetmap.org/tile/0.2/gpx?;http://www.openstreetmap.org/api/wms/0.2/landsat/?request=GetMap&layers=modis,global_mosaic&styles=&srs=EPSG:4326&FORMAT=image/jpeg">
|
||||||
<param name="apiurl" value="http://www.openstreetmap.org/api/0.3/">
|
<param name="apiurl" value="<%= SERVER_URL %>/api/<%= API_VERSION %>/">
|
||||||
Your browser needs to support Java to edit maps.<br>
|
Your browser needs to support Java to edit maps.<br>
|
||||||
<a href="http://java.com/en/download/index.jsp">Download Java here</a>
|
<a href="http://java.com/en/download/index.jsp">Download Java here</a>
|
||||||
</applet>
|
</applet>
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
<td class="<%= cl %>">
|
<td class="<%= cl %>">
|
||||||
<% if trace.inserted %>
|
<% if trace.inserted %>
|
||||||
<a href="<%= url_for :controller => 'trace', :action => 'view', :id => trace.id, :user_login => trace.user.display_name %>"><img src="<%= url_for :controller => 'trace', :action => 'icon', :id => trace.id, :user_login => trace.user.display_name %>" border="0"></a>
|
<a href="<%= url_for :controller => 'trace', :action => 'view', :id => trace.id, :user_login => trace.user.display_name %>"><img src="<%= url_for :controller => 'trace', :action => 'icon', :id => trace.id, :user_login => trace.user.display_name %>" border="0"></a>
|
||||||
|
<% else %>
|
||||||
|
<span style="color:red">PENDING</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td class="<%= cl %>"><%= link_to trace.name, {:controller => 'trace', :action => 'view', :display_name => trace.user.display_name, :id => trace.id} %>
|
<td class="<%= cl %>"><%= link_to trace.name, {:controller => 'trace', :action => 'view', :display_name => trace.user.display_name, :id => trace.id} %>
|
||||||
|
@ -12,14 +14,14 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
... <%= time_ago_in_words( trace.timestamp ) %> ago</span>
|
... <%= time_ago_in_words( trace.timestamp ) %> ago</span>
|
||||||
<%= link_to 'more', {:controller => 'trace', :action => 'view', :display_name => trace.user.display_name, :id => trace.id} %> /
|
<%= link_to 'more', {:controller => 'trace', :action => 'view', :display_name => trace.user.display_name, :id => trace.id} %> /
|
||||||
<a href="/edit.html?lat=34.1032333&lon=-118.2272333&zoom=14" title="create maps">map</a><br />
|
<a href="/edit.html?lat=<%= trace.latitude %>&lon=<%= trace.longitude %>&zoom=14" title="create maps">map</a><br />
|
||||||
<%= trace.description %>
|
<%= trace.description %>
|
||||||
<br />
|
<br />
|
||||||
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 => 'bytag', :tag => tag.tag %>
|
<%= link_to tag.tag, :controller => 'trace', :action => @paging_action, :tag => tag.tag %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
|
17
app/views/trace/_trace_optionals.rhtml
Normal file
17
app/views/trace/_trace_optionals.rhtml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<% content_for "optionals" do %>
|
||||||
|
<div class="optionalbox">
|
||||||
|
<h2>Tags</h2>
|
||||||
|
<% 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>
|
||||||
|
<% end %>
|
19
app/views/trace/_trace_paging_nav.rhtml
Normal file
19
app/views/trace/_trace_paging_nav.rhtml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<%
|
||||||
|
range_start = ((@page - 1) * @traces_per_page) + 1
|
||||||
|
range_end = (@page==@max_page ? @max_trace : (@page * @traces_per_page))
|
||||||
|
%>
|
||||||
|
|
||||||
|
Showing page
|
||||||
|
<%= @page %> (<%= range_start %><%
|
||||||
|
if (@max_trace != range_start) # if more than 1 trace on page
|
||||||
|
%>-<%= range_end %><%
|
||||||
|
end %>
|
||||||
|
of <%= @max_trace %>)
|
||||||
|
|
||||||
|
<% if @page > 1 %>
|
||||||
|
| <%= link_to 'previous page', {:controller => 'trace', :action => @paging_action, :page => @page-1}, {:title => 'previous page'} %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if @page < @max_page %>
|
||||||
|
| <%= link_to 'next page', {:controller => 'trace', :action => @paging_action, :page => @page+1}, {:title => 'next page'} %>
|
||||||
|
<% end %>
|
|
@ -1,8 +1,8 @@
|
||||||
<h1>Public GPS Traces</h1>
|
<h1>Public GPS Traces</h1>
|
||||||
|
|
||||||
<br /><br />
|
<br />
|
||||||
|
|
||||||
<span class="rsssmall"><a href="<%= url_for :controller => 'trace', :action => 'georss' %>"><img src="http://<%= SERVER_URL %>/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 %>
|
||||||
|
@ -11,16 +11,7 @@
|
||||||
|
|
||||||
|
|
||||||
<br /><br />
|
<br /><br />
|
||||||
Showing page
|
<%= render (:partial => 'trace_paging_nav') %>
|
||||||
<% if @page > 0 %>
|
|
||||||
<%= link_to '<<<', {:controller => 'trace', :action => 'list', :page => @page-1}, {:title => 'previous page'} %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= @page %>
|
|
||||||
|
|
||||||
<%= link_to '>>>', {:controller => 'trace', :action => 'list', :page => @page+1}, {:title => 'next page'} %>
|
|
||||||
|
|
||||||
(<%= 1+(@page * 20)%>-<%= (1+@page) * 20 %>)
|
|
||||||
|
|
||||||
<table id="keyvalue" cellpadding="3">
|
<table id="keyvalue" cellpadding="3">
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -29,3 +20,6 @@ Showing page
|
||||||
</tr>
|
</tr>
|
||||||
<%= render :partial => 'trace', :collection => @traces %>
|
<%= render :partial => 'trace', :collection => @traces %>
|
||||||
</table>
|
</table>
|
||||||
|
<%= render (:partial => 'trace_paging_nav') %>
|
||||||
|
|
||||||
|
<%= render (:partial => 'trace_optionals') %>
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
<h1>Your GPS Traces</h1>
|
<h1>Your GPS Traces</h1>
|
||||||
|
|
||||||
<%= link_to 'see all traces', {:controller => 'trace', :action => 'list'} %><br /><br />
|
<br />
|
||||||
|
|
||||||
|
<%= link_to 'See all traces', {:controller => 'trace', :action => 'list'} %><br /><br />
|
||||||
|
|
||||||
<% if @user %>
|
<% if @user %>
|
||||||
<%= start_form_tag({:action => 'create'}, :multipart => true) %>
|
<%= start_form_tag({:action => 'create'}, :multipart => true) %>
|
||||||
|
@ -19,16 +21,16 @@
|
||||||
|
|
||||||
<%= end_form_tag %>
|
<%= end_form_tag %>
|
||||||
|
|
||||||
|
<%= render (:partial => 'trace_paging_nav') %>
|
||||||
<table id="keyvalue" cellpadding="3">
|
<table id="keyvalue" cellpadding="3">
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
<%= render :partial => 'trace', :collection => @traces %>
|
<%= render (:partial => 'trace', :collection => @traces) unless @traces.nil? %>
|
||||||
</table>
|
</table>
|
||||||
|
<%= render (:partial => 'trace_paging_nav') %>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<%= render (:partial => 'trace_optionals') %>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ development:
|
||||||
adapter: mysql
|
adapter: mysql
|
||||||
database: openstreetmap
|
database: openstreetmap
|
||||||
username: openstreetmap
|
username: openstreetmap
|
||||||
password: openstreetmap
|
password:
|
||||||
host: localhost
|
host: localhost
|
||||||
|
|
||||||
# Warning: The database defined as 'test' will be erased and
|
# Warning: The database defined as 'test' will be erased and
|
||||||
|
|
|
@ -5,10 +5,13 @@
|
||||||
# ENV['RAILS_ENV'] ||= 'production'
|
# ENV['RAILS_ENV'] ||= 'production'
|
||||||
|
|
||||||
# Specifies gem version of Rails to use when vendor/rails is not present
|
# Specifies gem version of Rails to use when vendor/rails is not present
|
||||||
RAILS_GEM_VERSION = '1.1.6'
|
RAILS_GEM_VERSION = '1.2.3'
|
||||||
|
|
||||||
# Bootstrap the Rails environment, frameworks, and default configuration
|
# Bootstrap the Rails environment, frameworks, and default configuration
|
||||||
require File.join(File.dirname(__FILE__), 'boot')
|
require File.join(File.dirname(__FILE__), 'boot')
|
||||||
|
|
||||||
|
# Application constants needed for routes.rb - must go before Initializer call
|
||||||
|
API_VERSION = ENV['OSM_API_VERSION'] || '0.4'
|
||||||
|
|
||||||
Rails::Initializer.run do |config|
|
Rails::Initializer.run do |config|
|
||||||
# Settings in config/environments/* take precedence those specified here
|
# Settings in config/environments/* take precedence those specified here
|
||||||
|
@ -51,8 +54,6 @@ end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# Include your application configuration below
|
# Include your application configuration below
|
||||||
|
|
||||||
API_VERSION = ENV['OSM_API_VERSION'] || '0.4'
|
|
||||||
SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org'
|
SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org'
|
||||||
|
|
||||||
ActionMailer::Base.server_settings = {
|
ActionMailer::Base.server_settings = {
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
ActionController::Routing::Routes.draw do |map|
|
ActionController::Routing::Routes.draw do |map|
|
||||||
|
|
||||||
# API
|
# API
|
||||||
API_VERSION = '0.4' # change this in envronment.rb too
|
|
||||||
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
|
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", :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
|
||||||
|
|
||||||
map.connect "api/#{API_VERSION}/segment/create", :controller => 'segment', :action => 'create'
|
map.connect "api/#{API_VERSION}/segment/create", :controller => 'segment', :action => 'create'
|
||||||
|
@ -33,12 +32,17 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
map.connect '/traces', :controller => 'trace', :action => 'list'
|
map.connect '/traces', :controller => 'trace', :action => 'list'
|
||||||
map.connect '/traces/page/:page', :controller => 'trace', :action => 'list'
|
map.connect '/traces/page/:page', :controller => 'trace', :action => 'list'
|
||||||
map.connect '/traces/mine', :controller => 'trace', :action => 'mine'
|
map.connect '/traces/mine', :controller => 'trace', :action => 'mine'
|
||||||
|
map.connect '/traces/mine/page/:page', :controller => 'trace', :action => 'mine'
|
||||||
|
map.connect '/traces/mine/tag/:tag', :controller => 'trace', :action => 'mine'
|
||||||
|
map.connect '/traces/mine/tag/:tag/page/:page', :controller => 'trace', :action => 'mine'
|
||||||
map.connect '/traces/rss', :controller => 'trace', :action => 'georss'
|
map.connect '/traces/rss', :controller => 'trace', :action => 'georss'
|
||||||
map.connect '/traces/user/:display_name/', :controller => 'trace', :action => 'list', :id => nil
|
map.connect '/traces/user/:display_name/', :controller => 'trace', :action => 'list', :id => nil
|
||||||
|
map.connect '/traces/user/:display_name/page/:page', :controller => 'trace', :action => 'list', :id => nil
|
||||||
map.connect '/traces/user/:display_name/:id', :controller => 'trace', :action => 'view', :id => nil
|
map.connect '/traces/user/:display_name/:id', :controller => 'trace', :action => 'view', :id => nil
|
||||||
map.connect '/traces/user/:display_name/:id/picture', :controller => 'trace', :action => 'picture', :id => nil
|
map.connect '/traces/user/:display_name/:id/picture', :controller => 'trace', :action => 'picture', :id => nil
|
||||||
map.connect '/traces/user/:display_name/:id/icon', :controller => 'trace', :action => 'icon', :id => nil
|
map.connect '/traces/user/:display_name/:id/icon', :controller => 'trace', :action => 'icon', :id => nil
|
||||||
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
|
||||||
|
|
||||||
# fall through
|
# fall through
|
||||||
map.connect ':controller/:action/:id'
|
map.connect ':controller/:action/:id'
|
||||||
|
|
|
@ -17,6 +17,7 @@ alter table current_way_tags change v v varchar(255) not null default '';
|
||||||
|
|
||||||
alter table gpx_files change private public boolean default 1 not null;
|
alter table gpx_files change private public boolean default 1 not null;
|
||||||
update gpx_files set public = !public;
|
update gpx_files set public = !public;
|
||||||
|
create index gpx_files_visible_public_idx on gpx_files(visible, public);
|
||||||
|
|
||||||
alter table gpx_file_tags change sequence_id sequence_id int(11);
|
alter table gpx_file_tags change sequence_id sequence_id int(11);
|
||||||
alter table gpx_file_tags drop primary key;
|
alter table gpx_file_tags drop primary key;
|
||||||
|
@ -25,3 +26,4 @@ create index gpx_file_tags_gpxid_idx on gpx_file_tags(gpx_id);
|
||||||
alter table gpx_file_tags add id int(20) auto_increment not null, add primary key(id);
|
alter table gpx_file_tags add id int(20) auto_increment not null, add primary key(id);
|
||||||
|
|
||||||
alter table users add preferences text;
|
alter table users add preferences text;
|
||||||
|
create index users_display_name_idx on users(display_name);
|
|
@ -23,8 +23,9 @@ while($running) do
|
||||||
begin
|
begin
|
||||||
|
|
||||||
logger.info("GPX Import importing #{trace.name} from #{trace.user.email}")
|
logger.info("GPX Import importing #{trace.name} from #{trace.user.email}")
|
||||||
|
|
||||||
gzipped = `file -b /tmp/#{trace.id}.gpx`.chomp =~/^gzip/
|
# TODO *nix specific, could do to work on windows... would be functionally inferior though - check for '.gz'
|
||||||
|
gzipped = `file -b /tmp/#{trace.id}.gpx`.chomp =~/^gzip/
|
||||||
|
|
||||||
if gzipped
|
if gzipped
|
||||||
logger.info("gzipped")
|
logger.info("gzipped")
|
||||||
|
|
BIN
public/images/RSS.gif
Normal file
BIN
public/images/RSS.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 652 B |
|
@ -1,2 +1,2 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
Dir[File.dirname(__FILE__) + "/../lib/daemons/*_ctl"].each {|f| `#{f} #{ARGV.first}`}
|
Dir[File.dirname(__FILE__) + "/../lib/daemons/*_ctl"].each {|f| `ruby #{f} #{ARGV.first}`} # TODO remove ruby - hack for windows
|
Loading…
Add table
Add a link
Reference in a new issue