refactor(carto): geo area as component
This commit is contained in:
parent
ded0a41975
commit
f563e210f3
7 changed files with 21 additions and 6 deletions
|
@ -2,7 +2,7 @@
|
|||
- if editing
|
||||
= link_to '#', data: { action: 'geo-area#onClick' } do
|
||||
= geo_area.label
|
||||
= text_field_tag :description, geo_area.description, data: { action: 'focus->geo-area#onFocus input->geo-area#onInput', geo_area_target: 'description' }, placeholder: 'Description', class: 'no-margin'
|
||||
= text_field_tag :description, geo_area.description, data: { action: 'focus->geo-area#onFocus input->geo-area#onInput', geo_area_target: 'description' }, placeholder: 'Description', class: 'no-margin', id: "geo_area_#{geo_area.id}_description"
|
||||
- else
|
||||
= link_to '#', data: { action: 'geo-area#onClick' } do
|
||||
= geo_area.label
|
7
app/components/dossiers/geo_area_component.rb
Normal file
7
app/components/dossiers/geo_area_component.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class Dossiers::GeoAreaComponent < ApplicationComponent
|
||||
attr_reader :geo_area, :editing
|
||||
|
||||
def initialize(geo_area:, editing:)
|
||||
@geo_area, @editing = geo_area, editing
|
||||
end
|
||||
end
|
|
@ -3,7 +3,7 @@
|
|||
.areas
|
||||
%ul
|
||||
- champ.selections_utilisateur.slice(0, 20).each do |geo_area|
|
||||
= render partial: 'shared/champs/carte/geo_area', locals: { geo_area: geo_area, editing: editing }
|
||||
= render Dossiers::GeoAreaComponent.new(geo_area:, editing:)
|
||||
- if champ.selections_utilisateur.size > 20
|
||||
%li
|
||||
%span
|
||||
|
@ -14,4 +14,4 @@
|
|||
.areas
|
||||
%ul
|
||||
- champ.cadastres.each do |geo_area|
|
||||
= render partial: 'shared/champs/carte/geo_area', locals: { geo_area: geo_area, editing: editing }
|
||||
= render Dossiers::GeoAreaComponent.new(geo_area:, editing:)
|
7
app/components/dossiers/geo_areas_component.rb
Normal file
7
app/components/dossiers/geo_areas_component.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class Dossiers::GeoAreasComponent < ApplicationComponent
|
||||
attr_reader :champ, :editing
|
||||
|
||||
def initialize(champ:, editing:)
|
||||
@champ, @editing = champ, editing
|
||||
end
|
||||
end
|
|
@ -8,4 +8,4 @@
|
|||
autocompleteScreenReaderInstructions: t("combo_search_component.screen_reader_instructions"))
|
||||
|
||||
.geo-areas{ id: dom_id(@champ, :geo_areas) }
|
||||
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: @champ, editing: true }
|
||||
= render Dossiers::GeoAreasComponent.new(champ: @champ, editing: true)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
= turbo_stream.update dom_id(@champ, :geo_areas), partial: 'shared/champs/carte/geo_areas', locals: { champ: @champ, editing: true }
|
||||
= turbo_stream.update dom_id(@champ, :geo_areas) do
|
||||
= render Dossiers::GeoAreasComponent.new(champ: @champ, editing: true)
|
||||
|
||||
- if @focus
|
||||
= turbo_stream.dispatch 'map:feature:focus', bbox: @champ.bounding_box
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
- if champ.geometry?
|
||||
= react_component("MapReader", { featureCollection: champ.to_feature_collection, options: champ.render_options } )
|
||||
.geo-areas
|
||||
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: false }
|
||||
= render Dossiers::GeoAreasComponent.new(champ:, editing: false)
|
||||
|
|
Loading…
Reference in a new issue