From 93e3f5877ed5557ecb13b3b010626d31bb8f4910 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 9 Sep 2022 11:36:25 +0200 Subject: [PATCH] fix(champ_label_component): add missing helpers --- .../champ_label_content_component.rb | 14 ++++++++++++++ .../champ_label_content_component.html.haml | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/components/editable_champ/champ_label_content_component.rb b/app/components/editable_champ/champ_label_content_component.rb index 44cf3ece6..9981e297b 100644 --- a/app/components/editable_champ/champ_label_content_component.rb +++ b/app/components/editable_champ/champ_label_content_component.rb @@ -2,4 +2,18 @@ class EditableChamp::ChampLabelContentComponent < ApplicationComponent def initialize(champ:, seen_at: nil) @champ, @seen_at = champ, seen_at end + + def highlight_if_unseen_class + if highlight? + 'highlighted' + end + end + + def highlight? + @champ.updated_at.present? && @seen_at&.<(@champ.updated_at) + end + + def try_format_datetime(datetime) + datetime.present? ? I18n.l(datetime) : '' + end end diff --git a/app/components/editable_champ/champ_label_content_component/champ_label_content_component.html.haml b/app/components/editable_champ/champ_label_content_component/champ_label_content_component.html.haml index 8d13141a6..9ac355378 100644 --- a/app/components/editable_champ/champ_label_content_component/champ_label_content_component.html.haml +++ b/app/components/editable_champ/champ_label_content_component/champ_label_content_component.html.haml @@ -3,7 +3,7 @@ %span.mandatory * - if @champ.updated_at.present? && @seen_at.present? - %span.updated-at{ class: highlight_if_unseen_class(@seen_at, @champ.updated_at) } + %span.updated-at{ class: highlight_if_unseen_class } = "modifié le #{try_format_datetime(@champ.updated_at)}" - if @champ.rebased_at.present? && @champ.rebased_at > (@seen_at || @champ.updated_at) && controller.current_user.owns_or_invite?(@champ.dossier)