diff --git a/app/components/attachment/gallery_item_component.rb b/app/components/attachment/gallery_item_component.rb index 0de346602..8e5ce2814 100644 --- a/app/components/attachment/gallery_item_component.rb +++ b/app/components/attachment/gallery_item_component.rb @@ -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 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 50aeecd71..93a5fe5cb 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 @@ -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?) diff --git a/app/views/shared/champs/piece_justificative/_show.html.haml b/app/views/shared/champs/piece_justificative/_show.html.haml index 70041de21..46c3c0f3d 100644 --- a/app/views/shared/champs/piece_justificative/_show.html.haml +++ b/app/views/shared/champs/piece_justificative/_show.html.haml @@ -2,25 +2,7 @@ - if profile == 'instructeur' .gallery-items-list - champ.piece_justificative_file.attachments.with_all_variant_records.each do |attachment| - .gallery-item - - blob = attachment.blob - - 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: "#{champ.libelle} -- #{sanitize(blob.filename.to_s)}" do - .thumbnail - = image_tag(preview_url_for(attachment), loading: :lazy) - .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button } - = 'Visualiser' - - - elsif displayable_image?(blob) - = link_to image_url(blob_url(attachment)), title: "#{champ.libelle} -- #{sanitize(blob.filename.to_s)}", data: { src: blob.url }, class: 'gallery-link' do - .thumbnail - = image_tag(variant_url_for(attachment), loading: :lazy) - .fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button } - = 'Visualiser' - - else - .thumbnail - = image_tag('apercu-indisponible.png') - = render Attachment::ShowComponent.new(attachment:, new_tab: true, truncate: true) + = render Attachment::GalleryItemComponent.new(attachment:, gallery_demande: true) - else %ul - champ.piece_justificative_file.attachments.each do |attachment| diff --git a/spec/components/attachment/gallery_item_component_spec.rb b/spec/components/attachment/gallery_item_component_spec.rb index 53a4ce17d..7dbdab7e4 100644 --- a/spec/components/attachment/gallery_item_component_spec.rb +++ b/spec/components/attachment/gallery_item_component_spec.rb @@ -7,8 +7,9 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do let(:types_de_champ_public) { [{ type: :piece_justificative }] } let(:dossier) { create(:dossier, :with_populated_champs, :en_construction, procedure:) } let(:filename) { attachment.blob.filename.to_s } + let(:gallery_demande) { false } - let(:component) { described_class.new(attachment: attachment) } + let(:component) { described_class.new(attachment: attachment, gallery_demande:) } subject { render_inline(component).to_html } @@ -23,6 +24,14 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do expect(subject).to have_link(filename) expect(component.title).to eq("#{libelle} -- #{filename}") end + + context "when gallery item is in page Demande" do + let(:gallery_demande) { true } + + it "does not display libelle" do + expect(subject).not_to have_text(libelle) + end + end end context "when attachment is from a commentaire" do