From 95a574bc3afee95bb928e596f78ecad46c9038da Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 22 Dec 2020 11:15:59 +0100 Subject: [PATCH] Delete Command Working --- .../UI/Spaces/Docs-Space/DocsSpace.js | 287 ++++++++++++++---- 1 file changed, 221 insertions(+), 66 deletions(-) diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index 76a8e6b3e..c10a99cf0 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -797,76 +797,153 @@ function newSuperalgosDocSpace() { } function detectCommands() { - - if (command.toLowerCase() === 'help add') { - renderCommandResultsPage( - [ - "Command Add syntax: ", - "Option 1: Add Node to Project: Node Type", - "Example: Add Node to Superalgos: Task Manager", - "Option 2: Add Concpet to Project: Concept Name", - "Example: Add Concept to Superalgos: Attaching Nodes", - "Option 3: Add Topic to Project: Topic->Part Name->Page Number", - "Example: Add Topic to Superalgos: Contributing->Code->2" - ] - ) - return - } - const newParagraphText = "Left click and Edit to enter edit mode and change this text. ENTER to write new paragraphs. ESC to exit edit mode." - let splittedCommand = command.split(': ') - if (splittedCommand[1] === undefined) { - renderCommandResultsPage(["Syntax Error. Keyword : missing: Example: Add Concept to Superalgos: New Concept Name. The keyword is a : character plus a blank space. Type Hekp Add to learn the command's syntax."]) - return - } - let primaryCommand = splittedCommand[0] - let secondaryCommand = splittedCommand[1] - let splittedPrimaryCommand = primaryCommand.split(' ') - - if (splittedPrimaryCommand[0].toLowerCase() === 'add') { - if (splittedPrimaryCommand[2] !== 'to') { - renderCommandResultsPage(["Syntax Error. Keyword to missing: Example: Add Concept to Superalgos: New Concept Name. Type Hekp Add to learn the command's syntax."]) - return - } - - if (splittedPrimaryCommand.length < 4) { - renderCommandResultsPage(["Syntax Error. Too few Add Command parameters. Found " + splittedPrimaryCommand.length + ". Expected at least 4. Type Hekp Add to learn the command's syntax."]) - return - } - - if (secondaryCommand === '') { - renderCommandResultsPage(["Syntax Error. Node, Concept or Topic name can not be undefined."]) - return - } - - switch (splittedPrimaryCommand[1].toLowerCase()) { - case 'node': { - addNode(splittedPrimaryCommand[3], secondaryCommand) - return - } - case 'concept': { - addConcept(splittedPrimaryCommand[3], secondaryCommand) - return - } - case 'topic': { - let splittedSecondaryCommand = secondaryCommand.split('->') - if (splittedSecondaryCommand.length < 3) { - renderCommandResultsPage(["Syntax Error. Too few Topic parameters. Found " + splittedSecondaryCommand.length + ". Expected 3. Type Hekp Add to learn the command's syntax."]) - return - } - addTopic(splittedPrimaryCommand[3], splittedSecondaryCommand[0], splittedSecondaryCommand[1], splittedSecondaryCommand[2]) - return - } - default: { - renderCommandResultsPage(["Syntax Error. Expected Node, Concept or Topic. Found " + splittedCommand[1] + ""]) - return - } - } - } + if (checkAddCommand() === undefined) { return } + if (checkDeleteCommand() === undefined) { return } renderSearchResultsPage() + function checkAddCommand() { + if (command.toLowerCase() === 'help add') { + renderCommandResultsPage( + [ + "Add command syntax: ", + "Option 1: Add Node to Project: Node Type", + "Example: Add Node to Superalgos: Task Manager", + "Option 2: Add Concpet to Project: Concept Name", + "Example: Add Concept to Superalgos: Attaching Nodes", + "Option 3: Add Topic to Project: Topic->Part Name->Page Number", + "Example: Add Topic to Superalgos: Contributing->Code->2" + ] + ) + return + } + if (command.indexOf('Add') !== 0 && command.indexOf('add') !== 0) { return 'Not Add Command' } + + let splittedCommand = command.split(': ') + if (splittedCommand[1] === undefined) { + renderCommandResultsPage(["Syntax Error. Keyword : missing: Example: Add Concept to Superalgos: New Concept Name. The keyword is a : character plus a blank space. Type Hekp Add to learn the command's syntax."]) + return + } + let primaryCommand = splittedCommand[0] + let secondaryCommand = splittedCommand[1] + + let splittedPrimaryCommand = primaryCommand.split(' ') + + if (splittedPrimaryCommand[0].toLowerCase() === 'add') { + if (splittedPrimaryCommand[2] !== 'to') { + renderCommandResultsPage(["Syntax Error. Keyword to missing: Example: Add Concept to Superalgos: New Concept Name. Type Hekp Add to learn the command's syntax."]) + return + } + + if (splittedPrimaryCommand.length < 4) { + renderCommandResultsPage(["Syntax Error. Too few Add Command parameters. Found " + splittedPrimaryCommand.length + ". Expected at least 4. Type Hekp Add to learn the command's syntax."]) + return + } + + if (secondaryCommand === '') { + renderCommandResultsPage(["Syntax Error. Node, Concept or Topic name can not be undefined."]) + return + } + + switch (splittedPrimaryCommand[1].toLowerCase()) { + case 'node': { + addNode(splittedPrimaryCommand[3], secondaryCommand) + return + } + case 'concept': { + addConcept(splittedPrimaryCommand[3], secondaryCommand) + return + } + case 'topic': { + let splittedSecondaryCommand = secondaryCommand.split('->') + if (splittedSecondaryCommand.length < 3) { + renderCommandResultsPage(["Syntax Error. Too few Topic parameters. Found " + splittedSecondaryCommand.length + ". Expected 3. Type Hekp Add to learn the command's syntax."]) + return + } + addTopic(splittedPrimaryCommand[3], splittedSecondaryCommand[0], splittedSecondaryCommand[1], splittedSecondaryCommand[2]) + return + } + default: { + renderCommandResultsPage(["Syntax Error. Expected Node, Concept or Topic. Found " + splittedCommand[1] + ""]) + return + } + } + return 'Not Add Command' + } + } + + function checkDeleteCommand() { + if (command.toLowerCase() === 'help delete') { + renderCommandResultsPage( + [ + "Delete command syntax: ", + "Option 1: Delete Node from Project: Node Type", + "Example: Delete Node from Superalgos: Task Manager", + "Option 2: Delete Concpet from Project: Concept Name", + "Example: Delete Concept from Superalgos: Attaching Nodes", + "Option 3: Delete Topic from Project: Topic->Part Name->Page Number", + "Example: Delete Topic from Superalgos: Contributing->Code->2" + ] + ) + return + } + if (command.indexOf('Delete') !== 0 && command.indexOf('delete') !== 0) { return 'Not Delete Command' } + + let splittedCommand = command.split(': ') + if (splittedCommand[1] === undefined) { + renderCommandResultsPage(["Syntax Error. Keyword : missing: Example: Delete Concept from Superalgos: Concept Name. The keyword is a : character plus a blank space. Type Hekp Delete to learn the command's syntax."]) + return + } + let primaryCommand = splittedCommand[0] + let secondaryCommand = splittedCommand[1] + + let splittedPrimaryCommand = primaryCommand.split(' ') + + if (splittedPrimaryCommand[0].toLowerCase() === 'delete') { + if (splittedPrimaryCommand[2] !== 'from') { + renderCommandResultsPage(["Syntax Error. Keyword from missing: Example: Delete Concept from Superalgos: Concept Name. Type Hekp Delete to learn the command's syntax."]) + return + } + + if (splittedPrimaryCommand.length < 4) { + renderCommandResultsPage(["Syntax Error. Too few Delete Command parameters. Found " + splittedPrimaryCommand.length + ". Expected at least 4. Type Hekp Delete to learn the command's syntax."]) + return + } + + if (secondaryCommand === '') { + renderCommandResultsPage(["Syntax Error. Node, Concept or Topic name can not be undefined."]) + return + } + + switch (splittedPrimaryCommand[1].toLowerCase()) { + case 'node': { + deleteNode(splittedPrimaryCommand[3], secondaryCommand) + return + } + case 'concept': { + deleteConcept(splittedPrimaryCommand[3], secondaryCommand) + return + } + case 'topic': { + let splittedSecondaryCommand = secondaryCommand.split('->') + if (splittedSecondaryCommand.length < 3) { + renderCommandResultsPage(["Syntax Error. Too few Topic parameters. Found " + splittedSecondaryCommand.length + ". Expected 3. Type Hekp Delete to learn the command's syntax."]) + return + } + deleteTopic(splittedPrimaryCommand[3], splittedSecondaryCommand[0], splittedSecondaryCommand[1], splittedSecondaryCommand[2]) + return + } + default: { + renderCommandResultsPage(["Syntax Error. Expected Node, Concept or Topic. Found " + splittedCommand[1] + ""]) + return + } + } + return 'Not Delete Command' + } + } + function addNode(project, type) { let template = { type: type, @@ -887,7 +964,7 @@ function newSuperalgosDocSpace() { renderCommandResultsPage(["Node " + type + " already exist."]) return } - + SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema.push(template) SCHEMAS_BY_PROJECT.get(project).map.docsNodeSchema.set(type, template) navigateTo('Node', type, project) @@ -947,6 +1024,84 @@ function newSuperalgosDocSpace() { SCHEMAS_BY_PROJECT.get(project).map.docsTopicSchema.set(type, template) navigateTo('Topic', type, project) } + + function deleteNode(project, type) { + if (SCHEMAS_BY_PROJECT.get(project) === undefined) { + renderCommandResultsPage(["Project " + project + " does not exist."]) + return + } + let exist = SCHEMAS_BY_PROJECT.get(project).map.docsNodeSchema.get(type) + if (exist === undefined) { + renderCommandResultsPage(["Node " + type + " does not exist."]) + return + } + + SCHEMAS_BY_PROJECT.get(project).map.docsNodeSchema.delete(type) + renderCommandResultsPage(["Node " + type + " deleted."]) + + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema.length; i++) { + schemaDocument = SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema[i] + if (schemaDocument.type === type) { + schemaDocument = SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema.splice(i, 1) + break + } + } + } + + function deleteConcept(project, type) { + if (SCHEMAS_BY_PROJECT.get(project) === undefined) { + renderCommandResultsPage(["Project " + project + " does not exist."]) + return + } + let exist = SCHEMAS_BY_PROJECT.get(project).map.docsConceptSchema.get(type) + if (exist === undefined) { + renderCommandResultsPage(["Concept " + type + " does not exist."]) + return + } + + SCHEMAS_BY_PROJECT.get(project).map.docsConceptSchema.delete(type) + renderCommandResultsPage(["Concept " + type + " deleted."]) + + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema.length; i++) { + schemaDocument = SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema[i] + if (schemaDocument.type === type) { + schemaDocument = SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema.splice(i, 1) + break + } + } + } + + function deleteTopic(project, topic, type, pageNumber) { + if (SCHEMAS_BY_PROJECT.get(project) === undefined) { + renderCommandResultsPage(["Project " + project + " does not exist."]) + return + } + let exist = SCHEMAS_BY_PROJECT.get(project).map.docsTopicSchema.get(type) + if (exist === undefined) { + renderCommandResultsPage(["Topic " + type + " does not exist."]) + return + } else { + if (exist.pageNumber !== pageNumber) { + renderCommandResultsPage(["Page Number " + pageNumber + " does not match with page number found: " + exist.pageNumber + "."]) + return + } + if (exist.topic !== topic) { + renderCommandResultsPage(["Topic " + topic + " does not match with topic found: " + exist.topic + "."]) + return + } + } + + SCHEMAS_BY_PROJECT.get(project).map.docsTopicSchema.delete(type) + renderCommandResultsPage(["Topic " + type + " deleted."]) + + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema.length; i++) { + schemaDocument = SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema[i] + if (schemaDocument.type === type) { + schemaDocument = SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema.splice(i, 1) + break + } + } + } } function renderCommandResultsPage(resultArray) {