mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
refactor: extract method respond_with_relations_tab_update
This commit is contained in:
@@ -59,15 +59,7 @@ class WorkPackageRelationsController < ApplicationController
|
||||
service_result = Relations::CreateService.new(user: current_user)
|
||||
.call(create_relation_params)
|
||||
|
||||
if service_result.success?
|
||||
@work_package.reload
|
||||
component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package,
|
||||
relation_to_scroll_to: service_result.result)
|
||||
replace_via_turbo_stream(component:)
|
||||
respond_with_turbo_streams
|
||||
else
|
||||
respond_with_turbo_streams(status: :unprocessable_entity)
|
||||
end
|
||||
respond_with_relations_tab_update(service_result, relation_to_scroll_to: service_result.result)
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -76,30 +68,30 @@ class WorkPackageRelationsController < ApplicationController
|
||||
model: @relation)
|
||||
.call(update_relation_params)
|
||||
|
||||
if service_result.success?
|
||||
@work_package.reload
|
||||
component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package)
|
||||
replace_via_turbo_stream(component:)
|
||||
respond_with_turbo_streams
|
||||
else
|
||||
respond_with_turbo_streams(status: :unprocessable_entity)
|
||||
end
|
||||
respond_with_relations_tab_update(service_result)
|
||||
end
|
||||
|
||||
def destroy
|
||||
service_result = Relations::DeleteService.new(user: current_user, model: @relation).call
|
||||
|
||||
respond_with_relations_tab_update(service_result)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def respond_with_relations_tab_update(service_result, **)
|
||||
if service_result.success?
|
||||
component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package.reload)
|
||||
@work_package.reload
|
||||
component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package, **)
|
||||
replace_via_turbo_stream(component:)
|
||||
render_success_flash_message_via_turbo_stream(message: I18n.t(:notice_successful_update))
|
||||
|
||||
respond_with_turbo_streams
|
||||
else
|
||||
respond_with_turbo_streams(status: :unprocessable_entity)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_work_package
|
||||
@work_package = WorkPackage.find(params[:work_package_id])
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user