Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Refactor time_entry_hours journal formatter

Mir Bhatia6f887a7a4a47
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c5c168b5f0f..4037ef9429b 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -997,11 +997,10 @@ en:
parent_without_of: "Subproject"
parent_no_longer: "No longer subproject of"
time_entry:
- created: "%{last} hours"
- created_single: "%{last} hour"
- updated: "changed from %{first} hours to %{last} hours"
- updated_first_single: "changed from %{first} hour to %{last} hours"
- updated_last_single: "changed from %{first} hours to %{last} hour"
+ hour:
+ one: "%{count} hour"
+ other: "%{count} hours"
+ updated: "changed from %{first} to %{last}"
logged_for: "Logged for"
filter:
changeset: "Changesets"
diff --git a/lib/open_project/journal_formatter/time_entry_hours.rb b/lib/open_project/journal_formatter/time_entry_hours.rb
index b17a4f427ec..d5401cf969b 100644
--- a/lib/open_project/journal_formatter/time_entry_hours.rb
+++ b/lib/open_project/journal_formatter/time_entry_hours.rb
@@ -28,44 +28,32 @@
class OpenProject::JournalFormatter::TimeEntryHours < JournalFormatter::Base
def render(_key, values, options = { html: true })
- label_text = I18n.t('activerecord.attributes.project.public_value.title')
label_text = 'Spent time'
label_text << ':' if !values.first
label_text = content_tag(:strong, label_text) if options[:html]
# TODO - Italicize
- # Mismatch between @event.event_path and linked WP in item_component???
- first = (values.first % 1).zero? ? values.first.to_i : values.first if values.first
- last = (values.last % 1).zero? ? values.last.to_i : values.last
+ first = format_float(values.first) if values.first
+ last = format_float(values.last)
- # TODO - Refactor?
value = \
- if values.first
- if values.first == 1
- I18n.t(:'activity.item.time_entry.updated_first_single',
- first: first,
- last: last)
- elsif values.last == 1
- I18n.t(:'activity.item.time_entry.updated_last_single',
- first: first,
- last: last)
- else
- I18n.t(:'activity.item.time_entry.updated',
- first: first,
- last: last)
- end
+ if first
+ I18n.t(:'activity.item.time_entry.updated',
+ first: I18n.t(:'activity.item.time_entry.hour', count: first),
+ last: I18n.t(:'activity.item.time_entry.hour', count: last))
else
- if values.last == 1
- I18n.t(:'activity.item.time_entry.created_single',
- last: last)
- else
- I18n.t(:'activity.item.time_entry.created',
- last: last)
- end
+ I18n.t(:'activity.item.time_entry.hour',
+ count: last)
end
# value = content_tag(:i, value) if options[:html]
I18n.t(:text_journal_of, label: label_text, value:)
end
+
+ private
+
+ def format_float(val)
+ (val % 1).zero? ? val.to_i : val
+ end
end
diff --git a/lib_static/plugins/acts_as_journalized/lib/journal_formatter/base.rb b/lib_static/plugins/acts_as_journalized/lib/journal_formatter/base.rb
index 8667e06cc67..d2bc990518f 100644
--- a/lib_static/plugins/acts_as_journalized/lib/journal_formatter/base.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/journal_formatter/base.rb
@@ -45,7 +45,6 @@ module JournalFormatter
end
def render(key, values, options = { html: true })
- binding.pry
label, old_value, value = format_details(key, values)
if options[:html]