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
refactor: use more conventional way to render the progress modal
Christophe Bliardc033715f5163
diff --git a/app/components/work_packages/progress/base_modal_component.rb b/app/components/work_packages/progress/base_modal_component.rbindex c5c957751e5..e63d03d379f 100644--- a/app/components/work_packages/progress/base_modal_component.rb+++ b/app/components/work_packages/progress/base_modal_component.rb@@ -33,6 +33,7 @@ module WorkPackages# rubocop:disable OpenProject/AddPreviewForViewComponentclass BaseModalComponent < ApplicationComponent# rubocop:enable OpenProject/AddPreviewForViewComponent+ include OpTurbo::StreamableFIELD_MAP = {"estimatedTime" => :estimated_hours,diff --git a/app/components/work_packages/progress/status_based/modal_body_component.html.erb b/app/components/work_packages/progress/status_based/modal_body_component.html.erbindex 216aa755e12..4a450a6ae7c 100644--- a/app/components/work_packages/progress/status_based/modal_body_component.html.erb+++ b/app/components/work_packages/progress/status_based/modal_body_component.html.erb@@ -1,4 +1,4 @@-<%= turbo_frame_tag "work_package_progress_modal" do %>+<%= component_wrapper do %><%= primer_form_with(model: work_package,url: submit_path,diff --git a/app/components/work_packages/progress/work_based/modal_body_component.html.erb b/app/components/work_packages/progress/work_based/modal_body_component.html.erbindex 62501f7aac8..a7f60117026 100644--- a/app/components/work_packages/progress/work_based/modal_body_component.html.erb+++ b/app/components/work_packages/progress/work_based/modal_body_component.html.erb@@ -1,4 +1,4 @@-<%= turbo_frame_tag "work_package_progress_modal" do %>+<%= component_wrapper do %><%= primer_form_with(model: work_package,url: submit_path,diff --git a/app/controllers/work_packages/progress_controller.rb b/app/controllers/work_packages/progress_controller.rbindex 676fd79e928..127ce1d74d7 100644--- a/app/controllers/work_packages/progress_controller.rb+++ b/app/controllers/work_packages/progress_controller.rb@@ -29,6 +29,8 @@# ++class WorkPackages::ProgressController < ApplicationController+ include OpTurbo::ComponentStream+ERROR_PRONE_ATTRIBUTES = %i[status_idestimated_hoursremaining_hours@@ -41,17 +43,27 @@ class WorkPackages::ProgressController < ApplicationControllermake_fake_initial_work_packageset_progress_attributes_to_work_package- render progress_modal_component+ render_modalenddef editfind_work_packageset_progress_attributes_to_work_package- render progress_modal_component+ render_modal+ end++ def preview+ if params[:work_package_id]+ find_work_package+ else+ make_fake_initial_work_package+ end++ set_progress_attributes_to_work_package+ render_modalend- # rubocop:disable Metrics/AbcSizedef createmake_fake_initial_work_packageservice_call = set_progress_attributes_to_work_package@@ -61,13 +73,16 @@ class WorkPackages::ProgressController < ApplicationController.intersect?(ERROR_PRONE_ATTRIBUTES)respond_to do |format|format.turbo_stream do+ update_via_turbo_stream(+ component: progress_modal_component,+ method: "morph"+ )+# Bundle 422 status code into stream response so# Angular has context as to the success or failure of# the request in order to fetch the new set of Work Package# attributes in the ancestry solely on success.- render turbo_stream: [- turbo_stream.morph("work_package_progress_modal", progress_modal_component)- ], status: :unprocessable_entity+ respond_with_turbo_streams(status: :unprocessable_entity)endendelse@@ -76,7 +91,6 @@ class WorkPackages::ProgressController < ApplicationControllerpercentageDone: @work_package.done_ratio }endend- # rubocop:enable Metrics/AbcSizedef updatefind_work_package@@ -86,21 +100,20 @@ class WorkPackages::ProgressController < ApplicationController.call(work_package_progress_params)if service_call.success?- respond_to do |format|- format.turbo_stream do- render turbo_stream: []- end- end+ head :okelserespond_to do |format|format.turbo_stream do+ update_via_turbo_stream(+ component: progress_modal_component,+ method: "morph"+ )+# Bundle 422 status code into stream response so# Angular has context as to the success or failure of# the request in order to fetch the new set of Work Package# attributes in the ancestry solely on success.- render turbo_stream: [- turbo_stream.morph("work_package_progress_modal", progress_modal_component)- ], status: :unprocessable_entity+ respond_with_turbo_streams(status: :unprocessable_entity)endendend@@ -108,6 +121,13 @@ class WorkPackages::ProgressController < ApplicationControllerprivate+ def render_modal+ render :modal,+ locals: {+ progress_modal_component:+ }+ end+def progress_modal_componentmodal_class.new(@work_package, focused_field:, touched_field_map:)enddiff --git a/app/views/work_packages/progress/modal.html.erb b/app/views/work_packages/progress/modal.html.erbnew file mode 100644index 00000000000..759657f59b0--- /dev/null+++ b/app/views/work_packages/progress/modal.html.erb@@ -0,0 +1,5 @@+<%=+ turbo_frame_tag("work_package_progress_modal") do+ render(progress_modal_component)+ end+%>diff --git a/spec/controllers/work_packages/progress_controller_spec.rb b/spec/controllers/work_packages/progress_controller_spec.rbindex 88f05a16cd0..448c0584d40 100644--- a/spec/controllers/work_packages/progress_controller_spec.rb+++ b/spec/controllers/work_packages/progress_controller_spec.rb@@ -69,7 +69,7 @@ RSpec.describe WorkPackages::ProgressController doparams["work_package"]["remaining_hours"] = "3"params["work_package"]["remaining_hours_touched"] = "true"- get("new", params:, as: :turbo_stream)+ get("new", params:)assigned_work_package = assigns(:work_package)expect(assigned_work_package).to be_new_record@@ -88,7 +88,7 @@ RSpec.describe WorkPackages::ProgressController doparams["work_package"]["remaining_hours"] = "3"params["work_package"]["remaining_hours_touched"] = "true"- get("new", params:, as: :turbo_stream)+ get("new", params:)assigned_work_package = assigns(:work_package)expect(progress_errors(assigned_work_package)).to match(@@ -106,7 +106,7 @@ RSpec.describe WorkPackages::ProgressController doparams["work_package"]["remaining_hours"] = "3"params["work_package"]["remaining_hours_touched"] = "true"- get("new", params:, as: :turbo_stream)+ get("new", params:)assigned_work_package = assigns(:work_package)expect(progress_errors(assigned_work_package)).to be_empty@@ -133,7 +133,7 @@ RSpec.describe WorkPackages::ProgressController doparams["work_package"]["estimated_hours"] = "50h"params["work_package"]["estimated_hours_touched"] = "true"- get("edit", params:, as: :turbo_stream)+ get("edit", params:)assigned_work_package = assigns(:work_package)expect(assigned_work_package.estimated_hours).to eq(50)@@ -151,7 +151,7 @@ RSpec.describe WorkPackages::ProgressController doparams["work_package"]["estimated_hours"] = "50h"params["work_package"]["estimated_hours_touched"] = "true"- get("edit", params:, as: :turbo_stream)+ get("edit", params:)assigned_work_package = assigns(:work_package)expect(progress_errors(assigned_work_package)).to be_empty@@ -167,7 +167,7 @@ RSpec.describe WorkPackages::ProgressController doparams["work_package"]["estimated_hours"] = "50h"params["work_package"]["estimated_hours_touched"] = "true"- get("edit", params:, as: :turbo_stream)+ get("edit", params:)assigned_work_package = assigns(:work_package)expect(progress_errors(assigned_work_package)).to match(