]> git.openstreetmap.org Git - rails.git/blob - app/controllers/browse_controller.rb
Eager load node and way details when processing a map call.
[rails.git] / app / controllers / browse_controller.rb
1 class BrowseController < ApplicationController
2   layout 'site'
3
4   before_filter :authorize_web  
5   before_filter { |c| c.check_database_readable(true) }
6
7   def start 
8   end
9   
10   
11   
12   def relation 
13     @relation = Relation.find(params[:id])
14    
15     @name = @relation.tags['name'].to_s 
16     if @name.length == 0:
17       @name = "#" + @relation.id.to_s
18     end
19         
20     @title = 'Relation | ' + (@name)
21     @next = Relation.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @relation.id }] ) 
22     @prev = Relation.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @relation.id }] ) 
23   rescue ActiveRecord::RecordNotFound
24     @type = "relation"
25     render :action => "not_found", :status => :not_found
26   end
27   
28   def relation_history
29     @relation = Relation.find(params[:id])
30      
31     @name = @relation.tags['name'].to_s 
32     if @name.length == 0:
33       @name = "#" + @relation.id.to_s
34     end
35         
36     @title = 'Relation History | ' + (@name)
37   rescue ActiveRecord::RecordNotFound
38     @type = "relation"
39     render :action => "not_found", :status => :not_found
40   end
41   
42   def way 
43     @way = Way.find(params[:id])
44      
45     @name = @way.tags['name'].to_s 
46     if @name.length == 0:
47       @name = "#" + @way.id.to_s
48     end
49         
50     @title = 'Way | ' + (@name)
51     @next = Way.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @way.id }] ) 
52     @prev = Way.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @way.id }] ) 
53   rescue ActiveRecord::RecordNotFound
54     @type = "way"
55     render :action => "not_found", :status => :not_found
56   end
57   
58   def way_history 
59     @way = Way.find(params[:id])
60      
61     @name = @way.tags['name'].to_s 
62     if @name.length == 0:
63       @name = "#" + @way.id.to_s
64     end
65         
66     @title = 'Way History | ' + (@name)
67   rescue ActiveRecord::RecordNotFound
68     @type = "way"
69     render :action => "not_found", :status => :not_found
70   end
71
72   def node 
73     @node = Node.find(params[:id])
74      
75     @name = @node.tags_as_hash['name'].to_s 
76     if @name.length == 0:
77       @name = "#" + @node.id.to_s
78     end
79         
80     @title = 'Node | ' + (@name)
81     @next = Node.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @node.id }] ) 
82     @prev = Node.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @node.id }] ) 
83   rescue ActiveRecord::RecordNotFound
84     @type = "node"
85     render :action => "not_found", :status => :not_found
86   end
87   
88   def node_history 
89     @node = Node.find(params[:id])
90      
91     @name = @node.tags_as_hash['name'].to_s 
92     if @name.length == 0:
93       @name = "#" + @node.id.to_s
94     end
95         
96     @title = 'Node History | ' + (@name)
97   rescue ActiveRecord::RecordNotFound
98     @type = "way"
99     render :action => "not_found", :status => :not_found
100   end
101   
102   def changeset
103     @changeset = Changeset.find(params[:id])
104     @node_pages, @nodes = paginate(:old_nodes, :conditions => {:changeset_id => @changeset.id}, :per_page => 20, :parameter => 'node_page')
105     @way_pages, @ways = paginate(:old_ways, :conditions => {:changeset_id => @changeset.id}, :per_page => 20, :parameter => 'way_page')
106     @relation_pages, @relations = paginate(:old_relations, :conditions => {:changeset_id => @changeset.id}, :per_page => 20, :parameter => 'relation_page')
107       
108     @title = "Changeset | #{@changeset.id}"
109     @next = Changeset.find(:first, :order => "id ASC", :conditions => [ "id > :id", { :id => @changeset.id }] ) 
110     @prev = Changeset.find(:first, :order => "id DESC", :conditions => [ "id < :id", { :id => @changeset.id }] ) 
111   rescue ActiveRecord::RecordNotFound
112     @type = "changeset"
113     render :action => "not_found", :status => :not_found
114   end
115 end