From 49b85262c5a1944d7fdb50e43900a4adb13aba6c Mon Sep 17 00:00:00 2001 From: Dennis Tang Date: Thu, 19 Apr 2018 14:43:20 +0000 Subject: Resolve "Improve tooltips of collapsed sidebars" --- app/serializers/entity_date_helper.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'app/serializers') diff --git a/app/serializers/entity_date_helper.rb b/app/serializers/entity_date_helper.rb index 71d9a65fb58..464217123b4 100644 --- a/app/serializers/entity_date_helper.rb +++ b/app/serializers/entity_date_helper.rb @@ -1,5 +1,6 @@ module EntityDateHelper include ActionView::Helpers::DateHelper + include ActionView::Helpers::TagHelper def interval_in_words(diff) return 'Not started' unless diff @@ -34,4 +35,30 @@ module EntityDateHelper duration_hash end + + # Generates an HTML-formatted string for remaining dates based on start_date and due_date + # + # It returns "Past due" for expired entities + # It returns "Upcoming" for upcoming entities + # If due date is provided, it returns "# days|weeks|months remaining|ago" + # If start date is provided and elapsed, with no due date, it returns "# days elapsed" + def remaining_days_in_words(entity) + if entity.try(:expired?) + content_tag(:strong, 'Past due') + elsif entity.try(:upcoming?) + content_tag(:strong, 'Upcoming') + elsif entity.due_date + is_upcoming = (entity.due_date - Date.today).to_i > 0 + time_ago = time_ago_in_words(entity.due_date) + content = time_ago.gsub(/\d+/) { |match| "#{match}" } + content.slice!("about ") + content << " " + (is_upcoming ? _("remaining") : _("ago")) + content.html_safe + elsif entity.start_date && entity.start_date.past? + days = entity.elapsed_days + content = content_tag(:strong, days) + content << " #{'day'.pluralize(days)} elapsed" + content.html_safe + end + end end -- cgit v1.2.3