流水线节点管理和模板管理

This commit is contained in:
xxq250 2024-05-07 14:08:46 +08:00
parent 5a61933857
commit 8ae91ff558
48 changed files with 1348 additions and 9 deletions

View File

@ -0,0 +1,75 @@
class Action::NodeInputsController < ApplicationController
before_action :require_admin, except: [:index]
before_action :find_action_node
def index
@node_inputs = @node.action_node_inputs
respond_to do |format|
format.html
format.json
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
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.update(node_input_params)
respond_to do |format|
format.html { redirect_to action_node_node_inputs_path(@node), notice: '更新成功.' }
format.json { render_ok(data: @node_input.as_json) }
end
end
def destroy
if @node_input.destroy!
flash[:success] = '删除成功'
else
flash[:danger] = '删除失败'
end
redirect_to "api/actions/nodes"
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, :input_type, :description, :is_required, :sort_no)
else
params.permit(:name, :input_type, :description, :is_required, :sort_no)
end
end
end

View File

@ -0,0 +1,76 @@
class Action::NodeSelectsController < ApplicationController
before_action :require_admin, except: [:index]
before_action :find_action_node
def index
@node_selects = @node.action_node_selects
respond_to do |format|
format.html
format.json
end
end
def create
@node_select = Action::NodeSelect.new(node_select_params)
@node_select.action_node = @node
respond_to do |format|
if @node_select.save
format.html { redirect_to action_node_node_selects_path(@node), notice: '创建成功.' }
format.json { render_ok(data: @node_select.as_json) }
else
format.html { render :new }
format.json { render json: @node_select.errors, status: -1 }
end
end
end
def new
end
def show
end
def edit
end
def update
@node_select.update(node_select_params)
respond_to do |format|
format.html { redirect_to action_node_node_selects_path(@node), notice: '更新成功.' }
format.json { render_ok(data: @node_select.as_json) }
end
end
def destroy
if @node_select.destroy!
flash[:success] = '删除成功'
else
flash[:danger] = '删除失败'
end
redirect_to "api/actions/nodes"
end
private
def find_action_node
@node = Action::Node.find(params[:node_id])
if params[:id].present?
@node_select = @node.action_node_selects.find(params[:id])
else
@node_select = Action::NodeSelect.new
end
end
def node_select_params
if params.require(:action_node_select)
params.require(:action_node_select).permit(:name, :val, :val_ext, :description, :sort_no)
else
params.permit(:name, :val, :val_ext, :description, :sort_no)
end
end
end

View File

@ -0,0 +1,64 @@
class Action::NodeTypesController < ApplicationController
before_action :require_admin, except: [:index]
before_action :find_node_type, except: [:index, :create, :new]
def index
@node_types = Action::NodeType.all
end
def create
@node_type = Action::NodeType.new(node_types_params)
respond_to do |format|
if @node_type.save
format.html { redirect_to action_node_types_path, notice: '创建成功.' }
format.json { render_ok(data: @node_type.as_json) }
else
format.html { render :new }
format.json { render json: @node_type.errors, status: -1 }
end
end
end
def show
end
def new
@node_type = Action::NodeType.new
end
def edit
end
def update
@node_type.update(node_types_params)
respond_to do |format|
format.html { redirect_to action_node_types_path, notice: '更新成功.' }
format.json { render_ok(data: @node_type.as_json) }
end
end
def destroy
if @node_type.destroy!
flash[:success] = '删除成功'
else
flash[:danger] = '删除失败'
end
redirect_to action_node_types_path
end
private
def find_node_type
@node_type = Action::NodeType.find(params[:id])
end
def node_types_params
if params.require(:action_node_type)
params.require(:action_node_type).permit(:name, :description, :sort_no)
else
params.permit(:name, :description, :sort_no)
end
end
end

View File

