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: Correct subproject activity items

Mir Bhatiaa60107a5b775
diff --git a/app/models/journal.rb b/app/models/journal.rb
index c400d1c6e39..419d48f9c38 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -43,7 +43,7 @@ class Journal < ApplicationRecord
register_journal_formatter :active_status, OpenProject::JournalFormatter::ActiveStatus
register_journal_formatter :template, OpenProject::JournalFormatter::Template
register_journal_formatter :visibility, OpenProject::JournalFormatter::Visibility
- # register_journal_formatter :subproject, OpenProject::JournalFormatter::Subproject
+ register_journal_formatter :subproject_named_association, OpenProject::JournalFormatter::SubprojectNamedAssociation
# Make sure each journaled model instance only has unique version ids
validates :version, uniqueness: { scope: %i[journable_id journable_type] }
diff --git a/app/models/project.rb b/app/models/project.rb
index bacffe15879..56540350b29 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -110,7 +110,7 @@ class Project < ApplicationRecord
register_journal_formatted_fields(:plaintext, 'name')
register_journal_formatted_fields(:diff, 'description')
register_journal_formatted_fields(:visibility, 'public')
- register_journal_formatted_fields(:named_association, 'parent_id') # Replace with custom for parent?
+ register_journal_formatted_fields(:subproject_named_association, 'parent_id') # Replace with custom for parent?
register_journal_formatted_fields(:custom_field, /custom_fields_\d+/)
has_paper_trail
diff --git a/config/locales/en.yml b/config/locales/en.yml
index ed4021634e9..a313782ea87 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -543,6 +543,7 @@ en:
identifier: "Identifier"
latest_activity_at: "Latest activity at"
parent: "Subproject of"
+ parent_without_of: "Subproject"
public_value:
title: "Visibility"
true: "public"
@@ -2844,6 +2845,7 @@ en:
text_journal_changed_with_diff: "%{label} changed (%{link})"
text_journal_deleted: "%{label} deleted (%{old})"
text_journal_deleted_with_diff: "%{label} deleted (%{link})"
+ text_journal_of: "%{label} %{value}"
text_journal_set_to: "%{label} set to %{value}"
text_journal_set_with_diff: "%{label} set (%{link})"
text_journal_label_value: "%{label} %{value}"
diff --git a/lib/open_project/journal_formatter/subproject.rb b/lib/open_project/journal_formatter/subproject_named_association.rb
similarity index 53%
rename from lib/open_project/journal_formatter/subproject.rb
rename to lib/open_project/journal_formatter/subproject_named_association.rb
index 86778f75da3..be0f1bf516b 100644
--- a/lib/open_project/journal_formatter/subproject.rb
+++ b/lib/open_project/journal_formatter/subproject_named_association.rb
@@ -25,14 +25,41 @@
#
# See COPYRIGHT and LICENSE files for more details.
#++
+class OpenProject::JournalFormatter::SubprojectNamedAssociation < JournalFormatter::NamedAssociation
+ private
-class OpenProject::JournalFormatter::Subproject < JournalFormatter::Base
- def render(key, values, options = { html: true })
- # label_text = options[:html] ? content_tag(:strong, label(key)) : label(key)
- # activated_text = values.last ? I18n.t('scheduling.activated') : I18n.t('scheduling.deactivated')
+ def format_details(key, values, cache:)
+ binding.pry
+ if values.first.nil?
+ label = label(key)
+ else
+ label = I18n.t("activerecord.attributes.project.parent_without_of")
+ end
- # I18n.t(:text_journal_label_value, label: label_text, value: activated_text)
+ old_value, value = *format_values(values, key, cache:)
- # Maybe need to revert some of 5570e2c?
+ [label, old_value, value]
+ end
+
+ def render_ternary_detail_text(label, value, old_value, options)
+ binding.pry
+ return I18n.t(:text_journal_deleted, label:, old: old_value) if value.blank?
+ return I18n.t(:text_journal_of, label:, value:) if old_value.blank?
+
+ linebreak = should_linebreak?(old_value.to_s, value.to_s)
+
+ if options[:html]
+ I18n.t(:text_journal_changed_html,
+ label:,
+ linebreak: linebreak ? "<br/>".html_safe : '',
+ old: old_value,
+ new: value)
+ else
+ I18n.t(:text_journal_changed_plain,
+ label:,
+ linebreak: linebreak ? "\n" : '',
+ old: old_value,
+ new: value)
+ end
end
end