Merge pull request #6296 from tchak/improuve-revision-changes

Improve procedure revisions
This commit is contained in:
Paul Chavard 2021-06-24 11:50:59 +02:00 committed by GitHub
commit 9fa3e63cd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 191 additions and 94 deletions

View file

@ -109,3 +109,15 @@
}
}
}
ul.revision-changes {
list-style: none;
ul {
list-style: none;
li {
padding-top: 0.25 * $default-padding;
}
}
}

View file

@ -44,7 +44,7 @@ module NewAdministrateur
end
def apercu
@dossier = procedure_without_control.new_dossier
@dossier = procedure_without_control.draft_revision.new_dossier
@tab = apercu_tab
end

View file

@ -81,7 +81,7 @@ module Users
end
def generate_empty_pdf(procedure)
@dossier = procedure.new_dossier
@dossier = procedure.active_revision.new_dossier
s = render_to_string(template: 'dossiers/dossier_vide', formats: [:pdf])
send_data(s, :filename => "#{procedure.libelle}.pdf")
end

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

@ -361,21 +361,13 @@ class Procedure < ApplicationRecord
end
def draft_changed?
publiee? && published_revision.changed?(draft_revision)
publiee? && published_revision.changed?(draft_revision) && revision_changes.present?
end
def revision_changes
published_revision.compare(draft_revision)
end
def revision_types_de_champ_private_changes
revision_changes.filter { |change| change[:private] }
end
def revision_types_de_champ_changes
revision_changes.filter { |change| !change[:private] }
end
def accepts_new_dossiers?
publiee? || brouillon?
end
@ -406,17 +398,6 @@ class Procedure < ApplicationRecord
Flipper.enabled?(feature, self)
end
# Warning: dossier after_save build_default_champs must be removed
# to save a dossier created from this method
def new_dossier
Dossier.new(
revision: active_revision,
champs: active_revision.build_champs,
champs_private: active_revision.build_champs_private,
groupe_instructeur: defaut_groupe_instructeur
)
end
def path_customized?
!path.match?(/[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}/)
end

View file

@ -112,6 +112,15 @@ class ProcedureRevision < ApplicationRecord
changes
end
def new_dossier
Dossier.new(
revision: self,
champs: build_champs,
champs_private: build_champs_private,
groupe_instructeur: procedure.defaut_groupe_instructeur
)
end
private
def compare_types_de_champ(from_tdc, to_tdc)
@ -207,6 +216,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

@ -2,7 +2,7 @@
%h2.card-title Publiez votre démarche
= form_tag admin_procedure_publish_path(procedure_id: procedure.id), method: :put, class: 'form' do
- if procedure.draft_changed?
%p.mb-4 Publiez une nouvelle version de votre démarche. Les changements suivants seront appliqués :
%p.mb-4 Publiez une nouvelle version de votre démarche. Les modifications suivantes seront appliquées :
= render partial: 'revision_changes', locals: { changes: procedure.revision_changes }
- else
%p.mb-4 Publiez votre démarche, et partagez la à vos usagers. Aucune modification ne sera possible.

View file

@ -1,35 +1,48 @@
%ul
%ul.revision-changes
- changes.each do |change|
- postfix = change[:private] ? '_private' : ''
- case change[:op]
- when :add
%li.mb-1= "Le champ « #{change[:label]} » a été ajouté."
%li.mb-1= t("add#{postfix}", label: change[:label], scope: [:new_administrateur, :revision_changes])
- when :remove
%li.mb-1= "Le champ « #{change[:label]} » a été supprimé."
%li.mb-1= t("remove#{postfix}", label: change[:label], scope: [:new_administrateur, :revision_changes])
- when :update
- case change[:attribute]
- when :libelle
%li.mb-1= "Le libellé du champ « #{change[:label]} » a changé en « #{change[:to]} »."
%li.mb-1= t("update_libelle#{postfix}", label: change[:label], to: change[:to], scope: [:new_administrateur, :revision_changes])
- when :type_champ
%li.mb-1= "Le type du champ « #{change[:label]} » a changé. Il est maintenant de type « #{t("activerecord.attributes.type_de_champ.type_champs.#{change[:to]}")} »."
%li.mb-1= t("update_type_champ#{postfix}", label: change[:label], to: t("activerecord.attributes.type_de_champ.type_champs.#{change[:to]}"), scope: [:new_administrateur, :revision_changes])
- when :description
%li.mb-1= "La description du champ « #{change[:label]} » a changé. La nouvelle description est « #{change[:to]} »."
%li.mb-1= t("update_description#{postfix}", label: change[:label], to: change[:to], scope: [:new_administrateur, :revision_changes])
- when :mandatory
- if change[:from] == false
%li.mb-1= "Le champ « #{change[:label]} » est maintenant obligatoire."
%li.mb-1= t(:enabled, label: change[:label], scope: [:new_administrateur, :revision_changes, "update_mandatory#{postfix}"])
- else
%li.mb-1= "Le champ « #{change[:label]} » n'est plus obligatoire."
%li.mb-1= t(:disabled, label: change[:label], scope: [:new_administrateur, :revision_changes, "update_mandatory#{postfix}"])
- when :piece_justificative_template
%li.mb-1= "Le champ « #{change[:label]} » a changé de modèle de pièce justificative."
%li.mb-1= t("update_piece_justificative_template#{postfix}", label: change[:label], scope: [:new_administrateur, :revision_changes])
- when :drop_down_options
- 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é."
= t("update_drop_down_options#{postfix}", label: change[:label], scope: [:new_administrateur, :revision_changes])
%ul
- if added.present?
%li= "Valeurs ajoutés : #{added.map{ |term| "« #{term.strip} »" }.join(", ")}."
%li= t(:add_option, items: added.map{ |term| "« #{term.strip} »" }.join(", "), scope: [:new_administrateur, :revision_changes])
- if removed.present?
%li= "Valeurs supprimés : #{removed.map{ |term| "« #{term.strip} »" }.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])
%li= t(:remove_option, items: removed.map{ |term| "« #{term.strip} »" }.join(", "), scope: [:new_administrateur, :revision_changes])
- when :carte_layers
- added = change[:to].sort - change[:from].sort
- removed = change[:from].sort - change[:to].sort
%li.mb-1
= t("update_carte_layers#{postfix}", label: change[:label], scope: [:new_administrateur, :revision_changes])
%ul
- if added.present?
%li= t(:add_option, items: added.map{ |term| "« #{t(term, scope: [:new_administrateur, :carte_layers])} »" }.join(", "), scope: [:new_administrateur, :revision_changes])
- if removed.present?
%li= t(:remove_option, items: removed.map{ |term| "« #{t(term, scope: [:new_administrateur, :carte_layers])} »" }.join(", "), scope: [:new_administrateur, :revision_changes])
- move_changes, move_private_changes = changes.filter { |change| change[:op] == :move }.partition { |change| !change[:private] }
- if move_changes.size != 0
%li.mb-1= t(:move, count: move_changes.size, scope: [:new_administrateur, :revision_changes])
- if move_private_changes.size != 0
%li.mb-1= t(:move_private, count: move_private_changes.size, scope: [:new_administrateur, :revision_changes])

