refactor(dossier): refactor pieces jointes

This commit is contained in:
Eric Leroy-Terquem 2024-07-02 18:45:41 +02:00
parent 3516bae008
commit 3bbcda9c04
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
3 changed files with 31 additions and 39 deletions

View file

@ -364,9 +364,24 @@ module Instructeurs
def pieces_jointes def pieces_jointes
@dossier = current_instructeur.dossiers.find(params[:dossier_id]) @dossier = current_instructeur.dossiers.find(params[:dossier_id])
@champs_with_pieces_jointes = @dossier
champs_attachments_and_libelles = @dossier
.champs .champs
.filter { _1.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp]) } .filter { _1.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp]) }
.flat_map do |c|
c.piece_justificative_file.map do |attachment|
[attachment, c.libelle]
end
end
commentaires_attachments_and_libelles = @dossier
.commentaires
.map(&:piece_jointe)
.map(&:attachments)
.flatten
.map { [_1, 'Messagerie'] }
@attachments_and_libelles = champs_attachments_and_libelles + commentaires_attachments_and_libelles
end end
private private

View file

@ -8,11 +8,19 @@ module BlobImageProcessorConcern
end end
def representation_required? def representation_required?
attachments.any? { _1.record.class == Champs::TitreIdentiteChamp || _1.record.class == Champs::PieceJustificativeChamp || _1.record.class == Commentaire } from_champ? || from_messagerie?
end end
private private
def from_champ?
attachments.any? { _1.record.class == Champs::TitreIdentiteChamp || _1.record.class == Champs::PieceJustificativeChamp }
end
def from_messagerie?
attachments.any? { _1.record.class == Commentaire }
end
def watermark_required? def watermark_required?
attachments.any? { _1.record.class == Champs::TitreIdentiteChamp } attachments.any? { _1.record.class == Champs::TitreIdentiteChamp }
end end

View file

@ -4,63 +4,32 @@
.fr-container .fr-container
.gallery.gallery-pieces-jointes{ "data-controller": "lightbox" } .gallery.gallery-pieces-jointes{ "data-controller": "lightbox" }
- @champs_with_pieces_jointes.each do |champ| - @attachments_and_libelles.each do |attachment, libelle|
- champ.piece_justificative_file.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} -- #{blob.filename}" 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
.champ-libelle
= champ.libelle.truncate(25)
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true)
- elsif displayable_image?(blob)
= link_to image_url(blob_url(attachment)), title: "#{champ.libelle} -- #{blob.filename}", 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
.champ-libelle
= champ.libelle.truncate(25)
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true)
- else
.thumbnail
= image_tag('apercu-indisponible.png')
.champ-libelle
= champ.libelle.truncate(25)
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true)
- @dossier.commentaires.map(&:piece_jointe).map(&:attachments).flatten.each do |attachment|
.gallery-item .gallery-item
- blob = attachment.blob - blob = attachment.blob
- if displayable_pdf?(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: "Messagerie -- #{blob.filename}" do = link_to blob.url, id: blob.id, data: { iframe: true, src: blob.url }, class: 'gallery-link', type: blob.content_type, title: "#{libelle} -- #{blob.filename}" do
.thumbnail .thumbnail
= image_tag(preview_url_for(attachment), loading: :lazy) = image_tag(preview_url_for(attachment), 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
Messagerie = libelle.truncate(25)
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true) = render Attachment::ShowComponent.new(attachment: attachment, truncate: true)
- elsif displayable_image?(blob) - elsif displayable_image?(blob)
= link_to image_url(blob_url(attachment)), title: "Messagerie -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do = link_to image_url(blob_url(attachment)), title: "#{libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do
.thumbnail .thumbnail
= image_tag(variant_url_for(attachment), loading: :lazy) = image_tag(variant_url_for(attachment), 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
Messagerie = libelle.truncate(25)
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true) = render Attachment::ShowComponent.new(attachment: attachment, truncate: true)
- else - else
.thumbnail .thumbnail
= image_tag('apercu-indisponible.png') = image_tag('apercu-indisponible.png')
.champ-libelle .champ-libelle
Messagerie = libelle.truncate(25)
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true) = render Attachment::ShowComponent.new(attachment: attachment, truncate: true)