From 4b53808b5c52bc45d75a6899d39bedebbc654650 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Tue, 23 Apr 2024 14:51:59 +0200 Subject: [PATCH] fix(gallery): add variants on thumbnails --- app/models/champs/piece_justificative_champ.rb | 5 +++++ app/models/champs/titre_identite_champ.rb | 6 ++++++ app/views/instructeurs/dossiers/pieces_jointes.html.haml | 2 +- app/views/shared/champs/piece_justificative/_show.html.haml | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/champs/piece_justificative_champ.rb b/app/models/champs/piece_justificative_champ.rb index 37f50d888..8d9435d17 100644 --- a/app/models/champs/piece_justificative_champ.rb +++ b/app/models/champs/piece_justificative_champ.rb @@ -1,6 +1,11 @@ class Champs::PieceJustificativeChamp < Champ FILE_MAX_SIZE = 200.megabytes + has_many_attached :piece_justificative_file do |attachable| + attachable.variant :small, resize: '300x300' + attachable.variant :medium, resize: '400x400' + end + # TODO: if: -> { validate_champ_value? || validation_context == :prefill } validates :piece_justificative_file, size: { less_than: FILE_MAX_SIZE }, diff --git a/app/models/champs/titre_identite_champ.rb b/app/models/champs/titre_identite_champ.rb index 86df81ee3..05b67e802 100644 --- a/app/models/champs/titre_identite_champ.rb +++ b/app/models/champs/titre_identite_champ.rb @@ -1,6 +1,12 @@ class Champs::TitreIdentiteChamp < Champ FILE_MAX_SIZE = 20.megabytes ACCEPTED_FORMATS = ['image/png', 'image/jpeg'] + + has_many_attached :piece_justificative_file do |attachable| + attachable.variant :small, resize: '300x300' + attachable.variant :medium, resize: '400x400' + end + # TODO: if: -> { validate_champ_value? || validation_context == :prefill } validates :piece_justificative_file, content_type: ACCEPTED_FORMATS, size: { less_than: FILE_MAX_SIZE } diff --git a/app/views/instructeurs/dossiers/pieces_jointes.html.haml b/app/views/instructeurs/dossiers/pieces_jointes.html.haml index ba4a228f5..386a31852 100644 --- a/app/views/instructeurs/dossiers/pieces_jointes.html.haml +++ b/app/views/instructeurs/dossiers/pieces_jointes.html.haml @@ -25,7 +25,7 @@ - elsif blob.content_type.in?(AUTHORIZED_IMAGE_TYPES) = link_to image_url(blob.url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do .thumbnail - = image_tag(blob.url, loading: :lazy) + = image_tag(attachment.variant(:medium), loading: :lazy) .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button } Visualiser .champ-libelle diff --git a/app/views/shared/champs/piece_justificative/_show.html.haml b/app/views/shared/champs/piece_justificative/_show.html.haml index 3e8998f81..525546d8f 100644 --- a/app/views/shared/champs/piece_justificative/_show.html.haml +++ b/app/views/shared/champs/piece_justificative/_show.html.haml @@ -19,6 +19,6 @@ - elsif blob.content_type.in?(AUTHORIZED_IMAGE_TYPES) = link_to image_url(blob.url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do .thumbnail - = image_tag(blob.url, loading: :lazy) + = image_tag(attachment.variant(:small), loading: :lazy) .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button } = 'Visualiser'