Merge pull request #2555 from alexandrustefan/develop
Auto fix missing references using checkForMissingReferences utility function
This commit is contained in:
2 files changed
+40
-11
No files matched your search
@@ -29,6 +29,7 @@ function newFoundationsDocsSearchEngine() {
|
||||
|
||||
function finalize() {
|
||||
thisObject.docsIndex = undefined
|
||||
thisObject.documentIndex = undefined
|
||||
}
|
||||
|
||||
function setUpSearchEngine(callbackFunction) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function newFoundationsFunctionLibraryWorkspaceFunctions() {
|
||||
let thisObject = {
|
||||
addMissingWorkspaceProjects: addMissingWorkspaceProjects,
|
||||
checkForMissingReferences: checkForMissingReferences
|
||||
checkForMissingReferences: checkForMissingReferences
|
||||
}
|
||||
|
||||
return thisObject
|
||||
@@ -21,10 +21,12 @@ function newFoundationsFunctionLibraryWorkspaceFunctions() {
|
||||
|
||||
if (alreadyExist === false) {
|
||||
let child = UI.projects.visualScripting.functionLibraries.uiObjectsFromNodes.addUIObject(node, project + ' Project', rootNodes, project)
|
||||
if (child === undefined) { continue }
|
||||
if (child === undefined) {
|
||||
continue
|
||||
}
|
||||
child.project = project
|
||||
child.projectDefinition.name = project
|
||||
child.projectDefinition.config = "{ \n \"codeName\": \"" + project + "\"\n}"
|
||||
child.projectDefinition.config = "{ \n \"codeName\": \"" + project + "\"\n}"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,24 +34,50 @@ function newFoundationsFunctionLibraryWorkspaceFunctions() {
|
||||
// This function scales the current workspace and highlights any nodes that have unresolved references
|
||||
function checkForMissingReferences(rootNodes) {
|
||||
let nodes
|
||||
let docIndex = UI.projects.education.spaces.docsSpace.searchEngine.documentIndex
|
||||
|
||||
|
||||
for (let i = 0; i < rootNodes.length; i++) {
|
||||
if (rootNodes[i] !== undefined) {
|
||||
nodes = UI.projects.visualScripting.utilities.hierarchy.getHiriarchyMap(rootNodes[i])
|
||||
nodes = UI.projects.visualScripting.utilities.hierarchy.getHiriarchyMap(rootNodes[i])
|
||||
for (let [key, value] of nodes) {
|
||||
// Check nodes that have a saved reference parent
|
||||
if (value.savedPayload.referenceParent !== undefined) {
|
||||
// Highlight nodes that do not have an active reference connected to their reference parent
|
||||
if (value.payload.referenceParent === undefined) {
|
||||
console.log("[WARN] Reference Parent not found in the current workspace.\n Node:", value.name, " Type:", value.type, " ID:", key, " Node Object:", value)
|
||||
UI.projects.foundations.spaces.floatingSpace.inMapMode = true
|
||||
value.payload.uiObject.setWarningMessage('Reference Parent not found in the current workspace.', 10)
|
||||
// Filter out data mines in the trading mine process dependencies
|
||||
if (value.type !== 'Data Mine Data Dependencies' && value.type !== 'Data Dependency') {
|
||||
if (value.payload.referenceParent === undefined) {
|
||||
console.log("[WARN] Reference Parent not found in the current workspace.\n Node:", value.name, " Type:", value.type, " ID:", key, " Node Object:", value)
|
||||
UI.projects.foundations.spaces.floatingSpace.inMapMode = true
|
||||
// value.payload.uiObject.setWarningMessage('Reference Parent not found in the current workspace.', 10)
|
||||
|
||||
// Search in the workspace for the reference and try to attach it
|
||||
docIndex.search(value.savedPayload.referenceParent.type, {
|
||||
pluck: 'docsSchemaDocument:type',
|
||||
enrich: true,
|
||||
limit: 1000
|
||||
}).then(function (results) {
|
||||
let workspaceItems = results.filter(function (result) {
|
||||
return result.doc.category === 'Workspace'
|
||||
})
|
||||
if (workspaceItems.length > 0) {
|
||||
// Not the wisest choice to get the first result, but the search engine will for sure return the most relevant doc as first.
|
||||
UI.projects.foundations.spaces.designSpace.workspace.getNodeById(workspaceItems[0].doc.docsSchemaDocument.nodeId).then(function (node) {
|
||||
console.log("Found a node to attach to: ", node)
|
||||
UI.projects.visualScripting.functionLibraries.attachDetach.referenceAttachNode(value, node)
|
||||
console.log("Attached successfully")
|
||||
})
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user