2024-09-06 17:17:57 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Attachment::GalleryItemComponent < ApplicationComponent
|
|
|
|
include GalleryHelper
|
2024-09-11 22:01:09 +02:00
|
|
|
attr_reader :attachment, :seen_at
|
2024-09-06 17:17:57 +02:00
|
|
|
|
2024-09-11 22:01:09 +02:00
|
|
|
def initialize(attachment:, gallery_demande: false, seen_at: nil)
|
2024-09-06 17:17:57 +02:00
|
|
|
@attachment = attachment
|
2024-09-09 10:33:31 +02:00
|
|
|
@gallery_demande = gallery_demande
|
2024-09-11 22:01:09 +02:00
|
|
|
@seen_at = seen_at
|
2024-09-06 17:17:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def blob
|
|
|
|
attachment.blob
|
|
|
|
end
|
|
|
|
|
2024-09-09 10:33:31 +02:00
|
|
|
def gallery_demande? = @gallery_demande
|
|
|
|
|
2024-09-06 17:17:57 +02:00
|
|
|
def libelle
|
2024-09-10 11:43:25 +02:00
|
|
|
from_dossier? ? attachment.record.libelle : 'Pièce jointe au message'
|
|
|
|
end
|
|
|
|
|
|
|
|
def from_dossier?
|
|
|
|
attachment.record.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp])
|
|
|
|
end
|
|
|
|
|
|
|
|
def from_messagerie?
|
|
|
|
attachment.record.is_a?(Commentaire)
|
|
|
|
end
|
|
|
|
|
|
|
|
def from_messagerie_instructeur?
|
|
|
|
from_messagerie? && attachment.record.instructeur.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def from_messagerie_usager?
|
|
|
|
from_messagerie? && attachment.record.instructeur.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def origin
|
|
|
|
case
|
|
|
|
when from_dossier?
|
|
|
|
'Dossier usager'
|
|
|
|
when from_messagerie_instructeur?
|
|
|
|
'Messagerie (instructeur)'
|
|
|
|
when from_messagerie_usager?
|
|
|
|
'Messagerie (usager)'
|
|
|
|
end
|
2024-09-06 17:17:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
|
|
|
"#{libelle} -- #{sanitize(blob.filename.to_s)}"
|
|
|
|
end
|
2024-09-09 09:48:45 +02:00
|
|
|
|
|
|
|
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
|
2024-09-09 18:01:24 +02:00
|
|
|
|
|
|
|
def created_at
|
|
|
|
attachment.record.created_at
|
|
|
|
end
|
|
|
|
|
|
|
|
def updated?
|
2024-09-10 11:43:25 +02:00
|
|
|
from_dossier? && updated_at > attachment.record.dossier.depose_at
|
2024-09-09 18:01:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def updated_at
|
|
|
|
blob.created_at
|
|
|
|
end
|
|
|
|
|
|
|
|
def badge_updated_class
|
|
|
|
class_names(
|
|
|
|
"fr-badge fr-badge--sm" => true,
|
2024-09-11 22:01:09 +02:00
|
|
|
"fr-badge--new" => seen_at.present? && updated_at&.>(seen_at)
|
2024-09-09 18:01:24 +02:00
|
|
|
)
|
|
|
|
end
|
2024-09-06 17:17:57 +02:00
|
|
|
end
|