Status transitions editing

This commit is contained in:
2026-04-25 15:37:07 +03:00
parent bf78009df8
commit 2a0a70c290
5 changed files with 65 additions and 2 deletions
@@ -18,12 +18,30 @@ module ProjectAdmin
@form = ProjectAdmin::Workflows::Statuses::BatchUpdate.new(form_params)
if @form.call(@workflow)
redirect_to project_admin_workflow_path(@project, @workflow)
redirect_to(action: :edit_transitions)
else
render :edit
end
end
def edit_transitions
@form = ProjectAdmin::Workflows::Statuses::UpdateTransitions.from_model(@workflow)
end
def batch_update_transitions
form_params = params.expect(workflow: { task_statuses_attributes: [[:id, { next_status_ids: [] }]] })
if form_params[:task_statuses_attributes].respond_to?(:keys)
form_params[:task_statuses_attributes] = form_params[:task_statuses_attributes].values
end
@form = ProjectAdmin::Workflows::Statuses::UpdateTransitions.new(form_params)
if @form.call(@workflow)
redirect_to project_admin_workflow_path(@project, @workflow)
else
render :edit_transitions
end
end
private
def fetch_workflow
+2 -1
View File
@@ -17,7 +17,8 @@ module ProjectAdminHelper
def project_admin_workflow_frame(workflow, &)
links = {
'Data' => edit_project_admin_workflow_path(workflow.project, workflow),
'Statuses' => edit_project_admin_workflow_statuses_path(workflow.project, workflow)
'Statuses' => edit_project_admin_workflow_statuses_path(workflow.project, workflow),
'Transitions' => edit_transitions_project_admin_workflow_statuses_path(workflow.project, workflow)
}
title = "Editing workflow #{workflow.name} for project #{workflow.project.name}"
admin_frame(links, title:, back_path: project_admin_workflow_path(workflow.project, workflow), &)
@@ -0,0 +1,33 @@
# frozen_string_literal: true
module ProjectAdmin
module Workflows
module Statuses
class UpdateTransitions < ApplicationService
class TaskStatus
include ActiveModel::Model
include ActiveModel::Attributes
attribute :id, :integer
attribute :next_status_ids
end
attr_accessor :task_statuses
def self.from_model(workflow)
new(task_statuses_attributes: workflow.task_statuses
.includes(:next_statuses)
.map { |ts| { id: ts.id, next_status_ids: ts.next_status_ids } })
end
def task_statuses_attributes=(attributes)
@task_statuses = Array(attributes).map { |e| TaskStatus.new(e) }
end
def call(workflow)
workflow.update(task_statuses_attributes: task_statuses.map(&:attributes))
end
end
end
end
end
@@ -0,0 +1,9 @@
= project_admin_workflow_frame(@workflow) do
= form_with model: @workflow, scope: :workflow, url: transitions_project_admin_workflow_statuses_path(@project, @workflow), method: :put, data: {'turbo-frame': '_top'} do |f|
= f.fields_for :task_statuses do |tsf|
section
div= task_status_badge tsf.object
div= tsf.collection_checkboxes :next_status_ids, @workflow.task_statuses - [tsf.object], :id, :name
.submit
= f.submit
+2
View File
@@ -25,6 +25,8 @@ Rails.application.routes.draw do
resources :statuses, only: %i[index] do
get :edit, on: :collection
put '/', action: :batch_update, on: :collection
get :edit_transitions, on: :collection
put '/transitions', action: :batch_update_transitions, on: :collection
end
end
end