fixed 节点数据提取修正

This commit is contained in:
xxq250 2024-12-10 11:08:37 +08:00
parent e5c030270b
commit f9cf1e3a13
1 changed files with 7 additions and 7 deletions

View File

@ -103,11 +103,11 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
next if node.blank?
node.label = job["data"]["label"] if job["data"]["label"].present?
node.node_id = job["id"] if job["id"].present?
next_edge_nodes = JSON.parse(demo2.to_json)["edges"].select { |edge| edge["source"]["cell"].include?(job["id"]) }
next_edge_nodes = pipeline_json["edges"].select { |edge| edge["source"]["cell"].include?(job["id"]) }
node_ids = next_edge_nodes.map { |t| t["target"]["cell"] }
next_step_node = JSON.parse(demo2.to_json)["nodes"].select { |node| node_ids.include?(node["id"]) && !node["data"]["name"].to_s.include?("job") }&.first
next_step_node = pipeline_json["nodes"].select { |node| node_ids.include?(node["id"]) && !node["data"]["name"].to_s.include?("job") }&.first
node.sub_nodes = []
get_all_child_nodes(node, next_step_node) if next_step_node.present?
get_all_child_nodes(pipeline_json, node, next_step_node) if next_step_node.present?
@job_nodes.push(node)
end
yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding)
@ -170,13 +170,13 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
steps_nodes
end
def get_all_child_nodes(job_node, target_node)
def get_all_child_nodes(pipeline_json, job_node, target_node)
job_node.sub_nodes.push(get_node_info(target_node))
target_edge = JSON.parse(demo2.to_json)["edges"].select { |node| node["source"]["cell"].to_s.include?(target_node["id"]) }&.first
target_edge = pipeline_json["edges"].select { |node| node["source"]["cell"].to_s.include?(target_node["id"]) }&.first
# 判断是否有子节点
if target_edge.present?
next_node = JSON.parse(demo2.to_json)["nodes"].select { |node| node["id"].include?(target_edge["target"]["cell"]) }.first
get_all_child_nodes(job_node, next_node)
next_node = pipeline_json["nodes"].select { |node| node["id"].include?(target_edge["target"]["cell"]) }.first
get_all_child_nodes(pipeline_json, job_node, next_node)
end
end