feat(gallery): add badge for date of created_at or updated_at

This commit is contained in:
Eric Leroy-Terquem 2024-09-09 18:01:24 +02:00
parent 3560d73b58
commit df08617387
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
6 changed files with 36 additions and 0 deletions

View file

@ -13,6 +13,10 @@
object-fit: cover;
}
.champ-updated {
width: 100%;
}
.thumbnail {
position: relative;
display: flex;

View file

@ -34,4 +34,23 @@ class Attachment::GalleryItemComponent < ApplicationComponent
end
end
end
def created_at
attachment.record.created_at
end
def updated?
attachment.record.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp]) && updated_at > attachment.record.dossier.depose_at
end
def updated_at
blob.created_at
end
def badge_updated_class
class_names(
"fr-badge fr-badge--sm" => true,
"fr-badge--new" => updated?
)
end
end

View file

@ -0,0 +1,3 @@
en:
created_at: "Added on %{datetime}"
updated_at: "Updated on %{datetime}"

View file

@ -0,0 +1,3 @@
fr:
created_at: "Ajoutée le %{datetime}"
updated_at: "Modifiée le %{datetime}"

View file

@ -1,4 +1,7 @@
.gallery-item
- if !gallery_demande?
.fr-mb-2v.champ-updated{ class: badge_updated_class }
= t(updated? ? '.updated_at' : '.created_at', datetime: helpers.try_format_datetime(updated_at, format: :veryshort))
- if displayable_pdf?(blob) || displayable_image?(blob)
= gallery_link(blob) do
.thumbnail

View file

@ -25,6 +25,10 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do
expect(component.title).to eq("#{libelle} -- #{filename}")
end
it "displays when gallery item has been added" do
expect(subject).to have_text(component.helpers.try_format_datetime(attachment.record.created_at, format: :veryshort))
end
context "when gallery item is in page Demande" do
let(:gallery_demande) { true }