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 + '