From 33344995d8505f6c44919a97e53022c00c290e08 Mon Sep 17 00:00:00 2001 From: mfo Date: Tue, 14 May 2024 18:31:16 +0200 Subject: [PATCH] feat(TransitionsRules): add custom message and refine ui --- app/assets/stylesheets/02_utils.scss | 1 - .../transitions_rules_component.html.haml | 59 +++++++++++-------- .../invalid_transitions_rules_component.rb | 4 ++ ...alid_transitions_rules_component.html.haml | 2 +- .../pending_republish_component.fr.yml | 2 +- .../pending_republish_component.html.haml | 2 +- .../procedure/revision_changes_component.rb | 5 ++ .../revision_changes_component.fr.yml | 7 ++- .../revision_changes_component.html.haml | 4 ++ .../transitions_rules_controller.rb | 8 +++ app/models/procedure_revision_change.rb | 10 ++++ .../locales/models/procedure_revision/fr.yml | 7 +++ config/routes.rb | 1 + ...neligble_message_to_procedure_revisions.rb | 5 ++ db/schema.rb | 3 +- .../transitions_rules_controller_spec.rb | 11 ++++ 16 files changed, 99 insertions(+), 32 deletions(-) create mode 100644 config/locales/models/procedure_revision/fr.yml create mode 100644 db/migrate/20240514075727_add_dossier_ineligble_message_to_procedure_revisions.rb diff --git a/app/assets/stylesheets/02_utils.scss b/app/assets/stylesheets/02_utils.scss index d66a5c81ab9..3aa08df2df0 100644 --- a/app/assets/stylesheets/02_utils.scss +++ b/app/assets/stylesheets/02_utils.scss @@ -167,7 +167,6 @@ .element-warning { border: 4px solid var(--border-plain-warning); - border-radius: 5px; } // Labels that we only want for screen readers diff --git a/app/components/conditions/transitions_rules_component/transitions_rules_component.html.haml b/app/components/conditions/transitions_rules_component/transitions_rules_component.html.haml index 636ad1c10fd..2f86992d803 100644 --- a/app/components/conditions/transitions_rules_component/transitions_rules_component.html.haml +++ b/app/components/conditions/transitions_rules_component/transitions_rules_component.html.haml @@ -1,30 +1,41 @@ %div{ id: dom_id(@revision, :transitions_rules) } - = form_tag admin_procedure_transitions_rules_path(@revision.procedure_id), method: :patch, data: { turbo: true, controller: 'autosave' }, class: 'form width-100' do - - if @condition.present? - .conditionnel.fr-mt-3w.width-100 - %table.condition-table.mt-2{ class: class_names('element-warning' => pending_changes?) } - %thead - %tr - %th.far-left - %th.target Champ Cible - %th.operator Opérateur - %th.value Valeur - %th.delete-column - %tbody - - rows.each.with_index do |(targeted_champ, operator_name, value), row_index| - %tr - %td.far-left= far_left_tag(row_index) - %td.target= left_operand_tag(targeted_champ, row_index) - %td.operator= operator_tag(operator_name, targeted_champ, row_index) - %td.value= right_operand_tag(targeted_champ, value, row_index, operator_name) - %td.delete-column= delete_condition_tag(row_index) + %div{ class: class_names('element-warning' => pending_changes?, 'fr-p-3w': pending_changes?) } + %h2.fr-h2 + Gestion des critères d'eligibilité - = render Procedure::PendingRepublishComponent.new(procedure: @revision.procedure, render_if: pending_changes?) - %p.fr-mt-3w= add_condition_tag + = form_tag admin_procedure_transitions_rules_path(@revision.procedure_id), method: :patch, data: { turbo: true, controller: 'autosave' }, class: 'form width-100' do + - if @condition.present? + .conditionnel.fr-mt-3w.width-100 + %table.condition-table.mt-2 + %thead + %tr + %th.far-left + %th.target Champ Cible + %th.operator Opérateur + %th.value Valeur + %th.delete-column + %tbody + - rows.each.with_index do |(targeted_champ, operator_name, value), row_index| + %tr + %td.far-left= far_left_tag(row_index) + %td.target= left_operand_tag(targeted_champ, row_index) + %td.operator= operator_tag(operator_name, targeted_champ, row_index) + %td.value= right_operand_tag(targeted_champ, value, row_index, operator_name) + %td.delete-column= delete_condition_tag(row_index) + %tfoot + %tr + %td{ colspan: 5 }= add_condition_tag + - else + = tag.button "Activer l'éligibilité des dossiers", formaction: add_condition_path, formvalidate: true, class: 'fr-btn fr-btn--primary' - - else - = tag.button "Activer l'éligibilité des dossiers", formaction: add_condition_path, formvalidate: true, class: 'fr-btn fr-btn--primary' + - if @condition.present? + %h2.fr-h2.fr-mt-3w Message d'inéligibilité + = form_for(@revision, url: change_message_admin_procedure_transitions_rules_path(@revision.procedure_id)) do |f| + = render Dsfr::InputComponent.new(form: f, attribute: :dossier_ineligble_message, input_type: :text_area, opts: {rows: 5}) + %p.fr-mb-0= f.submit "Modifier le message d'inéligibilité", class: 'fr-btn' + = render Procedure::PendingRepublishComponent.new(procedure: @revision.procedure, render_if: pending_changes?) - if @condition.present? - = button_to 'Désactiver l’éligibilité des dossiers', delete_all_admin_procedure_transitions_rules_path(@revision.procedure), method: :delete, class: 'fr-btn' + %h2.fr-h2.fr-mt-3w Désactivation des critères d'eligibilité + = button_to 'Désactiver l’éligibilité des dossiers', delete_all_admin_procedure_transitions_rules_path(@revision.procedure), method: :delete, class: 'fr-btn fr-btn--tertiary' diff --git a/app/components/dossiers/invalid_transitions_rules_component.rb b/app/components/dossiers/invalid_transitions_rules_component.rb index 6ebea6a9d65..be236cf7b53 100644 --- a/app/components/dossiers/invalid_transitions_rules_component.rb +++ b/app/components/dossiers/invalid_transitions_rules_component.rb @@ -9,6 +9,10 @@ def render? transitions_rules_computable? && !can_passer_en_construction? end + def error_message + @dossier.revision.dossier_ineligble_message || t('.modal.body', procedure_libelle: @dossier.procedure.libelle) + end + private def transitions_rules_computable? diff --git a/app/components/dossiers/invalid_transitions_rules_component/invalid_transitions_rules_component.html.haml b/app/components/dossiers/invalid_transitions_rules_component/invalid_transitions_rules_component.html.haml index 6548b074f86..540752b789b 100644 --- a/app/components/dossiers/invalid_transitions_rules_component/invalid_transitions_rules_component.html.haml +++ b/app/components/dossiers/invalid_transitions_rules_component/invalid_transitions_rules_component.html.haml @@ -13,4 +13,4 @@ %h1#fr-modal-title-modal-1.fr-modal__title %span.fr-icon-arrow-right-line.fr-icon--lg> = t('.modal.title') - %p= t('.modal.body', procedure_libelle: @dossier.procedure.libelle) + %p= error_message diff --git a/app/components/procedure/pending_republish_component/pending_republish_component.fr.yml b/app/components/procedure/pending_republish_component/pending_republish_component.fr.yml index 3c02c563d79..eb941cdbab1 100644 --- a/app/components/procedure/pending_republish_component/pending_republish_component.fr.yml +++ b/app/components/procedure/pending_republish_component/pending_republish_component.fr.yml @@ -1,4 +1,4 @@ --- fr: pending_republish_html: | - Cette modification ne sera appliquée qu'à la prochaine publication. Vous pouvez vérifier puis publier les modifications sur l'écran de gestion de la démarche \ No newline at end of file + Ces modifications ne seront appliquées qu'à la prochaine publication. Vous pouvez vérifier puis publier les modifications sur l'écran de gestion de la démarche \ No newline at end of file diff --git a/app/components/procedure/pending_republish_component/pending_republish_component.html.haml b/app/components/procedure/pending_republish_component/pending_republish_component.html.haml index 15c01ba7abc..eab7f62fc87 100644 --- a/app/components/procedure/pending_republish_component/pending_republish_component.html.haml +++ b/app/components/procedure/pending_republish_component/pending_republish_component.html.haml @@ -1,3 +1,3 @@ -= render Dsfr::AlertComponent.new(state: :warning, extra_class_names: 'fr-mt-3w') do |c| += render Dsfr::AlertComponent.new(state: :warning) do |c| - c.with_body do = t('.pending_republish_html', href: admin_procedure_path(@procedure.id)) diff --git a/app/components/procedure/revision_changes_component.rb b/app/components/procedure/revision_changes_component.rb index fd0bb403735..ad7a4652e7e 100644 --- a/app/components/procedure/revision_changes_component.rb +++ b/app/components/procedure/revision_changes_component.rb @@ -1,6 +1,7 @@ class Procedure::RevisionChangesComponent < ApplicationComponent def initialize(new_revision:, previous_revision:) @previous_revision = previous_revision + @new_revision = new_revision @tdc_changes = previous_revision.compare_types_de_champ(new_revision) @public_move_changes, @private_move_changes = @tdc_changes.filter { _1.op == :move }.partition { !_1.private? } @@ -9,6 +10,10 @@ def initialize(new_revision:, previous_revision:) @transition_rules_changes = previous_revision.compare_transitions_rules(new_revision) end + def dossier_ineligble_message_changed? + @new_revision.dossier_ineligble_message != @previous_revision.dossier_ineligble_message + end + private def total_dossiers 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 51722548206..eafb09f8c5e 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 @@ -81,6 +81,7 @@ fr: remove_expression_reguliere_error_message: Le message d’erreur de l’expression régulière de l’annotation privée « %{label} » a été supprimé. update_expression_reguliere_error_message: Le message d’erreur de l’expression régulière de l’annotation privée « %{label} » a été modifiée. Le nouveau message est « %{to} ». transitions_rules: - add: La condition d’elligibilité « %{new_condition} » a été ajoutée. - remove: La condition d’elligibilité « %{previous_condition} » a été supprimée - update: La conditon d’elligibilité « %{previous_condition} » a été changée pour « %{new_condition} » \ No newline at end of file + add: La condition d’eligibilité « %{new_condition} » a été ajoutée. + remove: La condition d’eligibilité « %{previous_condition} » a été supprimée + update: La conditon d’eligibilité « %{previous_condition} » a été changée pour « %{new_condition} » + dossier_ineligble_message_changed: "Le message d’eligibilité a été changé : « %{new_dossier_ineligble_message} »" 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 ef437161102..5ead2541af5 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 @@ -180,3 +180,7 @@ - @transition_rules_changes.each do |change| - list.with_item do = t(".transitions_rules.#{change.op}", previous_condition: change.previous_condition, new_condition: change.new_condition) + + - if dossier_ineligble_message_changed? + - list.with_item do + = t('.transitions_rules.dossier_ineligble_message_changed', new_dossier_ineligble_message: @new_revision.dossier_ineligble_message) diff --git a/app/controllers/administrateurs/transitions_rules_controller.rb b/app/controllers/administrateurs/transitions_rules_controller.rb index c3df1a439b4..40149cbf191 100644 --- a/app/controllers/administrateurs/transitions_rules_controller.rb +++ b/app/controllers/administrateurs/transitions_rules_controller.rb @@ -5,6 +5,14 @@ class TransitionsRulesController < AdministrateurController def edit end + def change_message + if revision.update(params.require(:procedure_revision).permit(:dossier_ineligble_message)) + redirect_to edit_admin_procedure_transitions_rules_path(@procedure) + else + render :edit + end + end + def add_row condition = Logic.add_empty_condition_to(revision.transitions_rules) revision.update!(transitions_rules: condition) diff --git a/app/models/procedure_revision_change.rb b/app/models/procedure_revision_change.rb index f78a0032018..428b1074d9c 100644 --- a/app/models/procedure_revision_change.rb +++ b/app/models/procedure_revision_change.rb @@ -107,4 +107,14 @@ def op = :remove class ChangeTransitionsRule < TransitionsRulesChange def op = :update end + + class ChangeDossierIneligbleMessage + attr_reader :previous_revision, :new_revision + def initialize(previous_revision, new_revision) + @previous_revision = previous_revision + @new_revision = new_revision + end + + def op = :update + end end diff --git a/config/locales/models/procedure_revision/fr.yml b/config/locales/models/procedure_revision/fr.yml new file mode 100644 index 00000000000..bf1ce9cdffd --- /dev/null +++ b/config/locales/models/procedure_revision/fr.yml @@ -0,0 +1,7 @@ +fr: + activerecord: + attributes: + procedure_revision: + dossier_ineligble_message: Message d'inéligibilité + hints: + dossier_ineligble_message: "Ce message sera affiché à l'usager si son dossier ne correspond pas à vos critères d'éligibilité" diff --git a/config/routes.rb b/config/routes.rb index 68f2c6fc463..907e58e42fb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -620,6 +620,7 @@ patch :add_row, on: :member delete :delete_row, on: :member delete :delete_all, on: :member + patch :change_message end patch :update_defaut_groupe_instructeur, controller: 'routing_rules', as: :update_defaut_groupe_instructeur diff --git a/db/migrate/20240514075727_add_dossier_ineligble_message_to_procedure_revisions.rb b/db/migrate/20240514075727_add_dossier_ineligble_message_to_procedure_revisions.rb new file mode 100644 index 00000000000..782b4a111bb --- /dev/null +++ b/db/migrate/20240514075727_add_dossier_ineligble_message_to_procedure_revisions.rb @@ -0,0 +1,5 @@ +class AddDossierIneligbleMessageToProcedureRevisions < ActiveRecord::Migration[7.0] + def change + add_column :procedure_revisions, :dossier_ineligble_message, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 4656a42c50c..bfb2ecb14df 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_04_17_053843) do +ActiveRecord::Schema[7.0].define(version: 2024_05_14_075727) do # These are extensions that must be enabled in order to support this database enable_extension "pg_buffercache" enable_extension "pg_stat_statements" @@ -848,6 +848,7 @@ create_table "procedure_revisions", force: :cascade do |t| t.datetime "created_at", precision: nil, null: false + t.text "dossier_ineligble_message" t.bigint "dossier_submitted_message_id" t.bigint "procedure_id", null: false t.datetime "published_at", precision: nil diff --git a/spec/controllers/administrateurs/transitions_rules_controller_spec.rb b/spec/controllers/administrateurs/transitions_rules_controller_spec.rb index 2910313733a..9ec3c7f9442 100644 --- a/spec/controllers/administrateurs/transitions_rules_controller_spec.rb +++ b/spec/controllers/administrateurs/transitions_rules_controller_spec.rb @@ -160,4 +160,15 @@ end end end + + describe 'change_message' do + let(:dossier_ineligble_message) { 'panpan' } + before { sign_in(admin.user) } + it 'works' do + expect { patch :change_message, params: { procedure_id: procedure.id, procedure_revision: { dossier_ineligble_message: } } } + .to change { procedure.reload.draft_revision.dossier_ineligble_message } + .from(nil).to(dossier_ineligble_message) + expect(response).to redirect_to(edit_admin_procedure_transitions_rules_path(procedure)) + end + end end