diff --git a/Client/httpInterface.js b/Client/httpInterface.js index d974b3a78..e5858d785 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -602,6 +602,52 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } break } + case 'Update': { + try { + const message = unescape(requestParameters[3]) + const username = unescape(requestParameters[4]) + const token = unescape(requestParameters[5]) + + update() + + async function update() { + let message = await doGit() + + let customResponse = { + result: global.CUSTOM_OK_RESPONSE.result, + message: message + } + respondWithContent(JSON.stringify(customResponse), httpResponse) + } + + async function doGit() { + const simpleGit = require('simple-git'); + const options = { + baseDir: process.cwd(), + binary: 'git', + maxConcurrentProcesses: 6, + } + const git = simpleGit(options) + + return await git.pull('upstream', 'in-app-documentation') + } + + } catch (err) { + console.log('[ERROR] httpInterface -> App -> Update -> Method call produced an error.') + console.log('[ERROR] httpInterface -> App -> Update -> err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> App -> Update -> commitMessage = ' + commitMessage) + console.log('[ERROR] httpInterface -> App -> Update -> username = ' + username) + console.log('[ERROR] httpInterface -> App -> Update -> token = ' + token) + + let error = { + result: 'Fail Because', + message: err.message, + stack: err.stack + } + respondWithContent(JSON.stringify(error), httpResponse) + } + break + } } } break diff --git a/Projects/Superalgos/Schemas/Docs-Topics/app-commands-002-app-update-command.json b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-002-app-update-command.json new file mode 100644 index 000000000..3c7341b28 --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-002-app-update-command.json @@ -0,0 +1,37 @@ +{ + "topic": "App Commands", + "pageNumber": "2", + "type": "App Update Command", + "definition": { + "text": "Use this command to update your local installation of Superalgos to the latest version available. ", + "updated": 1610449365984 + }, + "paragraphs": [ + { + "style": "Title", + "text": "Syntax", + "updated": 1610449451990 + }, + { + "style": "Json", + "text": "docs.update Message" + }, + { + "style": "Title", + "text": "Parameters" + }, + { + "style": "List", + "text": "Message: This is optional. It is the message that is going to be recorded at Github.com when we merge for you the branch of the main repository into the branch of your fork.", + "updated": 1610449466750 + }, + { + "style": "Title", + "text": "Examples" + }, + { + "style": "Json", + "text": "app.update" + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/Schemas/Docs-Topics/app-commands-errors-001-app-error-contribution-not-sent.json b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-errors-001-app-error-contribution-not-sent.json index c56501b93..f08d1fe9c 100644 --- a/Projects/Superalgos/Schemas/Docs-Topics/app-commands-errors-001-app-error-contribution-not-sent.json +++ b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-errors-001-app-error-contribution-not-sent.json @@ -3,14 +3,14 @@ "pageNumber": "1", "type": "App Error Contribution Not Sent", "definition": { - "text": "There was a problmen trying to send your contribution to your fork of the Superalgos repository.", - "updated": 1609859551082 + "text": "There was a problmen trying to send your contribution to your fork of the Superalgos repository, or from your fork to the Superalgos/Superalgos main repository.", + "updated": 1610441932801 }, "paragraphs": [ { "style": "Text", - "text": "Left click and Edit to enter edit mode and change this text. ENTER to write new paragraphs. ESC to exit edit mode. 2", - "updated": 1609860582103 + "text": "You will need to check for the Client's console for details on what happened. After you fix the issue that prevented the App Contribute Command to run, you might try again.", + "updated": 1610441999433 } ] } \ No newline at end of file diff --git a/Projects/Superalgos/Schemas/Docs-Topics/app-commands-errors-002-app-error-github-credentials-missing.json b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-errors-002-app-error-github-credentials-missing.json index 5688aad8e..e767a40c3 100644 --- a/Projects/Superalgos/Schemas/Docs-Topics/app-commands-errors-002-app-error-github-credentials-missing.json +++ b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-errors-002-app-error-github-credentials-missing.json @@ -3,8 +3,8 @@ "pageNumber": "2", "type": "App Error Github Credentials Missing", "definition": { - "text": "In order to manage contributions from within the app, you first need to provide your Github.com credentials so that we can get you authenticated when pushing your changes to the remote repository.", - "updated": 1609945324462 + "text": "In order to manage contributions from within the app, or update the app by running a command; you first need to provide your Github.com credentials so that we can get you authenticated when pushing your changes to the remote repository.", + "updated": 1610449696988 }, "paragraphs": [ { @@ -21,6 +21,18 @@ "text": "To solve this issue follow the following instructions on how to set up your GitHub.com credentials so that the system can automate the tasks needed to submit your contributions to the main repository of the Superalgos project.", "updated": 1609945787577 }, + { + "style": "Title", + "text": "Applies to" + }, + { + "style": "List", + "text": "App Contribute Command" + }, + { + "style": "List", + "text": "App Update Command" + }, { "style": "Include", "text": "Superalgos->Topic->App Contribute Command->Block Authentication", diff --git a/Projects/Superalgos/Schemas/Docs-Topics/app-commands-errors-003-app-error-update-failed.json b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-errors-003-app-error-update-failed.json new file mode 100644 index 000000000..9cce99af6 --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-errors-003-app-error-update-failed.json @@ -0,0 +1,14 @@ +{ + "topic": "App Commands Errors", + "pageNumber": "3", + "type": "App Error Update Failed", + "definition": { + "text": "Write here a summary for this topic page." + }, + "paragraphs": [ + { + "style": "Text", + "text": "Left click and Edit to enter edit mode and change this text. ENTER to write new paragraphs. ESC to exit edit mode." + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/Schemas/Docs-Topics/app-commands-messages-003-app-message-updating-your-local-app.json b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-messages-003-app-message-updating-your-local-app.json new file mode 100644 index 000000000..d1f82b8dc --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-messages-003-app-message-updating-your-local-app.json @@ -0,0 +1,14 @@ +{ + "topic": "App Commands Messages", + "pageNumber": "3", + "type": "App Message Updating Your Local App", + "definition": { + "text": "Write here a summary for this topic page." + }, + "paragraphs": [ + { + "style": "Text", + "text": "Left click and Edit to enter edit mode and change this text. ENTER to write new paragraphs. ESC to exit edit mode." + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/Schemas/Docs-Topics/app-commands-messages-004-app-message-update-succeed-new-version-found.json b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-messages-004-app-message-update-succeed-new-version-found.json new file mode 100644 index 000000000..509eb2f5d --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-messages-004-app-message-update-succeed-new-version-found.json @@ -0,0 +1,16 @@ +{ + "topic": "App Commands Messages", + "pageNumber": "4", + "type": "App Message Update Succeed - New Version Found", + "definition": { + "text": "The update process ran successfully. It found a new version of Superalgos and it download it replacing the current one. In order for the new changes to take effect, you need to restart the Client and refresh the UI page.", + "updated": 1610454363656 + }, + "paragraphs": [ + { + "style": "Success", + "text": "You now have the latest version of Superalgos. Just remeber to restart the Client and the UI.", + "updated": 1610454408134 + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/Schemas/Docs-Topics/app-commands-messages-005-app-message-update-succeed-already-up-to-date.json b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-messages-005-app-message-update-succeed-already-up-to-date.json new file mode 100644 index 000000000..31c015f14 --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/app-commands-messages-005-app-message-update-succeed-already-up-to-date.json @@ -0,0 +1,16 @@ +{ + "topic": "App Commands Messages", + "pageNumber": "5", + "type": "App Message Update Succeed - Already Up-To-Date", + "definition": { + "text": "The update process was executed successfully, but no changes where found since you were running the latest version of Superalgos. No further action need to be taken.", + "updated": 1610454235682 + }, + "paragraphs": [ + { + "style": "Success", + "text": "You are up-to-date. No need to reboot the Client or refresh the UI page.", + "updated": 1610454271911 + } + ] +} \ 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 66e155ebc..e645b8790 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js @@ -18,18 +18,22 @@ function newSuperalgosDocsCommmandInterface() { function detectCommands() { if (detectAppCommands() === true) { return } - detectDocsCommands() + if (detectDocsCommands() === true) { return } + + /* If we can not detect any app or docs commands, then we assume the users is running a search query */ + UI.projects.superalgos.spaces.docsSpace.searchResultsPage.render() } function detectAppCommands() { - if (checkContributeCommand() === undefined) { return } else { return true } + if (checkContributeCommand() === undefined) { return true } + if (checkUpdateCommand() === undefined) { return true } function checkContributeCommand() { if (UI.projects.superalgos.spaces.docsSpace.commandInterface.command.toLowerCase() === 'app.help app.contribute') { UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Contribute Command') return } - if (UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf('App.Contribute') !== 0 && UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf('app.contribute') !== 0) { return } + if (UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf('App.Contribute') !== 0 && UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf('app.contribute') !== 0) { return 'Not Contribute Commands' } /* Set up the commit message */ let message = UI.projects.superalgos.spaces.docsSpace.commandInterface.command.trim().substring(UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf(' ') + 1, UI.projects.superalgos.spaces.docsSpace.commandInterface.command.length) @@ -41,27 +45,27 @@ function newSuperalgosDocsCommmandInterface() { let apisNode = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByType('APIs') if (apisNode === undefined) { UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error Github Credentials Missing', 'Anchor Github Credentials Missing') - return true + return } if (apisNode.githubAPI === undefined) { UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error Github Credentials Missing', 'Anchor Github Credentials Missing') - return true + return } let config = JSON.parse(apisNode.githubAPI.config) if (config.username === undefined || config.username === "") { UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error Github Credentials Missing', 'Anchor Github Credentials Missing') - return true + return } if (config.token === undefined || config.token === "") { UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error Github Credentials Missing', 'Anchor Github Credentials Missing') - return true + return } httpRequest(undefined, 'App/Contribute/' + message + '/' + config.username + '/' + config.token, onResponse) UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Message Creating Pull Request') - return true + return function onResponse(err, data) { /* Lets check the result of the call through the http interface */ @@ -69,11 +73,61 @@ function newSuperalgosDocsCommmandInterface() { if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result && data.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Message Contribution Succeed') } else { - if (data.message === 'File Github.json does not exist.') { - UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error Github Credentials Missing', 'Anchor Github Credentials Missing') + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error Contribution Not Sent', 'Anchor Contribution Not Sent') + } + } + } + + function checkUpdateCommand() { + if (UI.projects.superalgos.spaces.docsSpace.commandInterface.command.toLowerCase() === 'app.help app.update') { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Update Command') + return + } + if (UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf('App.Update') !== 0 && UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf('app.update') !== 0) { return 'Not Update Commands' } + + /* Set up the commit message */ + let message = UI.projects.superalgos.spaces.docsSpace.commandInterface.command.trim().substring(UI.projects.superalgos.spaces.docsSpace.commandInterface.command.indexOf(' ') + 1, UI.projects.superalgos.spaces.docsSpace.commandInterface.command.length) + if (message.toLowerCase() === 'app.update') { + message = 'Updating my Superalgos Fork and local Repository' + } + + /* Find the Username and Password */ + let apisNode = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByType('APIs') + if (apisNode === undefined) { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error Github Credentials Missing', 'Anchor Github Credentials Missing') + return + } + if (apisNode.githubAPI === undefined) { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error Github Credentials Missing', 'Anchor Github Credentials Missing') + return + } + + let config = JSON.parse(apisNode.githubAPI.config) + if (config.username === undefined || config.username === "") { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error Github Credentials Missing', 'Anchor Github Credentials Missing') + return + } + if (config.token === undefined || config.token === "") { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error Github Credentials Missing', 'Anchor Github Credentials Missing') + return + } + + httpRequest(undefined, 'App/Update/' + message + '/' + config.username + '/' + config.token, onResponse) + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Message Updating Your Local App') + + return + + function onResponse(err, data) { + /* Lets check the result of the call through the http interface */ + data = JSON.parse(data) + if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result && data.result === GLOBAL.CUSTOM_OK_RESPONSE.result) { + if (data.message.summary.changes + data.message.summary.deletions + data.message.summary.insertions > 0) { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Message Update Succeed - New Version Found') } else { - UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error Contribution Not Sent', 'Anchor Contribution Not Sent') + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Message Update Succeed - Already Up-To-Date') } + } else { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error Update Failed', 'Anchor Update Failed') } } } @@ -81,15 +135,13 @@ function newSuperalgosDocsCommmandInterface() { function detectDocsCommands() { - if (checkHelpCommand() === undefined) { return } - if (checkGotoCommand() === undefined) { return } - if (checkAddCommand() === undefined) { return } - if (checkDeleteCommand() === undefined) { return } - if (checkRepaginateCommand() === undefined) { return } - if (checkUReIndexCommand() === undefined) { return } - if (checkUSaveCommand() === undefined) { return } - - UI.projects.superalgos.spaces.docsSpace.searchResultsPage.render() + if (checkHelpCommand() === undefined) { return true } + if (checkGotoCommand() === undefined) { return true } + if (checkAddCommand() === undefined) { return true } + if (checkDeleteCommand() === undefined) { return true } + if (checkRepaginateCommand() === undefined) { return true } + if (checkUReIndexCommand() === undefined) { return true } + if (checkUSaveCommand() === undefined) { return true } function checkHelpCommand() { if (UI.projects.superalgos.spaces.docsSpace.commandInterface.command.toLowerCase() === 'docs.help') { diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index 737fea298..f0a85ed6c 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -195,7 +195,12 @@ function newSuperalgosDocSpace() { thisObject.mainSearchPage.render() } else { - UI.projects.superalgos.spaces.docsSpace.navigateTo(UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project, UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.category, UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.type) + UI.projects.superalgos.spaces.docsSpace.navigateTo( + UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.project, + UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.category, + UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.type, + UI.projects.superalgos.spaces.docsSpace.currentDocumentBeingRendered.anchor + ) } } diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocumentPage.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocumentPage.js index c87ffc495..661ff43f6 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocumentPage.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocumentPage.js @@ -1874,8 +1874,6 @@ function newSuperalgosDocsDocumentPage() { } function exitEditMode() { - /* This will make the Client to save this in a file overwritting the previous version*/ - thisObject.docsSchemaDocument.updated = true /* We will update the paragraph that was being edited*/ let editing diff --git a/Projects/Superalgos/UI/Utilities/Docs.js b/Projects/Superalgos/UI/Utilities/Docs.js index 7e3dc6f81..27151d24c 100644 --- a/Projects/Superalgos/UI/Utilities/Docs.js +++ b/Projects/Superalgos/UI/Utilities/Docs.js @@ -111,8 +111,13 @@ function newSuperalgosUtilitiesDocs() { function setTextBasedOnLanguage(paragraph, text) { if (UI.projects.superalgos.spaces.docsSpace.language === UI.projects.superalgos.globals.docs.DEFAULT_LANGUAGE) { if (paragraph.text !== text) { + + /* This will make the Client to save this in a file overwritting the previous version*/ + UI.projects.superalgos.spaces.docsSpace.documentPage.docsSchemaDocument.updated = true + paragraph.text = text paragraph.updated = (new Date()).valueOf() + } return } else { @@ -131,6 +136,10 @@ function newSuperalgosUtilitiesDocs() { let translation = paragraph.translations[i] if (translation.language === UI.projects.superalgos.spaces.docsSpace.language) { if (translation.text !== text) { + + /* This will make the Client to save this in a file overwritting the previous version*/ + UI.projects.superalgos.spaces.docsSpace.documentPage.docsSchemaDocument.updated = true + translation.text = text translation.updated = (new Date()).valueOf() } @@ -143,6 +152,9 @@ function newSuperalgosUtilitiesDocs() { updated: (new Date()).valueOf() } paragraph.translations.push(translation) + + /* This will make the Client to save this in a file overwritting the previous version*/ + UI.projects.superalgos.spaces.docsSpace.documentPage.docsSchemaDocument.updated = true return }