]> git.openstreetmap.org Git - rails.git/blob - app/controllers/browse_controller.rb
Adding new browse controller test, which is mostly stubs just now. Also adding the...
[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_availability(true) }
6
7   def start 
8   end
9   
10   def index
11     @nodes = Node.find(:all, :order => "timestamp DESC", :limit=> 20)  
12   end
13   
14   def relation 
15     begin
16       @relation = Relation.find(params[:id])
17      
18       @name = @relation.tags['name'].to_s 
19       if @name.length == 0:
20           @name = "#" + @relation.id.to_s
21       end
22         
23       @title = 'Relation | ' + (@name)
24       @next = Relation.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @relation.id }] ) 
25       @prev = Relation.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @relation.id }] ) 
26     rescue ActiveRecord::RecordNotFound
27       @type = "relation"
28       render :action => "not_found", :status => :not_found
29     end
30   end
31   
32   def relation_history
33     begin
34       @relation = Relation.find(params[:id])
35      
36       @name = @relation.tags['name'].to_s 
37       if @name.length == 0:
38           @name = "#" + @relation.id.to_s
39       end
40         
41       @title = 'Relation History | ' + (@name)
42     rescue ActiveRecord::RecordNotFound
43       @type = "relation"
44       render :action => "not_found", :status => :not_found
45     end
46   end
47   
48   def way 
49     begin
50       @way = Way.find(params[:id])
51      
52       @name = @way.tags['name'].to_s 
53       if @name.length == 0:
54           @name = "#" + @way.id.to_s
55       end
56         
57       @title = 'Way | ' + (@name)
58       @next = Way.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @way.id }] ) 
59       @prev = Way.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @way.id }] ) 
60     rescue ActiveRecord::RecordNotFound
61       @type = "way"
62       render :action => "not_found", :status => :not_found
63     end
64   end
65   
66   def way_history 
67     begin
68       @way = Way.find(params[:id])
69      
70       @name = @way.tags['name'].to_s 
71       if @name.length == 0:
72           @name = "#" + @way.id.to_s
73       end
74         
75       @title = 'Way History | ' + (@name)
76     rescue ActiveRecord::RecordNotFound
77       @type = "way"
78       render :action => "not_found", :status => :not_found
79     end
80   end
81
82   def node 
83     begin
84       @node = Node.find(params[:id])
85      
86       @name = @node.tags_as_hash['name'].to_s 
87       if @name.length == 0:
88           @name = "#" + @node.id.to_s
89       end
90         
91       @title = 'Node | ' + (@name)
92       @next = Node.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @node.id }] ) 
93       @prev = Node.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @node.id }] ) 
94     rescue ActiveRecord::RecordNotFound
95       @type = "node"
96       render :action => "not_found", :status => :not_found
97     end
98   end
99   
100   def node_history 
101     begin
102       @node = Node.find(params[:id])
103      
104       @name = @node.tags_as_hash['name'].to_s 
105       if @name.length == 0:
106           @name = "#" + @node.id.to_s
107       end
108         
109       @title = 'Node History | ' + (@name)
110     rescue ActiveRecord::RecordNotFound
111       @type = "way"
112       render :action => "not_found", :status => :not_found
113     end
114   end
115   
116   def changeset
117     begin
118       @changeset = Changeset.find(params[:id])
119       
120       @title = "Changeset | #{@changeset.id}"
121       @next = Changeset.find(:first, :order => "id ASC", :conditions => [ "id > :id", { :id => @changeset.id }] ) 
122       @prev = Changeset.find(:first, :order => "id DESC", :conditions => [ "id < :id", { :id => @changeset.id }] ) 
123     rescue ActiveRecord::RecordNotFound
124       @type = "changeset"
125       render :action => "not_found", :status => :not_found
126     end
127   end
128 end