way stuff

This commit is contained in:
Steve Coast 2006-08-26 20:49:16 +00:00
parent 97978ceeb9
commit 222d31e435
23 changed files with 233 additions and 13 deletions

28
README
View file

@ -1,13 +1,27 @@
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.

View file

@ -0,0 +1,2 @@
class CurrentWaySegmentController < ApplicationController
end

View file

@ -0,0 +1,2 @@
class OldWayController < ApplicationController
end

View file

@ -0,0 +1,29 @@
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

View file

@ -0,0 +1,2 @@
class WayTagController < ApplicationController
end

View file

@ -0,0 +1,2 @@
module CurrentWaySegmentHelper
end

View file

@ -0,0 +1,2 @@
module OldWayHelper
end

View file

@ -0,0 +1,2 @@
module WayHelper
end

View file

@ -0,0 +1,2 @@
module WayTagHelper
end

View file

@ -0,0 +1,2 @@
class CurrentWaySegment < ActiveRecord::Base
end

14
app/models/old_way.rb Normal file
View file

@ -0,0 +1,14 @@
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

81
app/models/way.rb Normal file
View file

@ -0,0 +1,81 @@
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

6
app/models/way_tag.rb Normal file
View file

@ -0,0 +1,6 @@
class WayTag < ActiveRecord::Base
set_table_name 'current_way_tags'
belongs_to :way, :foreign_key => 'id'
end

View file

@ -49,20 +49,19 @@
<div id="logo"> <div id="logo">
<center> <center>
<h1>OpenStreetMap</h1> <h1>OpenStreetMap</h1>
<img src="/images/osm_logo.png" width="120" height="120"/><br/> <img src="/images/osm_logo.png" width="120" height="120"/><br/>
<nobr><h2>The Free Wiki World Map</h2></nobr> <nobr><h2>The Free Wiki World Map</h2></nobr>
</center> </center>
</div> </div>
<% unless @user %>
<div id="intro"> <div id="intro">
OpenStreetMap is a free editable map of the whole world. It is made by people like you. OpenStreetMap is a free editable map of the whole world. It is made by people like you.
<p/> <p/>
OpenStreetMap allows you to view, edit and use geographical data in a collaborative way from anywhere on Earth. OpenStreetMap allows you to view, edit and use geographical data in a collaborative way from anywhere on Earth.
<p/> <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>. 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> </div>
<% end %>
<div id="left_menu"> <div id="left_menu">
<a href="http://wiki.openstreetmap.org">Help & Wiki</a><br /> <a href="http://wiki.openstreetmap.org">Help & Wiki</a><br />

View file

@ -9,6 +9,11 @@ ActionController::Routing::Routes.draw do |map|
map.connect 'api/0.4/segment/:id/history', :controller => 'segment', :action => 'history' 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/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 '/', :controller => 'site', :action => 'index'
map.connect '/index.html', :controller => 'site', :action => 'index' map.connect '/index.html', :controller => 'site', :action => 'index'
map.connect '/edit.html', :controller => 'site', :action => 'edit' map.connect '/edit.html', :controller => 'site', :action => 'edit'

View file

@ -7,3 +7,9 @@ $ su
> exit > exit
# exit # exit
$ mysql openstreetmap -u openstreetmap -p < db/create_database.sql $ 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)

View file

@ -3,9 +3,15 @@ alter table current_nodes modify tags text not null;
alter table current_nodes modify id bigint(64) not null auto_increment; alter table current_nodes modify id bigint(64) not null auto_increment;
alter table nodes modify tags text not null; alter table nodes modify tags text not null;
drop table meta_segments; drop table meta_segments;
alter table current_segments modify tags text not null; alter table current_segments modify tags text not null;
alter table current_segments modify id bigint(64) not null auto_increment; alter table current_segments modify id bigint(64) not null auto_increment;
alter table segments modify tags text not null; 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 '';

View file

@ -0,0 +1,11 @@
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

View file

@ -0,0 +1,11 @@
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

View file

@ -0,0 +1,11 @@
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

View file

@ -0,0 +1,11 @@
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 B

View file

@ -70,7 +70,7 @@ body {
padding-top: 5px; padding-top: 5px;
padding-bottom: 7px; padding-bottom: 7px;
font-size: 13px; font-size: 13px;
background: url(tab_bottom.gif) repeat-x bottom; background: url('/images/tab_bottom.gif') repeat-x bottom;
} }
#intro { #intro {
@ -246,7 +246,7 @@ hides rule from IE5-Mac \*/
margin: 0; margin: 0;
padding-left: 215px; padding-left: 215px;
padding-top: 5px; padding-top: 5px;
background: url(tab_bottom.gif) repeat-x bottom; background: url('/images/tab_bottom.gif') repeat-x bottom;
} }
#tabnav li #tabnav li
{ {