Merge pull request #6230 from tchak/cadastres-descriptions

Enable add descriptions to cadastres
This commit is contained in:
Paul Chavard 2021-05-26 12:00:42 +02:00 committed by GitHub
commit a1b48fa1df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 26 deletions

View file

@ -10,12 +10,12 @@ class Champs::CarteController < ApplicationController
def create
champ = policy_scope(Champ).find(params[:champ_id])
geo_area = if params_source == GeoArea.sources.fetch(:cadastre)
champ.geo_areas.find_by("properties->>'id' = :id", id: params_feature[:properties][:id])
champ.geo_areas.find_by("properties->>'id' = :id", id: create_params_feature[:properties][:id])
end
if geo_area.nil?
geo_area = champ.geo_areas.build(source: params_source, properties: {})
save_feature!(geo_area, params_feature)
save_feature!(geo_area, create_params_feature)
end
render json: { feature: geo_area.to_feature }, status: :created
@ -24,7 +24,7 @@ class Champs::CarteController < ApplicationController
def update
champ = policy_scope(Champ).find(params[:champ_id])
geo_area = champ.geo_areas.find(params[:id])
save_feature!(geo_area, params_feature)
save_feature!(geo_area, update_params_feature)
head :no_content
end
@ -42,7 +42,7 @@ class Champs::CarteController < ApplicationController
params[:source]
end
def params_feature
def create_params_feature
params.require(:feature).permit(properties: [
:filename,
:description,
@ -60,6 +60,12 @@ class Champs::CarteController < ApplicationController
end
end
def update_params_feature
params.require(:feature).permit(properties: [:description]).tap do |feature|
feature[:geometry] = params[:feature][:geometry]
end
end
def save_feature!(geo_area, feature)
if feature[:geometry]
geo_area.geometry = feature[:geometry]

View file

@ -25,7 +25,7 @@ class Champ < ApplicationRecord
# We declare champ specific relationships (Champs::CarteChamp, Champs::SiretChamp and Champs::RepetitionChamp)
# here because otherwise we can't easily use includes in our queries.
has_many :geo_areas, dependent: :destroy
has_many :geo_areas, -> { order(:created_at) }, dependent: :destroy, inverse_of: :champ
belongs_to :etablissement, optional: true, dependent: :destroy
has_many :champs, -> { ordered }, foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy

View file

@ -0,0 +1,11 @@
%li{ class: editing ? '' : 'flex column mb-2' }
- if editing
= link_to '#', data: { geo_area: geo_area.id } do
= geo_area_label(geo_area)
= text_field_tag :description, geo_area.description, data: { geo_area: geo_area.id }, placeholder: 'Description', class: 'no-margin'
- else
= link_to '#', data: { geo_area: geo_area.id } do
= geo_area_label(geo_area)
- if geo_area.description.present?
%span
= geo_area.description

View file

@ -3,28 +3,11 @@
.areas
%ul
- champ.selections_utilisateur.each do |geo_area|
%li{ class: editing ? '' : 'flex column mb-2' }
- if editing
= link_to '#', data: { geo_area: geo_area.id } do
= geo_area_label(geo_area)
= text_field_tag :description, geo_area.description, data: { geo_area: geo_area.id }, placeholder: 'Description de la sélection', class: 'no-margin'
- else
= link_to '#', data: { geo_area: geo_area.id } do
= geo_area_label(geo_area)
- if geo_area.description.present?
%span
= geo_area.description
= render partial: 'shared/champs/carte/geo_area', locals: { geo_area: geo_area, editing: editing }
- if champ.cadastres?
.areas-title Parcelles cadastrales
.areas
- if !champ.geometry?
Aucune zone tracée
- elsif champ.cadastres.blank?
= t('errors.messages.cadastres_empty', count: champ.selections_utilisateur.size)
- else
%ul
- champ.cadastres.each do |geo_area|
%li.flex.column.mb-2
= link_to '#', data: { geo_area: geo_area.id } do
= geo_area_label(geo_area)
= render partial: 'shared/champs/carte/geo_area', locals: { geo_area: geo_area, editing: editing }