Move investments sidebar map view to a component
This way we remove some logic from the (huge) investments controller class.
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
<div class="map">
|
||||||
|
<%= render_map(map_location, investments_coordinates: coordinates) %>
|
||||||
|
</div>
|
||||||
22
app/components/budgets/investments/map_component.rb
Normal file
22
app/components/budgets/investments/map_component.rb
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
class Budgets::Investments::MapComponent < ApplicationComponent
|
||||||
|
attr_reader :heading, :investments
|
||||||
|
|
||||||
|
def initialize(investments, heading:)
|
||||||
|
@investments = investments
|
||||||
|
@heading = heading
|
||||||
|
end
|
||||||
|
|
||||||
|
def render?
|
||||||
|
map_location&.available?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def map_location
|
||||||
|
MapLocation.from_heading(heading) if heading.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def coordinates
|
||||||
|
MapLocation.where(investment: investments).map(&:json_data)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -20,7 +20,6 @@ module Budgets
|
|||||||
|
|
||||||
before_action :load_ballot, only: [:index, :show]
|
before_action :load_ballot, only: [:index, :show]
|
||||||
before_action :load_heading, only: [:index, :show]
|
before_action :load_heading, only: [:index, :show]
|
||||||
before_action :load_map, only: [:index]
|
|
||||||
before_action :set_random_seed, only: :index
|
before_action :set_random_seed, only: :index
|
||||||
before_action :load_categories, only: :index
|
before_action :load_categories, only: :index
|
||||||
before_action :set_default_investment_filter, only: :index
|
before_action :set_default_investment_filter, only: :index
|
||||||
@@ -41,10 +40,9 @@ module Budgets
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@investments = investments.page(params[:page]).per(PER_PAGE).for_render
|
@investments = investments.page(params[:page]).per(PER_PAGE).for_render
|
||||||
|
|
||||||
@investment_ids = @investments.ids
|
@investment_ids = @investments.ids
|
||||||
@investments_map_coordinates = MapLocation.where(investment: investments).map(&:json_data)
|
|
||||||
|
|
||||||
|
@investments_in_map = investments
|
||||||
@tag_cloud = tag_cloud
|
@tag_cloud = tag_cloud
|
||||||
@remote_translations = detect_remote_translations(@investments)
|
@remote_translations = detect_remote_translations(@investments)
|
||||||
end
|
end
|
||||||
@@ -179,9 +177,5 @@ module Budgets
|
|||||||
params[:filter] ||= "selected"
|
params[:filter] ||= "selected"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_map
|
|
||||||
@map_location = MapLocation.from_heading(@heading) if @heading.present?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
<div class="map">
|
|
||||||
<%= render_map(@map_location, investments_coordinates: @investments_map_coordinates) %>
|
|
||||||
</div>
|
|
||||||
@@ -22,10 +22,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= render Budgets::Investments::ContentBlocksComponent.new(@heading) %>
|
<%= render Budgets::Investments::ContentBlocksComponent.new(@heading) %>
|
||||||
|
<%= render Budgets::Investments::MapComponent.new(@investments_in_map, heading: @heading) %>
|
||||||
<% if @map_location&.available? %>
|
|
||||||
<%= render "budgets/investments/map" %>
|
|
||||||
<% end %>
|
|
||||||
<%= render "shared/tag_cloud", taggable: "Budget::Investment" %>
|
<%= render "shared/tag_cloud", taggable: "Budget::Investment" %>
|
||||||
<%= render "budgets/investments/categories" %>
|
<%= render "budgets/investments/categories" %>
|
||||||
<%= render Budgets::Investments::FiltersComponent.new %>
|
<%= render Budgets::Investments::FiltersComponent.new %>
|
||||||
|
|||||||
Reference in New Issue
Block a user