From df08617387f177146d4a88eb85fd51dd8a79cf1b Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Mon, 9 Sep 2024 18:01:24 +0200 Subject: [PATCH] feat(gallery): add badge for date of created_at or updated_at --- app/assets/stylesheets/gallery.scss | 4 ++++ .../attachment/gallery_item_component.rb | 19 +++++++++++++++++++ .../gallery_item_component.en.yml | 3 +++ .../gallery_item_component.fr.yml | 3 +++ .../gallery_item_component.html.haml | 3 +++ .../attachment/gallery_item_component_spec.rb | 4 ++++ 6 files changed, 36 insertions(+) create mode 100644 app/components/attachment/gallery_item_component/gallery_item_component.en.yml create mode 100644 app/components/attachment/gallery_item_component/gallery_item_component.fr.yml diff --git a/app/assets/stylesheets/gallery.scss b/app/assets/stylesheets/gallery.scss index eb2bec9ee..524535356 100644 --- a/app/assets/stylesheets/gallery.scss +++ b/app/assets/stylesheets/gallery.scss @@ -13,6 +13,10 @@ object-fit: cover; } + .champ-updated { + width: 100%; + } + .thumbnail { position: relative; display: flex; diff --git a/app/components/attachment/gallery_item_component.rb b/app/components/attachment/gallery_item_component.rb index 8e5ce2814..8944d677a 100644 --- a/app/components/attachment/gallery_item_component.rb +++ b/app/components/attachment/gallery_item_component.rb @@ -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 diff --git a/app/components/attachment/gallery_item_component/gallery_item_component.en.yml b/app/components/attachment/gallery_item_component/gallery_item_component.en.yml new file mode 100644 index 000000000..7e273db89 --- /dev/null +++ b/app/components/attachment/gallery_item_component/gallery_item_component.en.yml @@ -0,0 +1,3 @@ +en: + created_at: "Added on %{datetime}" + updated_at: "Updated on %{datetime}" diff --git a/app/components/attachment/gallery_item_component/gallery_item_component.fr.yml b/app/components/attachment/gallery_item_component/gallery_item_component.fr.yml new file mode 100644 index 000000000..788df7462 --- /dev/null +++ b/app/components/attachment/gallery_item_component/gallery_item_component.fr.yml @@ -0,0 +1,3 @@ +fr: + created_at: "Ajoutée le %{datetime}" + updated_at: "Modifiée le %{datetime}" 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 93a5fe5cb..486f14cef 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 @@ -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 diff --git a/spec/components/attachment/gallery_item_component_spec.rb b/spec/components/attachment/gallery_item_component_spec.rb index 7dbdab7e4..ec80160bf 100644 --- a/spec/components/attachment/gallery_item_component_spec.rb +++ b/spec/components/attachment/gallery_item_component_spec.rb @@ -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 }