Merge pull request #8012 from tchak/fix-procedure-publication-errors-improuvements
fix(publication): improve publication warnings
This commit is contained in:
commit
379800a5a6
6 changed files with 55 additions and 24 deletions
30
app/components/procedure/publication_warning_component.rb
Normal file
30
app/components/procedure/publication_warning_component.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
class Procedure::PublicationWarningComponent < ApplicationComponent
|
||||||
|
def initialize(procedure:)
|
||||||
|
@procedure = procedure
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def render?
|
||||||
|
@procedure.validate(:publication)
|
||||||
|
@procedure.errors.delete(:path)
|
||||||
|
@procedure.errors.any?
|
||||||
|
end
|
||||||
|
|
||||||
|
def error_messages
|
||||||
|
@procedure.errors
|
||||||
|
.to_hash(full_messages: true)
|
||||||
|
.map do |attribute, messages|
|
||||||
|
[messages, error_correction_page(attribute)]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def error_correction_page(attribute)
|
||||||
|
case attribute
|
||||||
|
when :draft_revision
|
||||||
|
champs_admin_procedure_path(@procedure)
|
||||||
|
when :initiated_mail, :received_mail, :closed_mail, :refused_mail, :without_continuation_mail
|
||||||
|
admin_procedure_mail_templates_path(@procedure)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
= render Dsfr::AlertComponent.new(state: :warning, title: "Des problèmes empêchent la publication de la démarche") do |c|
|
||||||
|
- c.body do
|
||||||
|
- error_messages.each do |(messages, path)|
|
||||||
|
%p.mt-2
|
||||||
|
= messages.to_sentence
|
||||||
|
- if path.present?
|
||||||
|
= "(#{link_to 'corriger', path, class: 'fr-link'})"
|
|
@ -30,12 +30,6 @@ module ProcedureHelper
|
||||||
t(action, scope: [:modal, :publish, key])
|
t(action, scope: [:modal, :publish, key])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a hash of { attribute: full_message } errors.
|
|
||||||
def procedure_publication_errors(procedure)
|
|
||||||
procedure.validate(:publication)
|
|
||||||
procedure.errors.to_hash(full_messages: true).except(:path)
|
|
||||||
end
|
|
||||||
|
|
||||||
def procedure_auto_archive_date(procedure)
|
def procedure_auto_archive_date(procedure)
|
||||||
I18n.l(procedure.auto_archive_on - 1.day, format: '%-d %B %Y')
|
I18n.l(procedure.auto_archive_on - 1.day, format: '%-d %B %Y')
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,25 +1,15 @@
|
||||||
.card.mb-4
|
.card.mb-4
|
||||||
%h2.card-title Publiez votre démarche
|
%h2.card-title Publiez votre démarche
|
||||||
= form_tag admin_procedure_publish_path(procedure_id: procedure.id), method: :put, class: 'form' do
|
= form_tag admin_procedure_publish_path(procedure_id: procedure.id), method: :put, class: 'form' do
|
||||||
- publication_errors = procedure_publication_errors(procedure)
|
= render Procedure::PublicationWarningComponent.new(procedure: procedure)
|
||||||
- if publication_errors.present?
|
.mt-2
|
||||||
.card.warning
|
|
||||||
.card-title Des problèmes empêchent la publication de la démarche
|
|
||||||
- publication_errors.each do |_attribute, full_messages|
|
|
||||||
%p= full_messages.to_sentence
|
|
||||||
|
|
||||||
- if procedure.draft_changed?
|
- 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 }
|
||||||
- if procedure.close?
|
- if procedure.close?
|
||||||
%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 partial: 'publication_form_inputs', locals: { procedure: procedure, closed_procedures: @closed_procedures }
|
= render partial: 'publication_form_inputs', locals: { procedure: procedure, closed_procedures: @closed_procedures }
|
||||||
|
|
||||||
- else
|
|
||||||
%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 }
|
|
||||||
|
|
||||||
- else
|
- else
|
||||||
= render partial: 'publication_form_inputs', locals: { procedure: procedure, closed_procedures: @closed_procedures }
|
= render partial: 'publication_form_inputs', locals: { procedure: procedure, closed_procedures: @closed_procedures }
|
||||||
|
|
||||||
.flex.justify-end
|
.flex.justify-end
|
||||||
= submit_tag procedure_publish_label(procedure, :submit), { disabled: publication_errors.present?, class: "fr-btn fr-btn--primary", id: 'publish' }
|
= submit_tag procedure_publish_label(procedure, :submit), { disabled: procedure.errors.present?, class: "fr-btn fr-btn--primary", id: 'publish' }
|
||||||
|
|
|
@ -19,7 +19,12 @@ en:
|
||||||
declarative_with_state/accepte: Accepted
|
declarative_with_state/accepte: Accepted
|
||||||
api_particulier_token: Token API Particulier
|
api_particulier_token: Token API Particulier
|
||||||
lien_dpo: DPO contact
|
lien_dpo: DPO contact
|
||||||
routing_criteria_name: Routee criteria name
|
routing_criteria_name: Routing criteria name
|
||||||
|
initiated_mail: File sorted for processing notification email
|
||||||
|
received_mail: File submitted notification email
|
||||||
|
closed_mail: File sorted as accepted notification email
|
||||||
|
refused_mail: File sorted as refused notification email
|
||||||
|
without_continuation_mail: File sorted with no further action notification email
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
procedure:
|
procedure:
|
||||||
|
|
|
@ -20,6 +20,11 @@ fr:
|
||||||
api_particulier_token: Jeton API Particulier
|
api_particulier_token: Jeton API Particulier
|
||||||
lien_dpo: Contact du DPO
|
lien_dpo: Contact du DPO
|
||||||
routing_criteria_name: Nomination du routage
|
routing_criteria_name: Nomination du routage
|
||||||
|
initiated_mail: L’email de notification de passage de dossier en instruction
|
||||||
|
received_mail: L’email de notification de dépot de dossier
|
||||||
|
closed_mail: L’email de notification d’acceptation de dossier
|
||||||
|
refused_mail: L’email de notification de refus de dossier
|
||||||
|
without_continuation_mail: L’email de notification de classement sans suite de dossier
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
procedure:
|
procedure:
|
||||||
|
|
Loading…
Reference in a new issue