way stuff
authorSteve Coast <steve@asklater.com>
Sat, 26 Aug 2006 20:49:16 +0000 (20:49 +0000)
committerSteve Coast <steve@asklater.com>
Sat, 26 Aug 2006 20:49:16 +0000 (20:49 +0000)
23 files changed:
README
app/controllers/current_way_segment_controller.rb [new file with mode: 0644]
app/controllers/old_way_controller.rb [new file with mode: 0644]
app/controllers/way_controller.rb [new file with mode: 0644]
app/controllers/way_tag_controller.rb [new file with mode: 0644]
app/helpers/current_way_segment_helper.rb [new file with mode: 0644]
app/helpers/old_way_helper.rb [new file with mode: 0644]
app/helpers/way_helper.rb [new file with mode: 0644]
app/helpers/way_tag_helper.rb [new file with mode: 0644]
app/models/current_way_segment.rb [new file with mode: 0644]
app/models/old_way.rb [new file with mode: 0644]
app/models/way.rb [new file with mode: 0644]
app/models/way_tag.rb [new file with mode: 0644]
app/views/layouts/site.rhtml
config/routes.rb
db/README
db/migrate.sql
db/migrate/008_create_ways.rb [new file with mode: 0644]
db/migrate/009_create_old_ways.rb [new file with mode: 0644]
db/migrate/010_create_way_tags.rb [new file with mode: 0644]
db/migrate/011_create_current_way_segments.rb [new file with mode: 0644]
public/images/tab_bottom.gif [new file with mode: 0644]
public/stylesheets/site.css

diff --git a/README b/README
index 74c8ed145ce9f166f773a5de44d79b0c7e492536..280e798fbf4699296f4eaeae2d52d123ed3193e8 100644 (file)
--- a/README
+++ b/README
@@ -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.
diff --git a/app/controllers/current_way_segment_controller.rb b/app/controllers/current_way_segment_controller.rb
new file mode 100644 (file)
index 0000000..9e3e9e2
--- /dev/null
@@ -0,0 +1,2 @@
+class CurrentWaySegmentController < ApplicationController
+end
diff --git a/app/controllers/old_way_controller.rb b/app/controllers/old_way_controller.rb
new file mode 100644 (file)
index 0000000..7fbed26
--- /dev/null
@@ -0,0 +1,2 @@
+class OldWayController < ApplicationController
+end
diff --git a/app/controllers/way_controller.rb b/app/controllers/way_controller.rb
new file mode 100644 (file)
index 0000000..2c94821
--- /dev/null
@@ -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
diff --git a/app/controllers/way_tag_controller.rb b/app/controllers/way_tag_controller.rb
new file mode 100644 (file)
index 0000000..16763b3
--- /dev/null
@@ -0,0 +1,2 @@
+class WayTagController < ApplicationController
+end
diff --git a/app/helpers/current_way_segment_helper.rb b/app/helpers/current_way_segment_helper.rb
new file mode 100644 (file)
index 0000000..a772c66
--- /dev/null
@@ -0,0 +1,2 @@
+module CurrentWaySegmentHelper
+end
diff --git a/app/helpers/old_way_helper.rb b/app/helpers/old_way_helper.rb
new file mode 100644 (file)
index 0000000..d7982a6
--- /dev/null
@@ -0,0 +1,2 @@
+module OldWayHelper
+end
diff --git a/app/helpers/way_helper.rb b/app/helpers/way_helper.rb
new file mode 100644 (file)
index 0000000..e597a98
--- /dev/null
@@ -0,0 +1,2 @@
+module WayHelper
+end
diff --git a/app/helpers/way_tag_helper.rb b/app/helpers/way_tag_helper.rb
new file mode 100644 (file)
index 0000000..66a53ff
--- /dev/null
@@ -0,0 +1,2 @@
+module WayTagHelper
+end
diff --git a/app/models/current_way_segment.rb b/app/models/current_way_segment.rb
new file mode 100644 (file)
index 0000000..2920b9e
--- /dev/null
@@ -0,0 +1,2 @@
+class CurrentWaySegment < ActiveRecord::Base
+end
diff --git a/app/models/old_way.rb b/app/models/old_way.rb
new file mode 100644 (file)
index 0000000..3f978d3
--- /dev/null
@@ -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
diff --git a/app/models/way.rb b/app/models/way.rb
new file mode 100644 (file)
index 0000000..2773ecc
--- /dev/null
@@ -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
diff --git a/app/models/way_tag.rb b/app/models/way_tag.rb
new file mode 100644 (file)
index 0000000..5ce7c8f
--- /dev/null
@@ -0,0 +1,6 @@
+class WayTag < ActiveRecord::Base
+  set_table_name 'current_way_tags'
+
+  belongs_to :way, :foreign_key => 'id'
+
+end
index aaf4e0324298f56b1079e005e731db30eb8b0dec..95c273e4091e488a7cbd9ee4b6c5269445cd4285 100644 (file)
     <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 />
index 8f251f7d3d8b510c94690987f84de1a4b5e0d276..7ba5ad9027fe68d5eda6832cb3ad9fc73542cb5e 100644 (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', :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'
index 68fc8e6ceb571b44bb02672a7ffd8bb8612d4285..4a7067e6c8a2e7c49a1014c0b7565244569bfbcd 100644 (file)
--- a/db/README
+++ b/db/README
@@ -7,3 +7,9 @@ $ su
 > 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)
index abbc0ae244e240533900444bbdce3f2b6b504ee5..2d55fb552fe1b44540228a887f7d0733781194f2 100644 (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 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 '';
+
diff --git a/db/migrate/008_create_ways.rb b/db/migrate/008_create_ways.rb
new file mode 100644 (file)
index 0000000..6b34865
--- /dev/null
@@ -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
diff --git a/db/migrate/009_create_old_ways.rb b/db/migrate/009_create_old_ways.rb
new file mode 100644 (file)
index 0000000..317e455
--- /dev/null
@@ -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
diff --git a/db/migrate/010_create_way_tags.rb b/db/migrate/010_create_way_tags.rb
new file mode 100644 (file)
index 0000000..267f61b
--- /dev/null
@@ -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
diff --git a/db/migrate/011_create_current_way_segments.rb b/db/migrate/011_create_current_way_segments.rb
new file mode 100644 (file)
index 0000000..5926566
--- /dev/null
@@ -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
diff --git a/public/images/tab_bottom.gif b/public/images/tab_bottom.gif
new file mode 100644 (file)
index 0000000..da70aaf
Binary files /dev/null and b/public/images/tab_bottom.gif differ
index 9b29cd806f39b47a078d785a28ec3a5ed0e141da..2a38965916320aa83a8c36f6f888a75b3c36559a 100644 (file)
@@ -70,7 +70,7 @@ body {
   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
@@ -246,7 +246,7 @@ hides rule from IE5-Mac \*/
   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