Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show "node also part of ways" as nested lists on way pages #5317

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions app/views/browse/_way.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,28 @@
<details <%= "open" if way.way_nodes.count < 10 %>>
<summary><%= t ".nodes_count", :count => way.way_nodes.count %></summary>
<ul class="list-unstyled">
<% visited_way_nodes = {} %>
<% way.way_nodes.each do |wn| %>
<li>
<%= element_single_current_link "node", wn.node %>
<% related_ways = wn.node.ways.reject { |w| w.id == wn.way_id } %>
<% if related_ways.size > 0 then %>
(<%= t ".also_part_of_html",
:count => related_ways.size,
:related_ways => to_sentence(related_ways.map { |w| element_single_current_link "way", w }) %>)
<% related_ways = wn.node.ways.uniq.sort.reject { |w| w.id == wn.way_id } %>
<% if related_ways.size.zero? %>
<%= element_single_current_link "node", wn.node %>
<% else %>
<div>
<%= element_single_current_link "node", wn.node %>
</div>
<%= tag.details :class => "ms-4", :open => !visited_way_nodes[wn.node.id] do %>
<summary><%= t ".also_part_of_ways", :count => related_ways.size %></summary>
<ul class="list-unstyled">
<% related_ways.each do |related_way| %>
<li>
<%= element_single_current_link "way", related_way %>
</li>
<% end %>
</ul>
<% end %>
<% end %>
<% visited_way_nodes[wn.node.id] = true %>
</li>
<% end %>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ en:
nodes_count:
one: "%{count} node"
other: "%{count} nodes"
also_part_of_html:
one: "part of way %{related_ways}"
other: "part of ways %{related_ways}"
also_part_of_ways:
one: "also part of %{count} other way"
other: "also part of %{count} other ways"
relation:
title_html: "Relation: %{name}"
history_title_html: "Relation History: %{name}"
Expand Down
124 changes: 124 additions & 0 deletions test/controllers/ways_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,128 @@ def test_show_timeout
assert_dom "h2", "Timeout Error"
assert_dom "p", /#{Regexp.quote("the way with the id #{way.id}")}/
end

def test_show_nodes
way = create(:way_with_nodes, :nodes_count => 2)

get way_path(way, :xhr => true)
assert_response :success
assert_dom "ul:has(> li a[href='#{node_path way.nodes[0]}']):has(> li a[href='#{node_path way.nodes[0]}'])", :count => 1 do
assert_dom "> li", :count => 2 do |list_items|
assert_dom list_items[0], "a[href='#{node_path way.nodes[0]}']"
assert_dom list_items[1], "a[href='#{node_path way.nodes[1]}']"
end
end
end

##
# shows another way that shares a node
#
# (b)--1--(a)--2--(c)
#
def test_show_nodes_also_part_of_way
way1 = create(:way)
way2 = create(:way)
node_a = create(:node)
node_b = create(:node)
node_c = create(:node)
create(:way_node, :way => way1, :node => node_a, :sequence_id => 1)
create(:way_node, :way => way1, :node => node_b, :sequence_id => 2)
create(:way_node, :way => way2, :node => node_a, :sequence_id => 1)
create(:way_node, :way => way2, :node => node_c, :sequence_id => 2)

get way_path(way1, :xhr => true)
assert_response :success
assert_dom "ul:has(> li a[href='#{node_path node_a}']):has(> li a[href='#{node_path node_b}'])", :count => 1 do
assert_dom "> li", :count => 2 do |list_items|
assert_dom list_items[0], "a[href='#{node_path node_a}']"
assert_dom list_items[1], "a[href='#{node_path node_b}']"
assert_dom list_items[1], "ul", :count => 0
assert_dom list_items[0], "ul", :count => 1 do
assert_dom "> li", :count => 1 do |sub_list_items|
assert_dom sub_list_items[0], "a[href='#{way_path way2}']"
end
end
end
end
end

##
# node shared with a looped way shouldn't cause that way appear twice in the "part of ways" sublist
#
# (b)--1--(a)--2--(c)
# \ /
# \ /
# (d)
#
def test_show_nodes_also_part_of_looped_way
way1 = create(:way)
way2 = create(:way)
node_a = create(:node)
node_b = create(:node)
node_c = create(:node)
node_d = create(:node)
create(:way_node, :way => way1, :node => node_a, :sequence_id => 1)
create(:way_node, :way => way1, :node => node_b, :sequence_id => 2)
create(:way_node, :way => way2, :node => node_a, :sequence_id => 1)
create(:way_node, :way => way2, :node => node_c, :sequence_id => 2)
create(:way_node, :way => way2, :node => node_d, :sequence_id => 3)
create(:way_node, :way => way2, :node => node_a, :sequence_id => 4)

get way_path(way1, :xhr => true)
assert_response :success
assert_dom "ul:has(> li a[href='#{node_path node_a}']):has(> li a[href='#{node_path node_b}'])", :count => 1 do
assert_dom "> li", :count => 2 do |list_items|
assert_dom list_items[0], "a[href='#{node_path node_a}']"
assert_dom list_items[1], "a[href='#{node_path node_b}']"
assert_dom list_items[1], "ul", :count => 0
assert_dom list_items[0], "ul", :count => 1 do
assert_dom "> li", :count => 1 do |sub_list_items|
assert_dom sub_list_items[0], "a[href='#{way_path way2}']"
end
end
end
end
end

##
# shows two ways that share a node
#
# (b)--1--(a)--2--(c)
# \
# 3
# \
# (d)
#
def test_show_nodes_also_part_of_2_ways
way1 = create(:way)
way2 = create(:way)
way3 = create(:way)
node_a = create(:node)
node_b = create(:node)
node_c = create(:node)
node_d = create(:node)
create(:way_node, :way => way1, :node => node_a, :sequence_id => 1)
create(:way_node, :way => way1, :node => node_b, :sequence_id => 2)
create(:way_node, :way => way2, :node => node_a, :sequence_id => 1)
create(:way_node, :way => way2, :node => node_c, :sequence_id => 2)
create(:way_node, :way => way3, :node => node_a, :sequence_id => 1)
create(:way_node, :way => way3, :node => node_d, :sequence_id => 2)

get way_path(way1, :xhr => true)
assert_response :success
assert_dom "ul:has(> li a[href='#{node_path node_a}']):has(> li a[href='#{node_path node_b}'])", :count => 1 do
assert_dom "> li", :count => 2 do |list_items|
assert_dom list_items[0], "a[href='#{node_path node_a}']"
assert_dom list_items[1], "a[href='#{node_path node_b}']"
assert_dom list_items[1], "ul", :count => 0
assert_dom list_items[0], "ul", :count => 1 do
assert_dom "> li", :count => 2 do |sub_list_items|
assert_dom sub_list_items[0], "a[href='#{way_path way2}']"
assert_dom sub_list_items[1], "a[href='#{way_path way3}']"
end
end
end
end
end
end
Loading