Expose all optional layers in TypeDeChamp editor
This commit is contained in:
parent
cad8ee31d8
commit
eaa9b1c071
5 changed files with 99 additions and 28 deletions
|
@ -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
|
||||
|
|
|
@ -137,14 +137,13 @@ const TypeDeChamp = sortableElement(
|
|||
url={typeDeChamp.piece_justificative_template_url}
|
||||
/>
|
||||
<TypeDeChampCarteOptions isVisible={isCarte}>
|
||||
<TypeDeChampCarteOption
|
||||
label="Cadastres"
|
||||
handler={updateHandlers.cadastres}
|
||||
/>
|
||||
<TypeDeChampCarteOption
|
||||
label="Zones naturelles protégées"
|
||||
handler={updateHandlers.mnhn}
|
||||
/>
|
||||
{Object.entries(OPTIONS_FIELDS).map(([field, label]) => (
|
||||
<TypeDeChampCarteOption
|
||||
key={field}
|
||||
label={label}
|
||||
handler={updateHandlers[field]}
|
||||
/>
|
||||
))}
|
||||
</TypeDeChampCarteOptions>
|
||||
<TypeDeChampRepetitionOptions
|
||||
isVisible={isRepetition}
|
||||
|
@ -182,7 +181,7 @@ function createUpdateHandler(dispatch, typeDeChamp, field, index, prefix) {
|
|||
return {
|
||||
id: `${prefix ? `${prefix}-` : ''}champ-${index}-${field}`,
|
||||
name: field,
|
||||
value: typeDeChamp[field],
|
||||
value: getValue(typeDeChamp, field),
|
||||
onChange: ({ target }) =>
|
||||
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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue