Class: Avo::Index::ResourceMapComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Avo::Index::ResourceMapComponent
- Defined in:
- app/components/avo/index/resource_map_component.rb
Overview
Render a map view for a list of resources, where each resource is expected to have an attribute/attribute set representing its location.
Instance Attribute Summary collapse
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #grid_layout_classes ⇒ Object
-
#initialize(resources: nil, resource: nil, reflection: nil, parent_record: nil, parent_resource: nil, pagy: nil, query: nil) ⇒ ResourceMapComponent
constructor
A new instance of ResourceMapComponent.
- #map_component_order_class ⇒ Object
- #map_view_table_layout ⇒ Object
- #render_table? ⇒ Boolean
- #resource_location_markers ⇒ Object
- #resource_mapkick_options ⇒ Object
- #table_component_order_class ⇒ Object
- #table_positioned_at_the_start ⇒ Object
- #table_positioned_horizontally ⇒ Object
- #table_positioned_vertically ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(resources: nil, resource: nil, reflection: nil, parent_record: nil, parent_resource: nil, pagy: nil, query: nil) ⇒ ResourceMapComponent
Returns a new instance of ResourceMapComponent.
10 11 12 13 14 15 16 17 18 19 |
# File 'app/components/avo/index/resource_map_component.rb', line 10 def initialize(resources: nil, resource: nil, reflection: nil, parent_record: nil, parent_resource: nil, pagy: nil, query: nil) super @resources = resources @resource = resource @reflection = reflection @parent_record = parent_record @parent_resource = parent_resource @pagy = pagy @query = query end |
Instance Attribute Details
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
8 9 10 |
# File 'app/components/avo/index/resource_map_component.rb', line 8 def resources @resources end |
Instance Method Details
#grid_layout_classes ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'app/components/avo/index/resource_map_component.rb', line 21 def grid_layout_classes return unless render_table? if table_positioned_horizontally "grid-flow-row sm:grid-flow-col grid-rows-1 auto-cols-fr" elsif table_positioned_vertically "grid-flow-row grid-cols-1" end end |
#map_component_order_class ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/components/avo/index/resource_map_component.rb', line 39 def map_component_order_class if render_table? && table_positioned_at_the_start "order-last" else "order-first" end end |
#map_view_table_layout ⇒ Object
59 60 61 |
# File 'app/components/avo/index/resource_map_component.rb', line 59 def map_view_table_layout .dig(:table, :layout) end |
#render_table? ⇒ Boolean
81 82 83 |
# File 'app/components/avo/index/resource_map_component.rb', line 81 def render_table? .dig(:table, :visible) end |
#resource_location_markers ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/components/avo/index/resource_map_component.rb', line 63 def resource_location_markers # If we have no proc and no default location method, don't try to create markers return [] unless resource_mappable? resources .map do |resource| Avo::ExecutionContext.new(target: marker_proc, record: resource.record).handle end .compact .filter do |coordinates| coordinates[:latitude].present? && coordinates[:longitude].present? end end |
#resource_mapkick_options ⇒ Object
77 78 79 |
# File 'app/components/avo/index/resource_map_component.rb', line 77 def [:mapkick_options] || {} end |
#table_component_order_class ⇒ Object
47 48 49 50 51 52 53 |
# File 'app/components/avo/index/resource_map_component.rb', line 47 def table_component_order_class if table_positioned_at_the_start "order-first" else "order-last" end end |
#table_positioned_at_the_start ⇒ Object
55 56 57 |
# File 'app/components/avo/index/resource_map_component.rb', line 55 def table_positioned_at_the_start %i[left top].include?(map_view_table_layout) end |
#table_positioned_horizontally ⇒ Object
31 32 33 |
# File 'app/components/avo/index/resource_map_component.rb', line 31 def table_positioned_horizontally %i[left right].include?(map_view_table_layout) end |
#table_positioned_vertically ⇒ Object
35 36 37 |
# File 'app/components/avo/index/resource_map_component.rb', line 35 def table_positioned_vertically %i[bottom top].include?(map_view_table_layout) end |