diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index 2d47ae429..bb8601229 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -54,6 +54,7 @@ function newSuperalgosDocSpace() { setUpContextMenu() setUpMenuItemsMap() setUpSearchEngine() + setUpWorkspaceSchemas() isInitialized = true function setUpContextMenu() { @@ -261,6 +262,66 @@ function newSuperalgosDocSpace() { } } + function setUpWorkspaceSchemas() { + /* + We will scan the whole workspace and create an array with all of its nodes. + */ + let rootNodes = UI.projects.superalgos.spaces.designSpace.workspace.workspaceNode.rootNodes + let allNodesFound = [] + for (let i = 0; i < rootNodes.length; i++) { + let rootNode = rootNodes[i] + if (rootNode !== null) { + let nodeArray = UI.projects.superalgos.utilities.branches.nodeBranchToArray(rootNode) + allNodesFound = allNodesFound.concat(nodeArray) + } + } + /* + We will create a document for each node, so that can later be indexed into the search engine. + */ + for (let j = 0; j < PROJECTS_ARRAY.length; j++) { + let project = PROJECTS_ARRAY[j] + SCHEMAS_BY_PROJECT.get(project).array.workspaceNodeSchema = [] + + for (let i = 0; i < allNodesFound.length; i++) { + let node = allNodesFound[i] + if (node.project === project) { + let document = { + type: node.type, + definition: node.name, + paragraphs: [] + } + if (node.config !== undefined) { + let paragraph + paragraph = { + style: "Subtitle", + text: "Config" + } + document.paragraphs.push(paragraph) + paragraph = { + syle: "Json", + text: node.config + } + document.paragraphs.push(paragraph) + } + if (node.code !== undefined) { + let paragraph + paragraph = { + style: "Subtitle", + text: "Code" + } + document.paragraphs.push(paragraph) + paragraph = { + syle: "Javascript", + text: node.code + } + document.paragraphs.push(paragraph) + } + } + SCHEMAS_BY_PROJECT.get(project).array.workspaceNodeSchema.push(document) + } + } + } + function setUpSearchEngine() { for (let j = 0; j < PROJECTS_ARRAY.length; j++) { let project = PROJECTS_ARRAY[j] @@ -2320,7 +2381,7 @@ function newSuperalgosDocSpace() { } function resize() { - thisObject.container.frame.width = 1000 + thisObject.container.frame.width = 900 thisObject.container.frame.height = browserCanvas.height // - TOP_SPACE_HEIGHT thisObject.container.frame.position.x = browserCanvas.width thisObject.container.frame.position.y = 0 // TOP_SPACE_HEIGHT diff --git a/Projects/Superalgos/UI/Utilities/Branches.js b/Projects/Superalgos/UI/Utilities/Branches.js index e1d86b784..f31eb5655 100644 --- a/Projects/Superalgos/UI/Utilities/Branches.js +++ b/Projects/Superalgos/UI/Utilities/Branches.js @@ -9,12 +9,15 @@ function newSuperalgosUtilitiesBranches() { function nodeBranchToArray(node, nodeType) { /* This function scans a node branch for a certain node type and - return an array of with all the nodes of that type found. + return an array of with all the nodes of that type found. Note that once + a node with a matching type is found, it's children are not further scanned. + + If nodeType is undefined, then all nodes of this branch will be returned in + the array, including the children of the nodes added to the result array. */ if (node === undefined) { return } - if (nodeType === undefined) { return } - let resultArray = [] - scanNodeBranch(node, nodeType) + let resultArray = [] + scanNodeBranch(node) return resultArray function scanNodeBranch(startingNode) { @@ -23,9 +26,13 @@ function newSuperalgosUtilitiesBranches() { let nodeDefinition = getNodeDefinition(startingNode) if (nodeDefinition === undefined) { return } - if (startingNode.type === nodeType) { + if (nodeType === undefined) { resultArray.push(startingNode) - return + } else { + if (startingNode.type === nodeType) { + resultArray.push(startingNode) + return + } } if (nodeDefinition.childrenNodesProperties === undefined) { return }