feat(attestation): can toggle activation
This commit is contained in:
parent
cd07ee173f
commit
cf58c48843
6 changed files with 49 additions and 13 deletions
|
@ -26,6 +26,8 @@ class Dsfr::CalloutComponent < ApplicationComponent
|
|||
"fr-callout--brown-caramel"
|
||||
when :success
|
||||
"fr-callout--green-emeraude"
|
||||
when :neutral
|
||||
# default
|
||||
else
|
||||
"fr-background-alt--blue-france"
|
||||
end
|
||||
|
|
|
@ -60,6 +60,12 @@ module Administrateurs
|
|||
def update
|
||||
attestation_params = editor_params
|
||||
|
||||
# toggle activation
|
||||
if @attestation_template.persisted? && @attestation_template.activated? != cast_bool(attestation_params[:activated])
|
||||
@procedure.attestation_templates.v2.update_all(activated: attestation_params[:activated])
|
||||
render :update && return
|
||||
end
|
||||
|
||||
if @attestation_template.published?
|
||||
@attestation_template = @attestation_template.dup
|
||||
@attestation_template.state = :draft
|
||||
|
@ -123,7 +129,7 @@ module Administrateurs
|
|||
end
|
||||
|
||||
def editor_params
|
||||
params.required(:attestation_template).permit(:official_layout, :label_logo, :label_direction, :tiptap_body, :footer, :logo, :signature, :activated, :state)
|
||||
params.required(:attestation_template).permit(:activated, :official_layout, :label_logo, :label_direction, :tiptap_body, :footer, :logo, :signature, :activated, :state)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,8 +6,4 @@
|
|||
Revenir à l’écran de gestion
|
||||
|
||||
.fr-col-12.fr-col-md-8.text-right
|
||||
|
||||
- if attestation_template.published?
|
||||
%p.fr-hint-text Cette attestation est actuellement délivrée aux usagers.
|
||||
|
||||
%span#autosave-notice
|
||||
|
|
|
@ -36,13 +36,23 @@
|
|||
L’attestation est émise au moment où un dossier est accepté, elle est jointe à l’email d’accusé d’acceptation.
|
||||
Elle est également disponible au téléchargement depuis l’espace personnel de l’usager.
|
||||
|
||||
.fr-fieldset__element
|
||||
= render Dsfr::CalloutComponent.new(title: "Activation de la délivrance de l’attestation", theme: :neutral) do |c|
|
||||
- c.with_html_body do
|
||||
.fr-toggle.fr-toggle--label-left
|
||||
= f.check_box :activated, class: "fr-toggle__input", id: dom_id(@attestation_template, :activated)
|
||||
%label.fr-toggle__label{ for: dom_id(@attestation_template, :activated),
|
||||
data: { fr_checked_label: "Activée", fr_unchecked_label: "Désactivée" } }
|
||||
Activer cette option permet la délivrance automatique de l’attestation dès l’acceptation du dossier.
|
||||
Désactiver cette option arrête immédiatement l’émission de nouvelles attestations.
|
||||
|
||||
.fr-fieldset__element
|
||||
%h2.fr-h4 En-tête
|
||||
|
||||
.fr-fieldset__element
|
||||
.fr-toggle.fr-toggle--label-left
|
||||
= f.check_box :official_layout, class: "fr-toggle__input", id: dom_id(@attestation_template, :official_layout), data: { "attestation-target": "layoutToggle"}
|
||||
%label.fr-toggle__label{ for: dom_id(@attestation_template, :official_layout), data: { fr_checked_label: "Activé", fr_unchecked_label: "Désactivé" } }
|
||||
%label.fr-toggle__label{ for: dom_id(@attestation_template, :official_layout), data: { fr_checked_label: "Oui", fr_unchecked_label: "Non" } }
|
||||
Je souhaite générer une attestation à la charte de l’état (logo avec Marianne)
|
||||
|
||||
.fr-fieldset__element{ class: class_names("hidden" => !@attestation_template.official_layout?), data: { "attestation-target": 'logoMarianneLabelFieldset'} }
|
||||
|
@ -125,4 +135,4 @@
|
|||
|
||||
.padded-fixed-footer
|
||||
.fixed-footer#fixed_footer
|
||||
= render partial: "fixed_footer", locals: { procedure: @procedure, attestation_template: @attestation_template }
|
||||
= render partial: "fixed_footer", locals: { procedure: @procedure }
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
- if @attestation_template.previously_new_record? || @attestation_template.state_changed?
|
||||
= turbo_stream.update "fixed_footer", render(partial: "fixed_footer", locals: { procedure: @procedure, attestation_template: @attestation_template })
|
||||
- if @attestation_template.draft?
|
||||
= turbo_stream.update "sticky-header", render(partial: "sticky_header")
|
||||
|
||||
= turbo_stream.show 'autosave-notice'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
describe Administrateurs::AttestationTemplateV2sController, type: :controller do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:attestation_template) { build(:attestation_template, :v2) }
|
||||
let!(:procedure) { create(:procedure, administrateur: admin, attestation_template: attestation_template, libelle: "Ma démarche") }
|
||||
let(:procedure) { create(:procedure, administrateur: admin, attestation_template:, libelle: "Ma démarche") }
|
||||
let(:logo) { fixture_file_upload('spec/fixtures/files/white.png', 'image/png') }
|
||||
let(:signature) { fixture_file_upload('spec/fixtures/files/black.png', 'image/png') }
|
||||
|
||||
|
@ -11,7 +11,7 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do
|
|||
label_logo: "Ministère des specs",
|
||||
label_direction: "RSPEC",
|
||||
footer: "en bas",
|
||||
activated: false,
|
||||
activated: true,
|
||||
tiptap_body: {
|
||||
type: :doc,
|
||||
content: [
|
||||
|
@ -147,7 +147,7 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do
|
|||
expect(attestation_template.label_logo).to eq("Ministère des specs")
|
||||
expect(attestation_template.label_direction).to eq("RSPEC")
|
||||
expect(attestation_template.footer).to eq("en bas")
|
||||
expect(attestation_template.activated).to eq(false)
|
||||
expect(attestation_template.activated).to eq(true)
|
||||
expect(attestation_template.tiptap_body).to eq(update_params[:tiptap_body])
|
||||
|
||||
expect(response.body).to include("Formulaire enregistré")
|
||||
|
@ -189,7 +189,7 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do
|
|||
expect(attestation_template.label_logo).to eq("Ministère des specs")
|
||||
expect(attestation_template.label_direction).to eq("RSPEC")
|
||||
expect(attestation_template.footer).to eq("en bas")
|
||||
expect(attestation_template.activated).to eq(false)
|
||||
expect(attestation_template.activated).to eq(true)
|
||||
expect(attestation_template.tiptap_body).to eq(update_params[:tiptap_body])
|
||||
|
||||
expect(response.body).to include("Formulaire enregistré")
|
||||
|
@ -232,6 +232,29 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'toggle activation' do
|
||||
let(:update_params) { super().merge(activated: false) }
|
||||
|
||||
it 'toggle attribute of current published attestation' do
|
||||
subject
|
||||
expect(procedure.attestation_templates.v2.count).to eq(1)
|
||||
expect(procedure.attestation_templates.v2.first.activated?).to eq(false)
|
||||
expect(flash.notice).to be_nil
|
||||
end
|
||||
|
||||
context 'when there is a draft' do
|
||||
before {
|
||||
create(:attestation_template, :v2, :draft, procedure:)
|
||||
}
|
||||
|
||||
it 'toggle attribute of both draft & published v2 attestations' do
|
||||
subject
|
||||
expect(procedure.attestation_templates.v2.count).to eq(2)
|
||||
expect(procedure.attestation_templates.v2.all?(&:activated?)).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST reset' do
|
||||
|
|
Loading…
Reference in a new issue