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

Fix modal rendering for new work packages

Aaron Contreras80a992e551ba
diff --git a/app/controllers/work_packages/progress_controller.rb b/app/controllers/work_packages/progress_controller.rb
index 8d34771fad6..b55e7369463 100644
--- a/app/controllers/work_packages/progress_controller.rb
+++ b/app/controllers/work_packages/progress_controller.rb
@@ -40,18 +40,24 @@ class WorkPackages::ProgressController < ApplicationController
helper_method :modal_class
+ def new
+ build_up_brand_new_work_package
+
+ render modal_class.new(@work_package,
+ focused_field: params[:field],
+ touched_field_map:)
+ end
+
def edit
- build_up_new_work_package
+ build_up_work_package
render modal_class.new(@work_package,
focused_field: params[:field],
- touched_field_map: params.require(:work_package).permit("estimated_hours_touched",
- "remaining_hours_touched",
- "status_id_touched").to_h)
+ touched_field_map:)
end
def create
- service_call = build_up_new_work_package
+ service_call = build_up_brand_new_work_package
if service_call.errors
.map(&:attribute)
@@ -75,7 +81,7 @@ class WorkPackages::ProgressController < ApplicationController
service_call = WorkPackages::UpdateService
.new(user: current_user,
model: @work_package)
- .call(update_work_package_params)
+ .call(work_package_params)
if service_call.success?
respond_to do |format|
@@ -110,13 +116,19 @@ class WorkPackages::ProgressController < ApplicationController
@work_package = WorkPackage.new
end
+ def touched_field_map
+ params.require(:work_package).permit("estimated_hours_touched",
+ "remaining_hours_touched",
+ "status_id_touched").to_h
+ end
+
def extract_persisted_progress_attributes
@persisted_progress_attributes = @work_package
.attributes
.slice("estimated_hours", "remaining_hours", "status_id")
end
- def update_work_package_params
+ def work_package_params
params.require(:work_package)
.permit(allowed_params)
end
@@ -130,33 +142,45 @@ class WorkPackages::ProgressController < ApplicationController
end
def reject_params_that_dont_differ_from_persisted_values
- update_work_package_params.reject do |key, value|
+ 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 final_params
+ def filtered_work_package_params
{}.tap do |filtered_params|
- if params.require(:work_package)[:estimated_hours_touched] == "true"
- filtered_params[:estimated_hours] = update_work_package_params.fetch("estimated_hours")
- end
+ filtered_params[:estimated_hours] = work_package_params["estimated_hours"] if estimated_hours_touched?
+ filtered_params[:remaining_hours] = work_package_params["remaining_hours"] if remaining_hours_touched?
+ filtered_params[:status_id] = work_package_params["status_id"] if status_id_touched?
+ end
+ end
- if params.require(:work_package)[:remaining_hours_touched] == "true"
- filtered_params[:remaining_hours] = update_work_package_params.fetch("remaining_hours")
- end
+ def estimated_hours_touched?
+ params.require(:work_package)[:estimated_hours_touched] == "true"
+ end
- if params.require(:work_package)[:status_id_touched] == "true"
- filtered_params[:status_id] = update_work_package_params.fetch("status_id")
- end
- end
+ def remaining_hours_touched?
+ params.require(:work_package)[:remaining_hours_touched] == "true"
+ end
+
+ def status_id_touched?
+ params.require(:work_package)[:status_id_touched] == "true"
+ end
+
+ def build_up_work_package
+ WorkPackages::SetAttributesService
+ .new(user: current_user,
+ model: @work_package,
+ contract_class: WorkPackages::CreateContract)
+ .call(filtered_work_package_params)
end
- def build_up_new_work_package
+ def build_up_brand_new_work_package
WorkPackages::SetAttributesService
.new(user: current_user,
model: @work_package,
contract_class: WorkPackages::CreateContract)
- .call(final_params)
+ .call(work_package_params)
end
def formatted_duration(hours)
diff --git a/app/forms/work_packages/progress_form.rb b/app/forms/work_packages/progress_form.rb
index 14d9e3dc068..f6b5c82f14f 100644
--- a/app/forms/work_packages/progress_form.rb
+++ b/app/forms/work_packages/progress_form.rb
@@ -61,6 +61,9 @@ class WorkPackages::ProgressForm < ApplicationForm
render_text_field(group, name: :estimated_hours, label: I18n.t(:label_work))
render_readonly_text_field(group, name: :remaining_hours, label: I18n.t(:label_remaining_work))
+ # Add a hidden field in create forms as the select field is disabled and is otherwise not included in the form payload
+ group.hidden(name: :status_id) if @work_package.new_record?
+
group.hidden(name: :status_id_touched,
value: @touched_field_map["status_id_touched"] || false,
data: { "work-packages--progress--touched-field-marker-target": "touchedFieldInput",
diff --git a/config/routes.rb b/config/routes.rb
index 202af54fff3..6c95f681534 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -523,7 +523,7 @@ Rails.application.routes.draw do
end
end
- resource :progress, only: %i[edit update], controller: "work_packages/progress"
+ resource :progress, only: %i[new edit update], controller: "work_packages/progress"
collection do
resource :progress,
only: :create,
diff --git a/frontend/src/app/core/path-helper/path-helper.service.ts b/frontend/src/app/core/path-helper/path-helper.service.ts
index 74f7cab322f..d3974bc0336 100644
--- a/frontend/src/app/core/path-helper/path-helper.service.ts
+++ b/frontend/src/app/core/path-helper/path-helper.service.ts
@@ -265,6 +265,10 @@ export class PathHelperService {
}
public workPackageProgressModalPath(workPackageId:string|number) {
+ if (workPackageId === 'new') {
+ return `${this.workPackagePath(workPackageId)}/progress/new`;
+ }
+
return `${this.workPackagePath(workPackageId)}/progress/edit`;
}
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts
index 5c320d54c05..202f0cdfecf 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts
@@ -216,6 +216,10 @@ export class ProgressPopoverEditFieldComponent extends ProgressEditFieldComponen
url.searchParams.set('work_package[remaining_hours]', this.formatter(this.resource.remainingTime));
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
url.searchParams.set('work_package[status_id]', this.statusFormatter(this.resource.status?.id as string));
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ if (this.resource?.id === 'new') {
+ url.searchParams.set('work_package[status_id_touched]', 'true');
+ }
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
this.frameSrc = url.toString();