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
Parse and format modal progress fields
Aaron Contrerasec5b0300d666
diff --git a/app/controllers/work_packages/progress_controller.rb b/app/controllers/work_packages/progress_controller.rbindex a1024129733..4c64000f87f 100644--- a/app/controllers/work_packages/progress_controller.rb+++ b/app/controllers/work_packages/progress_controller.rb@@ -130,7 +130,20 @@ class WorkPackages::ProgressController < ApplicationControllerdef work_package_paramsparams.require(:work_package)- .permit(allowed_params)+ .permit(allowed_params).tap do |wp_params|+ if wp_params["estimated_hours"].present?+ wp_params["estimated_hours"] =+ convert_duration_to_hours(wp_params["estimated_hours"])+ end+ if wp_params["remaining_hours"].present?+ wp_params["remaining_hours"] =+ convert_duration_to_hours(wp_params["remaining_hours"])+ end+ end+ end++ def convert_duration_to_hours(duration)+ ChronicDuration.parse(duration, keep_zero: true) / 3600.to_fenddef allowed_params@@ -141,12 +154,6 @@ class WorkPackages::ProgressController < ApplicationControllerendend- def reject_params_that_dont_differ_from_persisted_values- work_package_params.reject do |key, value|- @persisted_progress_attributes[key.to_s].to_f.to_s == value.to_f.to_s- end- end-def filtered_work_package_params{}.tap do |filtered_params|filtered_params[:estimated_hours] = work_package_params["estimated_hours"] if estimated_hours_touched?diff --git a/app/forms/work_packages/progress_form.rb b/app/forms/work_packages/progress_form.rbindex baf36ce3d0e..f74a1ba00d6 100644--- a/app/forms/work_packages/progress_form.rb+++ b/app/forms/work_packages/progress_form.rb@@ -97,7 +97,7 @@ class WorkPackages::ProgressForm < ApplicationFormdef ensure_only_one_error_for_remaining_work_exceeding_workif work_package.errors.added?(:remaining_hours, :cant_exceed_work) &&- work_package.errors.added?(:estimated_hours, :cant_be_inferior_to_remaining_work)+ work_package.errors.added?(:estimated_hours, :cant_be_inferior_to_remaining_work)error_to_delete =if @focused_field == :estimated_hours:remaining_hours@@ -156,8 +156,10 @@ class WorkPackages::ProgressForm < ApplicationFormerrors = @work_package.errors.where(name)if user_value = errors.map { |error| error.options[:value] }.find { !_1.nil? }user_value- else+ elsif name == :done_ratioformat_to_smallest_fractional_part(@work_package.public_send(name))+ else+ format_to_duration(@work_package.public_send(name))endend@@ -167,6 +169,13 @@ class WorkPackages::ProgressForm < ApplicationFormnumber % 1 == 0 ? number.to_i : numberend+ def format_to_duration(number)+ return number if number.nil?++ # Multiply by 3600 to convert hours to seconds+ ChronicDuration.output(number * 3600, keep_zero: true)+ end+def default_field_options(name)data = { "work-packages--progress--preview-progress-target": "progressInput","work-packages--progress--touched-field-marker-target": "progressInput",diff --git a/spec/features/work_packages/progress_modal_spec.rb b/spec/features/work_packages/progress_modal_spec.rbindex fee8996468c..3ce42590614 100644--- a/spec/features/work_packages/progress_modal_spec.rb+++ b/spec/features/work_packages/progress_modal_spec.rb@@ -340,8 +340,7 @@ RSpec.describe "Progress modal", :js, :with_cuprite docontext "with all values set" dobefore { update_work_package_with(work_package, estimated_hours: 10.0, remaining_hours: 2.12345) }- it "populates fields with correctly values formatted " \- "with the minimum fractional part if present, and 2 decimals max" do+ it "populates fields with correctly values formatted" dowork_package_table.visit_query(progress_query)work_package_table.expect_work_package_listed(work_package)@@ -351,8 +350,8 @@ RSpec.describe "Progress modal", :js, :with_cuprite dowork_edit_field.activate!- work_edit_field.expect_modal_field_value("10")- remaining_work_edit_field.expect_modal_field_value("2.12")+ work_edit_field.expect_modal_field_value("10h")+ remaining_work_edit_field.expect_modal_field_value("2h 7m 12s")percent_complete_edit_field.expect_modal_field_value("78", readonly: true)endend@@ -382,10 +381,10 @@ RSpec.describe "Progress modal", :js, :with_cuprite doexpect(work_package.estimated_hours).to eq(2.56)expect(work_package.remaining_hours).to eq(0.28)- # work should be displayed as 2.56, and remaining work as 0.28+ # work should be displayed as "2h 33m 36s", and remaining work as "16m 48s"work_edit_field.activate!- work_edit_field.expect_modal_field_value("2.56")- remaining_work_edit_field.expect_modal_field_value("0.28")+ work_edit_field.expect_modal_field_value("2h 33m 36s")+ remaining_work_edit_field.expect_modal_field_value("16m 48s")endend@@ -534,11 +533,11 @@ RSpec.describe "Progress modal", :js, :with_cuprite dowork_edit_field.set_value("12")page.driver.wait_for_network_idle # Wait for live-update to finish- remaining_work_edit_field.expect_modal_field_value("6")+ remaining_work_edit_field.expect_modal_field_value("6h")work_edit_field.set_value("14")page.driver.wait_for_network_idle # Wait for live-update to finish- remaining_work_edit_field.expect_modal_field_value("8")+ remaining_work_edit_field.expect_modal_field_value("8h")endspecify "Case 3: when work is set to 2h, " \@@ -556,11 +555,11 @@ RSpec.describe "Progress modal", :js, :with_cuprite dowork_edit_field.set_value("2")page.driver.wait_for_network_idle # Wait for live-update to finish- remaining_work_edit_field.expect_modal_field_value("0")+ remaining_work_edit_field.expect_modal_field_value("0h")work_edit_field.set_value("12")page.driver.wait_for_network_idle # Wait for live-update to finish- remaining_work_edit_field.expect_modal_field_value("6")+ remaining_work_edit_field.expect_modal_field_value("6h")endendend