View file

@ -33,22 +33,11 @@
= link_to 'Publier les modifications', admin_procedure_publication_path(@procedure), class: 'button primary', id: 'publish-procedure-link', data: { disable_with: "Publication..." }
- if @procedure.draft_changed?
- types_de_champ_changes = @procedure.revision_types_de_champ_changes
- types_de_champ_private_changes = @procedure.revision_types_de_champ_private_changes
- if types_de_champ_changes.present?
.container
.card.featured
.card-title
= t(:has_changes, count: types_de_champ_changes.size, scope: [:new_administrateur, :revision_changes])
= render partial: 'revision_changes', locals: { changes: types_de_champ_changes }
- if types_de_champ_private_changes.present?
.container
.card.featured
.card-title
= t(:has_private_changes, count: types_de_champ_private_changes.size, scope: [:new_administrateur, :revision_changes])
= render partial: 'revision_changes', locals: { changes: types_de_champ_private_changes }
.container
.card.featured
.card-title
= t(:has_changes, scope: [:new_administrateur, :revision_changes])
= render partial: 'revision_changes', locals: { changes: @procedure.revision_changes }
.container
%h2.procedure-admin-explanation Indispensable avant publication

View file

@ -27,13 +27,3 @@ fr:
existing_groupe:
one: "%{count} groupe existe"
other: "%{count} groupes existent"
revision_changes:
has_changes:
one: Un champ a été changé
other: "%{count} champs ont été changés"
has_private_changes:
one: Une annotation privée a été changée
other: "%{count} deux annotations privées ont été changées"
has_move_changes:
one: Un champ a changé de position
other: "%{count} champs ont changé de position"

View file

@ -0,0 +1,45 @@
fr:
new_administrateur:
revision_changes:
has_changes: Modifications en cours (appliqué à la prochaine publication)
add: Le champ « %{label} » a été ajouté
remove: Le champ « %{label} » a été supprimé
move:
one: La position dun champ a été modifiée
other: Les positions de %{count} champs ont été modifiées
update_libelle: Le libellé du champ « %{label} » a été modifié. Le nouveau libellé est « %{to} »
update_description: La description du champ « %{label} » a été modifiée. La nouvelle description est « %{to} »
update_type_champ: Le type du champ « %{label} » a été modifié. Il est maintenant de type « %{to} »
update_mandatory:
enable: Le champ « %{label} » est maintenant obligatoire
disable: Le champ « %{label} » nest plus obligatoire
update_piece_justificative_template: Le modèle de pièce justificative du champ « %{label} » a été modifié
update_drop_down_options: Les options de sélection du champ « %{label} » ont été modifiées
update_carte_layers: Les référentiels cartographiques du champ « %{label} » ont été modifiés
add_private: Lannotation privée « %{label} » a été ajoutée
remove_private: Lannotation privée « %{label} » a été supprimée
move_private:
one: La position dune annotation privée a été modifiée
other: Les positions de %{count} annotations privées ont été modifiées
update_libelle_private: Le libellé de lannotation privée « %{label} » a été modifié. Le nouveau libellé est « %{to} »
update_description_private: La description de lannotation privée « %{label} » a été modifiée. La nouvelle description est « %{to} »
update_type_champ_private: Le type de lannotation privée « %{label} » a été modifié. Elle est maintenant de type « %{to} »
update_mandatory_private:
enable: Lannotation privée « %{label} » est maintenant obligatoire
disable: Lannotation privée « %{label} » nest plus obligatoire
update_piece_justificative_template_private: Le modèle de pièce justificative de lannotation privée « %{label} » a été modifié
update_drop_down_options_private: Les options de sélection de lannotation privée « %{label} » ont été modifiées
update_carte_layers_private: Les référentiels cartographiques de lannotation privée « %{label} » ont été modifiés
add_option: "ajoutés : %{items}"
remove_option: "supprimés : %{items}"
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

View file

@ -927,7 +927,7 @@ describe Procedure do
])
end
let(:dossier) { procedure.new_dossier }
let(:dossier) { procedure.active_revision.new_dossier }
it { expect(dossier.procedure).to eq(procedure) }