The `use_helpers` method was added in ViewComponent 3.8.0, and it's included by default in all components since version 3.11.0. Note we sometimes delegated the `can?` method to the controller instead of the helpers, for no particularly reason. We're unifying that code as well.
37 lines
867 B
Ruby
37 lines
867 B
Ruby
class Budgets::MapComponent < ApplicationComponent
|
|
use_helpers :render_map
|
|
attr_reader :budget
|
|
|
|
def initialize(budget)
|
|
@budget = budget
|
|
end
|
|
|
|
def render?
|
|
feature?(:map) && !budget.informing?
|
|
end
|
|
|
|
private
|
|
|
|
def coordinates
|
|
if budget.publishing_prices_or_later? && budget.investments.selected.any?
|
|
investments = budget.investments.selected
|
|
else
|
|
investments = budget.investments
|
|
end
|
|
|
|
MapLocation.investments_json_data(investments)
|
|
end
|
|
|
|
def geozones_data
|
|
budget.geozones.map do |geozone|
|
|
{
|
|
outline_points: geozone.outline_points,
|
|
color: geozone.color,
|
|
headings: budget.headings.where(geozone: geozone).map do |heading|
|
|
link_to heading.name, budget_investments_path(budget, heading_id: heading.id)
|
|
end
|
|
}
|
|
end
|
|
end
|
|
end
|