diff --git a/app/components/procedure/revision_changes_component.rb b/app/components/procedure/revision_changes_component.rb new file mode 100644 index 000000000..fc31276de --- /dev/null +++ b/app/components/procedure/revision_changes_component.rb @@ -0,0 +1,16 @@ +class Procedure::RevisionChangesComponent < ApplicationComponent + def initialize(changes:, previous_revision:) + @changes = changes + @previous_revision = previous_revision + @public_move_changes, @private_move_changes = changes.filter { _1.op == :move }.partition { !_1.private? } + end + + private + + def total_dossiers + @total_dossiers ||= @previous_revision.dossiers + .visible_by_administration + .state_en_construction_ou_instruction + .size + end +end diff --git a/app/components/procedure/revision_changes_component/revision_changes_component.fr.yml b/app/components/procedure/revision_changes_component/revision_changes_component.fr.yml new file mode 100644 index 000000000..76345128c --- /dev/null +++ b/app/components/procedure/revision_changes_component/revision_changes_component.fr.yml @@ -0,0 +1,59 @@ +--- +fr: + no_changes: Aucune modification + breaking_change: + one: Un dossier en cours de traitement n’est pas compatible avec ce changement. + other: "%{count} dossiers en cours de traitement ne sont pas compatible avec ce changement." + add_option: "ajoutés : %{items}" + remove_option: "supprimés : %{items}" + public: + add: Le champ « %{label} » a été ajouté. + add_mandatory: Le champ obligatoire « %{label} » a été ajouté. + remove: Le champ « %{label} » a été supprimé. + move: + one: La position d’un 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} ». + remove_description: La description du champ « %{label} » a été supprimée. + update_drop_down_secondary_libelle: Le libellé secondaire du champ « %{label} » a été modifié. Le nouveau libellé est « %{to} ». + update_drop_down_secondary_description: La description secondaire 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_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 :" + enable_mandatory: Le champ « %{label} » est maintenant obligatoire. + disable_mandatory: Le champ « %{label} » n’est plus obligatoire. + enable_drop_down_other: Le champ « %{label} » comporte maintenant un choix « Autre ». + disable_drop_down_other: Le champ « %{label} » ne comporte plus de choix « Autre ». + update_carte_layers: "Les référentiels cartographiques du champ « %{label} » ont été modifiés :" + enable_update_collapsible_explanation: Le texte complementaire affichable au clique du champ « %{label} » a été ajouté. + disable_update_collapsible_explanation: Le texte complementaire affichable au clique du champ « %{label} » a été supprimée. + update_collapsible_explanation_text: Le texte complementaire affichable au clique du champ « %{label} » a été modifié. Le nouveau texte est « %{to} ». + remove_collapsible_explanation_text: Le texte complementaire affichable au clique du champ « %{label} » a été supprimée. + add_condition: Une condition a été ajoutée sur le champ « %{label} ». La nouvelle condition est « %{to} ». + remove_condition: La condition du champ « %{label} » a été supprimée. + update_condition: La condition du champ « %{label} » a été modifiée. La nouvelle condition est « %{to} ». + private: + add: L’annotation privée « %{label} » a été ajoutée. + remove: L’annotation privée « %{label} » a été supprimée. + move: + one: La position d’une annotation privée a été modifiée. + other: Les positions de %{count} annotations privées ont été modifiées. + update_libelle: Le libellé de l’annotation privée « %{label} » a été modifié. Le nouveau libellé est « %{to} ». + update_description: La description de l’annotation privée « %{label} » a été modifiée. La nouvelle description est « %{to} ». + remove_description: La description de l’annotation privée « %{label} » a été supprimée. + update_drop_down_secondary_libelle: Le libellé secondaire de l’annotation « %{label} » a été modifié. Le nouveau libellé est « %{to} ». + update_drop_down_secondary_description: La description secondaire de l’annotation « %{label} » a été modifiée. La nouvelle description est « %{to} ». + update_type_champ_private: Le type de l’annotation privée « %{label} » a été modifié. Elle est maintenant de type « %{to} ». + update_piece_justificative_template_private: Le modèle de pièce justificative de l’annotation privée « %{label} » a été modifié. + update_drop_down_options_private: "Les options de sélection de l’annotation privée « %{label} » ont été modifiées :" + update_carte_layers_private: "Les référentiels cartographiques de l’annotation privée « %{label} » ont été modifiés :" + enable_drop_down_other: L’annotation privée « %{label} » comporte maintenant un choix « Autre ». + disable_drop_down_other: L’annotation privée « %{label} » ne comporte plus de choix « Autre ». + enable_collapsible_explanation: Le texte complementaire affichable au clique de l’annotation privée « %{label} » a été ajouté. + disable_collapsible_explanation: Le texte complementaire affichable au clique de l’annotation privée « %{label} » a été supprimée. + update_collapsible_explanation: Le texte complementaire affichable au clique de l’annotation privée « %{label} » a été modifié. Le nouveau texte est « %{to} ». + remove_collapsible_explanation: Le texte complementaire affichable au clique de l’annotation privée « %{label} » a été supprimée. + add_condition: Une condition a été ajoutée sur l’annotation privée « %{label} ». La nouvelle condition est « %{to} ». + remove_condition: La condition de l’annotation privée « %{label} » a été supprimée. + update_condition: La condition de l’annotation privée « %{label} » a été modifiée. La nouvelle condition est « %{to} ». diff --git a/app/components/procedure/revision_changes_component/revision_changes_component.html.haml b/app/components/procedure/revision_changes_component/revision_changes_component.html.haml new file mode 100644 index 000000000..9a74529fb --- /dev/null +++ b/app/components/procedure/revision_changes_component/revision_changes_component.html.haml @@ -0,0 +1,137 @@ += render Dsfr::ListComponent.new do |list| + - list.with_empty do + = t('.no_changes') + + - @changes.each do |change| + - prefix = change.private? ? 'private' : 'public' + - case change.op + - when :add + - list.with_item do + - if change.mandatory? + = t('.public.add_mandatory', label: change.label) + - else + = t(".#{prefix}.add", label: change.label) + - if !total_dossiers.zero? && !change.can_rebase? + %strong + = t('.breaking_change', count: total_dossiers) + - when :remove + - list.with_item do + = t(".#{prefix}.remove", label: change.label) + - when :update + - case change.attribute + - when :libelle + - list.with_item do + = t(".#{prefix}.update_libelle", label: change.label, to: change.to) + - when :type_champ + - list.with_item do + = t(".#{prefix}.update_type_champ", label: change.label, to: t("activerecord.attributes.type_de_champ.type_champs.#{change.to}")) + - if !total_dossiers.zero? && !change.can_rebase? + %strong + = t('.breaking_change', count: total_dossiers) + - when :description + - list.with_item do + - if change.to.blank? + = t(".#{prefix}.remove_description", label: change.label, to: change.to) + - else + = t(".#{prefix}.update_description", label: change.label, to: change.to) + - when :drop_down_secondary_libelle + - list.with_item do + = t(".#{prefix}.update_drop_down_secondary_libelle", label: change.label, to: change.to) + - when :drop_down_secondary_description + - list.with_item do + = t(".#{prefix}.update_drop_down_secondary_description", label: change.label, to: change.to) + - when :mandatory + - if change.from == false + - list.with_item do + = t(".public.enable_mandatory", label: change.label) + - if !total_dossiers.zero? && !change.can_rebase? + %strong + = t(:breaking_change, count: total_dossiers) + - else + - list.with_item do + = t(".public.disable_mandatory", label: change.label) + - if !total_dossiers.zero? && !change.can_rebase? + %strong + = t(:breaking_change, count: total_dossiers) + - when :piece_justificative_template + - list.with_item do + = t(".#{prefix}.update_piece_justificative_template", label: change.label) + - when :drop_down_options + - added = change.to.sort - change.from.sort + - removed = change.from.sort - change.to.sort + - list.with_item do + = t(".#{prefix}.update_drop_down_options", label: change.label) + = render Dsfr::ListComponent.new do |list| + - if added.present? + - list.with_item do + = t('.add_option', items: added.map{ |term| "« #{term.strip} »" }.join(", ")) + - if removed.present? + - list.with_item do + = t('.remove_option', items: removed.map{ |term| "« #{term.strip} »" }.join(", ")) + - if !total_dossiers.zero? && !change.can_rebase? + %strong + = t('.breaking_change', count: total_dossiers) + - when :drop_down_other + - if change.from == false + - list.with_item do + = t(".#{prefix}.enable_drop_down_other", label: change.label) + - if !total_dossiers.zero? && !change.can_rebase? + %strong + = t('.breaking_change', count: total_dossiers) + - else + - list.with_item do + = t(".#{prefix}.disable_drop_down_other", label: change.label) + - if !total_dossiers.zero? && !change.can_rebase? + %strong + = t('.breaking_change', count: total_dossiers) + - when :carte_layers + - added = change.to.sort - change.from.sort + - removed = change.from.sort - change.to.sort + - list.with_item do + = t(".#{prefix}.update_carte_layers", label: change.label) + = render Dsfr::ListComponent.new do |list| + - if added.present? + - list.with_item do + = t('.add_option', items: added.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", ")) + - if removed.present? + - list.with_item do + = t('.remove_option', items: removed.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", ")) + - when :collapsible_explanation_enabled + - if change.to + - list.with_item do + = t(".#{prefix}.enable_collapsible_explanation", label: change.label) + - else + - list.with_item do + = t(".#{prefix}.disable_collapsible_explanation", label: change.label) + - when :collapsible_explanation_text + - list.with_item do + - if change.to.blank? + = t(".#{prefix}.remove_collapsible_explanation_text", label: change.label, to: change.to) + - else + = t(".#{prefix}.update_collapsible_explanation_text", label: change.label, to: change.to) + - when :condition + - if change.from.nil? + - list.with_item do + = t(".#{prefix}.add_condition", label: change.label, to: change.to) + - if !total_dossiers.zero? && !change.can_rebase? + %strong + = t(:breaking_change, count: total_dossiers) + - elsif change.to.nil? + - list.with_item do + = t(".#{prefix}.remove_condition", label: change.label) + - if !total_dossiers.zero? && !change.can_rebase? + %strong + = t(:breaking_change, count: total_dossiers) + - else + - list.with_item do + = t(".#{prefix}.update_condition", label: change.label, to: change.to) + - if !total_dossiers.zero? && !change.can_rebase? + %strong + = t(:breaking_change, count: total_dossiers) + + - if @public_move_changes.present? + - list.with_item do + = t(".public.move", count: @public_move_changes.size) + - if @private_move_changes.present? + - list.with_item do + = t(".private.move", count: @private_move_changes.size) diff --git a/app/views/administrateurs/procedures/_publication_form.html.haml b/app/views/administrateurs/procedures/_publication_form.html.haml index 7e7301e86..df358c3b3 100644 --- a/app/views/administrateurs/procedures/_publication_form.html.haml +++ b/app/views/administrateurs/procedures/_publication_form.html.haml @@ -5,7 +5,7 @@ .mt-2 - if procedure.draft_changed? %p.mb-2 Publiez une nouvelle version de votre démarche. Les modifications suivantes seront appliquées : - = render partial: 'revision_changes', locals: { changes: procedure.revision_changes } + = render Procedure::RevisionChangesComponent.new changes: procedure.revision_changes, previous_revision: procedure.published_revision - if procedure.close? = render partial: 'publication_form_inputs', locals: { procedure: procedure, closed_procedures: @closed_procedures } - else diff --git a/app/views/administrateurs/procedures/_revision_change_type_de_champ.html.haml b/app/views/administrateurs/procedures/_revision_change_type_de_champ.html.haml deleted file mode 100644 index 45a286b8e..000000000 --- a/app/views/administrateurs/procedures/_revision_change_type_de_champ.html.haml +++ /dev/null @@ -1,96 +0,0 @@ -- postfix = change.private? ? '_private' : '' -- case change.op -- when :add - - list.with_item do - - if change.mandatory? - = t("add_mandatory", label: change.label, scope: [:administrateurs, :revision_changes]) - - else - = t("add#{postfix}", label: change.label, scope: [:administrateurs, :revision_changes]) -- when :remove - - list.with_item do - = t("remove#{postfix}", label: change.label, scope: [:administrateurs, :revision_changes]) -- when :update - - case change.attribute - - when :libelle - - list.with_item do - = t("update_libelle#{postfix}", label: change.label, to: change.to, scope: [:administrateurs, :revision_changes]) - - when :type_champ - - list.with_item do - = t("update_type_champ#{postfix}", label: change.label, to: t("activerecord.attributes.type_de_champ.type_champs.#{change.to}"), scope: [:administrateurs, :revision_changes]) - - when :description - - list.with_item do - = t("update_description#{postfix}", label: change.label, to: change.to, scope: [:administrateurs, :revision_changes]) - - when :drop_down_secondary_libelle - - list.with_item do - = t("update_drop_down_secondary_libelle#{postfix}", label: change.label, to: change.to, scope: [:administrateurs, :revision_changes]) - - when :drop_down_secondary_description - - list.with_item do - = t("update_drop_down_secondary_description#{postfix}", label: change.label, to: change.to, scope: [:administrateurs, :revision_changes]) - - when :mandatory - - if change.from == false - -# i18n-tasks-use t('administrateurs.revision_changes.update_mandatory.enabled') - -# i18n-tasks-use t('administrateurs.revision_changes.update_mandatory_private.enabled') - - list.with_item do - = t("administrateurs.revision_changes.update_mandatory#{postfix}.enabled", label: change.label) - - else - -# i18n-tasks-use t('administrateurs.revision_changes.update_mandatory.disabled') - -# i18n-tasks-use t('administrateurs.revision_changes.update_mandatory_private.disabled') - - list.with_item do - = t("administrateurs.revision_changes.update_mandatory#{postfix}.disabled", label: change.label) - - when :piece_justificative_template - -# i18n-tasks-use t('administrateurs.revision_changes.update_piece_justificative_template') - -# i18n-tasks-use t('administrateurs.revision_changes.update_piece_justificative_template_private') - - list.with_item do - = t("administrateurs.revision_changes.update_piece_justificative_template#{postfix}", label: change.label) - - when :drop_down_options - - added = change.to.sort - change.from.sort - - removed = change.from.sort - change.to.sort - - list.with_item do - = t("update_drop_down_options#{postfix}", scope: [:administrateurs, :revision_changes], label: change.label) - = render Dsfr::ListComponent.new do |list| - - if added.present? - - list.with_item do - = t(:add_option, scope: [:administrateurs, :revision_changes], items: added.map{ |term| "« #{term.strip} »" }.join(", ")) - - if removed.present? - - list.with_item do - = t(:remove_option, scope: [:administrateurs, :revision_changes], items: removed.map{ |term| "« #{term.strip} »" }.join(", ")) - - when :drop_down_other - - if change.from == false - - list.with_item do - = t("administrateurs.revision_changes.update_drop_down_other#{postfix}.enabled", label: change.label) - - else - - list.with_item do - = t("administrateurs.revision_changes.update_drop_down_other#{postfix}.disabled", label: change.label) - - when :carte_layers - - added = change.to.sort - change.from.sort - - removed = change.from.sort - change.to.sort - - list.with_item do - = t("update_carte_layers#{postfix}", scope: [:administrateurs, :revision_changes], label: change.label) - = render Dsfr::ListComponent.new do |list| - - if added.present? - - list.with_item do - = t(:add_option, scope: [:administrateurs, :revision_changes], items: added.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", ")) - - if removed.present? - - list.with_item do - = t(:remove_option, scope: [:administrateurs, :revision_changes], items: removed.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", ")) - - when :collapsible_explanation_enabled - - if change.to - - list.with_item do - = t("administrateurs.revision_changes.update_collapsible_explanation_enabled#{postfix}.enabled", label: change.label) - - else - - list.with_item do - = t("administrateurs.revision_changes.update_collapsible_explanation_enabled#{postfix}.disabled", label: change.label) - - when :collapsible_explanation_text - - list.with_item do - = t("administrateurs.revision_changes.update_collapsible_explanation_text#{postfix}", label: change.label, text: change.to) - - - when :condition - - if change.from.nil? - - list.with_item do - = t(:add_condition, scope: [:administrateurs, :revision_changes], label: change.label, to: change.to) - - elsif change.to.nil? - - list.with_item do - = t(:remove_condition, scope: [:administrateurs, :revision_changes], label: change.label) - - else - - list.with_item do - = t(:update_condition, scope: [:administrateurs, :revision_changes], label: change.label, to: change.to) diff --git a/app/views/administrateurs/procedures/_revision_changes.html.haml b/app/views/administrateurs/procedures/_revision_changes.html.haml deleted file mode 100644 index e440a2dde..000000000 --- a/app/views/administrateurs/procedures/_revision_changes.html.haml +++ /dev/null @@ -1,12 +0,0 @@ -= render Dsfr::ListComponent.new do |list| - - list.with_empty do - = t(:no_changes, scope: [:administrateurs, :revision_changes]) - - = render partial: "administrateurs/procedures/revision_change_type_de_champ", collection: changes, as: :change, locals: { list: list } - - move_changes, move_private_changes = changes.filter { _1.op == :move }.partition { !_1.private? } - - if move_changes.present? - - list.with_item do - = t(:move, scope: [:administrateurs, :revision_changes], count: move_changes.size) - - if move_private_changes.present? - - list.with_item do - = t(:move_private, scope: [:administrateurs, :revision_changes], count: move_private_changes.size) diff --git a/app/views/administrateurs/procedures/modifications.html.haml b/app/views/administrateurs/procedures/modifications.html.haml index 33c184352..a3775ada7 100644 --- a/app/views/administrateurs/procedures/modifications.html.haml +++ b/app/views/administrateurs/procedures/modifications.html.haml @@ -28,5 +28,5 @@ %p= t('.dossiers_en_construction', count: dossiers_en_construction_count) - elsif !dossiers_en_instruction_count.zero? %p= t('.dossiers_en_instruction', count: dossiers_en_instruction_count) - = render partial: 'revision_changes', locals: { changes: changes } + = render Procedure::RevisionChangesComponent.new changes:, previous_revision: - previous_revision = revision diff --git a/app/views/administrateurs/procedures/show.html.haml b/app/views/administrateurs/procedures/show.html.haml index 4a16cbf3d..0088f2cde 100644 --- a/app/views/administrateurs/procedures/show.html.haml +++ b/app/views/administrateurs/procedures/show.html.haml @@ -47,7 +47,7 @@ .card.featured .card-title = t(:has_changes, scope: [:administrateurs, :revision_changes]) - = render partial: 'revision_changes', locals: { changes: @procedure.revision_changes } + = render Procedure::RevisionChangesComponent.new changes: @procedure.revision_changes, previous_revision: @procedure.published_revision .flex.mt-2.justify-end = button_to "Réinitialiser les modifications", admin_procedure_reset_draft_path(@procedure), class: 'fr-btn fr-btn--secondary fr-mr-2w', method: :put = button_to 'Publier les modifications', admin_procedure_publication_path(@procedure), class: 'fr-btn', id: 'publish-procedure-link', data: { disable_with: "Publication..." }, disabled: !@procedure.draft_revision.valid?, method: :get diff --git a/config/locales/views/administrateurs/revision_changes/fr.yml b/config/locales/views/administrateurs/revision_changes/fr.yml index 1571ff65e..e3c4473d6 100644 --- a/config/locales/views/administrateurs/revision_changes/fr.yml +++ b/config/locales/views/administrateurs/revision_changes/fr.yml @@ -1,57 +1,7 @@ fr: administrateurs: revision_changes: - no_changes: Aucune modification 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 d’un 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_drop_down_secondary_libelle: Le libellé secondaire du champ « %{label} » a été modifié. Le nouveau libellé est « %{to} » - update_drop_down_secondary_description: La description secondaire 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: - enabled: Le champ « %{label} » est maintenant obligatoire - disabled: Le champ « %{label} » n’est 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_drop_down_other: - enabled: Le champ « %{label} » comporte maintenant un choix « Autre » - disabled: Le champ « %{label} » ne comporte plus de choix « Autre » - update_carte_layers: Les référentiels cartographiques du champ « %{label} » ont été modifiés - update_collapsible_explanation_enabled: - enabled: "Le texte complementaire affichable au clique du champ « %{label} » a été ajouté" - disabled: "Le texte complementaire affichable au clique du champ « %{label} » a été supprimée" - update_collapsible_explanation_text: "Le texte complementaire affichable au clique du champ « %{label} » a été modifié. Il est maintenant « %{text} »." - add_private: L’annotation privée « %{label} » a été ajoutée - add_mandatory: Le champ obligatoire « %{label} » a été ajouté - remove_private: L’annotation privée « %{label} » a été supprimée - move_private: - one: La position d’une 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 l’annotation privée « %{label} » a été modifié. Le nouveau libellé est « %{to} » - update_description_private: La description de l’annotation privée « %{label} » a été modifiée. La nouvelle description est « %{to} » - update_drop_down_secondary_libelle_private: Le libellé secondaire de l’annotation « %{label} » a été modifié. Le nouveau libellé est « %{to} » - update_drop_down_secondary_description_private: La description secondaire de l’annotation « %{label} » a été modifiée. La nouvelle description est « %{to} » - update_type_champ_private: Le type de l’annotation privée « %{label} » a été modifié. Elle est maintenant de type « %{to} » - update_mandatory_private: - enabled: L’annotation privée « %{label} » est maintenant obligatoire - disabled: L’annotation privée « %{label} » n’est plus obligatoire - update_piece_justificative_template_private: Le modèle de pièce justificative de l’annotation privée « %{label} » a été modifié - update_drop_down_options_private: Les options de sélection de l’annotation privée « %{label} » ont été modifiées - update_carte_layers_private: Les référentiels cartographiques de l’annotation privée « %{label} » ont été modifiés - update_collapsible_explanation_enabled_private: - enabled: "Le texte complementaire affichable au clique de l’annotation privée « %{label} » a été ajouté" - disabled: "Le texte complementaire affichable au clique de l’annotation privée « %{label} » a été supprimée" - update_collapsible_explanation_private: "Le texte complementaire affichable au clique de l’annotation privée « %{label} » a été modifié. Il est maintenant « %{text} »." - add_option: "ajoutés : %{items}" - remove_option: "supprimés : %{items}" - add_condition: Une condition a été ajoutée sur le champ « %{label} ». La nouvelle condition est « %{to} » - remove_condition: La condition du champ « %{label} » a été supprimée. - update_condition: La condition du champ « %{label} » a été modifiée. La nouvelle condition est « %{to} » carte_layers: unesco: UNESCO arretes_protection: Arrêtés de protection