Node Utilites migrated
This commit is contained in:
1 parent
4c84cebf65
commit
b454eea2a6
15 files changed
+241
-222
No files matched your search
@@ -353,7 +353,14 @@
|
||||
"fileName": "ProcessFunctions.js"
|
||||
}
|
||||
],
|
||||
"utilities": [],
|
||||
"utilities": [
|
||||
{
|
||||
"name": "Node Functions",
|
||||
"propertyName": "nodeFunctions",
|
||||
"functionName": "newSuperalgosUtilitiesNodeFunctions",
|
||||
"fileName": "NodeFunctions.js"
|
||||
}
|
||||
],
|
||||
"botClasses": []
|
||||
},
|
||||
"CL": {}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
exports.newSuperalgosUtilitiesNodeFunctions = function () {
|
||||
|
||||
let thisObject = {
|
||||
nodeBrachToArray: nodeBrachToArray,
|
||||
findNodeInNodeMesh: findNodeInNodeMesh,
|
||||
nodeMeshToPathArray: nodeMeshToPathArray,
|
||||
findNodeInNodeArray: findNodeInNodeArray,
|
||||
filterOutNodeWihtoutReferenceParentFromNodeArray: filterOutNodeWihtoutReferenceParentFromNodeArray
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function nodeBrachToArray(node, nodeType) {
|
||||
let resultArray = []
|
||||
scanNodeBranch(node, nodeType)
|
||||
return resultArray
|
||||
|
||||
function scanNodeBranch(startingNode) {
|
||||
let nodeDefinition = global.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type)
|
||||
if (nodeDefinition === undefined) { return }
|
||||
|
||||
if (startingNode.type === nodeType) {
|
||||
resultArray.push(startingNode)
|
||||
return
|
||||
}
|
||||
|
||||
if (nodeDefinition.properties === undefined) { return }
|
||||
for (let i = 0; i < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
scanNodeBranch(startingNode[property.name])
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let startingNodePropertyArray = startingNode[property.name]
|
||||
if (startingNodePropertyArray !== undefined) {
|
||||
for (let m = 0; m < startingNodePropertyArray.length; m++) {
|
||||
scanNodeBranch(startingNodePropertyArray[m])
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function findNodeInNodeMesh (node, nodeType) {
|
||||
/*
|
||||
This function scans a node mesh for a certain node type and
|
||||
returns the first instance found.
|
||||
*/
|
||||
let nodeFound
|
||||
scanNodeMesh(node, nodeType)
|
||||
return nodeFound
|
||||
|
||||
function scanNodeMesh(startingNode) {
|
||||
if (startingNode === undefined) { return }
|
||||
if (nodeFound !== undefined) { return }
|
||||
|
||||
let nodeDefinition = global.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type)
|
||||
if (nodeDefinition === undefined) { return }
|
||||
|
||||
if (startingNode.type === nodeType) {
|
||||
nodeFound = startingNode
|
||||
return
|
||||
}
|
||||
|
||||
/* We scan through this node children */
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
scanNodeMesh(startingNode[property.name])
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let startingNodePropertyArray = startingNode[property.name]
|
||||
if (startingNodePropertyArray !== undefined) {
|
||||
for (let m = 0; m < startingNodePropertyArray.length; m++) {
|
||||
scanNodeMesh(startingNodePropertyArray[m])
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* We scan parents nodes. */
|
||||
if (startingNode.parentNode !== undefined) {
|
||||
scanNodeMesh(startingNode.parentNode)
|
||||
}
|
||||
/* We scan reference parents too. */
|
||||
if (startingNode.referenceParent !== undefined) {
|
||||
scanNodeMesh(startingNode.referenceParent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function nodeMeshToPathArray (node, nodeId) {
|
||||
/*
|
||||
This function scans a node mesh for a certain node if and
|
||||
returns an array with the path within that mesh to the
|
||||
requested node.
|
||||
*/
|
||||
let nodeArray = []
|
||||
scanNodeMesh(node)
|
||||
return nodeArray
|
||||
|
||||
function scanNodeMesh(startingNode) {
|
||||
if (startingNode === undefined) { return }
|
||||
|
||||
let nodeDefinition = global.APP_SCHEMA_MAP.get(startingNode.project + '-' + startingNode.type)
|
||||
if (nodeDefinition === undefined) { return }
|
||||
|
||||
if (startingNode.id === nodeId) {
|
||||
nodeArray.push(startingNode)
|
||||
return
|
||||
}
|
||||
|
||||
/* We scan through this node children */
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
scanNodeMesh(startingNode[property.name])
|
||||
if (nodeArray.length > 0) {
|
||||
nodeArray.unshift(startingNode)
|
||||
return
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let startingNodePropertyArray = startingNode[property.name]
|
||||
if (startingNodePropertyArray !== undefined) {
|
||||
for (let m = 0; m < startingNodePropertyArray.length; m++) {
|
||||
scanNodeMesh(startingNodePropertyArray[m])
|
||||
if (nodeArray.length > 0) {
|
||||
nodeArray.unshift(startingNode)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* We scan parents nodes. */
|
||||
if (startingNode.parentNode !== undefined) {
|
||||
scanNodeMesh(startingNode.parentNode)
|
||||
if (nodeArray.length > 0) {
|
||||
nodeArray.unshift(startingNode)
|
||||
return
|
||||
}
|
||||
}
|
||||
/* We scan reference parents too. */
|
||||
if (startingNode.referenceParent !== undefined) {
|
||||
scanNodeMesh(startingNode.referenceParent)
|
||||
if (nodeArray.length > 0) {
|
||||
nodeArray.unshift(startingNode)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function findNodeInNodeArray (nodeArray, nodeType) {
|
||||
for (let i = 0; i < nodeArray.length; i++) {
|
||||
let node = nodeArray[i]
|
||||
if (node.type === nodeType) {
|
||||
return node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function filterOutNodeWihtoutReferenceParentFromNodeArray (nodeArray) {
|
||||
let filteredNodeArray = []
|
||||
for (let i = 0; i < nodeArray.length; i++) {
|
||||
let arrayItem = nodeArray[i]
|
||||
if (arrayItem.referenceParent === undefined) {
|
||||
continue
|
||||
} else {
|
||||
filteredNodeArray.push(arrayItem)
|
||||
}
|
||||
}
|
||||
return filteredNodeArray
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user