From 5b5ffaf90f54b19379223ee912fe6a4f59234fcd Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 9 Dec 2024 13:04:32 +0300 Subject: [PATCH 1/1] Allow to specify browse icon priorities --- app/helpers/browse_helper.rb | 4 ++-- config/browse_icons.yml | 2 +- config/initializers/browse_icons.rb | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/helpers/browse_helper.rb b/app/helpers/browse_helper.rb index 5cc12bb00..6619a1e92 100644 --- a/app/helpers/browse_helper.rb +++ b/app/helpers/browse_helper.rb @@ -1,6 +1,6 @@ module BrowseHelper def element_icon(type, object) - selected_icon_data = { :filename => "#{type}.svg" } + selected_icon_data = { :filename => "#{type}.svg", :priority => 1 } unless object.redacted? target_tags = object.tags.find_all { |k, _v| BROWSE_ICONS.key? k }.sort @@ -8,7 +8,7 @@ module BrowseHelper target_tags.each do |k, v| icon_data = BROWSE_ICONS[k][v] || BROWSE_ICONS[k][:*] - selected_icon_data = icon_data if icon_data + selected_icon_data = icon_data if icon_data && icon_data[:priority] > selected_icon_data[:priority] end end diff --git a/config/browse_icons.yml b/config/browse_icons.yml index d59c23682..f24d7676c 100644 --- a/config/browse_icons.yml +++ b/config/browse_icons.yml @@ -144,7 +144,7 @@ railway: tram: { filename: "tram.20.png" } shop: - :*: { filename: "shop_convenience.p.16.png" } + :*: { filename: "shop_convenience.p.16.png", priority: 20 } alcohol: { filename: "shop_alcohol.16.png" } bakery: { filename: "shop_bakery.16.png" } bicycle: { filename: "shop_bicycle.16.png" } diff --git a/config/initializers/browse_icons.rb b/config/initializers/browse_icons.rb index cb53848e8..a55df97b6 100644 --- a/config/initializers/browse_icons.rb +++ b/config/initializers/browse_icons.rb @@ -2,7 +2,9 @@ begin BROWSE_ICONS = YAML.load_file(Rails.root.join("config/browse_icons.yml")).transform_values do |tag_key_data| transformed_tag_key_data = {} tag_key_data.each do |tag_value, tag_value_data| - transformed_tag_key_data[tag_value] = tag_value_data.deep_symbolize_keys + tag_value_data = tag_value_data.deep_symbolize_keys + tag_value_data[:priority] ||= tag_value == :* ? 10 : 100 + transformed_tag_key_data[tag_value] = tag_value_data end transformed_tag_key_data end -- 2.39.5