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
Render Project status on activities
Aaron Contreras29cd71645bf9
diff --git a/app/models/journal.rb b/app/models/journal.rbindex 3799827e5fb..9fc5fcbffd5 100644--- a/app/models/journal.rb+++ b/app/models/journal.rb@@ -41,6 +41,7 @@ class Journal < ApplicationRecordregister_journal_formatter :schedule_manually, OpenProject::JournalFormatter::ScheduleManuallyregister_journal_formatter :ignore_non_working_days, OpenProject::JournalFormatter::IgnoreNonWorkingDaysregister_journal_formatter :active_status, OpenProject::JournalFormatter::ActiveStatus+ register_journal_formatter :project_status_code, OpenProject::JournalFormatter::ProjectStatusCoderegister_journal_formatter :template, OpenProject::JournalFormatter::Templateregister_journal_formatter :visibility, OpenProject::JournalFormatter::Visibilityregister_journal_formatter :subproject_named_association, OpenProject::JournalFormatter::SubprojectNamedAssociationdiff --git a/app/models/project.rb b/app/models/project.rbindex 4478c620495..65fee13a900 100644--- a/app/models/project.rb+++ b/app/models/project.rb@@ -107,6 +107,7 @@ class Project < ApplicationRecordregister_journal_formatted_fields(:plaintext, 'identifier')register_journal_formatted_fields(:plaintext, 'name')register_journal_formatted_fields(:diff, 'description')+ register_journal_formatted_fields(:project_status_code, 'status_code')register_journal_formatted_fields(:visibility, 'public')register_journal_formatted_fields(:subproject_named_association, 'parent_id')register_journal_formatted_fields(:custom_field, /custom_fields_\d+/)diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 162ef8bf790..3ab831b9b1d 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -551,7 +551,7 @@ en:true: "public"false: "private"queries: "Queries"- status_code: 'Status'+ status_code: 'Project status'status_explanation: 'Status description'status_codes:not_started: 'Not started'diff --git a/lib/open_project/journal_formatter/project_status_code.rb b/lib/open_project/journal_formatter/project_status_code.rbnew file mode 100644index 00000000000..2fbe084d9be--- /dev/null+++ b/lib/open_project/journal_formatter/project_status_code.rb@@ -0,0 +1,45 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++class OpenProject::JournalFormatter::ProjectStatusCode < JournalFormatter::Attribute+ private++ def format_values(values)+ values.map do |value|+ if value.nil?+ ''+ else+ I18n.t("activerecord.attributes.project.status_codes.#{status_code_key_for(value)}")+ end+ end+ end++ def status_code_key_for(value)+ Project.status_codes.key(value)+ end+enddiff --git a/spec/features/activities/project_attributes_activity_spec.rb b/spec/features/activities/project_attributes_activity_spec.rbindex 8883c291e1e..5012968b414 100644--- a/spec/features/activities/project_attributes_activity_spec.rb+++ b/spec/features/activities/project_attributes_activity_spec.rb@@ -57,6 +57,7 @@ describe 'Project attributes activities' donew_project_attributes = {name: 'a new project name',description: 'a new project description',+ status_code: 'on_track',public: true,parent: nil,identifier: 'a-new-project-name',@@ -88,6 +89,7 @@ describe 'Project attributes activities' do# own fieldsexpect(page).to have_selector('li', text: "Name changed from #{previous_project_attributes['name']} to #{project.name}")expect(page).to have_selector('li', text: 'Description set (Details)')+ expect(page).to have_selector('li', text: "Project status set to On track")expect(page).to have_selector('li', text: 'Visibility set to public')expect(page).to have_selector('li', text: "No longer subproject of #{parent_project.name}")expect(page).to have_selector('li', text: 'Project unarchived')diff --git a/spec/lib/journal_formatter/project_status_code_spec.rb b/spec/lib/journal_formatter/project_status_code_spec.rbnew file mode 100644index 00000000000..4005d911666--- /dev/null+++ b/spec/lib/journal_formatter/project_status_code_spec.rb@@ -0,0 +1,81 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'++RSpec.describe OpenProject::JournalFormatter::ProjectStatusCode do+ def status_code_as_integer(status)+ Project.status_codes.fetch(status, nil)+ end++ describe '#render' do+ let(:journal) { build_stubbed(:project_journal) }+ let(:instance) { described_class.new(journal) }+ let(:status_code_key) { 'status_code' }++ context 'when setting a status' do+ let(:old_value) { nil }+ let(:new_value) { status_code_as_integer('off_track') }+ let(:expected) do+ I18n.t(:text_journal_set_to,+ label: "<strong>Project status</strong>",+ value: "<i>Off track</i>")+ end++ it { expect(instance.render(status_code_key, [old_value, new_value])).to eq(expected) }+ end++ context 'when deleting a status' do+ let(:old_value) { status_code_as_integer('discontinued') }+ let(:new_value) { nil }+ let(:expected) do+ I18n.t(:text_journal_deleted,+ label: "<strong>Project status</strong>",+ old: "<strike><i>Discontinued</i></strike>")+ end++ it { expect(instance.render(status_code_key, [old_value, new_value])).to eq(expected) }+ end++ context 'when modifying a status' do+ let(:old_value) { status_code_as_integer('off_track') }+ let(:new_value) { status_code_as_integer('on_track') }+ let(:expected) do+ I18n.t(:text_journal_changed_plain,+ label: "<strong>Project status</strong>",+ linebreak: nil,+ old: "<i>Off track</i>",+ new: "<i>On track</i>")+ end++ it { expect(instance.render(status_code_key, [old_value, new_value])).to eq(expected) }+ end+ end+end