From deb965bcce89b8b6ee4c0b0acd7e92bebc036bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 7 Mar 2023 15:59:24 +0100 Subject: [PATCH] Remove editable parameter in render_map The calls to `render_map` are confusing since there are so many parameters. We can assume that the map is editable if we pass the remove marker label. --- app/components/budgets/map_component.html.erb | 2 +- app/components/shared/map_location_component.html.erb | 2 +- app/components/shared/map_location_component.rb | 11 +++++++---- .../budgets/investments/_investment_detail.html.erb | 2 +- app/views/budgets/investments/_map.html.erb | 2 +- app/views/map_locations/_form_fields.html.erb | 2 +- app/views/proposals/_info.html.erb | 2 +- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/components/budgets/map_component.html.erb b/app/components/budgets/map_component.html.erb index 733ce56af..b839defa3 100644 --- a/app/components/budgets/map_component.html.erb +++ b/app/components/budgets/map_component.html.erb @@ -1,4 +1,4 @@

<%= t("budgets.index.map") %>

- <%= render_map(nil, "budgets", false, nil, coordinates) %> + <%= render_map(nil, "budgets", nil, coordinates) %>
diff --git a/app/components/shared/map_location_component.html.erb b/app/components/shared/map_location_component.html.erb index 38cf42d35..9283a2e3f 100644 --- a/app/components/shared/map_location_component.html.erb +++ b/app/components/shared/map_location_component.html.erb @@ -1,5 +1,5 @@ <%= tag.div(id: dom_id(map_location), class: "map_location map", data: data) %> -<% if editable %> +<% if editable? %> <%= remove_marker %> <% end %> diff --git a/app/components/shared/map_location_component.rb b/app/components/shared/map_location_component.rb index 1db74b044..9be1c86c0 100644 --- a/app/components/shared/map_location_component.rb +++ b/app/components/shared/map_location_component.rb @@ -1,11 +1,10 @@ class Shared::MapLocationComponent < ApplicationComponent - attr_reader :parent_class, :editable, :remove_marker_label, :investments_coordinates + attr_reader :parent_class, :remove_marker_label, :investments_coordinates delegate :map_location_input_id, to: :helpers - def initialize(map_location, parent_class, editable, remove_marker_label, investments_coordinates = nil) + def initialize(map_location, parent_class, remove_marker_label, investments_coordinates = nil) @map_location = map_location @parent_class = parent_class - @editable = editable @remove_marker_label = remove_marker_label @investments_coordinates = investments_coordinates end @@ -16,6 +15,10 @@ class Shared::MapLocationComponent < ApplicationComponent private + def editable? + remove_marker_label.present? + end + def latitude map_location.latitude.presence || Setting["map.latitude"] end @@ -48,7 +51,7 @@ class Shared::MapLocationComponent < ApplicationComponent map_zoom: zoom, map_tiles_provider: Rails.application.secrets.map_tiles_provider, map_tiles_provider_attribution: Rails.application.secrets.map_tiles_provider_attribution, - marker_editable: editable, + marker_editable: editable?, marker_remove_selector: "##{remove_marker_link_id}", latitude_input_selector: "##{map_location_input_id(parent_class, "latitude")}", longitude_input_selector: "##{map_location_input_id(parent_class, "longitude")}", diff --git a/app/views/budgets/investments/_investment_detail.html.erb b/app/views/budgets/investments/_investment_detail.html.erb index 046d1e659..456aac402 100644 --- a/app/views/budgets/investments/_investment_detail.html.erb +++ b/app/views/budgets/investments/_investment_detail.html.erb @@ -28,7 +28,7 @@ <% if feature?(:map) && map_location_available?(@investment.map_location) %>
- <%= render_map(investment.map_location, "budget_investment", false, nil) %> + <%= render_map(investment.map_location, "budget_investment", nil) %>
<% end %> diff --git a/app/views/budgets/investments/_map.html.erb b/app/views/budgets/investments/_map.html.erb index 3d26ee7bc..085e4fe90 100644 --- a/app/views/budgets/investments/_map.html.erb +++ b/app/views/budgets/investments/_map.html.erb @@ -1,3 +1,3 @@
- <%= render_map(@map_location, "budgets", false, nil, @investments_map_coordinates) %> + <%= render_map(@map_location, "budgets", nil, @investments_map_coordinates) %>
diff --git a/app/views/map_locations/_form_fields.html.erb b/app/views/map_locations/_form_fields.html.erb index 75236f140..07c0fba17 100644 --- a/app/views/map_locations/_form_fields.html.erb +++ b/app/views/map_locations/_form_fields.html.erb @@ -1,7 +1,7 @@ <%= form.label :map_location, label %>

<%= help %>

-<%= render_map(map_location, parent_class, editable = true, remove_marker_label) %> +<%= render_map(map_location, parent_class, remove_marker_label) %> <%= form.fields_for :map_location, map_location do |m_l_fields| %> <%= m_l_fields.hidden_field :latitude, diff --git a/app/views/proposals/_info.html.erb b/app/views/proposals/_info.html.erb index 88b31d6e2..686e8dfa1 100644 --- a/app/views/proposals/_info.html.erb +++ b/app/views/proposals/_info.html.erb @@ -42,7 +42,7 @@ <% if feature?(:map) && map_location_available?(@proposal.map_location) %>
- <%= render_map(@proposal.map_location, "proposal", false, nil) %> + <%= render_map(@proposal.map_location, "proposal", nil) %>
<% end %>