]> git.openstreetmap.org Git - rails.git/commitdiff
Merge data browser branch to trunk.
authorTom Hughes <tom@compton.nu>
Fri, 27 Jun 2008 23:09:05 +0000 (23:09 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 27 Jun 2008 23:09:05 +0000 (23:09 +0000)
app/controllers/amf_controller.rb
app/controllers/api_controller.rb
app/models/node.rb
app/models/relation.rb
app/models/way.rb
app/views/notifier/diary_comment_notification.rhtml
app/views/notifier/message_notification.rhtml
config/database.yml
lib/object_finder.rb [new file with mode: 0644]

index 359b45326b99137b89bfaaba944959b15a45d503..11ddc3f7c7ba8fe9148fc4e9f65ae3ec47948d86 100644 (file)
@@ -123,7 +123,9 @@ class AmfController < ApplicationController
     points = nodes_not_used_in_area.collect { |n| [n.id, n.lon_potlatch(baselong,masterscale), n.lat_potlatch(basey,masterscale), n.tags_as_hash] }
 
     # find the relations used by those nodes and ways
-    relation_ids = (Relation.find_for_nodes_and_ways(nodes_in_area.collect {|n| n.id}, way_ids)).collect {|n| n.id}.uniq
+    relations = nodes_in_area.collect { |node| node.containing_relations.visible }.flatten +
+                way_ids.collect { |id| Way.find(id).containing_relations.visible }.flatten
+    relation_ids = relations.collect { |relation| relation.id }.uniq
 
     [way_ids,points,relation_ids]
   end
index 26cb93a489cbd1f625b79ea727e0e58b78eccabf..9cf8977d332de0bfbf246ca126308cc1192160e2 100644 (file)
@@ -124,8 +124,6 @@ class ApiController < ApplicationController
       return
     end
 
-    relations = Array.new
-
     doc = OSM::API.new.get_xml_doc
 
     # get ways
@@ -170,19 +168,15 @@ class ApiController < ApplicationController
       end
     end 
 
-    relations = Relation.find_for_nodes_and_ways(visible_nodes.keys, way_ids)
+    relations = visible_nodes.values.collect { |node| node.containing_relations.visible }.flatten +
+                way_ids.collect { |id| Way.find(id).containing_relations.visible }.flatten
 
     # we do not normally return the "other" partners referenced by an relation, 
     # e.g. if we return a way A that is referenced by relation X, and there's 
     # another way B also referenced, that is not returned. But we do make 
     # an exception for cases where an relation references another *relation*; 
     # in that case we return that as well (but we don't go recursive here)
-    relation_ids = relations.collect { |relation| relation.id }
-    if relation_ids.length > 0
-        relations += Relation.find_by_sql("select e.* from current_relations e,current_relation_members em where " +
-            "e.visible=1 and " +
-            "em.id = e.id and em.member_type='relation' and em.member_id in (#{relation_ids.join(',')})")
-    end
+    relations += relations.collect { |relation| relation.containing_relations.visible }.flatten
 
     # this "uniq" may be slightly inefficient; it may be better to first collect and output
     # all node-related relations, then find the *not yet covered* way-related ones etc.
index be444bf3e252fee4832ea12e8c31dfa4124d9742..abfa44d676930d3310e4c0b73fc8bcc9bad194e5 100644 (file)
@@ -18,7 +18,7 @@ class Node < ActiveRecord::Base
   has_many :ways, :through => :way_nodes
 
   has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
-  has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation
+  has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation, :extend => ObjectFinder
 
   # Sanity check the latitude and longitude and add an error if it's broken
   def validate_position
index a1dc9f81d646195704f3dfc2a326997c39d63157..9ee118f6e0c22fb26f4bff0012e30e3cb2c92173 100644 (file)
@@ -11,7 +11,7 @@ class Relation < ActiveRecord::Base
   has_many :relation_tags, :foreign_key => 'id'
 
   has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
-  has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation
+  has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation, :extend => ObjectFinder
 
   def self.from_xml(xml, create=false)
     begin
@@ -105,29 +105,6 @@ class Relation < ActiveRecord::Base
     return el1
   end 
 
-    
-  # collect relationships. currently done in one big block at the end;
-  # may need to move this upwards if people want automatic completion of
-  # relationships, i.e. deliver referenced objects like we do with ways... 
-  # FIXME: rip out the fucking SQL
-  def self.find_for_nodes_and_ways(node_ids, way_ids)
-    relations = []
-
-    if node_ids.length > 0
-      relations += Relation.find_by_sql("select e.* from current_relations e,current_relation_members em where " +
-            "e.visible=1 and " +
-            "em.id = e.id and em.member_type='node' and em.member_id in (#{node_ids.join(',')})")
-    end
-    if way_ids.length > 0
-      relations += Relation.find_by_sql("select e.* from current_relations e,current_relation_members em where " +
-            "e.visible=1 and " +
-            "em.id = e.id and em.member_type='way' and em.member_id in (#{way_ids.join(',')})")
-    end
-
-    relations # if you don't do this then it returns nil and not []
-  end
-
-
   # FIXME is this really needed?
   def members
     unless @members
index b042be59eca4baecfecfe20e8fd3e3a0e9d610f3..64b11cf672aabebe946e5473a7da601a500d7201 100644 (file)
@@ -13,7 +13,7 @@ class Way < ActiveRecord::Base
   has_many :way_tags, :foreign_key => 'id'
 
   has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
-  has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation
+  has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation, :extend => ObjectFinder
 
   def self.from_xml(xml, create=false)
     begin
index 05b1f0886b9d59eb37e67ba19ca7ad9a0c06dc27..9d000e9d346d6b8a20709b4edae4589e02e78361 100644 (file)
@@ -1,5 +1,17 @@
 ***************************************************************************
-Please do not reply to this email. Use the OpenStreetMap web site to reply.
+*                                                                         *
+*                   Please do not reply to this email.                    *
+*                Use the OpenStreetMap web site to reply.                 *
+*                                                                         *
+*               Bitte antworten Sie nicht auf diese E-Mail.               *
+*          Verwenden Sie die OpenStreetMap Website zum antworten.         *
+*                                                                         *
+*                 Por favor, no responda a este mensaje.                  *
+*           Utilice el OpenStreetMap sitio web para responder.            *
+*                                                                         *
+*            S’il vous plaît de ne pas répondre à ce message.             *
+*           Utilisez le OpenStreetMap site Web pour y répondre.           *
+*                                                                         *
 ***************************************************************************
 
 Hi <%= @to_user %>,
@@ -16,5 +28,17 @@ and you can comment at <%= @commenturl %>
 or reply at <%= @replyurl %>
 
 ***************************************************************************
-Please do not reply to this email. Use the OpenStreetMap web site to reply.
+*                                                                         *
+*                   Please do not reply to this email.                    *
+*                Use the OpenStreetMap web site to reply.                 *
+*                                                                         *
+*               Bitte antworten Sie nicht auf diese E-Mail.               *
+*          Verwenden Sie die OpenStreetMap Website zum antworten.         *
+*                                                                         *
+*                 Por favor, no responda a este mensaje.                  *
+*           Utilice el OpenStreetMap sitio web para responder.            *
+*                                                                         *
+*            S’il vous plaît de ne pas répondre à ce message.             *
+*           Utilisez le OpenStreetMap site Web pour y répondre.           *
+*                                                                         *
 ***************************************************************************
index 82efbb1a9690f6b1d624ca12eacc042dfa56a966..55e464e1550e50421376302d276d529a9e6f9f09 100644 (file)
@@ -1,5 +1,17 @@
 ***************************************************************************
-Please do not reply to this email. Use the OpenStreetMap web site to reply.
+*                                                                         *
+*                   Please do not reply to this email.                    *
+*                Use the OpenStreetMap web site to reply.                 *
+*                                                                         *
+*               Bitte antworten Sie nicht auf diese E-Mail.               *
+*          Verwenden Sie die OpenStreetMap Website zum antworten.         *
+*                                                                         *
+*                 Por favor, no responda a este mensaje.                  *
+*           Utilice el OpenStreetMap sitio web para responder.            *
+*                                                                         *
+*            S’il vous plaît de ne pas répondre à ce message.             *
+*           Utilisez le OpenStreetMap site Web pour y répondre.           *
+*                                                                         *
 ***************************************************************************
 
 Hi <%= @to_user %>,
@@ -14,5 +26,17 @@ You can also read the message at <%= @readurl %>
 and you can reply at <%= @replyurl %>
 
 ***************************************************************************
-Please do not reply to this email. Use the OpenStreetMap web site to reply.
+*                                                                         *
+*                   Please do not reply to this email.                    *
+*                Use the OpenStreetMap web site to reply.                 *
+*                                                                         *
+*               Bitte antworten Sie nicht auf diese E-Mail.               *
+*          Verwenden Sie die OpenStreetMap Website zum antworten.         *
+*                                                                         *
+*                 Por favor, no responda a este mensaje.                  *
+*           Utilice el OpenStreetMap sitio web para responder.            *
+*                                                                         *
+*            S’il vous plaît de ne pas répondre à ce message.             *
+*           Utilisez le OpenStreetMap site Web pour y répondre.           *
+*                                                                         *
 ***************************************************************************
index 19b5dd8d5227ae5c04720b61afd9a101661c9cbe..b884f3b938fea8c5ea541e0d4af5fbbc16529dd7 100644 (file)
@@ -12,8 +12,9 @@
 #   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
 development:
   adapter: mysql
-  database: osm
-  user: root  
+  database: openstreetmap
+  username: openstreetmap
+  password: openstreetmap
   host: localhost
 
 # Warning: The database defined as 'test' will be erased and
diff --git a/lib/object_finder.rb b/lib/object_finder.rb
new file mode 100644 (file)
index 0000000..26608a7
--- /dev/null
@@ -0,0 +1,5 @@
+module ObjectFinder
+  def visible
+    find :all, :conditions => "#{proxy_reflection.table_name}.visible = 1"
+  end
+end