@ -0,0 +1,69 @@
class Action::NodesController < ApplicationController
before_action :require_admin, except: [:index]
before_action :find_action_node, except: [:index, :create, :new]
def index
@node_types = Action::NodeType.all
@no_type_nodes = Action::Node.where(action_node_types_id: nil)
respond_to do |format|
format.html { @nodes = Action::Node.all }
format.json
end
end
def create
@node = Action::Node.new(node_params)
respond_to do |format|
if @node.save
format.html { redirect_to action_nodes_path, notice: '创建成功.' }
format.json { render_ok(data: @node.as_json) }
else
format.html { render :new }
format.json { render json: @node.errors, status: -1 }
end
end
end
def new
@node = Action::Node.new
end
def show
end
def edit
end
def update
@node.update(node_params)
respond_to do |format|
format.html { redirect_to action_nodes_path, notice: '更新成功.' }
format.json { render_ok(data: @node.as_json) }
end
end
def destroy
if @node.destroy!
flash[:success] = '删除成功'
else
flash[:danger] = '删除失败'
end
redirect_to action_nodes_path
end
private
def find_action_node
@node = Action::Node.find(params[:id])
end
def node_params
if params.require(:action_node)
params.require(:action_node).permit(:name, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no)
else
params.permit(:name, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no)
end
end
end

View File

@ -0,0 +1,68 @@
class Action::TemplatesController < ApplicationController
before_action :require_admin, except: [:index]
before_action :find_action_template, except: [:index, :create, :new]
def index
@templates = Action::Template.all
respond_to do |format|
format.html
format.json
end
end
def create
@template = Action::Template.new(templates_params)
respond_to do |format|
if @template.save
format.html { redirect_to action_templates_path, notice: '创建成功.' }
format.json { render_ok(data: @template.as_json) }
else
format.html { render :new }
format.json { render json: @template.errors, status: -1 }
end
end
end
def show
end
def new
@template = Action::Template.new
end
def edit
end
def update
@template.update(templates_params)
respond_to do |format|
format.html { redirect_to action_templates_path, notice: '更新成功.' }
format.json { render_ok(data: @template.as_json) }
end
end
def destroy
if @template.destroy!
flash[:success] = '删除成功'
else
flash[:danger] = '删除失败'
end
redirect_to action_templates_path
end
private
def find_action_template
@template = Action::Template.find(params[:id])
end
def templates_params
if params.require(:action_template)
params.require(:action_template).permit(:name, :description, :img, :sort_no, :json, :yaml)
else
params.permit(:name, :description, :img, :sort_no, :json, :yaml)
end
end
end

View File

@ -0,0 +1,2 @@
module Action::NodeHelper
end

71
app/models/action/node.rb Normal file
View File

@ -0,0 +1,71 @@
# == Schema Information
#
# Table name: action_nodes
#
# id :integer not null, primary key
# name :string(255)
# full_name :string(255)
# description :string(255)
# icon :string(255)
# action_node_types_id :integer
# is_local :boolean default("0")
# local_url :string(255)
# yaml :text(65535)
# sort_no :integer default("0")
# use_count :integer default("0")
# user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_action_nodes_on_action_types_id (action_node_types_id)
# index_action_nodes_on_user_id (user_id)
#
class Action::Node < ApplicationRecord
self.table_name = 'action_nodes'
default_scope { order(sort_no: :asc) }
has_many :action_node_inputs, :class_name => 'Action::NodeInput', foreign_key: "action_nodes_id"
has_many :action_node_selects, :class_name => 'Action::NodeSelect', foreign_key: "action_nodes_id"
belongs_to :action_node_type, :class_name => 'Action::NodeType', foreign_key: "action_node_types_id"
belongs_to :user, optional: true
# def content_yaml
# "foo".to_yaml
# <<~YAML
# - name: Set up JDK ${{ matrix.java }}
# uses: actions/setup-java@v3
# with:
# distribution: 'temurin'
# java-version: ${{ matrix.java }}
# YAML
# end
def yaml_hash
<<~YAML
name: Check dist
on:
push:
branches:
- main
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:
jobs:
call-check-dist:
name: Check dist/
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
with:
node-version: '20.x'
YAML
end
end

View File

@ -0,0 +1,27 @@
# == Schema Information
#
# Table name: action_node_inputs
#
# id :integer not null, primary key
# action_nodes_id :integer
# name :string(255)
# input_type :string(255)
# description :string(255)
# is_required :boolean default("0")
# sort_no :string(255) default("0")
# user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_action_node_inputs_on_action_nodes_id (action_nodes_id)
# index_action_node_inputs_on_user_id (user_id)
#
class Action::NodeInput < ApplicationRecord
self.table_name = 'action_node_inputs'
default_scope { order(sort_no: :asc) }
belongs_to :action_node, :class_name => 'Action::Node', foreign_key: "action_nodes_id"
end

View File

