From 22292debda11f9940ed98faa5f9c01697d6bfcaa Mon Sep 17 00:00:00 2001 From: Thomas Wood Date: Sat, 2 May 2009 00:26:37 +0000 Subject: [PATCH] Data browser changes, make links more user friendly, displaying name tag where possible. Changes to models ok'd (and suggested as temporary solution) by TomH References #1777 --- app/controllers/browse_controller.rb | 64 ++++----------------- app/helpers/browse_helper.rb | 11 ++++ app/models/old_relation_member.rb | 2 + app/models/old_way_node.rb | 3 + app/views/browse/_changeset_details.rhtml | 6 +- app/views/browse/_containing_relation.rhtml | 2 +- app/views/browse/_node_details.rhtml | 2 +- app/views/browse/_relation_member.rhtml | 2 +- app/views/browse/_way_details.rhtml | 2 +- app/views/browse/node.rhtml | 4 ++ app/views/browse/node_history.rhtml | 4 ++ app/views/browse/relation.rhtml | 4 ++ app/views/browse/relation_history.rhtml | 4 ++ app/views/browse/way.rhtml | 4 ++ app/views/browse/way_history.rhtml | 4 ++ 15 files changed, 58 insertions(+), 60 deletions(-) diff --git a/app/controllers/browse_controller.rb b/app/controllers/browse_controller.rb index 6ace0817b..e9081f026 100644 --- a/app/controllers/browse_controller.rb +++ b/app/controllers/browse_controller.rb @@ -9,17 +9,10 @@ class BrowseController < ApplicationController - def relation + def relation @relation = Relation.find(params[:id]) - - @name = @relation.tags['name'].to_s - if @name.length == 0: - @name = "#" + @relation.id.to_s - end - - @title = 'Relation | ' + (@name) - @next = Relation.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @relation.id }] ) - @prev = Relation.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @relation.id }] ) + @next = Relation.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @relation.id }] ) + @prev = Relation.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @relation.id }] ) rescue ActiveRecord::RecordNotFound @type = "relation" render :action => "not_found", :status => :not_found @@ -27,73 +20,38 @@ class BrowseController < ApplicationController def relation_history @relation = Relation.find(params[:id]) - - @name = @relation.tags['name'].to_s - if @name.length == 0: - @name = "#" + @relation.id.to_s - end - - @title = 'Relation History | ' + (@name) rescue ActiveRecord::RecordNotFound @type = "relation" render :action => "not_found", :status => :not_found end - def way + def way @way = Way.find(params[:id]) - - @name = @way.tags['name'].to_s - if @name.length == 0: - @name = "#" + @way.id.to_s - end - - @title = 'Way | ' + (@name) - @next = Way.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @way.id }] ) - @prev = Way.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @way.id }] ) + @next = Way.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @way.id }] ) + @prev = Way.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @way.id }] ) rescue ActiveRecord::RecordNotFound @type = "way" render :action => "not_found", :status => :not_found end - def way_history + def way_history @way = Way.find(params[:id]) - - @name = @way.tags['name'].to_s - if @name.length == 0: - @name = "#" + @way.id.to_s - end - - @title = 'Way History | ' + (@name) rescue ActiveRecord::RecordNotFound @type = "way" render :action => "not_found", :status => :not_found end - def node + def node @node = Node.find(params[:id]) - - @name = @node.tags_as_hash['name'].to_s - if @name.length == 0: - @name = "#" + @node.id.to_s - end - - @title = 'Node | ' + (@name) - @next = Node.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @node.id }] ) - @prev = Node.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @node.id }] ) + @next = Node.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @node.id }] ) + @prev = Node.find(:first, :order => "id DESC", :conditions => [ "visible = true AND id < :id", { :id => @node.id }] ) rescue ActiveRecord::RecordNotFound @type = "node" render :action => "not_found", :status => :not_found end - def node_history + def node_history @node = Node.find(params[:id]) - - @name = @node.tags_as_hash['name'].to_s - if @name.length == 0: - @name = "#" + @node.id.to_s - end - - @title = 'Node History | ' + (@name) rescue ActiveRecord::RecordNotFound @type = "way" render :action => "not_found", :status => :not_found diff --git a/app/helpers/browse_helper.rb b/app/helpers/browse_helper.rb index 34302a8af..67420151c 100644 --- a/app/helpers/browse_helper.rb +++ b/app/helpers/browse_helper.rb @@ -2,4 +2,15 @@ module BrowseHelper def link_to_page(page, page_param) return link_to(page, page_param => page) end + + def printable_name(object, version=false) + name = object.id.to_s + if version + name = "#{name}, v#{object.version.to_s}" + end + if object.tags.include? 'name' + name = "#{object.tags['name'].to_s} (#{name})" + end + return name + end end diff --git a/app/models/old_relation_member.rb b/app/models/old_relation_member.rb index f0294d339..7bd7442dd 100644 --- a/app/models/old_relation_member.rb +++ b/app/models/old_relation_member.rb @@ -3,4 +3,6 @@ class OldRelationMember < ActiveRecord::Base set_primary_keys :id, :version, :sequence_id belongs_to :relation, :foreign_key=> :id + # A bit messy, referring to the current tables, should do for the data browser for now + belongs_to :member, :polymorphic => true end diff --git a/app/models/old_way_node.rb b/app/models/old_way_node.rb index 7420b5cfc..6234b85c2 100644 --- a/app/models/old_way_node.rb +++ b/app/models/old_way_node.rb @@ -4,4 +4,7 @@ class OldWayNode < ActiveRecord::Base set_primary_keys :id, :version, :sequence_id belongs_to :way, :foreign_key=> :id + + # A bit messy, referring to current nodes, should do for the data browser for now + belongs_to :node end diff --git a/app/views/browse/_changeset_details.rhtml b/app/views/browse/_changeset_details.rhtml index 13b64d340..6408b489b 100644 --- a/app/views/browse/_changeset_details.rhtml +++ b/app/views/browse/_changeset_details.rhtml @@ -53,7 +53,7 @@ <% @nodes.each do |node| %> - + <% end %>
<%= link_to "Node #{node.id.to_s}, version #{node.version.to_s}", :action => "node", :id => node.id.to_s %>
<%= link_to h(printable_name(node, true)), :action => "node", :id => node.id.to_s %>
@@ -67,7 +67,7 @@ <% @ways.each do |way| %> - + <% end %> <%= #render :partial => "containing_relation", :collection => changeset_details.containing_relation_members @@ -84,7 +84,7 @@ diff --git a/app/views/browse/_containing_relation.rhtml b/app/views/browse/_containing_relation.rhtml index 013a7b6d7..f5317f045 100644 --- a/app/views/browse/_containing_relation.rhtml +++ b/app/views/browse/_containing_relation.rhtml @@ -1,6 +1,6 @@ diff --git a/app/views/browse/node.rhtml b/app/views/browse/node.rhtml index e2db18f62..f798526a8 100644 --- a/app/views/browse/node.rhtml +++ b/app/views/browse/node.rhtml @@ -1,3 +1,7 @@ +<% +@name = printable_name @node +@title = 'Node | ' + @name +%>
<%= link_to "Way #{way.id.to_s}, version #{way.version.to_s}", :action => "way", :id => way.id.to_s %>
<%= link_to h(printable_name(way, true)), :action => "way", :id => way.id.to_s %>
<% @relations.each do |relation| %> - + <% end %>
<%= link_to "Relation #{relation.id.to_s}, version #{relation.version.to_s}", :action => "relation", :id => relation.id.to_s %>
<%= link_to h(printable_name(relation, true)), :action => "relation", :id => relation.id.to_s %>
- <%= link_to "Relation " + containing_relation.relation.id.to_s, :action => "relation", :id => containing_relation.relation.id.to_s %> + <%= link_to "Relation " + h(printable_name(containing_relation.relation)), :action => "relation", :id => containing_relation.relation.id.to_s %> <% unless containing_relation.member_role.blank? %> (as <%= h(containing_relation.member_role) %>) <% end %> diff --git a/app/views/browse/_node_details.rhtml b/app/views/browse/_node_details.rhtml index 1aa5bf69c..492aa06db 100644 --- a/app/views/browse/_node_details.rhtml +++ b/app/views/browse/_node_details.rhtml @@ -8,7 +8,7 @@ <% node_details.ways.each do |way| %> - + <% end %> <%= render :partial => "containing_relation", :collection => node_details.containing_relation_members %>
<%= link_to "Way " + way.id.to_s, :action => "way", :id => way.id.to_s %>
<%= link_to h(printable_name(way)), :action => "way", :id => way.id.to_s %>
diff --git a/app/views/browse/_relation_member.rhtml b/app/views/browse/_relation_member.rhtml index fe484c3cd..ce982e2db 100644 --- a/app/views/browse/_relation_member.rhtml +++ b/app/views/browse/_relation_member.rhtml @@ -1,7 +1,7 @@
<%= relation_member.member_type.capitalize %> - <%= link_to relation_member.member_id.to_s, :action => relation_member.member_type.downcase, :id => relation_member.member_id %> + <%= link_to h(printable_name(relation_member.member)), :action => relation_member.member_type.downcase, :id => relation_member.member_id.to_s %> <% unless relation_member.member_role.blank? %> as <%= h(relation_member.member_role) %> diff --git a/app/views/browse/_way_details.rhtml b/app/views/browse/_way_details.rhtml index 9dc35ad53..1122c80f3 100644 --- a/app/views/browse/_way_details.rhtml +++ b/app/views/browse/_way_details.rhtml @@ -7,7 +7,7 @@ <% way_details.way_nodes.each do |wn| %> - + <% end %>
<%= link_to "Node " + wn.node_id.to_s, :action => "node", :id => wn.node_id.to_s %>
<%= link_to h(printable_name(wn.node)), :action => "node", :id => wn.node_id.to_s %>
diff --git a/app/views/browse/node_history.rhtml b/app/views/browse/node_history.rhtml index 5fd3278c9..918be42dc 100644 --- a/app/views/browse/node_history.rhtml +++ b/app/views/browse/node_history.rhtml @@ -1,3 +1,7 @@ +<% +@name = printable_name @node +@title = 'Node History | ' + @name +%>

