Node Utilites migrated

This commit is contained in:
Luis Fernando Molina committed 2020-11-27 16:58:29 +01:00
1 parent 4c84cebf65
commit b454eea2a6
15 files changed
+241 -222

No files matched your search

-183
View File
@@ -33,189 +33,6 @@ exports.newGlobals = function newGlobals() {
return new Date(date.getUTCFullYear() + "-" + (date.getUTCMonth() + 1) + "-" + date.getUTCDate() + " " + "00:00" + GMT_SECONDS);
}
global.NODE_BRANCH_TO_ARRAY = function (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
}
}
}
}
}
global.FIND_NODE_IN_NODE_MESH = function (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)
}
}
}
global.NODE_MESH_TO_PATH_ARRAY = function (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
}
}
}
}
global.FIND_NODE_IN_NODE_ARRAY = function (nodeArray, nodeType) {
for (let i = 0; i < nodeArray.length; i++) {
let node = nodeArray[i]
if (node.type === nodeType) {
return node
}
}
}
global.FILTER_OUT_NODES_WITHOUT_REFERENCE_PARENT_FROM_NODE_ARRAY = function (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
}
global.EMIT_SESSION_STATUS = function (status, key) {
switch (status) {
case 'Running': {