Generalizing chainedToTheSameType part 1
This commit is contained in:
1 parent
e30f64dc0e
commit
6b42383e87
3 files changed
+87
-20
No files matched your search
@@ -14,13 +14,13 @@ function newNodeChildren () {
|
||||
childrenCount: 0,
|
||||
childIndex: undefined
|
||||
}
|
||||
let nodeDefinition = APP_SCHEMA_MAP.get(parentNode.type)
|
||||
if (nodeDefinition !== undefined) {
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
let parentNodeDefinition = APP_SCHEMA_MAP.get(parentNode.type)
|
||||
if (parentNodeDefinition !== undefined) {
|
||||
if (parentNodeDefinition.properties !== undefined) {
|
||||
let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children.
|
||||
|
||||
for (let i = 0; i < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[i]
|
||||
for (let i = 0; i < parentNodeDefinition.properties.length; i++) {
|
||||
let property = parentNodeDefinition.properties[i]
|
||||
if (parentNode[property.name] !== undefined) {
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
@@ -34,12 +34,24 @@ function newNodeChildren () {
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
let nodePropertyArray = parentNode[property.name]
|
||||
for (let j = 0; j < nodePropertyArray.length; j++) {
|
||||
let child = nodePropertyArray[j]
|
||||
response.childrenCount++
|
||||
if (child.id === childNode.id) {
|
||||
response.childIndex = response.childrenCount
|
||||
let nodeDefinition = APP_SCHEMA_MAP.get(childNode.type)
|
||||
if (nodeDefinition !== undefined) {
|
||||
let nodePropertyArray = parentNode[property.name]
|
||||
for (let j = 0; j < nodePropertyArray.length; j++) {
|
||||
let child = nodePropertyArray[j]
|
||||
if (nodeDefinition.chainedToSameType === true) {
|
||||
if (j < 1) {
|
||||
response.childrenCount++
|
||||
if (child.id === childNode.id) {
|
||||
response.childIndex = response.childrenCount
|
||||
}
|
||||
}
|
||||
} else {
|
||||
response.childrenCount++
|
||||
if (child.id === childNode.id) {
|
||||
response.childIndex = response.childrenCount
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,14 @@ function newNodeDeleter () {
|
||||
for (let j = 0; j < nodePropertyArray.length; j++) {
|
||||
let arrayItem = nodePropertyArray[j]
|
||||
if (arrayItem.id === node.id) {
|
||||
/* If this object is chained to the ones of the same type we need to give the next in the chain the reference to the current chain parent */
|
||||
if (nodeDefinition.chainedToSameType === true) {
|
||||
if (j < nodePropertyArray.length - 1) {
|
||||
let nextArrayItem = nodePropertyArray[j + 1]
|
||||
nextArrayItem.payload.chainParent = node.payload.chainParent
|
||||
}
|
||||
}
|
||||
|
||||
nodePropertyArray.splice(j, 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,33 @@ function newUiObjectsFromNodes () {
|
||||
}
|
||||
}
|
||||
|
||||
/* For the cases where an node is not chained to its parent but to the one at the parent before it at its collection */
|
||||
if (nodeDefinition.chainedToSameType === true) {
|
||||
let parentNodeDefinition = APP_SCHEMA_MAP.get(parentNode.type)
|
||||
if (parentNodeDefinition !== undefined) {
|
||||
if (parentNodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < parentNodeDefinition.properties.length; i++) {
|
||||
let property = parentNodeDefinition.properties[i]
|
||||
if (property.childType === node.type) {
|
||||
if (property.type === 'array') {
|
||||
if (parentNode[property.name] !== undefined) {
|
||||
if (parentNode[property.name].length > 1) {
|
||||
let nodeChildren = parentNode[property.name]
|
||||
for (let j = 0; j < nodeChildren.length; j++) {
|
||||
if (node.id === nodeChildren[j].id) {
|
||||
if (j > 0) {
|
||||
chainParent = nodeChildren[j - 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Create Self */
|
||||
createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset)
|
||||
|
||||
@@ -92,24 +119,44 @@ function newUiObjectsFromNodes () {
|
||||
}
|
||||
}
|
||||
|
||||
function addUIObject (parent, type) {
|
||||
function addUIObject (parentNode, type) {
|
||||
let object = {
|
||||
name: 'New ' + type,
|
||||
type: type
|
||||
}
|
||||
|
||||
let parentNodeDefinition = APP_SCHEMA_MAP.get(parent.type)
|
||||
let parentNodeDefinition = APP_SCHEMA_MAP.get(parentNode.type)
|
||||
if (parentNodeDefinition !== undefined) {
|
||||
/* Resolve Initial Values */
|
||||
let nodeDefinition = APP_SCHEMA_MAP.get(object.type)
|
||||
|
||||
if (nodeDefinition.isHierarchyHead === true) {
|
||||
parent.rootNodes.push(object)
|
||||
createUiObject(true, object.type, object.name, object, parent, undefined)
|
||||
parentNode.rootNodes.push(object)
|
||||
createUiObject(true, object.type, object.name, object, parentNode, undefined)
|
||||
return object
|
||||
}
|
||||
|
||||
createUiObject(true, object.type, object.name, object, parent, parent)
|
||||
/* For the cases where an node is not chained to its parent but to the one at the parent before it at its collection */
|
||||
let chainParent = parentNode
|
||||
if (nodeDefinition.chainedToSameType === true) {
|
||||
if (parentNodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < parentNodeDefinition.properties.length; i++) {
|
||||
let property = parentNodeDefinition.properties[i]
|
||||
if (property.childType === type) {
|
||||
if (property.type === 'array') {
|
||||
if (parentNode[property.name] !== undefined) {
|
||||
if (parentNode[property.name].length > 0) {
|
||||
let nodeChildren = parentNode[property.name]
|
||||
chainParent = nodeChildren[nodeChildren.length - 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
createUiObject(true, object.type, object.name, object, parentNode, chainParent)
|
||||
|
||||
if (nodeDefinition !== undefined) {
|
||||
if (nodeDefinition.initialValues !== undefined) {
|
||||
@@ -128,16 +175,16 @@ function newUiObjectsFromNodes () {
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (property.name !== previousPropertyName) {
|
||||
parent[property.name] = object
|
||||
parentNode[property.name] = object
|
||||
previousPropertyName = property.name
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'array': {
|
||||
if (parent[property.name] === undefined) {
|
||||
parent[property.name] = []
|
||||
if (parentNode[property.name] === undefined) {
|
||||
parentNode[property.name] = []
|
||||
}
|
||||
parent[property.name].push(object)
|
||||
parentNode[property.name].push(object)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user