Node History: <%= h(@name) %>

diff --git a/app/views/browse/relation.rhtml b/app/views/browse/relation.rhtml index f981938a7..89f826c17 100644 --- a/app/views/browse/relation.rhtml +++ b/app/views/browse/relation.rhtml @@ -1,3 +1,7 @@ +<% +@name = printable_name @relation +@title = 'Relation | ' + @name +%>
diff --git a/app/views/browse/relation_history.rhtml b/app/views/browse/relation_history.rhtml index 60e0ffd17..f6a3811ab 100644 --- a/app/views/browse/relation_history.rhtml +++ b/app/views/browse/relation_history.rhtml @@ -1,3 +1,7 @@ +<% +@name = printable_name @relation +@title = 'Relation History | ' + @name +%>

Relation History: <%= h(@name) %>

diff --git a/app/views/browse/way.rhtml b/app/views/browse/way.rhtml index 2e86e65f2..9a733bf9d 100644 --- a/app/views/browse/way.rhtml +++ b/app/views/browse/way.rhtml @@ -1,3 +1,7 @@ +<% +@name = printable_name @way +@title = 'Way | ' + @name +%>
diff --git a/app/views/browse/way_history.rhtml b/app/views/browse/way_history.rhtml index f44405ffa..c39cad54d 100644 --- a/app/views/browse/way_history.rhtml +++ b/app/views/browse/way_history.rhtml @@ -1,3 +1,7 @@ +<% +@name = printable_name @way +@title = 'Way History | ' + @name +%>

Way History: <%= h(@name) %>

-- 2.39.5