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,
|
:drop_down_list_value,
|
||||||
:piece_justificative_template_filename,
|
:piece_justificative_template_filename,
|
||||||
:piece_justificative_template_url,
|
:piece_justificative_template_url,
|
||||||
:cadastres,
|
:editable_options
|
||||||
:mnhn
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -75,8 +74,18 @@ module NewAdministrateur
|
||||||
:private,
|
:private,
|
||||||
:drop_down_list_value,
|
:drop_down_list_value,
|
||||||
:piece_justificative_template,
|
:piece_justificative_template,
|
||||||
:cadastres,
|
editable_options: [
|
||||||
:mnhn)
|
:cadastres,
|
||||||
|
:unesco,
|
||||||
|
:arretes_protection,
|
||||||
|
:conservatoire_littoral,
|
||||||
|
:reserves_chasse_faune_sauvage,
|
||||||
|
:reserves_biologiques,
|
||||||
|
:reserves_naturelles,
|
||||||
|
:natura_2000,
|
||||||
|
:zones_humides,
|
||||||
|
:znieff
|
||||||
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
def type_de_champ_update_params
|
def type_de_champ_update_params
|
||||||
|
@ -86,8 +95,18 @@ module NewAdministrateur
|
||||||
:mandatory,
|
:mandatory,
|
||||||
:drop_down_list_value,
|
:drop_down_list_value,
|
||||||
:piece_justificative_template,
|
:piece_justificative_template,
|
||||||
:cadastres,
|
editable_options: [
|
||||||
:mnhn)
|
:cadastres,
|
||||||
|
:unesco,
|
||||||
|
:arretes_protection,
|
||||||
|
:conservatoire_littoral,
|
||||||
|
:reserves_chasse_faune_sauvage,
|
||||||
|
:reserves_biologiques,
|
||||||
|
:reserves_naturelles,
|
||||||
|
:natura_2000,
|
||||||
|
:zones_humides,
|
||||||
|
:znieff
|
||||||
|
])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -137,14 +137,13 @@ const TypeDeChamp = sortableElement(
|
||||||
url={typeDeChamp.piece_justificative_template_url}
|
url={typeDeChamp.piece_justificative_template_url}
|
||||||
/>
|
/>
|
||||||
<TypeDeChampCarteOptions isVisible={isCarte}>
|
<TypeDeChampCarteOptions isVisible={isCarte}>
|
||||||
<TypeDeChampCarteOption
|
{Object.entries(OPTIONS_FIELDS).map(([field, label]) => (
|
||||||
label="Cadastres"
|
<TypeDeChampCarteOption
|
||||||
handler={updateHandlers.cadastres}
|
key={field}
|
||||||
/>
|
label={label}
|
||||||
<TypeDeChampCarteOption
|
handler={updateHandlers[field]}
|
||||||
label="Zones naturelles protégées"
|
/>
|
||||||
handler={updateHandlers.mnhn}
|
))}
|
||||||
/>
|
|
||||||
</TypeDeChampCarteOptions>
|
</TypeDeChampCarteOptions>
|
||||||
<TypeDeChampRepetitionOptions
|
<TypeDeChampRepetitionOptions
|
||||||
isVisible={isRepetition}
|
isVisible={isRepetition}
|
||||||
|
@ -182,7 +181,7 @@ function createUpdateHandler(dispatch, typeDeChamp, field, index, prefix) {
|
||||||
return {
|
return {
|
||||||
id: `${prefix ? `${prefix}-` : ''}champ-${index}-${field}`,
|
id: `${prefix ? `${prefix}-` : ''}champ-${index}-${field}`,
|
||||||
name: field,
|
name: field,
|
||||||
value: typeDeChamp[field],
|
value: getValue(typeDeChamp, field),
|
||||||
onChange: ({ target }) =>
|
onChange: ({ target }) =>
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'updateTypeDeChamp',
|
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) {
|
function createUpdateHandlers(dispatch, typeDeChamp, index, prefix) {
|
||||||
return FIELDS.reduce((handlers, field) => {
|
return FIELDS.reduce((handlers, field) => {
|
||||||
handlers[field] = createUpdateHandler(
|
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 = [
|
export const FIELDS = [
|
||||||
'cadastres',
|
|
||||||
'mnhn',
|
|
||||||
'description',
|
'description',
|
||||||
'drop_down_list_value',
|
'drop_down_list_value',
|
||||||
'libelle',
|
'libelle',
|
||||||
'mandatory',
|
'mandatory',
|
||||||
'parcelles_agricoles',
|
|
||||||
'parent_id',
|
'parent_id',
|
||||||
'piece_justificative_template',
|
'piece_justificative_template',
|
||||||
'private',
|
'private',
|
||||||
'quartiers_prioritaires',
|
'type_champ',
|
||||||
'type_champ'
|
...Object.keys(OPTIONS_FIELDS)
|
||||||
];
|
];
|
||||||
|
|
||||||
function readValue(input) {
|
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);
|
getUpdateHandler(typeDeChamp, state)(done);
|
||||||
|
|
||||||
|
|
|
@ -41,15 +41,27 @@ class Champs::CarteChamp < Champ
|
||||||
layer_enabled?(:cadastres)
|
layer_enabled?(:cadastres)
|
||||||
end
|
end
|
||||||
|
|
||||||
def mnhn?
|
def optional_layers
|
||||||
type_de_champ&.mnhn && type_de_champ.mnhn != '0'
|
[
|
||||||
|
: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
|
end
|
||||||
|
|
||||||
def render_options
|
def render_options
|
||||||
{
|
{
|
||||||
ign: Flipper.enabled?(:carte_ign, procedure),
|
ign: Flipper.enabled?(:carte_ign, procedure),
|
||||||
mnhn: mnhn?,
|
layers: optional_layers
|
||||||
cadastres: cadastres?
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ class TypeDeChamp < ApplicationRecord
|
||||||
belongs_to :parent, class_name: 'TypeDeChamp', optional: true
|
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
|
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 :revision_types_de_champ, class_name: 'ProcedureRevisionTypeDeChamp', dependent: :destroy, inverse_of: :type_de_champ
|
||||||
has_many :revisions, through: :revision_types_de_champ
|
has_many :revisions, through: :revision_types_de_champ
|
||||||
|
|
||||||
|
@ -253,6 +253,23 @@ class TypeDeChamp < ApplicationRecord
|
||||||
GraphQL::Schema::UniqueWithinType.encode('Champ', stable_id)
|
GraphQL::Schema::UniqueWithinType.encode('Champ', stable_id)
|
||||||
end
|
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 = {}
|
FEATURE_FLAGS = {}
|
||||||
|
|
||||||
def self.type_de_champ_types_for(procedure, user)
|
def self.type_de_champ_types_for(procedure, user)
|
||||||
|
@ -287,8 +304,7 @@ class TypeDeChamp < ApplicationRecord
|
||||||
:drop_down_list_value,
|
:drop_down_list_value,
|
||||||
:piece_justificative_template_filename,
|
:piece_justificative_template_filename,
|
||||||
:piece_justificative_template_url,
|
:piece_justificative_template_url,
|
||||||
:cadastres,
|
:editable_options
|
||||||
:mnhn
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
TYPES_DE_CHAMP = TYPES_DE_CHAMP_BASE
|
TYPES_DE_CHAMP = TYPES_DE_CHAMP_BASE
|
||||||
|
|
Loading…
Add table
Reference in a new issue