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

WIP: Format TimeEntry activities

Mir Bhatia5ca419841090
diff --git a/app/components/activities/item_component.html.erb b/app/components/activities/item_component.html.erb
index aea4394666f..fa402f21f11 100644
--- a/app/components/activities/item_component.html.erb
+++ b/app/components/activities/item_component.html.erb
@@ -1,6 +1,7 @@
<li class="op-activity-list--item">
<div class="op-activity-list--item-title">
<%= link_to @event.event_title.squish, @event.journal.journable_type == 'TimeEntry' ? "/work_packages/#{@event.journal.journable.work_package_id}" : @event.event_path %>
+ <%= link_to @event.event_title.squish, @event.event_path %>
<%= project_suffix %>
</div>
<%=
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 7c2c9eeb82d..7dc2b6bada2 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -993,6 +993,12 @@ en:
updated_on: "updated on %{datetime}"
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"
filter:
changeset: "Changesets"
message: "Forums"
diff --git a/lib/open_project/journal_formatter/time_entry_hours.rb b/lib/open_project/journal_formatter/time_entry_hours.rb
index e74a21bd5ed..b17a4f427ec 100644
--- a/lib/open_project/journal_formatter/time_entry_hours.rb
+++ b/lib/open_project/journal_formatter/time_entry_hours.rb
@@ -33,18 +33,36 @@ class OpenProject::JournalFormatter::TimeEntryHours < JournalFormatter::Base
label_text << ':' if !values.first
label_text = content_tag(:strong, label_text) if options[:html]
- # Need to
- # Italicize
- # Hour vs hours
- # Use I18n strings
+ # 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
+
+ # TODO - Refactor?
value = \
if values.first
- # I18n.t('activerecord.attributes.project.public_value.true')
- "changed from #{(values.first % 1).zero? ? values.first.to_i : values.first} hours to #{(values.last % 1).zero? ? values.last.to_i : values.last} hours"
+ 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
else
- # I18n.t('activerecord.attributes.project.public_value.false')
- "#{(values.last % 1).zero? ? values.last.to_i : values.last} hours"
+ 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
end
# value = content_tag(:i, value) if options[:html]
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 d2bc990518f..8667e06cc67 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,6 +45,7 @@ module JournalFormatter
end
def render(key, values, options = { html: true })
+ binding.pry
label, old_value, value = format_details(key, values)
if options[:html]
diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rb
index d1691075361..b18d5b2e62f 100644
--- a/modules/costs/app/models/time_entry.rb
+++ b/modules/costs/app/models/time_entry.rb
@@ -33,7 +33,7 @@ class TimeEntry < ApplicationRecord
belongs_to :work_package
belongs_to :user
belongs_to :activity, class_name: 'TimeEntryActivity'
-belongs_to :rate, -> { where(type: %w[HourlyRate DefaultHourlyRate]) }, class_name: 'Rate'
+ belongs_to :rate, -> { where(type: %w[HourlyRate DefaultHourlyRate]) }, class_name: 'Rate'
belongs_to :logged_by, class_name: 'User'
acts_as_customizable
@@ -58,6 +58,7 @@ belongs_to :rate, -> { where(type: %w[HourlyRate DefaultHourlyRate]) }, class_na
before_save :update_costs
register_journal_formatted_fields(:time_entry_hours, 'hours')
+ register_journal_formatted_fields(:named_association, 'work_package_id')
# register_journal_formatted_fields(:named_association, 'user_id')
def self.update_all(updates, conditions = nil, options = {})