diff --git a/app/components/attachment/gallery_item_component.rb b/app/components/attachment/gallery_item_component.rb index e32ae942f..0de346602 100644 --- a/app/components/attachment/gallery_item_component.rb +++ b/app/components/attachment/gallery_item_component.rb @@ -19,4 +19,16 @@ class Attachment::GalleryItemComponent < ApplicationComponent def title "#{libelle} -- #{sanitize(blob.filename.to_s)}" end + + def gallery_link(blob, &block) + if displayable_image?(blob) + link_to image_url(blob_url(attachment)), title: title, data: { src: blob.url }, class: 'gallery-link' do + yield + end + elsif displayable_pdf?(blob) + link_to blob.url, id: blob.id, data: { iframe: true, src: blob.url }, class: 'gallery-link', type: blob.content_type, title: title do + yield + end + end + end end diff --git a/app/components/attachment/gallery_item_component/gallery_item_component.html.haml b/app/components/attachment/gallery_item_component/gallery_item_component.html.haml index d59ade805..50aeecd71 100644 --- a/app/components/attachment/gallery_item_component/gallery_item_component.html.haml +++ b/app/components/attachment/gallery_item_component/gallery_item_component.html.haml @@ -1,16 +1,6 @@ .gallery-item - - if displayable_pdf?(blob) - = link_to blob.url, id: blob.id, data: { iframe: true, src: blob.url }, class: 'gallery-link', type: blob.content_type, title: title do - .thumbnail - = 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) - - - elsif displayable_image?(blob) - = link_to image_url(blob_url(attachment)), title: title, data: { src: blob.url }, class: 'gallery-link' do + - if displayable_pdf?(blob) || displayable_image?(blob) + = gallery_link(blob) do .thumbnail = image_tag(representation_url_for(attachment), loading: :lazy) .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }