diff options
author | Dennis Tang <dennis@dennistang.net> | 2018-04-19 17:43:20 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-04-19 17:43:20 +0300 |
commit | 49b85262c5a1944d7fdb50e43900a4adb13aba6c (patch) | |
tree | 9a24b282724d1fcfd9eec599db891a0cb2c6e517 /app/serializers | |
parent | 79905b5a0507bc75d6a960d9d85cce281e9041b3 (diff) |
Resolve "Improve tooltips of collapsed sidebars"
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/entity_date_helper.rb | 27 |
1 files changed, 27 insertions, 0 deletions
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| "<strong>#{match}</strong>" } + 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 |