refactor(gallery): use gallery component in gallery demande
This commit is contained in:
parent
664ef63e74
commit
3560d73b58
4 changed files with 23 additions and 27 deletions
|
@ -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
|
||||
|
|
|
@ -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?)
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue