Merge pull request #10375 from demarches-simplifiees/variants-for-thumbnails

Correctif(galerie): réduit la taille des images miniatures dans les pages /demande et /pieces_jointes
This commit is contained in:
Eric Leroy-Terquem 2024-04-30 07:35:23 +00:00 committed by GitHub
commit aeb807ca86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 2 deletions

View file

@ -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 },

View file

@ -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 }

View file

@ -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

View file

@ -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'