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
[57258] Indicate delta in remaining work derived message
Christophe Bliardbeb2e8017441
diff --git a/app/forms/work_packages/progress_form.rb b/app/forms/work_packages/progress_form.rbindex 09e9b71cd7c..b8acd0aaaf4 100644--- a/app/forms/work_packages/progress_form.rb+++ b/app/forms/work_packages/progress_form.rb@@ -183,10 +183,7 @@ class WorkPackages::ProgressForm < ApplicationFormenddef field_hint_message(field_name)- hint = work_package.derived_progress_hints[field_name]- return if hint.nil?-- I18n.t("work_package.progress.derivation_hints.#{field_name}.#{hint}")+ work_package.derived_progress_hint(field_name)&.messageenddef validation_message(name)diff --git a/app/models/work_package.rb b/app/models/work_package.rbindex 859a093eb4d..f7aef89f0ea 100644--- a/app/models/work_package.rb+++ b/app/models/work_package.rb@@ -332,12 +332,12 @@ class WorkPackage < ApplicationRecordwrite_attribute :done_ratio, convert_value_to_percentage(value)end- def derived_progress_hints=(hints)- @derived_progress_hints = hints+ def set_derived_progress_hint(field_name, hint, **params)+ derived_progress_hints[field_name] = ProgressHint.new("#{field_name}.#{hint}", params)end- def derived_progress_hints- @derived_progress_hints ||= {}+ def derived_progress_hint(field_name)+ derived_progress_hints[field_name]enddef duration_in_hours@@ -553,6 +553,10 @@ class WorkPackage < ApplicationRecordprivate+ def derived_progress_hints+ @derived_progress_hints ||= {}+ end+def add_time_entry_for(user, attributes)return if time_entry_blank?(attributes)diff --git a/app/models/work_package/progress_hint.rb b/app/models/work_package/progress_hint.rbnew file mode 100644index 00000000000..9fa24566b3f--- /dev/null+++ b/app/models/work_package/progress_hint.rb@@ -0,0 +1,54 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++# Hint to be displayed in the progress popover under a progress value.+#+# `key` is like `field_name`.`hint` and is used to build up the translation+# key. `params` is the translation parameters as some translation are+# parameterized.+class WorkPackage+ ProgressHint = Data.define(:key, :params) do+ def initialize(key:, params: {})+ super+ end++ def message+ I18n.t("work_package.progress.derivation_hints.#{key}", **to_hours(params))+ end++ def reason+ key.split(".", 2).last+ end++ def to_hours(params)+ params.transform_values { |value| DurationConverter.output(value.abs) }+ end+ end+enddiff --git a/app/services/work_packages/set_attributes_service/derive_progress_values_base.rb b/app/services/work_packages/set_attributes_service/derive_progress_values_base.rbindex c986209c714..3293be1010c 100644--- a/app/services/work_packages/set_attributes_service/derive_progress_values_base.rb+++ b/app/services/work_packages/set_attributes_service/derive_progress_values_base.rb@@ -157,8 +157,8 @@ class WorkPackages::SetAttributesServiceprivate- def set_hint(field, hint)- work_package.derived_progress_hints[field] = hint+ def set_hint(field, hint, **params)+ work_package.set_derived_progress_hint(field, hint, **params)enddef round_progress_valuesdiff --git a/app/services/work_packages/set_attributes_service/derive_progress_values_work_based.rb b/app/services/work_packages/set_attributes_service/derive_progress_values_work_based.rbindex 81a44326c5d..524eaa39fb5 100644--- a/app/services/work_packages/set_attributes_service/derive_progress_values_work_based.rb+++ b/app/services/work_packages/set_attributes_service/derive_progress_values_work_based.rb@@ -100,9 +100,9 @@ class WorkPackages::SetAttributesServiceelsif work_changed? && work_set? && remaining_work_set? && percent_complete_not_provided_by_user?delta = work - work_wasif delta.positive?- set_hint(:remaining_hours, :increased_like_work)+ set_hint(:remaining_hours, :increased_like_work, delta:)elsif delta.negative?- set_hint(:remaining_hours, :decreased_like_work)+ set_hint(:remaining_hours, :decreased_like_work, delta:)endself.remaining_work = (remaining_work + delta).clamp(0.0, work)elsif work_empty?diff --git a/config/locales/en.yml b/config/locales/en.ymlindex d0d10725d37..417a37910c0 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3773,9 +3773,9 @@ en:remaining_hours:cleared_because_work_is_empty: "Cleared because Work is empty."cleared_because_percent_complete_is_empty: "Cleared because % Complete is empty."- decreased_like_work: "Decreased by the same amount as Work."+ decreased_like_work: "Decreased by %{delta}, matching the reduction in Work."derived: "Derived from Work and % Complete."- increased_like_work: "Increased by the same amount as Work."+ increased_like_work: "Increased by %{delta}, matching the increase in Work."same_as_work: "Set to same value as Work."permissions:comment: "Comment"diff --git a/spec/features/work_packages/progress_modal_spec.rb b/spec/features/work_packages/progress_modal_spec.rbindex b51737261e0..9f07cedcc9f 100644--- a/spec/features/work_packages/progress_modal_spec.rb+++ b/spec/features/work_packages/progress_modal_spec.rb@@ -436,6 +436,8 @@ RSpec.describe "Progress modal", :js, :with_cuprite,progress_popover.openprogress_popover.set_values(work: "")progress_popover.expect_values(remaining_work: "")+ progress_popover.expect_hints(remaining_work: :cleared_because_work_is_empty,+ percent_complete: nil)endspecify "Case 2: when work is set to 12h, " \@@ -447,9 +449,13 @@ RSpec.describe "Progress modal", :js, :with_cuprite,progress_popover.openprogress_popover.set_values(work: "12")progress_popover.expect_values(remaining_work: "6h")+ progress_popover.expect_hints(remaining_work: { increased_like_work: { delta: 2 } },+ percent_complete: :derived)progress_popover.set_values(work: "14")progress_popover.expect_values(remaining_work: "8h")+ progress_popover.expect_hints(remaining_work: { increased_like_work: { delta: 4 } },+ percent_complete: :derived)endspecify "Case 3: when work is set to 2h, " \@@ -461,9 +467,13 @@ RSpec.describe "Progress modal", :js, :with_cuprite,progress_popover.openprogress_popover.set_values(work: "2")progress_popover.expect_values(remaining_work: "0h")+ progress_popover.expect_hints(remaining_work: { decreased_like_work: { delta: -8 } },+ percent_complete: :derived)progress_popover.set_values(work: "12")progress_popover.expect_values(remaining_work: "6h")+ progress_popover.expect_hints(remaining_work: { increased_like_work: { delta: 2 } },+ percent_complete: :derived)endspecify "Case 23-7: when remaining work or % complete are set, work never " \@@ -473,12 +483,21 @@ RSpec.describe "Progress modal", :js, :with_cuprite,progress_popover.openprogress_popover.set_values(remaining_work: "2h")progress_popover.expect_values(work: "10h", percent_complete: "80%")+ progress_popover.expect_hints(work: nil,+ remaining_work: nil,+ percent_complete: :derived)progress_popover.set_values(percent_complete: "50%")progress_popover.expect_values(work: "10h", remaining_work: "5h")+ progress_popover.expect_hints(work: nil,+ remaining_work: :derived,+ percent_complete: nil)progress_popover.set_values(remaining_work: "9h")progress_popover.expect_values(work: "10h", percent_complete: "10%")+ progress_popover.expect_hints(work: nil,+ remaining_work: nil,+ percent_complete: :derived)end# scenario from https://community.openproject.org/wp/57370@@ -490,11 +509,17 @@ RSpec.describe "Progress modal", :js, :with_cuprite,# clear workprogress_popover.set_values(work: "")progress_popover.expect_values(work: "", remaining_work: "", percent_complete: "60%")+ progress_popover.expect_hints(work: nil,+ remaining_work: :cleared_because_work_is_empty,+ percent_complete: nil)# set remaining workprogress_popover.set_values(remaining_work: "8h")# work is derivedprogress_popover.expect_values(work: "20h", remaining_work: "8h", percent_complete: "60%")+ progress_popover.expect_hints(work: :derived,+ remaining_work: nil,+ percent_complete: nil)end# scenario from https://community.openproject.org/wp/57370@@ -506,11 +531,17 @@ RSpec.describe "Progress modal", :js, :with_cuprite,# clear workprogress_popover.set_values(remaining_work: "")progress_popover.expect_values(work: "", remaining_work: "", percent_complete: "60%")+ progress_popover.expect_hints(work: :cleared_because_remaining_work_is_empty,+ remaining_work: nil,+ percent_complete: nil)- # set remaining work+ # set workprogress_popover.set_values(work: "20h")- # => work is derived+ # => remaining work is derivedprogress_popover.expect_values(work: "20h", remaining_work: "8h", percent_complete: "60%")+ progress_popover.expect_hints(work: nil,+ remaining_work: :derived,+ percent_complete: nil)end# scenario from https://community.openproject.org/wp/57370@@ -522,11 +553,17 @@ RSpec.describe "Progress modal", :js, :with_cuprite,# clear work and % completeprogress_popover.set_values(work: "", percent_complete: "")progress_popover.expect_values(work: "", remaining_work: "4h", percent_complete: "")+ progress_popover.expect_hints(work: nil,+ remaining_work: nil,+ percent_complete: nil)# set workprogress_popover.set_values(work: "20h")# => % complete is derivedprogress_popover.expect_values(work: "20h", remaining_work: "4h", percent_complete: "80%")+ progress_popover.expect_hints(work: nil,+ remaining_work: nil,+ percent_complete: :derived)end# scenario from https://community.openproject.org/wp/57370@@ -568,9 +605,15 @@ RSpec.describe "Progress modal", :js, :with_cuprite,progress_popover.openprogress_popover.set_values(remaining_work: "2h", percent_complete: "50%")progress_popover.expect_values(work: "4h")+ progress_popover.expect_hints(work: :derived,+ remaining_work: nil,+ percent_complete: nil)progress_popover.set_values(remaining_work: "10h")progress_popover.expect_values(work: "20h")+ progress_popover.expect_hints(work: :derived,+ remaining_work: nil,+ percent_complete: nil)end# scenario from https://community.openproject.org/wp/57370@@ -581,12 +624,21 @@ RSpec.describe "Progress modal", :js, :with_cuprite,progress_popover.openprogress_popover.set_values(percent_complete: "40%")progress_popover.expect_values(work: "", remaining_work: "", percent_complete: "40%")+ progress_popover.expect_hints(work: nil,+ remaining_work: nil,+ percent_complete: nil)progress_popover.set_values(remaining_work: "60h")progress_popover.expect_values(work: "100h", remaining_work: "60h", percent_complete: "40%")+ progress_popover.expect_hints(work: :derived,+ remaining_work: nil,+ percent_complete: nil)progress_popover.set_values(percent_complete: "80%")progress_popover.expect_values(work: "300h", remaining_work: "60h", percent_complete: "80%")+ progress_popover.expect_hints(work: :derived,+ remaining_work: nil,+ percent_complete: nil)endenddiff --git a/spec/models/work_package/progress_hint_spec.rb b/spec/models/work_package/progress_hint_spec.rbnew file mode 100644index 00000000000..2eb6c0bdb2f--- /dev/null+++ b/spec/models/work_package/progress_hint_spec.rb@@ -0,0 +1,73 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 "rails_helper"++RSpec.describe WorkPackage::ProgressHint, :aggreagate_failures do+ describe "#message" do+ it "returns the translated human message for a progress hint" do+ hint = described_class.new("remaining_hours.derived")+ expect(hint.message).to eq("Derived from Work and % Complete.")++ hint = described_class.new("done_ratio.derived")+ expect(hint.message).to eq("Derived from Work and Remaining work.")+ end++ it "converts parameter values to hours formatted according to setting" do+ hint = described_class.new("remaining_hours.increased_like_work", { delta: 2 })+ expect(hint.message).to eq("Increased by 2h, matching the increase in Work.")++ hint = described_class.new("remaining_hours.increased_like_work", { delta: 15.5 })+ expect(hint.message).to eq("Increased by 15.5h, matching the increase in Work.")++ hint = described_class.new("remaining_hours.decreased_like_work", { delta: -24 })+ expect(hint.message).to eq("Decreased by 24h, matching the reduction in Work.")++ with_settings(duration_format: "days_and_hours") do+ hint = described_class.new("remaining_hours.increased_like_work", { delta: 2 })+ expect(hint.message).to eq("Increased by 2h, matching the increase in Work.")++ hint = described_class.new("remaining_hours.increased_like_work", { delta: 15.5 })+ expect(hint.message).to eq("Increased by 1d 7.5h, matching the increase in Work.")++ hint = described_class.new("remaining_hours.decreased_like_work", { delta: -24 })+ expect(hint.message).to eq("Decreased by 3d, matching the reduction in Work.")+ end+ end++ it "rounds parameter values to 2 decimals" do+ hint = described_class.new("remaining_hours.increased_like_work", { delta: 0.995 })+ expect(hint.message).to eq("Increased by 1h, matching the increase in Work.")++ hint = described_class.new("remaining_hours.decreased_like_work", { delta: -100.004 })+ expect(hint.message).to eq("Decreased by 100h, matching the reduction in Work.")+ end+ end+enddiff --git a/spec/services/work_packages/set_attributes_service/derive_progress_values_work_based_spec.rb b/spec/services/work_packages/set_attributes_service/derive_progress_values_work_based_spec.rbindex ea32ec24b68..7cd47e90b1e 100644--- a/spec/services/work_packages/set_attributes_service/derive_progress_values_work_based_spec.rb+++ b/spec/services/work_packages/set_attributes_service/derive_progress_values_work_based_spec.rb@@ -123,7 +123,7 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBasedinclude_examples "update progress values",description: "remaining work is increased by the same amount, and % complete is derived",expected_hints: {- remaining_work: :increased_like_work,+ remaining_work: { increased_like_work: { delta: 10 } },percent_complete: :derived}end@@ -137,7 +137,7 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBasedinclude_examples "update progress values",description: "remaining work is set to 0h and % Complete is cleared",expected_hints: {- remaining_work: :decreased_like_work,+ remaining_work: { decreased_like_work: { delta: -10 } },percent_complete: :cleared_because_work_is_0h}end@@ -151,7 +151,7 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBasedinclude_examples "update progress values",description: "work and remaining work are set to 0h (rounded) and % Complete is cleared",expected_hints: {- remaining_work: :decreased_like_work,+ remaining_work: { decreased_like_work: { delta: -9.9951 } },percent_complete: :cleared_because_work_is_0h}end@@ -190,7 +190,7 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBasedinclude_examples "update progress values",description: "remaining work is decreased by the same amount, and % complete is derived",expected_hints: {- remaining_work: :decreased_like_work,+ remaining_work: { decreased_like_work: { delta: -2 } },percent_complete: :derived}end@@ -205,7 +205,7 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBasedinclude_examples "update progress values",description: "remaining work becomes 0h, and % complete becomes 100%",expected_hints: {- remaining_work: :decreased_like_work,+ remaining_work: { decreased_like_work: { delta: -8 } },percent_complete: :derived}end@@ -710,7 +710,7 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBasedinclude_examples "update progress values",description: "remaining work is increased like work, and % complete is set to 0%",expected_hints: {- remaining_hours: :increased_like_work,+ remaining_hours: { increased_like_work: { delta: 5 } },percent_complete: :derived}enddiff --git a/spec/services/work_packages/set_attributes_service/shared_examples.rb b/spec/services/work_packages/set_attributes_service/shared_examples.rbindex 7598a3605aa..8901ea74ee0 100644--- a/spec/services/work_packages/set_attributes_service/shared_examples.rb+++ b/spec/services/work_packages/set_attributes_service/shared_examples.rb@@ -60,6 +60,19 @@ RSpec.shared_examples_for "update progress values" do |description:, expected_hidescribed_class.new(work_package).callend+ def compact_progress_hints(work_package)+ %i[estimated_hours remaining_hours done_ratio]+ .index_with { |field_name| work_package.derived_progress_hint(field_name) }+ .compact+ .to_h do |field_name, progress_hint|+ if progress_hint.params.none?+ [field_name, progress_hint.reason.to_sym]+ else+ [field_name, { progress_hint.reason.to_sym => progress_hint.params }]+ end+ end+ end+it description dowork_package.attributes = set_attributesall_expected_attributes = {}@@ -81,7 +94,7 @@ RSpec.shared_examples_for "update progress values" do |description:, expected_hiexpect(work_package).to have_attributes(set_attributes.except(*all_expected_attributes.keys))if expected_hintsexpected_hints = expected_hints.transform_keys { to_work_package_field(_1) }- expect(work_package.derived_progress_hints).to eq(expected_hints)+ expect(compact_progress_hints(work_package)).to eq(expected_hints)end# work package is not saved and no errors are createdexpect(work_package).not_to have_received(:save)diff --git a/spec/support/components/work_packages/progress_popover.rb b/spec/support/components/work_packages/progress_popover.rbindex d1c8f5b2025..968018f2624 100644--- a/spec/support/components/work_packages/progress_popover.rb+++ b/spec/support/components/work_packages/progress_popover.rb@@ -135,8 +135,17 @@ module Componentsenddef expect_hint(field_name, hint)- expected_caption = hint && I18n.t("work_package.progress.derivation_hints.#{wp_field_name(field_name)}.#{hint}")- field(field_name).expect_caption(expected_caption)+ progress_hint =+ case hint+ when nil+ nil+ when Symbol+ WorkPackage::ProgressHint.new("#{wp_field_name(field_name)}.#{hint}")+ when Hash+ hint, params = hint.first+ WorkPackage::ProgressHint.new("#{wp_field_name(field_name)}.#{hint}", params)+ end+ field(field_name).expect_caption(progress_hint&.message)enddef expect_hints(**field_hint_pairs)