Skip to content

Commit

Permalink
Fix modal rendering for new work packages
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-contreras committed Apr 19, 2024
1 parent da1b482 commit 003bd67
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
66 changes: 45 additions & 21 deletions app/controllers/work_packages/progress_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],

Check notice

Code scanning / Brakeman

Render path contains parameter value. Note

Render path contains parameter value.
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],

Check notice

Code scanning / Brakeman

Render path contains parameter value. Note

Render path contains parameter value.
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_work_package

if service_call.errors
.map(&:attribute)
Expand All @@ -75,7 +81,7 @@ def update
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|
Expand Down Expand Up @@ -110,13 +116,19 @@ def set_work_package
@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
Expand All @@ -130,33 +142,45 @@ def allowed_params
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)
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@
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,
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/core/path-helper/path-helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}

Expand Down

0 comments on commit 003bd67

Please sign in to comment.