fix(gallery): add variants on thumbnails
This commit is contained in:
parent
396384cfa9
commit
4b53808b5c
4 changed files with 13 additions and 2 deletions
|
@ -1,6 +1,11 @@
|
||||||
class Champs::PieceJustificativeChamp < Champ
|
class Champs::PieceJustificativeChamp < Champ
|
||||||
FILE_MAX_SIZE = 200.megabytes
|
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 }
|
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
|
||||||
validates :piece_justificative_file,
|
validates :piece_justificative_file,
|
||||||
size: { less_than: FILE_MAX_SIZE },
|
size: { less_than: FILE_MAX_SIZE },
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
class Champs::TitreIdentiteChamp < Champ
|
class Champs::TitreIdentiteChamp < Champ
|
||||||
FILE_MAX_SIZE = 20.megabytes
|
FILE_MAX_SIZE = 20.megabytes
|
||||||
ACCEPTED_FORMATS = ['image/png', 'image/jpeg']
|
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 }
|
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
|
||||||
validates :piece_justificative_file, content_type: ACCEPTED_FORMATS, size: { less_than: FILE_MAX_SIZE }
|
validates :piece_justificative_file, content_type: ACCEPTED_FORMATS, size: { less_than: FILE_MAX_SIZE }
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
- elsif blob.content_type.in?(AUTHORIZED_IMAGE_TYPES)
|
- 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
|
= link_to image_url(blob.url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do
|
||||||
.thumbnail
|
.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 }
|
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }
|
||||||
Visualiser
|
Visualiser
|
||||||
.champ-libelle
|
.champ-libelle
|
||||||
|
|
|
@ -19,6 +19,6 @@
|
||||||
- elsif blob.content_type.in?(AUTHORIZED_IMAGE_TYPES)
|
- 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
|
= link_to image_url(blob.url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do
|
||||||
.thumbnail
|
.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 }
|
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }
|
||||||
= 'Visualiser'
|
= 'Visualiser'
|
||||||
|
|
Loading…
Reference in a new issue