@ -0,0 +1,39 @@
# == Schema Information
#
# Table name: action_node_selects
#
# id :integer not null, primary key
# action_nodes_id :integer
# name :string(255)
# val :string(255)
# val_ext :string(255)
# description :string(255)
# download_url :string(255)
# sort_no :integer default("0")
# use_count :integer default("0")
# user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_action_node_selects_on_action_nodes_id (action_nodes_id)
# index_action_node_selects_on_name (name)
# index_action_node_selects_on_user_id (user_id)
#
class Action::NodeSelect < ApplicationRecord
self.table_name = 'action_node_selects'
default_scope { order(sort_no: :asc) }
belongs_to :action_node, :class_name => 'Action::Node', foreign_key: "action_nodes_id"
belongs_to :user, optional: true
def value
if self.val_ext.blank?
self.val
else
"#{self.val}@#{self.val_ext}"
end
end
end

View File

@ -0,0 +1,18 @@
# == Schema Information
#
# Table name: action_node_types
#
# id :integer not null, primary key
# name :string(255)
# description :string(255)
# sort_no :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class Action::NodeType < ApplicationRecord
self.table_name = 'action_node_types'
default_scope { order(sort_no: :asc) }
has_many :action_nodes, :class_name => 'Action::Node', foreign_key: "action_node_types_id"
end

View File

@ -0,0 +1,20 @@
# == Schema Information
#
# Table name: action_templates
#
# id :integer not null, primary key
# name :string(255)
# description :string(255)
# img :string(255)
# sort_no :string(255) default("0")
# json :text(65535)
# yaml :text(65535)
# created_at :datetime not null
# updated_at :datetime not null
#
class Action::Template < ApplicationRecord
self.table_name = 'action_templates'
default_scope { order(sort_no: :asc) }
end

View File

@ -0,0 +1,39 @@
<%= form_with(model: node_input, url: action_node_node_inputs_path(@node), local: true) do |form| %>
<% if node_input.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(node_input.errors.count, "error") %> prohibited this node_input from being saved:</h2>
<ul>
<% node_input.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :name, "参数名称" %>
<%= form.text_field :name %>
</div>
<div class="field">
<%= form.label :input_type, "参数类型" %>
<%= form.text_field :input_type %>
</div>
<div class="field">
<%= form.label :description, "描述" %>
<%= form.text_area :description, rows: 5, :style => 'width:800px;' %>
</div>
<div class="field">
<%= form.label :is_required, "是否必填项" %>
<%= form.check_box("is_required", {}, "true", "false") %>
</div>
<div class="field">
<%= form.label :sort_no, "排序号" %>
<%= form.text_field :sort_no %>
</div>
<div class="actions" style="margin-top:10px;">
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>-->
<%= form.submit("保存") %>
</div>
<% end %>

View File

@ -0,0 +1,6 @@
json.extract! node_input, :id, :name, :input_type, :description
if node_input.input_type.to_s == "select"
json.select node.action_node_selects do |node_select|
json.partial! "node_select", locals: { node_select: node_select, node: node }
end
end

View File

@ -0,0 +1,4 @@
json.extract! node_select, :id, :version
if node.is_local?
json.local_url node.local_url
end

View File

@ -0,0 +1,47 @@
<h1>编辑
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往定制竞赛管理页面</a>-->
</h1>
<%= form_with(model: @node_input, url: action_node_node_input_path(@node,@node_input), local: true) do |form| %>
<% if @node_input.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@node_input.errors.count, "error") %> prohibited this node_input from being saved:</h2>
<ul>
<% @node_input.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :name, "参数名称" %>
<%= form.text_field :name %>
</div>
<div class="field">
<%= form.label :input_type, "参数类型" %>
<%= form.text_field :input_type %>
</div>
<div class="field">
<%= form.label :description, "描述" %>
<%= form.text_area :description, rows: 5, :style => 'width:800px;' %>
</div>
<div class="field">
<%= form.label :is_required, "是否必填项" %>
<%= form.check_box("is_required", {}, "true", "false") %>
</div>
<div class="field">
<%= form.label :sort_no, "排序号" %>
<%= form.text_field :sort_no %>
</div>
<div class="actions" style="margin-top:10px;">
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>-->
<%= form.submit("保存赛事") %>
</div>
<% end %>
<%= link_to 'Back', action_node_node_inputs_path(@node) %>

View File

