Merge pull request #6230 from tchak/cadastres-descriptions
Enable add descriptions to cadastres
This commit is contained in:
commit
a1b48fa1df
4 changed files with 26 additions and 26 deletions
|
@ -10,12 +10,12 @@ class Champs::CarteController < ApplicationController
|
||||||
def create
|
def create
|
||||||
champ = policy_scope(Champ).find(params[:champ_id])
|
champ = policy_scope(Champ).find(params[:champ_id])
|
||||||
geo_area = if params_source == GeoArea.sources.fetch(:cadastre)
|
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
|
end
|
||||||
|
|
||||||
if geo_area.nil?
|
if geo_area.nil?
|
||||||
geo_area = champ.geo_areas.build(source: params_source, properties: {})
|
geo_area = champ.geo_areas.build(source: params_source, properties: {})
|
||||||
save_feature!(geo_area, params_feature)
|
save_feature!(geo_area, create_params_feature)
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: { feature: geo_area.to_feature }, status: :created
|
render json: { feature: geo_area.to_feature }, status: :created
|
||||||
|
@ -24,7 +24,7 @@ class Champs::CarteController < ApplicationController
|
||||||
def update
|
def update
|
||||||
champ = policy_scope(Champ).find(params[:champ_id])
|
champ = policy_scope(Champ).find(params[:champ_id])
|
||||||
geo_area = champ.geo_areas.find(params[: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
|
head :no_content
|
||||||
end
|
end
|
||||||
|
@ -42,7 +42,7 @@ class Champs::CarteController < ApplicationController
|
||||||
params[:source]
|
params[:source]
|
||||||
end
|
end
|
||||||
|
|
||||||
def params_feature
|
def create_params_feature
|
||||||
params.require(:feature).permit(properties: [
|
params.require(:feature).permit(properties: [
|
||||||
:filename,
|
:filename,
|
||||||
:description,
|
:description,
|
||||||
|
@ -60,6 +60,12 @@ class Champs::CarteController < ApplicationController
|
||||||
end
|
end
|
||||||
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)
|
def save_feature!(geo_area, feature)
|
||||||
if feature[:geometry]
|
if feature[:geometry]
|
||||||
geo_area.geometry = feature[:geometry]
|
geo_area.geometry = feature[:geometry]
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Champ < ApplicationRecord
|
||||||
|
|
||||||
# We declare champ specific relationships (Champs::CarteChamp, Champs::SiretChamp and Champs::RepetitionChamp)
|
# We declare champ specific relationships (Champs::CarteChamp, Champs::SiretChamp and Champs::RepetitionChamp)
|
||||||
# here because otherwise we can't easily use includes in our queries.
|
# 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
|
belongs_to :etablissement, optional: true, dependent: :destroy
|
||||||
has_many :champs, -> { ordered }, foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy
|
has_many :champs, -> { ordered }, foreign_key: :parent_id, inverse_of: :parent, dependent: :destroy
|
||||||
|
|
||||||
|
|
11
app/views/shared/champs/carte/_geo_area.html.haml
Normal file
11
app/views/shared/champs/carte/_geo_area.html.haml
Normal 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
|
|
@ -3,28 +3,11 @@
|
||||||
.areas
|
.areas
|
||||||
%ul
|
%ul
|
||||||
- champ.selections_utilisateur.each do |geo_area|
|
- champ.selections_utilisateur.each do |geo_area|
|
||||||
%li{ class: editing ? '' : 'flex column mb-2' }
|
= render partial: 'shared/champs/carte/geo_area', locals: { geo_area: geo_area, editing: editing }
|
||||||
- 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
|
|
||||||
|
|
||||||
- if champ.cadastres?
|
- if champ.cadastres?
|
||||||
.areas-title Parcelles cadastrales
|
.areas-title Parcelles cadastrales
|
||||||
.areas
|
.areas
|
||||||
- if !champ.geometry?
|
|
||||||
Aucune zone tracée
|
|
||||||
- elsif champ.cadastres.blank?
|
|
||||||
= t('errors.messages.cadastres_empty', count: champ.selections_utilisateur.size)
|
|
||||||
- else
|
|
||||||
%ul
|
%ul
|
||||||
- champ.cadastres.each do |geo_area|
|
- champ.cadastres.each do |geo_area|
|
||||||
%li.flex.column.mb-2
|
= render partial: 'shared/champs/carte/geo_area', locals: { geo_area: geo_area, editing: editing }
|
||||||
= link_to '#', data: { geo_area: geo_area.id } do
|
|
||||||
= geo_area_label(geo_area)
|
|
||||||
|
|
Loading…
Reference in a new issue