RAILS_DEFAULT_LOGGER.info(" Message: putway, id=#{originalway}")
- # -- Check for null IDs or short ways
+ # -- Check for null IDs, short ways or lats=90
points.each do |a|
if a[2]==0 or a[2].nil? then return -2,"Server error - node with id 0 found in way #{originalway}." end
+ if coord2lat(a[1],masterscale,basey)==90 then return -2,"Server error - node with lat -90 found in way #{originalway}." end
end
if points.length<2 then return -2,"Server error - way is only #{points.length} points long." end
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
+ if OSM_STATUS == :database_offline
+ session :off
+ end
+
def authorize_web
if session[:user]
@user = User.find(session[:user])
end
end
+ def check_database_availability
+ if OSM_STATUS == :database_offline
+ redirect_to :controller => 'site', :action => 'offline'
+ end
+ end
+
def check_read_availability
- if API_STATUS == :offline
+ if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline
response.headers['Error'] = "Database offline for maintenance"
render :nothing => true, :status => :service_unavailable
return false
end
def check_write_availability
- if API_STATUS == :offline or API_STATUS == :readonly
+ if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline or OSM_STATUS == :api_readonly
response.headers['Error'] = "Database offline for maintenance"
render :nothing => true, :status => :service_unavailable
return false
before_filter :authorize_web
before_filter :require_user, :only => [:new]
+ before_filter :check_database_availability
def new
@title = 'new diary entry'
class TraceController < ApplicationController
+ layout 'site'
+
before_filter :authorize_web
before_filter :authorize, :only => [:api_details, :api_data, :api_create]
- layout 'site'
+ before_filter :check_database_availability, :except => [:api_details, :api_data, :api_create]
+ before_filter :check_read_availability, :only => [:api_details, :api_data, :api_create]
# 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
before_filter :authorize, :only => [:api_details, :api_gpx_files]
before_filter :authorize_web, :only => [:account, :go_public, :view, :diary, :make_friend, :remove_friend, :upload_image]
before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image]
+ before_filter :check_database_availability, :except => [:api_details, :api_gpx_files]
+ before_filter :check_read_availability, :only => [:api_details, :api_gpx_files]
filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation
end
def confirm
- token = UserToken.find_by_token(params[:confirm_string])
- if token and !token.user.active?
- @user = token.user
- @user.active = true
- @user.save!
- token.destroy
- flash[:notice] = 'Confirmed your account, thanks for signing up!'
- session[:user] = @user.id
- redirect_to :action => 'account', :display_name => @user.display_name
- else
- flash[:notice] = 'Something went wrong confirming that user.'
+ if params[:confirm_action]
+ token = UserToken.find_by_token(params[:confirm_string])
+ if token and !token.user.active?
+ @user = token.user
+ @user.active = true
+ @user.save!
+ token.destroy
+ flash[:notice] = 'Confirmed your account, thanks for signing up!'
+ session[:user] = @user.id
+ redirect_to :action => 'account', :display_name => @user.display_name
+ else
+ flash[:notice] = 'Something went wrong confirming that user.'
+ end
end
end
validates_numericality_of :latitude, :longitude
validate :validate_position
- has_many :ways, :through => :way_nodes
+ belongs_to :user
+
has_many :old_nodes, :foreign_key => :id
+
has_many :way_nodes
- belongs_to :user
-
+ has_many :ways, :through => :way_nodes
+
+ has_many :containing_relation_members, :as => :member
+ has_many :containing_relations, :through => :containing_relation_members
+
# Sanity check the latitude and longitude and add an error if it's broken
def validate_position
errors.add_to_base("Node is not in the world") unless in_world?
class OldRelationMember < ActiveRecord::Base
- belongs_to :user
-
set_table_name 'relation_members'
-
end
class OldRelationTag < ActiveRecord::Base
- belongs_to :user
-
set_table_name 'relation_tags'
-
end
class Relation < ActiveRecord::Base
require 'xml/libxml'
+ set_table_name 'current_relations'
+
belongs_to :user
+ has_many :old_relations, :foreign_key => 'id', :order => 'version'
+
has_many :relation_members, :foreign_key => 'id'
has_many :relation_tags, :foreign_key => 'id'
- has_many :old_relations, :foreign_key => 'id', :order => 'version'
-
- set_table_name 'current_relations'
+ has_many :containing_relation_members, :as => :member
+ has_many :containing_relations, :through => :containing_relation_members
def self.from_xml(xml, create=false)
begin
class RelationMember < ActiveRecord::Base
set_table_name 'current_relation_members'
-
- # problem with RelationMember is that it may link to any one
- # object (a node, a way, another relation), and belongs_to is
- # not flexible enough for that. So we do this, which is ugly,
- # but fortunately rails won't actually run the SQL behind that
- # unless someone really accesses .node, .way, or
- # .relation - which is what we do below based on member_type.
- # (and no: the :condition on belongs_to doesn't work here as
- # it is a condition on the *referenced* object not the
- # *referencing* object!)
- belongs_to :node, :foreign_key => "member_id"
- belongs_to :way, :foreign_key => "member_id"
- belongs_to :relation, :foreign_key => "member_id"
+ belongs_to :member, :polymorphic => true, :foreign_type => :member_class
+ belongs_to :relation, :foreign_key => :id
+
+ def after_find
+ self[:member_class] = self.member_type.capitalize
+ end
- # so we define this "member" function that returns whatever it
- # is.
-
- def member()
- return (member_type == "node") ? node : (member_type == "way") ? way : relation
+ def after_initialize
+ self[:member_class] = self.member_type.capitalize
end
- # NOTE - relations are SUBJECTS of memberships. The fact that nodes,
- # ways, and relations can be the OBJECT of a membership,
- # i.e. a node/way/relation can be referenced throgh a
- # RelationMember object, is NOT modelled in rails, i.e. these links
- # have to be resolved manually, on demand.
+ def before_save
+ self.member_type = self[:member_class].downcase
+ end
+
+ def member_type=(type)
+ self[:member_type] = type
+ self[:member_class] = type.capitalize
+ end
end
# If there are any existing points for this trace then delete
# them - we check for existing points first to avoid locking
# the table in the common case where there aren't any.
- if Tracepoint.exists?(['gpx_id = ?', self.id])
+ if Tracepoint.find(:first, :conditions => ['gpx_id = ?', self.id])
Tracepoint.delete_all(['gpx_id = ?', self.id])
end
class Way < ActiveRecord::Base
require 'xml/libxml'
+ set_table_name 'current_ways'
+
belongs_to :user
- has_many :nodes, :through => :way_nodes, :order => 'sequence_id'
+ has_many :old_ways, :foreign_key => 'id', :order => 'version'
+
has_many :way_nodes, :foreign_key => 'id', :order => 'sequence_id'
- has_many :way_tags, :foreign_key => 'id'
+ has_many :nodes, :through => :way_nodes, :order => 'sequence_id'
- has_many :old_ways, :foreign_key => 'id', :order => 'version'
+ has_many :way_tags, :foreign_key => 'id'
- set_table_name 'current_ways'
+ has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
+ has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation
def self.from_xml(xml, create=false)
begin
<li><%= link_to 'Export', {:controller => 'site', :action => 'export'}, {:id => 'exportanchor', :title => 'export map data', :class => exportclass} %></li>
<% end %>
<li><%= link_to 'GPS Traces', {:controller => 'trace', :action => 'list'}, {:id => 'traceanchor', :title => 'manage traces', :class => traceclass} %></li>
- <li><%= link_to 'User Diaries', {:controller => 'diary_entry', :action => 'list'}, {:id => 'diaryanchor', :title => 'view user diaries', :class => diaryclass} %></li>
+ <li><%= link_to 'User Diaries', {:controller => 'diary_entry', :action => 'list', :display_name => nil}, {:id => 'diaryanchor', :title => 'view user diaries', :class => diaryclass} %></li>
</ul>
</div>
</div>
<% end %>
- <% if API_STATUS == :offline %>
+ <% if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline %>
<div id="alert">
The OpenStreetMap database is currently offline while
essential database maintenance work is carried out.
</div>
- <% elsif API_STATUS == :readonly %>
+ <% elsif OSM_STATUS == :api_readonly %>
<div id="alert">
The OpenStreetMap database is currently in read-only mode while
essential database maintenance work is carried out.
-<% if API_STATUS == :offline %>
+<% if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline %>
<p>The OpenStreetMap database is currently offline while
essential database maintenance work is carried out.
</p>
-<% elsif API_STATUS == :readonly %>
+<% elsif OSM_STATUS == :api_readonly %>
<p>The OpenStreetMap database is currently in read-only mode while
essential database maintenance work is carried out.
</p>
<% lat = h(params['mlat']) %>
<% zoom = h(params['zoom'] || '12') %>
<% layers = h(params['layers']) %>
-<% elsif cookies.key?("location") %>
-<% lon,lat,zoom,layers = cookies["location"].split(",") %>
+<% elsif cookies.key?("_osm_location") %>
+<% lon,lat,zoom,layers = cookies["_osm_location"].split("|") %>
<% elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
<% lon = @user.home_lon %>
<% lat = @user.home_lat %>
<% lon = '-0.1' %>
<% lat = '51.5' %>
<% zoom = h(params['zoom'] || '5') %>
-<% layers = h(params['layers']) %>
<% end %>
+<% layers = h(params['layers']) %>
<% end %>
<%= javascript_include_tag '/openlayers/OpenLayers.js' %>
setMapCenter(centre, zoom);
<% end %>
- <% if layers %>
+ <% if !layers.nil? and !layers.empty? %>
setMapLayers("<%= layers %>");
<% end %>
updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
- document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
+ document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers;
}
function resizeContent() {
--- /dev/null
+<p>The OpenStreetMap database is currently offline while
+ essential database maintenance work is carried out.
+</p>
<h2><%= h(@title) %></h2>
-<img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :display_name => @trace.user.display_name %>">
+ <% if @trace.inserted %>
+ <img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :display_name => @trace.user.display_name %>">
+ <% else %>
+ <span style="color:red">PENDING</span>
+ <% end %>
<table border="0">
<tr>
+<h1>Confirm a user account</h1>
+
+<p>Press the confirm button below to activate your account.</p>
+
+<form method="post">
+<input type="hidden" name="confirm_string" value="<%= params[:confirm_string] %>">
+<input type="submit" name="confirm_action" value="Confrm">
+</form>
+
ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
-# DO NOT BUMP THIS TO 2.0.2 AS THE LIVE SERVERS CAN'T RUN THAT
-RAILS_GEM_VERSION = '2.0.1' unless defined? RAILS_GEM_VERSION
+RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
# Set the server URL
SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org'
# Application constants needed for routes.rb - must go before Initializer call
API_VERSION = ENV['OSM_API_VERSION'] || '0.5'
-# Set to :readonly to put the API in read-only mode or :offline to
-# take it completely offline
-API_STATUS = :online
+# Set application status - possible settings are:
+#
+# :online - online and operating normally
+# :api_readonly - site online but API in read-only mode
+# :api_offline - site online but API offline
+# :database_offline - database offline with site in emergency mode
+#
+OSM_STATUS = :online
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
# Skip frameworks you're not going to use (only works if using vendor/rails).
# To use Rails without a database, you must remove the Active Record framework
- # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
+ if OSM_STATUS == :database_offline
+ config.frameworks -= [ :active_record ]
+ end
# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
+require 'rubygems'
+gem 'composite_primary_keys', '= 0.9.93'
require 'composite_primary_keys'
map.connect '/export', :controller => 'site', :action => 'export'
map.connect '/login', :controller => 'user', :action => 'login'
map.connect '/logout', :controller => 'user', :action => 'logout'
+ map.connect '/offline', :controller => 'site', :action => 'offline'
map.connect '/user/new', :controller => 'user', :action => 'new'
map.connect '/user/save', :controller => 'user', :action => 'save'
map.connect '/user/confirm', :controller => 'user', :action => 'confirm'
for (var layers = map.getLayersBy("isBaseLayer", false), i = 0; i < layers.length; i++) {
var c = layerConfig.charAt(l++);
- layers[i].setVisibility(c == "T");
+ if (c == "T") {
+ layers[i].setVisibility(true);
+ } else if(c == "F") {
+ layers[i].setVisibility(false);
+ }
}
}