Handle carte layers changes

This commit is contained in:
Paul Chavard 2021-06-23 15:54:12 +02:00
parent c0f6909266
commit 8b2c2c6466
7 changed files with 109 additions and 30 deletions

View file

@ -36,29 +36,12 @@ class Champs::CarteChamp < Champ
end
end
def layer_enabled?(layer)
type_de_champ.options && type_de_champ.options[layer] && type_de_champ.options[layer] != '0'
end
def cadastres?
layer_enabled?(:cadastres)
type_de_champ.layer_enabled?(:cadastres)
end
def optional_layers
[
:unesco,
:arretes_protection,
:conservatoire_littoral,
:reserves_chasse_faune_sauvage,
:reserves_biologiques,
:reserves_naturelles,
:natura_2000,
:zones_humides,
:znieff,
:cadastres
].filter_map do |layer|
layer_enabled?(layer) ? layer : nil
end
type_de_champ.carte_optional_layers
end
def render_options

View file

@ -207,6 +207,17 @@ class ProcedureRevision < ApplicationRecord
to: to_type_de_champ.drop_down_list_options
}
end
elsif to_type_de_champ.carte?
if from_type_de_champ.carte_optional_layers != to_type_de_champ.carte_optional_layers
changes << {
op: :update,
attribute: :carte_layers,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.carte_optional_layers,
to: to_type_de_champ.carte_optional_layers
}
end
elsif to_type_de_champ.piece_justificative?
if from_type_de_champ.piece_justificative_template_checksum != to_type_de_champ.piece_justificative_template_checksum
changes << {

View file

@ -206,6 +206,10 @@ class TypeDeChamp < ApplicationRecord
type_champ == TypeDeChamp.type_champs.fetch(:titre_identite)
end
def carte?
type_champ == TypeDeChamp.type_champs.fetch(:carte)
end
def public?
!private?
end
@ -260,6 +264,16 @@ class TypeDeChamp < ApplicationRecord
(drop_down_list_options - drop_down_list_disabled_options).reject(&:empty?)
end
def layer_enabled?(layer)
options && options[layer] && options[layer] != '0'
end
def carte_optional_layers
TypesDeChamp::CarteTypeDeChamp::LAYERS.filter_map do |layer|
layer_enabled?(layer) ? layer : nil
end.sort
end
def to_typed_id
GraphQL::Schema::UniqueWithinType.encode('Champ', stable_id)
end
@ -269,16 +283,7 @@ class TypeDeChamp < ApplicationRecord
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)
options.slice(*TypesDeChamp::CarteTypeDeChamp::LAYERS)
end
FEATURE_FLAGS = {}

View file

@ -1,2 +1,14 @@
class TypesDeChamp::CarteTypeDeChamp < TypesDeChamp::TypeDeChampBase
LAYERS = [
:unesco,
:arretes_protection,
:conservatoire_littoral,
:reserves_chasse_faune_sauvage,
:reserves_biologiques,
:reserves_naturelles,
:natura_2000,
:zones_humides,
:znieff,
:cadastres
]
end

View file

@ -24,12 +24,22 @@
- added = change[:to].sort - change[:from].sort
- removed = change[:from].sort - change[:to].sort
%li.mb-1
= "Les options de sélection du champ « #{change[:label]} » ont changé."
= "Les options de sélection du champ « #{change[:label]} » ont changé :"
%ul
- if added.present?
%li= "Valeurs ajoutés : #{added.map{ |term| "« #{term.strip} »" }.join(", ")}."
- if removed.present?
%li= "Valeurs supprimés : #{removed.map{ |term| "« #{term.strip} »" }.join(", ")}."
- when :carte_layers
- added = change[:to].sort - change[:from].sort
- removed = change[:from].sort - change[:to].sort
%li.mb-1
= "Les référentiels cartographiques du champ « #{change[:label]} » ont changé :"
%ul
- if added.present?
%li= "Référentiels ajoutés : #{added.map{ |term| "« #{t(term, scope: [:new_administrateur, :carte_layers])} »" }.join(", ")}."
- if removed.present?
%li= "Référentiels supprimés : #{removed.map{ |term| "« #{t(term, scope: [:new_administrateur, :carte_layers])} »" }.join(", ")}."
- move_changes = changes.filter { |change| change[:op] == :move }.size
- if move_changes != 0
%li.mb-1= t(:has_move_changes, count: move_changes, scope: [:new_administrateur, :revision_changes])

View file

@ -37,3 +37,14 @@ fr:
has_move_changes:
one: Un champ a changé de position
other: "%{count} champs ont changé de position"
carte_layers:
unesco: UNESCO
arretes_protection: Arrêtés de protection
conservatoire_littoral: Conservatoire du Littoral
reserves_chasse_faune_sauvage: Réserves nationales de chasse et de faune sauvage
reserves_biologiques: Réserves biologiques
reserves_naturelles: Réserves naturelles
natura_2000: Natura 2000
zones_humides: Zones humides dimportance internationale
znieff: ZNIEFF
cadastres: Cadastre

View file

@ -312,6 +312,53 @@ describe ProcedureRevision do
to: ["one", "two"]
}
])
new_revision.find_or_clone_type_de_champ(new_revision.types_de_champ.last.types_de_champ.first.stable_id).update(type_champ: :carte)
new_revision.find_or_clone_type_de_champ(new_revision.types_de_champ.last.types_de_champ.first.stable_id).update(options: { cadastres: true, znieff: true })
expect(procedure.active_revision.compare(new_revision.reload)).to eq([
{
op: :remove,
label: type_de_champ_first.libelle,
private: false
},
{
op: :add,
label: "Un champ text",
private: false
},
{
op: :update,
attribute: :description,
label: type_de_champ_second.libelle,
private: false,
from: type_de_champ_second.description,
to: "une description"
},
{
op: :update,
attribute: :mandatory,
label: type_de_champ_second.libelle,
private: false,
from: false,
to: true
},
{
op: :update,
attribute: :type_champ,
label: "sub type de champ",
private: false,
from: "text",
to: "carte"
},
{
op: :update,
attribute: :carte_layers,
label: "sub type de champ",
private: false,
from: [],
to: [:cadastres, :znieff]
}
])
end
end
end