Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/5385'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Dec 10, 2024
2 parents e2839ae + dc52cdc commit 59fccd9
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 302 deletions.
180 changes: 0 additions & 180 deletions app/assets/stylesheets/browse.scss

This file was deleted.

33 changes: 9 additions & 24 deletions app/assets/stylesheets/common.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@use "sass:map";
@import "parameters";
@import "browse";
@import "bootstrap";
@import "rails_bootstrap_forms";

Expand Down Expand Up @@ -970,34 +969,20 @@ img.trace_image {

/* Rules for map sidebar icons */

.browse-section {
.node::before,
.way::before,
.relation::before {
display: inline-block;
width: 25px;
margin-left: -25px;
}
.browse-section .browse-element-list {
line-height: 1.25rem;

.node, .way, .relation {
margin-left: 25px;
.browse-icon {
height: 1.25rem;
}

.node::before { content: image-url('browse/node.svg'); }
.way::before { content: image-url('browse/way.svg'); }
.relation::before { content: image-url('browse/relation.svg'); }
}

@each $class, $item in $map-sidebar-icons {
.browse-section #{$class}::before {
content: image-url('browse/#{map.get($item, "filename")}');
.d-flex > .browse-icon {
height: max(20px, 1.25rem);
}

@if map.get($item, "invert") {
@include color-mode(dark) {
.browse-section #{$class}::before {
filter: invert(.8) hue-rotate(180deg);
}
@include color-mode(dark) {
.browse-icon-invertible {
filter: invert(.8) hue-rotate(180deg);
}
}
}
51 changes: 27 additions & 24 deletions app/helpers/browse_helper.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
module BrowseHelper
def element_icon(type, object)
selected_icon_data = { :filename => "#{type}.svg", :priority => 1 }

unless object.redacted?
target_tags = object.tags.find_all { |k, _v| BROWSE_ICONS.key? k }.sort
title = target_tags.map { |k, v| "#{k}=#{v}" }.to_sentence unless target_tags.empty?

target_tags.each do |k, v|
icon_data = BROWSE_ICONS[k][v] || BROWSE_ICONS[k][:*]
selected_icon_data = icon_data if icon_data && icon_data[:priority] > selected_icon_data[:priority]
end
end

image_tag "browse/#{selected_icon_data[:filename]}",
:size => 20,
:class => ["align-bottom object-fit-none browse-icon", { "browse-icon-invertible" => selected_icon_data[:invert] }],
:title => title
end

def element_single_current_link(type, object)
link_to object, { :class => element_class(type, object), :title => element_title(object), :rel => (link_follow(object) if type == "node") } do
link_to object, { :rel => (link_follow(object) if type == "node") } do
element_strikethrough object do
printable_element_name object
end
end
end

def element_list_item(type, object, &block)
tag.li :class => element_class(type, object), :title => element_title(object) do
element_strikethrough object, &block
def element_list_item(type, object, &)
tag.li(tag.div(element_icon(type, object) + tag.div(:class => "align-self-center", &), :class => "d-flex gap-1"))
end

def element_list_item_with_strikethrough(type, object, &)
element_list_item type, object do
element_strikethrough object, &
end
end

Expand Down Expand Up @@ -52,20 +75,6 @@ def element_strikethrough(object, &)
end
end

def element_class(type, object)
classes = [type]
classes += icon_tags(object).flatten.map { |t| h(t) } unless object.redacted?
classes.join(" ")
end

def element_title(object)
if object.redacted?
""
else
h(icon_tags(object).map { |k, v| "#{k}=#{v}" }.to_sentence)
end
end

def link_follow(object)
"nofollow" if object.tags.empty?
end
Expand Down Expand Up @@ -107,12 +116,6 @@ def sidebar_classic_pagination(pages, page_param)

private

ICON_TAGS = %w[aeroway amenity barrier building highway historic landuse leisure man_made natural office railway shop tourism waterway].freeze

def icon_tags(object)
object.tags.find_all { |k, _v| ICON_TAGS.include? k }.sort
end

def name_locales(object)
object.tags.keys.map { |k| Regexp.last_match(1) if k =~ /^name:(.*)$/ }.flatten
end
Expand Down
15 changes: 8 additions & 7 deletions app/views/browse/_containing_relation.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<li><%= linked_name = link_to printable_element_name(containing_relation.relation), containing_relation.relation, :class => "relation"
if containing_relation.member_role.blank?
linked_name
else
t ".entry_role_html", :relation_name => linked_name, :relation_role => containing_relation.member_role
end %>
</li>
<%= element_list_item "relation", containing_relation.relation do %>
<%= linked_name = link_to printable_element_name(containing_relation.relation), containing_relation.relation
if containing_relation.member_role.blank?
linked_name
else
t ".entry_role_html", :relation_name => linked_name, :relation_role => containing_relation.member_role
end %>
<% end %>
8 changes: 5 additions & 3 deletions app/views/browse/_node.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
<% unless node.ways.empty? %>
<details <%= "open" if node.ways.count < 10 %>>
<summary><%= t "browse.part_of_ways", :count => node.ways.uniq.count %></summary>
<ul class="list-unstyled">
<ul class="list-unstyled browse-element-list">
<% node.ways.uniq.each do |way| %>
<li><%= element_single_current_link "way", way %></li>
<%= element_list_item "way", way do %>
<%= element_single_current_link "way", way %>
<% end %>
<% end %>
</ul>
</details>
<% end %>
<% unless node.containing_relation_members.empty? %>
<details <%= "open" if node.containing_relation_members.count < 10 %>>
<summary><%= t "browse.part_of_relations", :count => node.containing_relation_members.uniq.count %></summary>
<ul class="list-unstyled">
<ul class="list-unstyled browse-element-list">
<%= render :partial => "browse/containing_relation", :collection => node.containing_relation_members.uniq %>
</ul>
</details>
Expand Down
4 changes: 2 additions & 2 deletions app/views/browse/_relation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<h4><%= t "browse.part_of" %></h4>
<details <%= "open" if relation.containing_relation_members.count < 10 %>>
<summary><%= t "browse.part_of_relations", :count => relation.containing_relation_members.uniq.count %></summary>
<ul class="list-unstyled">
<ul class="list-unstyled browse-element-list">
<%= render :partial => "browse/containing_relation", :collection => relation.containing_relation_members.uniq %>
</ul>
</details>
Expand All @@ -24,7 +24,7 @@
<h4><%= t ".members" %></h4>
<details <%= "open" if relation.relation_members.count < 10 %>>
<summary><%= t ".members_count", :count => relation.relation_members.count %></summary>
<ul class="list-unstyled">
<ul class="list-unstyled browse-element-list">
<%= render :partial => "browse/relation_member", :collection => relation.relation_members %>
</ul>
</details>
Expand Down
2 changes: 1 addition & 1 deletion app/views/browse/_relation_member.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% linked_name = link_to printable_element_name(relation_member.member), relation_member.member, { :rel => link_follow(relation_member.member) }
type_str = t ".type.#{relation_member.member_type.downcase}" %>
<%= element_list_item relation_member.member_type.downcase, relation_member.member do %>
<%= element_list_item_with_strikethrough relation_member.member_type.downcase, relation_member.member do %>
<%= if relation_member.member_role.blank?
t ".entry_html", :type => type_str, :name => linked_name
else
Expand Down
Loading

0 comments on commit 59fccd9

Please sign in to comment.