@ -0,0 +1,46 @@
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<h1>action 节点参数配置<%= link_to '>>>Back action节点首页', action_nodes_path %>
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点配置</a>-->
</h1>
<p>说明该界面适用于action 节点参数配置</p>
<table border="1">
<thead>
<tr>
<th>ID</th>
<th width="20%">参数名称</th>
<th width="25%">参数输入类型</th>
<th width="20%">参数描述</th>
<th>是否必填项</th>
<th>排序号</th>
<th>更新时间</th>
<th colspan="2">操作</th>
</tr>
</thead>
<!-- :id, :name, :input_type, :description, :sort_no,-->
<tbody>
<% @node_inputs.each do |info| %>
<tr>
<td><%= info.id %></td>
<td><%= info.name %></td>
<td><%= info.input_type %>
<% if info.input_type == "select" %>
<%= select_tag(:version, options_for_select(@node.action_node_selects.map(&:value)), class: 'form-control') %>
<%= link_to '修改选择项', edit_action_node_node_input_path(@node.id, info) %>
<% end %>
</td>
<td><%= info.description %></td>
<td><%= info.is_required %></td>
<td><%= info.sort_no %></td>
<td><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td><%= link_to '编辑', edit_action_node_node_input_path(@node.id, info) %></td>
<td><%= link_to 'Destroy', action_node_node_input_path(@node, info), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to '新增', new_action_node_node_input_path(@node) %>

View File

@ -0,0 +1,20 @@
json.types @node_types.each do |node_type|
if node_type.name.to_s == "未分类"
json.extract! node_type, :id, :name
json.nodes @no_type_nodes do |node|
json.extract! node, :id, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count
json.inputs node.action_node_inputs do |node_input|
json.partial! "node_input", locals: { node_input: node_input, node: node }
end
end
else
json.extract! node_type, :id, :name
json.nodes node_type.action_nodes do |node|
json.extract! node, :id, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count
json.inputs node.action_node_inputs do |node_input|
json.partial! "node_input", locals: { node_input: node_input, node: node }
end
end
end
end

View File

@ -0,0 +1,5 @@
<h1>新增</h1>
<%= render 'form', node_input: @node_input %>
<%= link_to 'Back', action_node_node_inputs_path(@node) %>

View File

@ -0,0 +1,7 @@
json.status 0
json.message "success"
json.extract! @node, :id, :name, :full_name, :description, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no, :use_count
json.inputs @node.action_node_inputs do |node_input|
json.partial! "node_input", locals: { node_input: node_input, node: @node }
end

View File

@ -0,0 +1,39 @@
<%= form_with(model: node_select, url: action_node_node_selects_path(@node), local: true) do |form| %>
<% if node_select.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(node_select.errors.count, "error") %> prohibited this node select from being saved:</h2>
<ul>
<% node_select.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :name, "选择项名称" %>
<%= form.text_field :name %>
</div>
<div class="field">
<%= form.label :val, "选择项值" %>
<%= form.text_field :val %>
</div>
<div class="field">
<%= form.label :val_ext, "选择项值扩展" %>
<%= form.text_field :val_ext %>
</div>
<div class="field">
<%= form.label :description, "描述" %>
<%= form.text_area :description, rows: 5, :style => 'width:800px;' %>
</div>
<div class="field">
<%= form.label :sort_no, "排序号" %>
<%= form.text_field :sort_no %>
</div>
<div class="actions" style="margin-top:10px;">
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>-->
<%= form.submit("保存") %>
</div>
<% end %>

View File

@ -0,0 +1,46 @@
<h1>编辑
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往定制竞赛管理页面</a>-->
</h1>
<%= form_with(model: @node_select, url: action_node_node_select_path(@node,@node_select), local: true) do |form| %>
<% if @node_select.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@node_select.errors.count, "error") %> prohibited this node select from being saved:</h2>
<ul>
<% @node_select.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :name, "选择项名称" %>
<%= form.text_field :name %>
</div>
<div class="field">
<%= form.label :val, "选择项值" %>
<%= form.text_field :val %>
</div>
<div class="field">
<%= form.label :val_ext, "选择项值扩展" %>
<%= form.text_field :val_ext %>
</div>
<div class="field">
<%= form.label :description, "描述" %>
<%= form.text_area :description, rows: 5, :style => 'width:800px;' %>
</div>
<div class="field">
<%= form.label :sort_no, "排序号" %>
<%= form.text_field :sort_no %>
</div>
<div class="actions" style="margin-top:10px;">
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>-->
<%= form.submit("保存") %>
</div>
<% end %>
<%= link_to 'Back', action_node_node_inputs_path(@node) %>

View File

@ -0,0 +1,43 @@
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<h1>action 节点参数配置<%= link_to '>>>Back action节点首页', action_nodes_path %>
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点配置</a>-->
</h1>
<p>说明该界面适用于action 节点参数配置</p>
<table border="1">
<thead>
<tr>
<th>ID</th>
<th width="10%">选择项名称</th>
<th width="10%">选择项值</th>
<th width="10%">选择项值扩展</th>
<th width="15%">描述</th>
<th width="20%">下载地址</th>
<th>排序号</th>
<th>更新时间</th>
<th colspan="2">操作</th>
</tr>
</thead>
<!-- :id, :name, :input_type, :description, :sort_no,-->
<tbody>
<% @node_selects.each do |info| %>
<tr>
<td><%= info.id %></td>
<td><%= info.name %></td>
<td><%= info.val %></td>
<td><%= info.val_ext %></td>
<td><%= info.description %></td>
<td><%= info.download_url %></td>
<td><%= info.sort_no %></td>
<td><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td><%= link_to '编辑', edit_action_node_node_select_path(@node.id, info) %></td>
<td><%= link_to 'Destroy', action_node_node_select_path(@node, info), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to '新增', new_action_node_node_input_path(@node) %>

View File

@ -0,0 +1,5 @@
<h1>新增</h1>
<%= render 'form', node_select: @node_select %>
<%= link_to 'Back', action_node_node_selects_path(@node) %>

View File

@ -0,0 +1,31 @@
<%= form_with(model: node_type, local: true) do |form| %>
<% if node_type.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(node_type.errors.count, "error") %> prohibited this node type from being saved:</h2>
<ul>
<% node_type.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :name, "分类名称" %>
<%= form.text_field :name %>
</div>
<div class="field">
<%= form.label :description, "描述" %>
<%= form.text_area :description, rows: 5, :style => 'width:800px;' %>
</div>
<div class="field">
<%= form.label :sort_no, "排序号" %>
<%= form.text_field :sort_no %>
</div>
<div class="actions" style="margin-top:10px;">
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>-->
<%= form.submit("保存") %>
</div>
<% end %>

View File

@ -0,0 +1,7 @@
<h1>编辑
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往定制竞赛管理页面</a>-->
</h1>
<%= render 'form', node_type: @node_type %>
<%= link_to 'Back', action_node_types_path %>

View File

@ -0,0 +1,37 @@
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<h1>action 节点分类配置<%= link_to '>>>Back action节点首页', action_nodes_path %>
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点配置</a>-->
</h1>
<p>说明该界面适用于action 节点分类配置</p>
<table border="1" width="100%">
<thead>
<tr>
<th>ID</th>
<th width="20%">分类名称</th>
<th width="25%">描述</th>
<th>排序号</th>
<th>更新时间</th>
<th colspan="2">操作</th>
</tr>
</thead>
<!-- :id, :name, :input_type, :description, :sort_no,-->
<tbody>
<% @node_types.each do |info| %>
<tr>
<td><%= info.id %></td>
<td><%= info.name %></td>
<td><%= info.description %></td>
<td><%= info.sort_no %></td>
<td><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td><%= link_to '编辑', edit_action_node_type_path(info) %></td>
<td><%= link_to 'Destroy', action_node_type_path(info), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to '新增', new_action_node_type_path %>

View File

@ -0,0 +1,5 @@
<h1>新增</h1>
<%= render 'form', node_type: @node_type %>
<%= link_to 'Back', action_node_types_path %>

View File

@ -0,0 +1,63 @@
<%= form_with(model: node, local: true) do |form| %>
<%# if node.errors.any? %>
<!-- <div id="error_explanation">-->
<!-- <h2><%#= pluralize(node.errors.count, "error") %> prohibited this node from being saved:</h2>-->
<!-- <ul>-->
<%# node.errors.full_messages.each do |message| %>
<!-- <li><%#= message %></li>-->
<%# end %>
<!-- </ul>-->
<!-- </div>-->
<%# end %>
<div class="form-group ">
<label for="status">类型:</label>
<%= form.select :action_node_types_id, options_for_select(Action::NodeType.all.map { |key| [key.name, key.id]}, node.action_node_types_id), {}, class: "form-control" %>
</div>
<div class="field">
<%= form.label :name, "节点名称" %>
<%= form.text_field :name %>
</div>
<div class="field">
<%= form.label :full_name, "节点全称" %>
<%= form.text_field :full_name %>
</div>
<div class="field">
<%= form.label :description, "描述" %>
<%= form.text_area :description, rows: 5, :style => 'width:800px;' %>
</div>
<div class="field">
<%= form.label :icon, "Icon图标" %>
<%= form.text_field :icon %>
</div>
<div class="field">
<%= form.label :is_local, "是否本地化" %>
<%= form.check_box("is_local", {}, "true", "false") %>
</div>
<div class="field">
<%= form.label :local_url, "本地化地址" %>
<%= form.text_field :local_url, :style => 'width:1200px;' %>
</div>
<div class="field">
<%= form.label :sort_no, "排序号" %>
<%= form.text_field :sort_no %>
</div>
<div class="field">
<%= form.label :yaml, "yaml语法代码" %>
<%= form.text_area :yaml, rows: 5, :style => 'width:1200px;' %>
</div>
<div class="actions" style="margin-top:10px;">
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>-->
<%= form.submit("保存") %>
</div>
<% end %>

View File

@ -0,0 +1,6 @@
json.extract! node_input, :id, :name, :input_type, :description
if node_input.input_type.to_s == "select"
json.select node.action_node_selects do |node_select|
json.partial! "node_select", locals: { node_select: node_select, node: node }
end
end

View File

@ -0,0 +1,4 @@
json.extract! node_select, :id, :val
if node.is_local?
json.local_url node.local_url
end

View File

@ -0,0 +1,7 @@
<h1>编辑
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往定制竞赛管理页面</a>-->
</h1>
<%= render 'form', node: @node %>
<%= link_to 'Back', action_nodes_path %>

View File

@ -0,0 +1,49 @@
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<h1>action 节点配置</h1>
<p><a href="<%= action_node_types_path %>" style="font-size: 14px;">>>前往节点分类配置</a></p>
<p><a href="<%= action_templates_path %>" style="font-size: 14px;">>>前往模板配置</a></p>
<p>说明该界面适用于action 节点配置参数配置</p>
<table border="1" width="100%">
<thead>
<tr>
<th>ID</th>
<th width="15%">节点名称</th>
<th width="20%">节点全称</th>
<th width="20%">节点描述</th>
<th width="10%">分类</th>
<!-- <th>是否本地化</th>-->
<!-- <th>本地化地址</th>-->
<!-- <th>yaml语法代码</th>-->
<th>排序号</th>
<th>更新时间</th>
<th colspan="3">操作</th>
</tr>
</thead>
<!-- :description, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no,-->
<tbody>
<% @nodes.each do |info| %>
<tr>
<td><%= info.id %></td>
<td><%= info.name %></td>
<td><%= info.full_name %></td>
<td><%= info.description %></td>
<td><%= info.action_node_type&.name %></td>
<!-- <td><%#= info.is_local? %></td>-->
<!-- <td><%#= info.local_url %></td>-->
<!-- <td><%#= info.yaml %></td>-->
<td><%= info.sort_no %></td>
<td><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td><%= link_to '编辑', edit_action_node_path(info) %></td>
<td><%= link_to '参数列表', action_node_node_inputs_path(info) %></td>
<td><%= link_to 'Destroy', info, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to '新增', new_action_node_path %>

View File

@ -0,0 +1,20 @@
json.types @node_types.each do |node_type|
if node_type.name.to_s == "未分类"
json.extract! node_type, :id, :name
json.nodes @no_type_nodes do |node|
json.extract! node, :id, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count
json.inputs node.action_node_inputs do |node_input|
json.partial! "node_input", locals: { node_input: node_input, node: node }
end
end
else
json.extract! node_type, :id, :name
json.nodes node_type.action_nodes do |node|
json.extract! node, :id, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count
json.inputs node.action_node_inputs do |node_input|
json.partial! "node_input", locals: { node_input: node_input, node: node }
end
end
end
end

View File

@ -0,0 +1,5 @@
<h1>新增</h1>
<%= render 'form', node: @node %>
<%= link_to 'Back', action_nodes_path %>

View File

@ -0,0 +1,7 @@
json.status 0
json.message "success"
json.extract! @node, :id, :name, :full_name, :description, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no, :use_count
json.inputs @node.action_node_inputs do |node_input|
json.partial! "node_input", locals: { node_input: node_input, node: @node }
end

View File

@ -0,0 +1,43 @@
<%= form_with(model: template, local: true) do |form| %>
<% if template.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(template.errors.count, "error") %> prohibited this node type from being saved:</h2>
<ul>
<% template.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :name, "模板名称" %>
<%= form.text_field :name %>
</div>
<div class="field">
<%= form.label :description, "描述" %>
<%= form.text_area :description, rows: 5, :style => 'width:800px;' %>
</div>
<div class="field">
<%= form.label :img, "配图" %>
<%= form.text_field :img %>
</div>
<div class="field">
<%= form.label :sort_no, "排序号" %>
<%= form.text_field :sort_no %>
</div>
<div class="field">
<%= form.label :yaml, "yaml语法代码" %>
<%= form.text_area :yaml, rows: 5, :style => 'width:1200px;' %>
</div>
<div class="field">
<%= form.label :json, "json语法代码" %>
<%= form.text_area :json, rows: 5, :style => 'width:1200px;' %>
</div>
<div class="actions" style="margin-top:10px;">
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>-->
<%= form.submit("保存") %>
</div>
<% end %>

View File

@ -0,0 +1,6 @@
<h1>编辑
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往定制竞赛管理页面</a>-->
</h1>
<%= render 'form', template: @template %>
<%= link_to 'Back', action_templates_path %>

View File

@ -0,0 +1,37 @@
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<h1>action 模板配置<%= link_to '>>>Back action节点首页', action_nodes_path %>
<!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点配置</a>-->
</h1>
<p>说明该界面适用于action 模板配置</p>
<table border="1" width="100%">
<thead>
<tr>
<th>ID</th>
<th width="20%">模板名称</th>
<th width="25%">描述</th>
<th>排序号</th>
<th>更新时间</th>
<th colspan="2">操作</th>
</tr>
</thead>
<!-- :id, :name, :input_type, :description, :sort_no,-->
<tbody>
<% @templates.each do |info| %>
<tr>
<td><%= info.id %></td>
<td><%= info.name %></td>
<td><%= info.description %></td>
<td><%= info.sort_no %></td>
<td><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td><%= link_to '编辑', edit_action_template_path(info) %></td>
<td><%= link_to 'Destroy', action_template_path(info), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to '新增', new_action_template_path %>

View File

@ -0,0 +1,3 @@
json.templates @templates.each do |tpl|
json.extract! tpl, :id, :name, :description, :img, :sort_no, :json, :yaml
end

View File

@ -0,0 +1,5 @@
<h1>新增</h1>
<%= render 'form', template: @template %>
<%= link_to 'Back', action_templates_path %>

View File

@ -0,0 +1 @@
json.extract! @template, :id, :name, :description, :img, :sort_no, :json, :yaml

View File

@ -510,6 +510,19 @@ Rails.application.routes.draw do
end
end
# scope module: :action do
#
# end
namespace :action do
resources :nodes do
resources :node_inputs
resources :node_selects
end
resources :node_types
resources :templates
end
# Project Area START
scope "/:owner/:repo",constraints: { repo: /[^\/]+/ } do
scope do
@ -1095,15 +1108,15 @@ Rails.application.routes.draw do
resources :sub_repertoires, only: [:index, :create, :edit, :update, :destroy]
resources :tag_repertoires, only: [:index, :create, :edit, :update, :destroy]
resources :salesmans, only: [:index, :create, :edit, :update, :destroy] do
post :batch_add, on: :collection
end
resources :salesman_channels, only: [:index, :create, :edit, :update, :destroy] do
post :batch_add, on: :collection
end
resources :salesman_customers, only: [:index, :create, :edit, :update, :destroy] do
post :batch_add, on: :collection
end
# resources :salesmans, only: [:index, :create, :edit, :update, :destroy] do
# post :batch_add, on: :collection
# end
# resources :salesman_channels, only: [:index, :create, :edit, :update, :destroy] do
# post :batch_add, on: :collection
# end
# resources :salesman_customers, only: [:index, :create, :edit, :update, :destroy] do
# post :batch_add, on: :collection
# end
end

View File

@ -0,0 +1,10 @@
class CreateActionNodeTypes < ActiveRecord::Migration[5.2]
def change
create_table :action_node_types do |t|
t.string :name
t.string :description
t.integer :sort_no, default: 0
t.timestamps
end
end
end

View File

@ -0,0 +1,18 @@
class CreateActionNodes < ActiveRecord::Migration[5.2]
def change
create_table :action_nodes do |t|
t.string :name
t.string :full_name
t.string :description
t.string :icon
t.references :action_node_types
t.boolean :is_local, default: false
t.string :local_url
t.text :yaml
t.integer :sort_no, default: 0
t.integer :use_count, default: 0
t.references :user
t.timestamps
end
end
end

View File

@ -0,0 +1,17 @@
class CreateActionNodeSelects < ActiveRecord::Migration[5.2]
def change
create_table :action_node_selects do |t|
t.references :action_nodes
t.string :name
t.string :val
t.string :val_ext
t.string :description
t.string :download_url
t.integer :sort_no, default: 0
t.integer :use_count, default: 0
t.references :user
t.timestamps
t.index :name
end
end
end

View File

@ -0,0 +1,14 @@
class CreateActionNodeInputs < ActiveRecord::Migration[5.2]
def change
create_table :action_node_inputs do |t|
t.references :action_nodes
t.string :name
t.string :input_type
t.string :description
t.boolean :is_required, default: false
t.string :sort_no, default: 0
t.references :user
t.timestamps
end
end
end

View File

@ -0,0 +1,13 @@
class CreateActionTemplates < ActiveRecord::Migration[5.2]
def change
create_table :action_templates do |t|
t.string :name
t.string :description
t.string :img
t.string :sort_no, default: 0
t.text :json
t.text :yaml
t.timestamps
end
end
end

View File

@ -0,0 +1,82 @@
# actions 下载包
# node go java
namespace :actions_download do
task go: :environment do
# curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=5ccebd935915fb6cfcae634b161047a2&state=open&sort=created&direction=desc&page=1&per_page=10'
# api_url = "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json"
api_url = "https://testgitea2.trustie.net/actions/go-versions/raw/branch/main/versions-manifest.json"
uri = URI.parse(api_url)
response = Net::HTTP.get_response(uri)
puts "gitee api response.code ===== #{response.code}"
lists = JSON.parse(response.body)
puts "lists.size =====#{lists.size}"
lists.each do |data|
version_arr = data['version'].to_s.split(".")
if version_arr[0].to_i == 1 && version_arr[1].to_i >= 18
action_node_select = Action::NodeSelect.find_or_initialize_by(name: "go-version", val: data["version"])
puts data["version"]
data['files'].each do |file|
if file['platform'] == "linux"
puts "download_url==#{file['download_url']}"
action_node_select.download_url = file['download_url']
end
end
action_node_select.action_nodes_id=1
action_node_select.save
end
end
end
task node: :environment do
# curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=5ccebd935915fb6cfcae634b161047a2&state=open&sort=created&direction=desc&page=1&per_page=10'
# api_url = "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json"
api_url = "https://testgitea2.trustie.net/actions/node-versions/raw/branch/main/versions-manifest.json"
uri = URI.parse(api_url)
response = Net::HTTP.get_response(uri)
puts "gitee api response.code ===== #{response.code}"
lists = JSON.parse(response.body)
puts "lists.size =====#{lists.size}"
lists.each do |data|
version_arr = data['version'].to_s.split(".")
if version_arr[0].to_i >= 16
puts data["version"]
action_node_select = Action::NodeSelect.find_or_initialize_by(name: "node-version", val: data["version"])
data['files'].each do |file|
if file['platform'] == "linux"
puts "download_url==#{file['download_url']}"
action_node_select.download_url = file['download_url']
end
end
action_node_select.action_nodes_id=2
action_node_select.save
end
end
end
task java: :environment do
# curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=5ccebd935915fb6cfcae634b161047a2&state=open&sort=created&direction=desc&page=1&per_page=10'
# api_url = "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json"
[0, 1, 2].each do |page|
api_url = "https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D?project=jdk&vendor=adoptium&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&os=linux&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=#{page}"
uri = URI.parse(api_url)
response = Net::HTTP.get_response(uri)
puts "gitee api response.code ===== #{response.code}"
lists = JSON.parse(response.body)
puts "lists.size =====#{lists.size}"
lists.each do |data|
puts data["release_name"]
puts "#{data['version_data']['major']}@#{data['version_data']['openjdk_version']}"
action_node_select = Action::NodeSelect.find_or_initialize_by(name: "java-version", val: "#{data['version_data']['major']}", val_ext: "#{data['version_data']['openjdk_version']}")
data['binaries'].each do |file|
puts "download_url==#{file['package']['link']}"
action_node_select.download_url = file['package']['link']
end
action_node_select.action_nodes_id=5
action_node_select.save
end
end
end
end