diff --git a/app/controllers/new_administrateur/types_de_champ_controller.rb b/app/controllers/new_administrateur/types_de_champ_controller.rb index 2f31b0118..160110985 100644 --- a/app/controllers/new_administrateur/types_de_champ_controller.rb +++ b/app/controllers/new_administrateur/types_de_champ_controller.rb @@ -59,8 +59,7 @@ module NewAdministrateur :drop_down_list_value, :piece_justificative_template_filename, :piece_justificative_template_url, - :cadastres, - :mnhn + :editable_options ] ) } @@ -75,8 +74,18 @@ module NewAdministrateur :private, :drop_down_list_value, :piece_justificative_template, - :cadastres, - :mnhn) + editable_options: [ + :cadastres, + :unesco, + :arretes_protection, + :conservatoire_littoral, + :reserves_chasse_faune_sauvage, + :reserves_biologiques, + :reserves_naturelles, + :natura_2000, + :zones_humides, + :znieff + ]) end def type_de_champ_update_params @@ -86,8 +95,18 @@ module NewAdministrateur :mandatory, :drop_down_list_value, :piece_justificative_template, - :cadastres, - :mnhn) + editable_options: [ + :cadastres, + :unesco, + :arretes_protection, + :conservatoire_littoral, + :reserves_chasse_faune_sauvage, + :reserves_biologiques, + :reserves_naturelles, + :natura_2000, + :zones_humides, + :znieff + ]) end end end diff --git a/app/javascript/components/TypesDeChampEditor/components/TypeDeChamp.js b/app/javascript/components/TypesDeChampEditor/components/TypeDeChamp.js index 98ad6af76..6dca0c980 100644 --- a/app/javascript/components/TypesDeChampEditor/components/TypeDeChamp.js +++ b/app/javascript/components/TypesDeChampEditor/components/TypeDeChamp.js @@ -137,14 +137,13 @@ const TypeDeChamp = sortableElement( url={typeDeChamp.piece_justificative_template_url} /> - - + {Object.entries(OPTIONS_FIELDS).map(([field, label]) => ( + + ))} dispatch({ type: 'updateTypeDeChamp', @@ -196,6 +195,14 @@ function createUpdateHandler(dispatch, typeDeChamp, field, index, prefix) { }; } +function getValue(obj, path) { + const [, optionsPath] = path.split('.'); + if (optionsPath) { + return (obj.editable_options || {})[optionsPath]; + } + return obj[path]; +} + function createUpdateHandlers(dispatch, typeDeChamp, index, prefix) { return FIELDS.reduce((handlers, field) => { handlers[field] = createUpdateHandler( @@ -209,19 +216,30 @@ function createUpdateHandlers(dispatch, typeDeChamp, index, prefix) { }, {}); } +const OPTIONS_FIELDS = { + 'options.cadastres': 'Cadastres', + 'options.unesco': 'UNESCO', + 'options.arretes_protection': 'Arrêtés de protection', + 'options.conservatoire_littoral': 'Conservatoire du Littoral', + 'options.reserves_chasse_faune_sauvage': + 'Réserves nationales de chasse et de faune sauvage', + 'options.reserves_biologiques': 'Réserves biologiques', + 'options.reserves_naturelles': 'Réserves naturelles', + 'options.natura_2000': 'Natura 2000', + 'options.zones_humides': 'Zones humides d’importance internationale', + 'options.znieff': 'ZNIEFF' +}; + export const FIELDS = [ - 'cadastres', - 'mnhn', 'description', 'drop_down_list_value', 'libelle', 'mandatory', - 'parcelles_agricoles', 'parent_id', 'piece_justificative_template', 'private', - 'quartiers_prioritaires', - 'type_champ' + 'type_champ', + ...Object.keys(OPTIONS_FIELDS) ]; function readValue(input) { diff --git a/app/javascript/components/TypesDeChampEditor/typeDeChampsReducer.js b/app/javascript/components/TypesDeChampEditor/typeDeChampsReducer.js index 35eb2d83a..c59ef2a1c 100644 --- a/app/javascript/components/TypesDeChampEditor/typeDeChampsReducer.js +++ b/app/javascript/components/TypesDeChampEditor/typeDeChampsReducer.js @@ -113,7 +113,13 @@ function updateTypeDeChamp( } } - typeDeChamp[field] = value; + if (field.startsWith('options.')) { + const [, optionsField] = field.split('.'); + typeDeChamp.editable_options = typeDeChamp.editable_options || {}; + typeDeChamp.editable_options[optionsField] = value; + } else { + typeDeChamp[field] = value; + } getUpdateHandler(typeDeChamp, state)(done); diff --git a/app/models/champs/carte_champ.rb b/app/models/champs/carte_champ.rb index d4cccbe48..d0c31ab36 100644 --- a/app/models/champs/carte_champ.rb +++ b/app/models/champs/carte_champ.rb @@ -41,15 +41,27 @@ class Champs::CarteChamp < Champ layer_enabled?(:cadastres) end - def mnhn? - type_de_champ&.mnhn && type_de_champ.mnhn != '0' + def optional_layers + [ + :unesco, + :arretes_protection, + :conservatoire_littoral, + :reserves_chasse_faune_sauvage, + :reserves_biologiques, + :reserves_naturelles, + :natura_2000, + :zones_humides, + :znieff, + :cadastres + ].map do |layer| + layer_enabled?(layer) ? layer : nil + end.compact end def render_options { ign: Flipper.enabled?(:carte_ign, procedure), - mnhn: mnhn?, - cadastres: cadastres? + layers: optional_layers } end diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 3a8e88f14..277541217 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -56,7 +56,7 @@ class TypeDeChamp < ApplicationRecord belongs_to :parent, class_name: 'TypeDeChamp', optional: true has_many :types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'TypeDeChamp', inverse_of: :parent, dependent: :destroy - store_accessor :options, :cadastres, :mnhn, :old_pj, :drop_down_options, :skip_pj_validation + store_accessor :options, :cadastres, :old_pj, :drop_down_options, :skip_pj_validation has_many :revision_types_de_champ, class_name: 'ProcedureRevisionTypeDeChamp', dependent: :destroy, inverse_of: :type_de_champ has_many :revisions, through: :revision_types_de_champ @@ -253,6 +253,23 @@ class TypeDeChamp < ApplicationRecord GraphQL::Schema::UniqueWithinType.encode('Champ', stable_id) end + def editable_options=(options) + self.options.merge!(options) + end + + def editable_options + options.slice(:cadastres, + :unesco, + :arretes_protection, + :conservatoire_littoral, + :reserves_chasse_faune_sauvage, + :reserves_biologiques, + :reserves_naturelles, + :natura_2000, + :zones_humides, + :znieff) + end + FEATURE_FLAGS = {} def self.type_de_champ_types_for(procedure, user) @@ -287,8 +304,7 @@ class TypeDeChamp < ApplicationRecord :drop_down_list_value, :piece_justificative_template_filename, :piece_justificative_template_url, - :cadastres, - :mnhn + :editable_options ] } TYPES_DE_CHAMP = TYPES_DE_CHAMP_BASE