forgeplus/app/controllers/action/node_inputs_controller.rb

90 lines
2.6 KiB
Ruby
Raw Permalink Normal View History

2024-05-07 14:08:46 +08:00
class Action::NodeInputsController < ApplicationController
2025-09-10 15:45:40 +08:00
# before_action :require_admin, except: [:index]
2024-05-07 14:08:46 +08:00
before_action :find_action_node
def index
@node_inputs = @node.action_node_inputs
respond_to do |format|
format.html
2025-01-02 14:43:11 +08:00
format.json{ render_ok(data: @node_inputs.as_json) }
2024-05-07 14:08:46 +08:00
end
end
def create
@node_input = Action::NodeInput.new(node_input_params)
@node_input.action_node = @node
respond_to do |format|
if @node_input.save!
2024-05-07 14:08:46 +08:00
format.html { redirect_to action_node_node_inputs_path(@node), notice: '创建成功.' }
format.json { render_ok(data: @node_input.as_json) }
else
format.html { render :new }
format.json { render json: @node_input.errors, status: -1 }
end
end
end
def new
end
def show
end
def edit
end
def update
@node_input.attributes = node_input_params
2024-05-07 14:08:46 +08:00
respond_to do |format|
2025-09-28 11:00:28 +08:00
if @node_input.save!
format.html { redirect_to action_node_node_inputs_path(@node), notice: '更新成功.' }
format.json { render_ok(data: @node_input.as_json) }
else
format.html { render :edit }
format.json { render json: @node_input.errors, status: -1 }
end
2024-05-07 14:08:46 +08:00
end
end
def destroy
if @node_input.destroy!
flash[:success] = '删除成功'
else
flash[:danger] = '删除失败'
end
2025-09-10 15:45:40 +08:00
respond_to do |format|
format.html { redirect_to action_nodes_path }
format.json { render_ok() }
end
2024-05-07 14:08:46 +08:00
end
private
def find_action_node
@node = Action::Node.find(params[:node_id])
if params[:id].present?
@node_input = @node.action_node_inputs.find(params[:id])
else
@node_input = Action::NodeInput.new
end
end
def node_input_params
if params.require(:action_node_input)
params.require(:action_node_input).permit(:name, :type, :input_type, :description, :is_required, :sort_no, :default_value)
2025-10-14 15:55:36 +08:00
elsif params.require(:action_node_inputs_with)
params.require(:action_node_inputs_with).permit(:name, :type, :input_type, :description, :is_required, :sort_no, :default_value)
elsif params.require(:action_node_inputs_env)
params.require(:action_node_inputs_env).permit(:name, :type, :input_type, :description, :is_required, :sort_no, :default_value)
elsif params.require(:action_node_inputs_other)
params.require(:action_node_inputs_other).permit(:name, :type, :input_type, :description, :is_required, :sort_no, :default_value)
2024-05-07 14:08:46 +08:00
else
params.permit(:name, :type, :input_type, :description, :is_required, :sort_no, :default_value)
2024-05-07 14:08:46 +08:00
end
end
end