+INSTALL
+=======
-Task one
-========
+* get rails working (http://www.rubyonrails.org/)
-Get OSM on rails with a 0.4 API, without changing the db schema
+* make your db (see db/README)
-see db/README for how to create the db
+* install ruby libxml bindings (FIXME: example apt-get lines etc for the weak)
-Two
-===
+* make sure you have a MTA listening on localhost:25 if you want mail
-change the schema
+* script/server
+* thats it
+
+HACKING
+=======
+
+log in to your site (proably localhost:3000)
+
+create a user and confirm it
+
+you want to play with the API (probably at localhost:3000/api/0.4/node/create etc)
+
+Lots of tests are needed to test the API.
+
+Lots of little things to make the site work like the old one.
--- /dev/null
+class CurrentWaySegmentController < ApplicationController
+end
--- /dev/null
+class OldWayController < ApplicationController
+end
--- /dev/null
+class WayController < ApplicationController
+ require 'xml/libxml'
+
+ before_filter :authorize
+
+ def create
+ if request.put?
+ way = Way.from_xml(request.raw_post, true)
+
+ if way
+ way.user_id = @user.id
+ if way.save_with_history
+
+
+ render :text => way.id
+ else
+ render :nothing => true, :status => 500
+ end
+ return
+ else
+ render :nothing => true, :status => 400 # if we got here the doc didnt parse
+ return
+ end
+ end
+
+ render :nothing => true, :status => 500 # something went very wrong
+ end
+
+end
--- /dev/null
+class WayTagController < ApplicationController
+end
--- /dev/null
+module CurrentWaySegmentHelper
+end
--- /dev/null
+module OldWayHelper
+end
--- /dev/null
+module WayHelper
+end
--- /dev/null
+module WayTagHelper
+end
--- /dev/null
+class CurrentWaySegment < ActiveRecord::Base
+end
--- /dev/null
+class OldWay < ActiveRecord::Base
+ set_table_name 'ways'
+
+ belongs_to :user
+
+ def self.from_way(way)
+ old_way = OldWay.new
+ old_way.user_id = way.user_id
+ old_way.timestamp = way.timestamp
+ old_way.id = way.id
+ return old_way
+ end
+
+end
--- /dev/null
+class Way < ActiveRecord::Base
+ require 'xml/libxml'
+
+ belongs_to :user
+ set_table_name 'current_ways'
+
+ def self.from_xml(xml, create=false)
+ p = XML::Parser.new
+ p.string = xml
+ doc = p.parse
+
+ way = Way.new
+
+ doc.find('//osm/way').each do |pt|
+ if !create and pt['id'] != '0'
+ way.id = pt['id'].to_i
+ end
+
+ if create
+ way.timestamp = Time.now
+ way.visible = true
+ else
+ if pt['timestamp']
+ way.timestamp = Time.parse(pt['timestamp'])
+ end
+ end
+
+ pt.find('tag').each do |tag|
+ way.add_tag_keyval(tag['k'], tag['v'])
+ end
+
+ pt.find('seg').each do |seg|
+ way.add_seg_num(seg['id'])
+ end
+
+
+ end
+
+ return way
+ end
+
+ def segs
+ @segs = Array.new unless @segs
+ @segs
+ end
+
+ def tags
+ @tags = Hash.new unless @tags
+ @tags
+ end
+
+ def add_seg_num(n)
+ @segs = Array.new unless @segs
+ @segs << n.to_i
+ end
+
+ def add_tag_keyval(k, v)
+ @tags = Hash.new unless @tags
+ @tags[k] = v
+ end
+
+ def save_with_history
+ t = Time.now
+ self.timestamp = t
+ self.save
+
+ WayTag.delete_all(['id = ?', self.id])
+
+ self.tags.each do |k,v|
+ tag = WayTag.new
+ tag.k = k
+ tag.v = v
+ tag.id = self.id
+ tag.save
+ end
+
+ old_way = OldWay.from_way(self)
+ old_way.save
+ end
+
+end
--- /dev/null
+class WayTag < ActiveRecord::Base
+ set_table_name 'current_way_tags'
+
+ belongs_to :way, :foreign_key => 'id'
+
+end
<div id="logo">
<center>
<h1>OpenStreetMap</h1>
-
<img src="/images/osm_logo.png" width="120" height="120"/><br/>
<nobr><h2>The Free Wiki World Map</h2></nobr>
</center>
</div>
-
+ <% unless @user %>
<div id="intro">
OpenStreetMap is a free editable map of the whole world. It is made by people like you.
<p/>
OpenStreetMap allows you to view, edit and use geographical data in a collaborative way from anywhere on Earth.
<p/>
OpenStreetMap's hosting is kindly supported by the <a href="http://www.vr.ucl.ac.uk">UCL VR Centre</a> and <a href="http://www.bytemark.co.uk">bytemark</a>.
-
</div>
+ <% end %>
<div id="left_menu">
<a href="http://wiki.openstreetmap.org">Help & Wiki</a><br />
map.connect 'api/0.4/segment/:id/history', :controller => 'segment', :action => 'history'
map.connect 'api/0.4/segment/:id', :controller => 'segment', :action => 'rest'
+ map.connect 'api/0.4/way/create', :controller => 'way', :action => 'create'
+
+
+ # misc site stuff
+
map.connect '/', :controller => 'site', :action => 'index'
map.connect '/index.html', :controller => 'site', :action => 'index'
map.connect '/edit.html', :controller => 'site', :action => 'edit'
> exit
# exit
$ mysql openstreetmap -u openstreetmap -p < db/create_database.sql
+
+(the last line above gets you to what the server has right now)
+
+$ mysql openstreetmap -u openstreetmap -p < db/migrate.sql
+
+(this line gets you to where its going to be when we go live with rails)
alter table current_nodes modify id bigint(64) not null auto_increment;
alter table nodes modify tags text not null;
-
drop table meta_segments;
alter table current_segments modify tags text not null;
alter table current_segments modify id bigint(64) not null auto_increment;
alter table segments modify tags text not null;
+drop table meta_ways
+alter table current_ways drop index current_ways_id_visible_idx;
+alter table current_ways modify id bigint(64) not null auto_increment, add primary key(id);
+
+alter table current_way_tags change k k varchar(255) not null default '';
+alter table current_way_tags change v v varchar(255) not null default '';
+
--- /dev/null
+class CreateWays < ActiveRecord::Migration
+ def self.up
+ create_table :ways do |t|
+ # t.column :name, :string
+ end
+ end
+
+ def self.down
+ drop_table :ways
+ end
+end
--- /dev/null
+class CreateOldWays < ActiveRecord::Migration
+ def self.up
+ create_table :old_ways do |t|
+ # t.column :name, :string
+ end
+ end
+
+ def self.down
+ drop_table :old_ways
+ end
+end
--- /dev/null
+class CreateWayTags < ActiveRecord::Migration
+ def self.up
+ create_table :way_tags do |t|
+ # t.column :name, :string
+ end
+ end
+
+ def self.down
+ drop_table :way_tags
+ end
+end
--- /dev/null
+class CreateCurrentWaySegments < ActiveRecord::Migration
+ def self.up
+ create_table :current_way_segments do |t|
+ # t.column :name, :string
+ end
+ end
+
+ def self.down
+ drop_table :current_way_segments
+ end
+end
padding-top: 5px;\r
padding-bottom: 7px;\r
font-size: 13px;\r
- background: url(tab_bottom.gif) repeat-x bottom;\r
+ background: url('/images/tab_bottom.gif') repeat-x bottom;\r
}\r
\r
#intro {\r
margin: 0;\r
padding-left: 215px;\r
padding-top: 5px;\r
- background: url(tab_bottom.gif) repeat-x bottom;\r
+ background: url('/images/tab_bottom.gif') repeat-x bottom;\r
}\r
#tabnav li\r
{\r