refactor(gallery): use gallery component in gallery demande

This commit is contained in:
Eric Leroy-Terquem 2024-09-09 10:33:31 +02:00
parent 664ef63e74
commit 3560d73b58
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
4 changed files with 23 additions and 27 deletions

View file

@ -4,14 +4,17 @@ class Attachment::GalleryItemComponent < ApplicationComponent
include GalleryHelper
attr_reader :attachment
def initialize(attachment:)
def initialize(attachment:, gallery_demande: false)
@attachment = attachment
@gallery_demande = gallery_demande
end
def blob
attachment.blob
end
def gallery_demande? = @gallery_demande
def libelle
attachment.record.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp]) ? attachment.record.libelle : 'Pièce jointe au message'
end

View file

@ -5,12 +5,14 @@
= image_tag(representation_url_for(attachment), loading: :lazy)
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }
Visualiser
.champ-libelle
= libelle.truncate(25)
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true)
- if !gallery_demande?
.champ-libelle
= libelle.truncate(25)
= render Attachment::ShowComponent.new(attachment:, truncate: true, new_tab: gallery_demande?)
- else
.thumbnail
= image_tag('apercu-indisponible.png')
.champ-libelle
= libelle.truncate(25)
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true)
- if !gallery_demande?
.champ-libelle
= libelle.truncate(25)
= render Attachment::ShowComponent.new(attachment:, truncate: true, new_tab: gallery_demande?)