feat(attestation): upload de logo and signature

This commit is contained in:
Colin Darie 2023-12-22 14:13:20 +01:00
parent bb19674339
commit e19780445b
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
3 changed files with 30 additions and 3 deletions

View file

@ -1,5 +1,7 @@
module Administrateurs
class AttestationTemplateV2sController < AdministrateurController
include UninterlacePngConcern
before_action :retrieve_procedure, :retrieve_attestation_template, :ensure_feature_active
def show
@ -52,7 +54,19 @@ module Administrateurs
end
def update
@attestation_template.update!(editor_params)
attestation_params = editor_params
logo_file = attestation_params.delete(:logo)
signature_file = attestation_params.delete(:signature)
if logo_file
attestation_params[:logo] = uninterlace_png(logo_file)
end
if signature_file
attestation_params[:signature] = uninterlace_png(signature_file)
end
@attestation_template.update!(attestation_params)
end
private
@ -66,7 +80,7 @@ module Administrateurs
end
def editor_params
params.required(:attestation_template).permit(:label_logo, :label_direction, :tiptap_body, :footer)
params.required(:attestation_template).permit(:official_layout, :label_logo, :label_direction, :tiptap_body, :footer, :logo, :signature, :activated)
end
end
end

View file

@ -7,6 +7,7 @@
.fr-grid-row.fr-grid-row--gutters
.fr-col-12.fr-col-md-8
= form_for @attestation_template, url: admin_procedure_attestation_template_v2_path(@procedure), data: { turbo: 'true', controller: 'autosubmit' } do |f|
= render NestedForms::FormOwnerComponent.new
%fieldset.fr-fieldset{ aria: { labelledby: 'edit-attestation' } }
%legend.fr-fieldset__legend#edit-attestation
%h1.fr-h2 Attestation
@ -21,6 +22,9 @@
= render Dsfr::InputComponent.new(form: f, attribute: :label_logo, input_type: :text_area, required: false, opts: { rows: 3 }) do |c|
- c.with_hint { "Exemple: Ministère de la Mer. 3 lignes maximum" }
%div{ id: dom_id(@attestation_template, :logo_attachment) }
= render Attachment::EditComponent.new(attached_file: @attestation_template.logo, direct_upload: false)
.fr-fieldset__element
= render Dsfr::InputComponent.new(form: f, attribute: :label_direction, input_type: :text_area, required: false, opts: { rows: 2 }) do |c|
- c.with_hint { "Exemple: Direction interministérielle du numérique. 2 lignes maximum" }
@ -55,7 +59,9 @@
%label.fr-label{ for: field_id(@attestation_template, :signature) } Tampon ou signature
%span.fr-hint-text
Dimensions conseillées : au minimum 500px de largeur ou de hauteur.
= render Attachment::EditComponent.new(attached_file: @attestation_template.signature, direct_upload: false)
%div{ id: dom_id(@attestation_template, :signature_attachment) }
= render Attachment::EditComponent.new(attached_file: @attestation_template.signature, direct_upload: false)
.fr-fieldset__element
= render Dsfr::InputComponent.new(form: f, attribute: :footer, input_type: :text_area, required: false, opts: { rows: 3 }) do |c|

View file

@ -0,0 +1,7 @@
- if @attestation_template.logo_blob&.previously_new_record?
= turbo_stream.update dom_id(@attestation_template, :logo_attachment) do
= render(Attachment::EditComponent.new(attached_file: @attestation_template.logo, direct_upload: false))
- if @attestation_template.signature_blob&.previously_new_record?
= turbo_stream.update dom_id(@attestation_template, :signature_attachment) do
= render(Attachment::EditComponent.new(attached_file: @attestation_template.signature, direct_upload: false))