mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
Update the respond_to_with_turbo_streams method to accept a service result too as a response.
This commit is contained in:
@@ -67,7 +67,7 @@ class Admin::CustomFields::CustomFieldProjectsController < ApplicationController
|
||||
)
|
||||
end
|
||||
|
||||
respond_to_with_turbo_streams(status: create_service.success? ? :ok : :unprocessable_entity)
|
||||
respond_to_with_turbo_streams(status: create_service)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -83,7 +83,7 @@ class Admin::CustomFields::CustomFieldProjectsController < ApplicationController
|
||||
)
|
||||
end
|
||||
|
||||
respond_to_with_turbo_streams(status: delete_service.success? ? :ok : :unprocessable_entity)
|
||||
respond_to_with_turbo_streams(status: delete_service)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -123,7 +123,7 @@ module Admin::Settings
|
||||
)
|
||||
end
|
||||
|
||||
respond_to_with_turbo_streams(status: create_service.success? ? :ok : :unprocessable_entity)
|
||||
respond_to_with_turbo_streams(status: create_service)
|
||||
end
|
||||
|
||||
def unlink
|
||||
@@ -139,7 +139,7 @@ module Admin::Settings
|
||||
)
|
||||
end
|
||||
|
||||
respond_to_with_turbo_streams(status: delete_service.success? ? :ok : :unprocessable_entity)
|
||||
respond_to_with_turbo_streams(status: delete_service)
|
||||
end
|
||||
|
||||
def move
|
||||
|
||||
@@ -32,10 +32,25 @@ module OpTurbo
|
||||
module ComponentStream
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
# Builds a turbo stream response block, supports different ways of building response statuses.
|
||||
# It can take a `result` object that will serve as a base for a status, or a `status` symbol
|
||||
# directly.
|
||||
#
|
||||
# @param status [Symbol, ServiceResult, Dry::Monads[:result]] the response status, if a result
|
||||
# object is provided, it is evaluated based on its state. Defaults to `:ok`.
|
||||
# @yield [format] Optional block to handle additional response formats
|
||||
# @yieldparam format [ActionController::MimeResponds::Collector]
|
||||
#
|
||||
def respond_to_with_turbo_streams(status: turbo_status, &format_block)
|
||||
resolved_status = if status.respond_to?(:success?)
|
||||
status.success? ? :ok : :unprocessable_entity
|
||||
else
|
||||
status
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream do
|
||||
render turbo_stream: turbo_streams, status:
|
||||
render turbo_stream: turbo_streams, status: resolved_status
|
||||
end
|
||||
|
||||
yield(format) if format_block
|
||||
|
||||
@@ -81,7 +81,7 @@ module Backlogs
|
||||
)
|
||||
end
|
||||
|
||||
respond_with_turbo_streams(status: call.success? ? :ok : :unprocessable_entity)
|
||||
respond_with_turbo_streams(status: call)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -119,7 +119,7 @@ class TimeEntriesController < ApplicationController
|
||||
errors: call.errors.full_messages.join(", ")))
|
||||
end
|
||||
|
||||
respond_with_turbo_streams(status: call.success? ? :ok : :bad_request)
|
||||
respond_with_turbo_streams(status: call)
|
||||
end
|
||||
|
||||
def destroy # rubocop:disable Metrics/AbcSize
|
||||
@@ -141,7 +141,7 @@ class TimeEntriesController < ApplicationController
|
||||
errors: call.errors.full_messages.join(", ")))
|
||||
end
|
||||
|
||||
respond_with_turbo_streams(status: call.success? ? :ok : :bad_request)
|
||||
respond_with_turbo_streams(status: call)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -60,15 +60,14 @@ module ::Overviews
|
||||
.new(user: current_user, model: @project_phase)
|
||||
.call(permitted_params.project_phase)
|
||||
|
||||
component, status =
|
||||
if service_call.success?
|
||||
[Overviews::ProjectPhases::SidePanelComponent.new(project: @project), :ok]
|
||||
else
|
||||
[Overviews::ProjectPhases::EditComponent.new(service_call.result), :unprocessable_entity]
|
||||
end
|
||||
component = if service_call.success?
|
||||
Overviews::ProjectPhases::SidePanelComponent.new(project: @project)
|
||||
else
|
||||
Overviews::ProjectPhases::EditComponent.new(service_call.result)
|
||||
end
|
||||
|
||||
update_via_turbo_stream(component:)
|
||||
respond_to_with_turbo_streams(status:)
|
||||
respond_to_with_turbo_streams(status: service_call)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
+3
-3
@@ -93,7 +93,7 @@ class Storages::Admin::Storages::ProjectStoragesController < ApplicationControll
|
||||
update_via_turbo_stream(component:, status: :bad_request)
|
||||
end
|
||||
|
||||
respond_with_turbo_streams(status: create_service.success? ? :ok : :unprocessable_entity)
|
||||
respond_with_turbo_streams(status: create_service)
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -108,7 +108,7 @@ class Storages::Admin::Storages::ProjectStoragesController < ApplicationControll
|
||||
update_via_turbo_stream(component:, status: :bad_request)
|
||||
end
|
||||
|
||||
respond_with_turbo_streams(status: update_service.success? ? :ok : :unprocessable_entity)
|
||||
respond_with_turbo_streams(status: update_service)
|
||||
end
|
||||
|
||||
def destroy_confirmation_dialog
|
||||
@@ -136,7 +136,7 @@ class Storages::Admin::Storages::ProjectStoragesController < ApplicationControll
|
||||
)
|
||||
end
|
||||
|
||||
respond_to_with_turbo_streams(status: delete_service.success? ? :ok : :unprocessable_entity)
|
||||
respond_to_with_turbo_streams(status: delete_service)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user