From: Steve Coast Date: Sat, 26 Aug 2006 20:49:16 +0000 (+0000) Subject: way stuff X-Git-Tag: live~9503 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/222d31e435f003ec59e84860d2fa5129449f69de way stuff --- diff --git a/README b/README index 74c8ed145..280e798fb 100644 --- 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 index 000000000..9e3e9e247 --- /dev/null +++ b/app/controllers/current_way_segment_controller.rb @@ -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 index 000000000..7fbed26ea --- /dev/null +++ b/app/controllers/old_way_controller.rb @@ -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 index 000000000..2c948214e --- /dev/null +++ b/app/controllers/way_controller.rb @@ -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 index 000000000..16763b356 --- /dev/null +++ b/app/controllers/way_tag_controller.rb @@ -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 index 000000000..a772c6630 --- /dev/null +++ b/app/helpers/current_way_segment_helper.rb @@ -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 index 000000000..d7982a661 --- /dev/null +++ b/app/helpers/old_way_helper.rb @@ -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 index 000000000..e597a980b --- /dev/null +++ b/app/helpers/way_helper.rb @@ -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 index 000000000..66a53ff34 --- /dev/null +++ b/app/helpers/way_tag_helper.rb @@ -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 index 000000000..2920b9e55 --- /dev/null +++ b/app/models/current_way_segment.rb @@ -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 index 000000000..3f978d3d4 --- /dev/null +++ b/app/models/old_way.rb @@ -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 index 000000000..2773ecc7b --- /dev/null +++ b/app/models/way.rb @@ -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 index 000000000..5ce7c8fbc --- /dev/null +++ b/app/models/way_tag.rb @@ -0,0 +1,6 @@ +class WayTag < ActiveRecord::Base + set_table_name 'current_way_tags' + + belongs_to :way, :foreign_key => 'id' + +end diff --git a/app/views/layouts/site.rhtml b/app/views/layouts/site.rhtml index aaf4e0324..95c273e40 100644 --- a/app/views/layouts/site.rhtml +++ b/app/views/layouts/site.rhtml @@ -49,20 +49,19 @@ - + <% unless @user %>
OpenStreetMap is a free editable map of the whole world. It is made by people like you.

OpenStreetMap allows you to view, edit and use geographical data in a collaborative way from anywhere on Earth.

OpenStreetMap's hosting is kindly supported by the UCL VR Centre and bytemark. -

+ <% end %>
Help & Wiki
diff --git a/config/routes.rb b/config/routes.rb index 8f251f7d3..7ba5ad902 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/db/README b/db/README index 68fc8e6ce..4a7067e6c 100644 --- 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) diff --git a/db/migrate.sql b/db/migrate.sql index abbc0ae24..2d55fb552 100644 --- a/db/migrate.sql +++ b/db/migrate.sql @@ -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 index 000000000..6b3486537 --- /dev/null +++ b/db/migrate/008_create_ways.rb @@ -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 index 000000000..317e455a3 --- /dev/null +++ b/db/migrate/009_create_old_ways.rb @@ -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 index 000000000..267f61be1 --- /dev/null +++ b/db/migrate/010_create_way_tags.rb @@ -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 index 000000000..592656674 --- /dev/null +++ b/db/migrate/011_create_current_way_segments.rb @@ -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 index 000000000..da70aafb4 Binary files /dev/null and b/public/images/tab_bottom.gif differ diff --git a/public/stylesheets/site.css b/public/stylesheets/site.css index 9b29cd806..2a3896591 100644 --- a/public/stylesheets/site.css +++ b/public/stylesheets/site.css @@ -70,7 +70,7 @@ body { padding-top: 5px; padding-bottom: 7px; font-size: 13px; - background: url(tab_bottom.gif) repeat-x bottom; + background: url('/images/tab_bottom.gif') repeat-x bottom; } #intro { @@ -246,7 +246,7 @@ hides rule from IE5-Mac \*/ margin: 0; padding-left: 215px; padding-top: 5px; - background: url(tab_bottom.gif) repeat-x bottom; + background: url('/images/tab_bottom.gif') repeat-x bottom; } #tabnav li {