Clonning Working
This commit is contained in:
1 parent
be2bbc8cf2
commit
31b074216c
3 files changed
+186
-16
No files matched your search
@@ -0,0 +1,167 @@
|
||||
function newNodeCloning () {
|
||||
const MODULE_NAME = 'Node Cloning'
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
thisObject = {
|
||||
getNodeClone: getNodeClone
|
||||
}
|
||||
return thisObject
|
||||
|
||||
function getNodeClone (node) {
|
||||
let idConversionMap = new Map()
|
||||
|
||||
let inmatureClone = cloneNode(node)
|
||||
let matureClone = redirectReferenceParents(inmatureClone)
|
||||
|
||||
return matureClone
|
||||
|
||||
function cloneNode (node) {
|
||||
if (node === undefined) { return }
|
||||
let nodeDefinition = APP_SCHEMA_MAP.get(node.type)
|
||||
if (nodeDefinition !== undefined) {
|
||||
let object = {
|
||||
type: node.type,
|
||||
subType: node.subType,
|
||||
name: node.name,
|
||||
code: node.code
|
||||
}
|
||||
|
||||
/* Children Nodes */
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (node[property.name] !== undefined) {
|
||||
object[property.name] = cloneNode(node[property.name])
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'array': {
|
||||
if (node[property.name] !== undefined) {
|
||||
let nodePropertyArray = node[property.name]
|
||||
object[property.name] = []
|
||||
for (let m = 0; m < nodePropertyArray.length; m++) {
|
||||
let protocolNode = cloneNode(nodePropertyArray[m])
|
||||
if (protocolNode !== undefined) {
|
||||
object[property.name].push(protocolNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object.id = newUniqueId()
|
||||
idConversionMap.set(node.id, object.id)
|
||||
|
||||
object.savedPayload = getSavedPayload(node)
|
||||
|
||||
return object
|
||||
}
|
||||
}
|
||||
|
||||
function redirectReferenceParents (node) {
|
||||
if (node === undefined) { return }
|
||||
let nodeDefinition = APP_SCHEMA_MAP.get(node.type)
|
||||
if (nodeDefinition !== undefined) {
|
||||
let object = {
|
||||
type: node.type,
|
||||
subType: node.subType,
|
||||
name: node.name,
|
||||
code: node.code
|
||||
}
|
||||
|
||||
/* Children Nodes */
|
||||
if (nodeDefinition.properties !== undefined) {
|
||||
for (let i = 0; i < nodeDefinition.properties.length; i++) {
|
||||
let property = nodeDefinition.properties[i]
|
||||
|
||||
switch (property.type) {
|
||||
case 'node': {
|
||||
if (node[property.name] !== undefined) {
|
||||
object[property.name] = redirectReferenceParents(node[property.name])
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'array': {
|
||||
if (node[property.name] !== undefined) {
|
||||
let nodePropertyArray = node[property.name]
|
||||
object[property.name] = []
|
||||
for (let m = 0; m < nodePropertyArray.length; m++) {
|
||||
let protocolNode = redirectReferenceParents(nodePropertyArray[m])
|
||||
if (protocolNode !== undefined) {
|
||||
object[property.name].push(protocolNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object.id = node.id
|
||||
|
||||
object.savedPayload = node.savedPayload
|
||||
|
||||
if (object.savedPayload !== undefined) {
|
||||
if (object.savedPayload.referenceParent !== undefined) {
|
||||
let newId = idConversionMap.get(object.savedPayload.referenceParent.id)
|
||||
if (newId !== undefined) {
|
||||
object.savedPayload.referenceParent.id = newId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return object
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getSavedPayload (node) {
|
||||
if (node.payload === undefined) { return }
|
||||
let savedPayload = {
|
||||
position: {
|
||||
x: node.payload.position.x,
|
||||
y: node.payload.position.y
|
||||
},
|
||||
targetPosition: {
|
||||
x: node.payload.targetPosition.x,
|
||||
y: node.payload.targetPosition.y
|
||||
},
|
||||
floatingObject: {
|
||||
isPinned: node.payload.floatingObject.isPinned,
|
||||
isFrozen: (node.payload.floatingObject.isFrozen && node.payload.floatingObject.frozenManually),
|
||||
isCollapsed: (node.payload.floatingObject.isCollapsed && node.payload.floatingObject.collapsedManually),
|
||||
isTensed: (node.payload.floatingObject.isTensed && node.payload.floatingObject.tensedManually)
|
||||
},
|
||||
uiObject: {
|
||||
isRunning: node.payload.uiObject.isRunning,
|
||||
shortcutKey: node.payload.uiObject.shortcutKey
|
||||
}
|
||||
}
|
||||
|
||||
/* Next for the ones that have a reference parent, we include it */
|
||||
if (node.payload.referenceParent !== undefined) {
|
||||
savedPayload.referenceParent = {
|
||||
type: node.payload.referenceParent.type,
|
||||
subType: node.payload.referenceParent.subType,
|
||||
name: node.payload.referenceParent.name,
|
||||
id: node.payload.referenceParent.id
|
||||
}
|
||||
} else {
|
||||
/* The referenceParent property can be inherited from the previous saved payload. */
|
||||
if (node.savedPayload !== undefined) {
|
||||
savedPayload.referenceParent = node.savedPayload.referenceParent
|
||||
}
|
||||
}
|
||||
|
||||
return savedPayload
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ function newWorkspace () {
|
||||
let functionLibraryNodeDeleter = newNodeDeleter()
|
||||
let functionLibraryUiObjectsFromNodes = newUiObjectsFromNodes()
|
||||
let functionLibraryProtocolNode = newProtocolNode()
|
||||
let functionLibraryNodeCloning = newNodeCloning()
|
||||
let functionLibraryTaskFunctions = newTaskFunctions()
|
||||
let functionLibrarySessionFunctions = newSessionFunctions()
|
||||
let functionLibraryShortcutKeys = newShortcutKeys()
|
||||
@@ -286,7 +287,7 @@ function newWorkspace () {
|
||||
break
|
||||
case 'Clone':
|
||||
{
|
||||
let text = JSON.stringify(functionLibraryProtocolNode.getProtocolNode(payload.node, false, false, true, true, true))
|
||||
let text = JSON.stringify(functionLibraryNodeCloning.getNodeClone(payload.node))
|
||||
|
||||
let nodeName = payload.node.name
|
||||
if (nodeName === undefined) {
|
||||
|
||||
@@ -115,7 +115,7 @@ function newUiObjectConstructor () {
|
||||
return
|
||||
}
|
||||
|
||||
function addLeftIcons (menuItemsInitialValues, floatingObject) {
|
||||
function addLeftIcons (menuItemsInitialValues, floatingObject, isPersonalData) {
|
||||
menuItemsInitialValues.push(
|
||||
{
|
||||
action: 'Pin / Unpin',
|
||||
@@ -202,19 +202,21 @@ function newUiObjectConstructor () {
|
||||
currentRadius: 0
|
||||
}
|
||||
)
|
||||
menuItemsInitialValues.push(
|
||||
{
|
||||
action: 'XXShare',
|
||||
actionFunction: floatingObject.payload.onMenuItemClick,
|
||||
label: undefined,
|
||||
visible: true,
|
||||
iconPathOn: 'menu-share',
|
||||
iconPathOff: 'menu-share',
|
||||
rawRadius: 8,
|
||||
targetRadius: 0,
|
||||
currentRadius: 0
|
||||
}
|
||||
)
|
||||
if (isPersonalData !== true) {
|
||||
menuItemsInitialValues.push(
|
||||
{
|
||||
action: 'Share',
|
||||
actionFunction: floatingObject.payload.onMenuItemClick,
|
||||
label: undefined,
|
||||
visible: true,
|
||||
iconPathOn: 'menu-share',
|
||||
iconPathOff: 'menu-share',
|
||||
rawRadius: 8,
|
||||
targetRadius: 0,
|
||||
currentRadius: 0
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function getMenuItemsInitialValues (uiObject, floatingObject, payload) {
|
||||
@@ -249,7 +251,7 @@ function newUiObjectConstructor () {
|
||||
}
|
||||
}
|
||||
if (nodeDefinition.addLeftIcons === true) {
|
||||
addLeftIcons(menuItemsInitialValues, floatingObject)
|
||||
addLeftIcons(menuItemsInitialValues, floatingObject, nodeDefinition.isPersonalData)
|
||||
}
|
||||
if (nodeDefinition.isPinned === true) {
|
||||
floatingObject.isPinned = true
|
||||
|
||||
Reference in new issue
Block a user