diff --git a/Client/httpInterface.js b/Client/httpInterface.js index 611e1c252..1eba9017c 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -464,6 +464,59 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } break } + case 'Save-Book-Schema': { + getBody(processRequest) + + async function processRequest(body) { + try { + let docsSchema = JSON.parse(body) + let project = requestParameters[3] + let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/Docs-Books' + + const fs = require('fs') + fs.rmdir(filePath, { recursive: true }, onDirDeleted) + + function onDirDeleted(err) { + if (err && err.code === 'EBUSY') { + throw ('Can not delete the folder ' + filePath + ' because a file in it is open by some other program.') + } + try { + fs.mkdirSync(filePath) + } catch (err) { + if (err.code !== 'EEXIST') { + throw (err) + } + } + + for (let i = 0; i < docsSchema.length; i++) { + let schemaDocument = docsSchema[i] + let fileContent = JSON.stringify(schemaDocument, undefined, 4) + let fileName = schemaDocument.type.toLowerCase() + for (let j = 0; j < 10; j++) { + fileName = fileName.replace(' ', '-') + } + fileName = fileName + '.json' + + fs.writeFileSync(filePath + '/' + fileName, fileContent) + } + respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse) + } + + } catch (err) { + console.log('[ERROR] httpInterface -> Docs -> Save-Book-Schema -> Method call produced an error.') + console.log('[ERROR] httpInterface -> Docs -> Save-Book-Schema -> err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> Docs -> Save-Book-Schema -> Params Received = ' + body) + + let error = { + result: 'Fail Because', + message: err.message, + stack: err.stack + } + respondWithContent(JSON.stringify(error), httpResponse) + } + } + break + } } break } @@ -1092,6 +1145,10 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE folder = 'Docs-Topics' break } + case 'DocsBooksSchema': { + folder = 'Docs-Books' + break + } } let schemaArray = [] diff --git a/Projects/Superalgos/Schemas/Docs-Books/how-to-trade.json b/Projects/Superalgos/Schemas/Docs-Books/how-to-trade.json new file mode 100644 index 000000000..37fd9111e --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Books/how-to-trade.json @@ -0,0 +1,14 @@ +{ + "type": "How To Trade", + "definition": { + "text": "This is the first Superalgos Book", + "updated": 1609687251447 + }, + "paragraphs": [ + { + "style": "Text", + "text": "And this is the first book paragraph.", + "updated": 1609687265149 + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js b/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js index 17f9ae34e..5f635923b 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js @@ -73,6 +73,10 @@ function newSuperalgosDocsCommmandInterface() { docsSchemaDocument = SCHEMAS_BY_PROJECT.get(project).map.docsTopicSchema.get(type) break } + case 'book': { + docsSchemaDocument = SCHEMAS_BY_PROJECT.get(project).map.docsBookSchema.get(type) + break + } default: { UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Category Not Valid', 'Anchor Category Not Valid') return @@ -146,6 +150,10 @@ function newSuperalgosDocsCommmandInterface() { addTopic(splittedPrimaryCommand[3], splittedSecondaryCommand[0], splittedSecondaryCommand[1], splittedSecondaryCommand[2]) return } + case 'book': { + addBook(splittedPrimaryCommand[3], secondaryCommand) + return + } default: { UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Category Not Valid', 'Anchor Category Not Valid') return @@ -211,6 +219,10 @@ function newSuperalgosDocsCommmandInterface() { deleteTopic(splittedPrimaryCommand[3], splittedSecondaryCommand[0], splittedSecondaryCommand[1], splittedSecondaryCommand[2]) return } + case 'book': { + deleteBook(splittedPrimaryCommand[3], secondaryCommand) + return + } default: { UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Category Not Valid', 'Anchor Category Not Valid') return @@ -227,8 +239,8 @@ function newSuperalgosDocsCommmandInterface() { } if (UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf('Docs.Reindex') !== 0 && UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf('docs.reindex') !== 0) { return 'Not Reindex Command' } - setUpWorkspaceSchemas() - thisObject.searchEngine.setUpSearchEngine() + UI.projects.superalgos.spaces.docsSpace.setUpWorkspaceSchemas() + UI.projects.superalgos.spaces.docsSpace.searchEngine.setUpSearchEngine() renderCommandResultsPage(["Succesfully rebuild the search engine indexes."]) } @@ -258,6 +270,10 @@ function newSuperalgosDocsCommmandInterface() { docsSchema = SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema httpRequest(JSON.stringify(docsSchema), 'Docs/Save-Topic-Schema/' + project, onResponse) requestsSent++ + + docsSchema = SCHEMAS_BY_PROJECT.get(project).array.docsBookSchema + httpRequest(JSON.stringify(docsSchema), 'Docs/Save-Book-Schema/' + project, onResponse) + requestsSent++ } function onResponse(err, data) { @@ -359,6 +375,33 @@ function newSuperalgosDocsCommmandInterface() { UI.projects.superalgos.spaces.docsSpace.navigateTo(project, 'Topic', type) } + function addBook(project, type) { + let template = { + type: type, + definition: { text: "Write here the summary / definition of this Book." }, + paragraphs: [ + { + style: "Text", + text: UI.projects.superalgos.globals.docs.NEW_PARAGRAPH_TEXT + } + ] + } + + if (SCHEMAS_BY_PROJECT.get(project) === undefined) { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Project Does Not Exist', 'Anchor Project Does Not Exist') + return + } + let exist = SCHEMAS_BY_PROJECT.get(project).map.docsBookSchema.get(type) + if (exist !== undefined) { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Page Already Exists', 'Anchor Page Already Exists') + return + } + + SCHEMAS_BY_PROJECT.get(project).array.docsBookSchema.push(template) + SCHEMAS_BY_PROJECT.get(project).map.docsBookSchema.set(type, template) + UI.projects.superalgos.spaces.docsSpace.navigateTo(project, 'Book', type) + } + function deleteNode(project, type) { if (SCHEMAS_BY_PROJECT.get(project) === undefined) { UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Project Does Not Exist', 'Anchor Project Does Not Exist') @@ -436,6 +479,29 @@ function newSuperalgosDocsCommmandInterface() { } } } + + function deleteBook(project, type) { + if (SCHEMAS_BY_PROJECT.get(project) === undefined) { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Project Does Not Exist', 'Anchor Project Does Not Exist') + return + } + let exist = SCHEMAS_BY_PROJECT.get(project).map.docsBookSchema.get(type) + if (exist === undefined) { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Error Page Does Not Exist', 'Anchor Page Does Not Exist') + return + } + + SCHEMAS_BY_PROJECT.get(project).map.docsBookSchema.delete(type) + renderCommandResultsPage(["Book " + type + " deleted."]) + + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsBookSchema.length; i++) { + docsSchemaDocument = SCHEMAS_BY_PROJECT.get(project).array.docsBookSchema[i] + if (docsSchemaDocument.type === type) { + docsSchemaDocument = SCHEMAS_BY_PROJECT.get(project).array.docsBookSchema.splice(i, 1) + break + } + } + } } function renderCommandResultsPage(resultArray) { diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index bf2d6d805..7956e897b 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -15,8 +15,9 @@ function newSuperalgosDocSpace() { menuLabelsMap: undefined, currentDocumentBeingRendered: undefined, previousDocumentBeingRendered: undefined, - paragraphMap: undefined, // Here we will store a map of paragraphs from the Docs Node, Concept or Topics Schema in order to find it when we need to update them. + paragraphMap: undefined, // Here we will store a map of paragraphs from the Docs Node, Concept, Topics or Books Schema in order to find it when we need to update them. textArea: undefined, + setUpWorkspaceSchemas: setUpWorkspaceSchemas, changeLanguage: changeLanguage, enterEditMode: enterEditMode, exitEditMode: exitEditMode, diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocumentPage.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocumentPage.js index ea9a6c24b..ab169fcf7 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocumentPage.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocumentPage.js @@ -49,6 +49,10 @@ function newSuperalgosDocsDocumentPage() { thisObject.docsSchemaDocument = SCHEMAS_BY_PROJECT.get(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project).map.workspaceSchema.get(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.nodeId) break } + case 'Book': { + thisObject.docsSchemaDocument = SCHEMAS_BY_PROJECT.get(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project).map.docsBookSchema.get(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.type) + break + } } if (thisObject.docsSchemaDocument === undefined) { @@ -75,6 +79,11 @@ function newSuperalgosDocsDocumentPage() { SCHEMAS_BY_PROJECT.get(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project).map.docsConceptSchema.set(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.type, template) break } + case 'Book': { + SCHEMAS_BY_PROJECT.get(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project).array.docsBookSchema.push(template) + SCHEMAS_BY_PROJECT.get(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project).map.docsBookSchema.set(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.type, template) + break + } } thisObject.docsSchemaDocument = template @@ -174,7 +183,7 @@ function newSuperalgosDocsDocumentPage() { /* We will test if we can draw an image here or not*/ let testElement = UI.projects.superalgos.spaces.designSpace.getIconByProjectAndType(project, type) - if ((category === 'Topic' || category === 'Concept') && testElement === undefined) { + if ((category === 'Topic' || category === 'Concept' || category === 'Book') && testElement === undefined) { HTML = HTML + '
Summary: ' + UI.projects.superalgos.utilities.docs.addToolTips(definitionText, UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.type) + '
' } else { HTML = HTML + '
' @@ -330,7 +339,11 @@ function newSuperalgosDocsDocumentPage() { includedSchemaDocument = SCHEMAS_BY_PROJECT.get(project).map.docsTopicSchema.get(type) break } - default: return 'Category provided (' + category + ') not valid. Use Node, Concept or Topic instead.' + case 'Book': { + includedSchemaDocument = SCHEMAS_BY_PROJECT.get(project).map.docsBookSchema.get(type) + break + } + default: return 'Category provided (' + category + ') not valid. Use Node, Concept, Topic or Book instead.' } if (includedSchemaDocument === undefined) { return category + ' document ' + type + ' not found at project ' + project diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/SearchResultsPage.js b/Projects/Superalgos/UI/Spaces/Docs-Space/SearchResultsPage.js index 0a58398e8..7027c2a0c 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/SearchResultsPage.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/SearchResultsPage.js @@ -1,6 +1,6 @@ function newSuperalgosDocsSearchResultsPage() { let thisObject = { - render: render, + render: render, initialize: initialize, finalize: finalize } @@ -181,7 +181,7 @@ function newSuperalgosDocsSearchResultsPage() { } function buildHTML() { - const tabs = ['All', 'Nodes', 'Concepts', 'Topics', 'Workspace'] + const tabs = ['All', 'Nodes', 'Concepts', 'Topics', 'Books', 'Workspace'] let HTML = '' HTML = HTML + '
' HTML = HTML + UI.projects.superalgos.spaces.docsSpace.mainSearchPage.addSearchHeader() diff --git a/Projects/Superalgos/UI/Utilities/Docs.js b/Projects/Superalgos/UI/Utilities/Docs.js index 50ffbf9e7..c4acd6a95 100644 --- a/Projects/Superalgos/UI/Utilities/Docs.js +++ b/Projects/Superalgos/UI/Utilities/Docs.js @@ -372,7 +372,7 @@ function newSuperalgosUtilitiesDocs() { let project = splittedTaggedText[2] /* - We will search across all DOC and CONCEPT SCHEMAS + We will search across all DOC SCHEMAS */ let found = false let docsSchemaDocument @@ -394,6 +394,11 @@ function newSuperalgosUtilitiesDocs() { found = true break } + docsSchemaDocument = SCHEMAS_BY_PROJECT.get(project).map.docsBookSchema.get(type) + if (docsSchemaDocument !== undefined) { + found = true + break + } } if (found === false) { return text @@ -597,6 +602,57 @@ function newSuperalgosUtilitiesDocs() { found = true break } + + /* Search in docsBookSchema */ + if (SCHEMAS_BY_PROJECT.get(project).map.docsBookSchema.get(cleanPhrase5) !== undefined) { + if (cleanPhrase5 !== excludedType) { + taggedText = taggedText + phrase5.replace(cleanPhrase5, TAGGING_STRING_SEPARATOR + 'Book' + '|' + cleanPhrase5 + '|' + project + TAGGING_STRING_SEPARATOR) + ' ' + } else { + taggedText = taggedText + phrase5 + ' ' + } + i = i + 4 + found = true + break + } + if (SCHEMAS_BY_PROJECT.get(project).map.docsBookSchema.get(cleanPhrase4) !== undefined) { + if (cleanPhrase4 !== excludedType) { + taggedText = taggedText + phrase4.replace(cleanPhrase4, TAGGING_STRING_SEPARATOR + 'Book' + '|' + cleanPhrase4 + '|' + project + TAGGING_STRING_SEPARATOR) + ' ' + } else { + taggedText = taggedText + phrase4 + ' ' + } + i = i + 3 + found = true + break + } + if (SCHEMAS_BY_PROJECT.get(project).map.docsBookSchema.get(cleanPhrase3) !== undefined) { + if (cleanPhrase3 !== excludedType) { + taggedText = taggedText + phrase3.replace(cleanPhrase3, TAGGING_STRING_SEPARATOR + 'Book' + '|' + cleanPhrase3 + '|' + project + TAGGING_STRING_SEPARATOR) + ' ' + } else { + taggedText = taggedText + phrase3 + ' ' + } + i = i + 2 + found = true + break + } + if (SCHEMAS_BY_PROJECT.get(project).map.docsBookSchema.get(cleanPhrase2) !== undefined) { + if (cleanPhrase2 !== excludedType) { + taggedText = taggedText + phrase2.replace(cleanPhrase2, TAGGING_STRING_SEPARATOR + 'Book' + '|' + cleanPhrase2 + '|' + project + TAGGING_STRING_SEPARATOR) + ' ' + } else { + taggedText = taggedText + phrase2 + ' ' + } + i = i + 1 + found = true + break + } + if (SCHEMAS_BY_PROJECT.get(project).map.docsBookSchema.get(cleanPhrase1) !== undefined) { + if (cleanPhrase1 !== excludedType) { + taggedText = taggedText + phrase1.replace(cleanPhrase1, TAGGING_STRING_SEPARATOR + 'Book' + '|' + cleanPhrase1 + '|' + project + TAGGING_STRING_SEPARATOR) + ' ' + } else { + taggedText = taggedText + phrase1 + ' ' + } + found = true + break + } } if (found === false) { diff --git a/UI/AppPostLoader.js b/UI/AppPostLoader.js index ede56fa5a..2b35301c5 100644 --- a/UI/AppPostLoader.js +++ b/UI/AppPostLoader.js @@ -42,13 +42,15 @@ function newAppPostLoader() { appSchema: [], docsNodeSchema: [], docsConceptSchema: [], - docsTopicSchema: [] + docsTopicSchema: [], + docsBookSchema: [] }, map: { appSchema: new Map(), docsNodeSchema: new Map(), docsConceptSchema: new Map(), - docsTopicSchema: new Map() + docsTopicSchema: new Map(), + docsBookSchema: new Map() } } SCHEMAS_BY_PROJECT.set(project, schemas) @@ -132,6 +134,26 @@ function newAppPostLoader() { webServerResponses++ if (webServerResponses === totalWebServerCalls) { startCanvas() } } + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/DocsBookSchema', onResponseBookSchema) + + function onResponseBookSchema(err, schema) { + try { + schemas.array.docsBookSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docsBookSchema.length; j++) { + let schemaDocument = schemas.array.docsBookSchema[j] + let key = schemaDocument.type + schemas.map.docsBookSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { startCanvas() } + } } }