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.
This commit is contained in:
Javi Martín
2023-03-07 15:59:24 +01:00
parent 19adae993e
commit deb965bcce
7 changed files with 13 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
<div class="map inline"> <div class="map inline">
<h2><%= t("budgets.index.map") %></h2> <h2><%= t("budgets.index.map") %></h2>
<%= render_map(nil, "budgets", false, nil, coordinates) %> <%= render_map(nil, "budgets", nil, coordinates) %>
</div> </div>

View File

@@ -1,5 +1,5 @@
<%= tag.div(id: dom_id(map_location), class: "map_location map", data: data) %> <%= tag.div(id: dom_id(map_location), class: "map_location map", data: data) %>
<% if editable %> <% if editable? %>
<%= remove_marker %> <%= remove_marker %>
<% end %> <% end %>

View File

@@ -1,11 +1,10 @@
class Shared::MapLocationComponent < ApplicationComponent 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 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 @map_location = map_location
@parent_class = parent_class @parent_class = parent_class
@editable = editable
@remove_marker_label = remove_marker_label @remove_marker_label = remove_marker_label
@investments_coordinates = investments_coordinates @investments_coordinates = investments_coordinates
end end
@@ -16,6 +15,10 @@ class Shared::MapLocationComponent < ApplicationComponent
private private
def editable?
remove_marker_label.present?
end
def latitude def latitude
map_location.latitude.presence || Setting["map.latitude"] map_location.latitude.presence || Setting["map.latitude"]
end end
@@ -48,7 +51,7 @@ class Shared::MapLocationComponent < ApplicationComponent
map_zoom: zoom, map_zoom: zoom,
map_tiles_provider: Rails.application.secrets.map_tiles_provider, map_tiles_provider: Rails.application.secrets.map_tiles_provider,
map_tiles_provider_attribution: Rails.application.secrets.map_tiles_provider_attribution, map_tiles_provider_attribution: Rails.application.secrets.map_tiles_provider_attribution,
marker_editable: editable, marker_editable: editable?,
marker_remove_selector: "##{remove_marker_link_id}", marker_remove_selector: "##{remove_marker_link_id}",
latitude_input_selector: "##{map_location_input_id(parent_class, "latitude")}", latitude_input_selector: "##{map_location_input_id(parent_class, "latitude")}",
longitude_input_selector: "##{map_location_input_id(parent_class, "longitude")}", longitude_input_selector: "##{map_location_input_id(parent_class, "longitude")}",

View File

@@ -28,7 +28,7 @@
<% if feature?(:map) && map_location_available?(@investment.map_location) %> <% if feature?(:map) && map_location_available?(@investment.map_location) %>
<div class="margin"> <div class="margin">
<%= render_map(investment.map_location, "budget_investment", false, nil) %> <%= render_map(investment.map_location, "budget_investment", nil) %>
</div> </div>
<% end %> <% end %>

View File

@@ -1,3 +1,3 @@
<div class="map"> <div class="map">
<%= render_map(@map_location, "budgets", false, nil, @investments_map_coordinates) %> <%= render_map(@map_location, "budgets", nil, @investments_map_coordinates) %>
</div> </div>

View File

@@ -1,7 +1,7 @@
<%= form.label :map_location, label %> <%= form.label :map_location, label %>
<p class="help-text" id="tag-list-help-text"><%= help %></p> <p class="help-text" id="tag-list-help-text"><%= help %></p>
<%= 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| %> <%= form.fields_for :map_location, map_location do |m_l_fields| %>
<%= m_l_fields.hidden_field :latitude, <%= m_l_fields.hidden_field :latitude,

View File

@@ -42,7 +42,7 @@
<% if feature?(:map) && map_location_available?(@proposal.map_location) %> <% if feature?(:map) && map_location_available?(@proposal.map_location) %>
<div class="margin"> <div class="margin">
<%= render_map(@proposal.map_location, "proposal", false, nil) %> <%= render_map(@proposal.map_location, "proposal", nil) %>
</div> </div>
<% end %> <% end %>