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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
WIP: Format TimeEntry activities
Mir Bhatia509719f84eaf
diff --git a/app/components/activities/item_component.rb b/app/components/activities/item_component.rbindex 0ec3da5b834..42be01b42a5 100644--- a/app/components/activities/item_component.rb+++ b/app/components/activities/item_component.rb@@ -38,8 +38,6 @@ class Activities::ItemComponent < ViewComponent::Base@current_project = current_project@display_user = display_user@activity_page = activity_page-- binding.pryenddef project_suffix@@ -56,7 +54,7 @@ class Activities::ItemComponent < ViewComponent::Baseenddef display_details?- return false if @event.journal.initial?+ return false if (@event.journal.initial? && @event.journal.journable_type != 'TimeEntry')rendered_details.present?enddiff --git a/app/models/journal.rb b/app/models/journal.rbindex 419d48f9c38..6bde5e6e412 100644--- a/app/models/journal.rb+++ b/app/models/journal.rb@@ -44,6 +44,7 @@ class Journal < ApplicationRecordregister_journal_formatter :template, OpenProject::JournalFormatter::Templateregister_journal_formatter :visibility, OpenProject::JournalFormatter::Visibilityregister_journal_formatter :subproject_named_association, OpenProject::JournalFormatter::SubprojectNamedAssociation+ register_journal_formatter :time_entry_hours, OpenProject::JournalFormatter::TimeEntryHours# Make sure each journaled model instance only has unique version idsvalidates :version, uniqueness: { scope: %i[journable_id journable_type] }diff --git a/spec/factories/journal/time_entry_journal_factory.rb b/lib/open_project/journal_formatter/time_entry_hours.rbsimilarity index 55%rename from spec/factories/journal/time_entry_journal_factory.rbrename to lib/open_project/journal_formatter/time_entry_hours.rbindex 19f9366aa89..e74a21bd5ed 100644--- a/spec/factories/journal/time_entry_journal_factory.rb+++ b/lib/open_project/journal_formatter/time_entry_hours.rb@@ -26,6 +26,28 @@# See COPYRIGHT and LICENSE files for more details.#++-FactoryBot.define do- factory :journal_time_entry_journal, class: 'Journal::TimeEntryJournal'+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]++ # Need to+ # Italicize+ # Hour vs hours+ # Use I18n strings++ 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"+ else+ # I18n.t('activerecord.attributes.project.public_value.false')+ "#{(values.last % 1).zero? ? values.last.to_i : values.last} hours"+ end+ # value = content_tag(:i, value) if options[:html]++ I18n.t(:text_journal_of, label: label_text, value:)+ endenddiff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rbindex 615ca1a5d3e..d1691075361 100644--- a/modules/costs/app/models/time_entry.rb+++ b/modules/costs/app/models/time_entry.rb@@ -57,8 +57,8 @@ belongs_to :rate, -> { where(type: %w[HourlyRate DefaultHourlyRate]) }, class_na# TODO: move into servicebefore_save :update_costs- register_journal_formatted_fields(:decimal, 'hours')- register_journal_formatted_fields(:named_association, 'user_id')+ register_journal_formatted_fields(:time_entry_hours, 'hours')+ # register_journal_formatted_fields(:named_association, 'user_id')def self.update_all(updates, conditions = nil, options = {})# instead of a update_all, perform an individual update during work_package#movediff --git a/modules/costs/spec/factories/journal/time_entry_journal_factory.rb.tempdelete b/modules/costs/spec/factories/journal/time_entry_journal_factory.rbsimilarity index 100%rename from modules/costs/spec/factories/journal/time_entry_journal_factory.rb.tempdeleterename to modules/costs/spec/factories/journal/time_entry_journal_factory.rbdiff --git a/spec/components/activities/item_component_spec.rb b/spec/components/activities/item_component_spec.rbindex 7032d4b21fa..495c655c18a 100644--- a/spec/components/activities/item_component_spec.rb+++ b/spec/components/activities/item_component_spec.rb@@ -123,13 +123,11 @@ RSpec.describe Activities::ItemComponent, type: :component doendcontext 'for TimeEntry activites' do- let(:journal) { build_stubbed(:time_entry_journal) } # Factory not registered: "time_entry_journal"+ let(:journal) { build_stubbed(:time_entry_journal) }it 'has the correct format when a TimeEntry is created' do- pending '# Factory not registered: "time_entry_journal"'component = described_class.new(event:)render_inline(component)-expect(component.project_suffix).to be_nilexpect(page).to have_css('.op-activity-list--item-title', text: /\A\s*Event Title\s*\z/)enddiff --git a/spec/factories/journal_factory.rb b/spec/factories/journal_factory.rbindex e568e615147..921effe28c4 100644--- a/spec/factories/journal_factory.rb+++ b/spec/factories/journal_factory.rb@@ -60,5 +60,10 @@ FactoryBot.define dojournable factory: :projectdata { build(:journal_project_journal) }end++ factory :time_entry_journal, class: 'Journal' do+ journable_type { 'TimeEntry' }+ data { build(:journal_time_entry_journal) }+ endendend