From e43c2f14074187a83fc75ccb1a1526e67ea4e0a9 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 19 Dec 2023 10:44:51 +0100 Subject: [PATCH] feat(procedure_revision.compate): track and show diff for TypeDeChamp.explication between draft and published revisions --- .../explication_component.html.haml | 2 +- .../revision_changes_component.fr.yml | 2 ++ .../revision_changes_component.html.haml | 3 +++ .../administrateurs/types_de_champ_controller.rb | 2 +- app/models/procedure_revision.rb | 13 ++++++++++--- app/models/type_de_champ.rb | 14 ++++++++------ 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/components/editable_champ/explication_component/explication_component.html.haml b/app/components/editable_champ/explication_component/explication_component.html.haml index 7d65c0f62..6c1bf44c7 100644 --- a/app/components/editable_champ/explication_component/explication_component.html.haml +++ b/app/components/editable_champ/explication_component/explication_component.html.haml @@ -9,4 +9,4 @@ .fr-collapse{ id: dom_id(@champ, :explanation) } = render SimpleFormatComponent.new(@champ.collapsible_explanation_text, allow_a: true) - if notice_explicative.attached? - = render Dsfr::DownloadComponent.new(attachment: notice_explicative, virus_not_analyzed: !notice_explicative.virus_scanner.started?, new_tab: true) \ No newline at end of file + = render Dsfr::DownloadComponent.new(attachment: notice_explicative, virus_not_analyzed: !notice_explicative.virus_scanner.started?, new_tab: true) 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 index 15b3c7b02..745d10127 100644 --- a/app/components/procedure/revision_changes_component/revision_changes_component.fr.yml +++ b/app/components/procedure/revision_changes_component/revision_changes_component.fr.yml @@ -24,6 +24,7 @@ fr: 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_notice_explicative: La notice explicative du champ « %{label} » a été modifiée. update_drop_down_options: "Les options de sélection du champ « %{label} » ont été modifiées :" update_drop_down_options_alert: "Le champ « %{label} » est utilisé pour le routage des dossiers. Veuillez mettre à jour la configuration des groupes d'instructeurs après avoir publié les modifications." enable_mandatory: Le champ « %{label} » est maintenant obligatoire. @@ -59,6 +60,7 @@ fr: update_drop_down_secondary_description: La description secondaire de l’annotation « %{label} » a été modifiée. La nouvelle description est « %{to} ». update_type_champ: Le type de l’annotation privée « %{label} » a été modifié. Elle est maintenant de type « %{to} ». update_piece_justificative_template: Le modèle de pièce justificative de l’annotation privée « %{label} » a été modifié. + update_notice_explicative: La notice explicative l’annotation privée « %{label} » a été modifiée. update_drop_down_options: "Les options de sélection de l’annotation privée « %{label} » ont été modifiées :" update_carte_layers: "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 ». 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 index 6dd90ef49..50e90ea76 100644 --- a/app/components/procedure/revision_changes_component/revision_changes_component.html.haml +++ b/app/components/procedure/revision_changes_component/revision_changes_component.html.haml @@ -59,6 +59,9 @@ - when :piece_justificative_template - list.with_item do = t(".#{prefix}.update_piece_justificative_template", label: change.label) + - when :notice_explicative + - list.with_item do + = t(".#{prefix}.update_notice_explicative", label: change.label) - when :drop_down_options - added = change.to.sort - change.from.sort - removed = change.from.sort - change.to.sort diff --git a/app/controllers/administrateurs/types_de_champ_controller.rb b/app/controllers/administrateurs/types_de_champ_controller.rb index 88aa11a95..8aecbd971 100644 --- a/app/controllers/administrateurs/types_de_champ_controller.rb +++ b/app/controllers/administrateurs/types_de_champ_controller.rb @@ -46,7 +46,7 @@ module Administrateurs def notice_explicative type_de_champ = draft.find_and_ensure_exclusive_use(params[:stable_id]) - byebug + if type_de_champ.notice_explicative.attach(params[:blob_signed_id]) @coordinate = draft.coordinate_for(type_de_champ) @morphed = [champ_component_from(@coordinate)] diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 636d22911..dff060439 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -363,11 +363,18 @@ class ProcedureRevision < ApplicationRecord 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 + if from_type_de_champ.checksum_for_attachment(:piece_justificative_template) != to_type_de_champ.checksum_for_attachment(:piece_justificative_template) changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ, :piece_justificative_template, - from_type_de_champ.piece_justificative_template_filename, - to_type_de_champ.piece_justificative_template_filename) + from_type_de_champ.filename_for_attachement(:piece_justificative_template), + to_type_de_champ.filename_for_attachement(:piece_justificative_template)) + end + elsif to_type_de_champ.explication? + if from_type_de_champ.checksum_for_attachment(:notice_explicative) != to_type_de_champ.checksum_for_attachment(:notice_explicative) + changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ, + :notice_explicative, + from_type_de_champ.filename_for_attachement(:notice_explicative), + to_type_de_champ.filename_for_attachement(:notice_explicative)) end elsif to_type_de_champ.textarea? if from_type_de_champ.character_limit != to_type_de_champ.character_limit diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 602b33d17..6aa4b2fd3 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -461,15 +461,17 @@ class TypeDeChamp < ApplicationRecord "TypesDeChamp::#{type_champ.classify}TypeDeChamp" end - def piece_justificative_template_filename - if piece_justificative_template.attached? - piece_justificative_template.filename + def filename_for_attachement(attachment_sym) + attachment = send(attachment_sym) + if attachment.attached? + attachment.filename end end - def piece_justificative_template_checksum - if piece_justificative_template.attached? - piece_justificative_template.checksum + def checksum_for_attachment(attachment_sym) + attachment = send(attachment_sym) + if attachment.attached? + attachment.checksum end end