diff --git a/Client/WebServer/index.html b/Client/WebServer/index.html index 17f9b6d59..b7d9789ef 100644 --- a/Client/WebServer/index.html +++ b/Client/WebServer/index.html @@ -56,8 +56,8 @@ onresize="onResize()">

The UI is loading...

-

Superalgos is free, open-source, and is - constantly improving thanks to the involvement of contributors!

+

Superalgos is free, open-source, and is + constantly improving thanks to the involvement of contributors:

Luis Fernando Molina, Julian Molina, Andreja Cobeljic, Matías Benitez, Ira Miller, Eduardo Remis, Jeff Braun, rico4dev, 9808us, Barry Low, Nikola Bjelogrlic, Hirajin Koizuko, Francisco J. Santillán, Norman, Viktoria B., Guillermo V., Daniel J., diff --git a/Client/httpInterface.js b/Client/httpInterface.js index e5858d785..515bef9fc 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -533,6 +533,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE const commitMessage = unescape(requestParameters[3]) const username = unescape(requestParameters[4]) const token = unescape(requestParameters[5]) + const currentBranch = unescape(requestParameters[6]) + const contributionsBranch = unescape(requestParameters[7]) contribute() @@ -553,7 +555,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE await git.add('./*') await git.commit(commitMessage) - await git.push('origin', 'in-app-documentation') + await git.push('origin', branch) } async function doGithub() { @@ -567,8 +569,8 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE const repo = 'Superalgos' const owner = 'Superalgos' - const head = username + ':in-app-documentation' - const base = 'in-app-documentation' + const head = username + ':' + contributionsBranch + const base = currentBranch const title = 'Contribution: ' + commitMessage try { @@ -604,10 +606,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } case 'Update': { try { - const message = unescape(requestParameters[3]) - const username = unescape(requestParameters[4]) - const token = unescape(requestParameters[5]) - + const currentBranch = unescape(requestParameters[3]) update() async function update() { @@ -629,7 +628,57 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE } const git = simpleGit(options) - return await git.pull('upstream', 'in-app-documentation') + return await git.pull('upstream', currentBranch) + } + + } 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 + } + + case 'Checkout': { + try { + const currentBranch = unescape(requestParameters[3]) + checkout() + + async function checkout() { + let result = await doGit() + + if (result === true) { + respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse) + } else { + respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse) + } + } + + async function doGit() { + const simpleGit = require('simple-git'); + const options = { + baseDir: process.cwd(), + binary: 'git', + maxConcurrentProcesses: 6, + } + const git = simpleGit(options) + try { + await git.checkout(currentBranch) + } catch (err) { + console.log('[ERROR] Error changing current branch to ' + currentBranch) + console.log(err.stack) + return false + } + return true } } catch (err) { diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index b80865cfd..783631241 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -208,6 +208,11 @@ "propertyName": "languages", "functionName": "newSuperalgosUtilitiesLanguages" }, + { + "name": "Git Branches", + "propertyName": "gitBranches", + "functionName": "newSuperalgosUtilitiesGitBranches" + }, { "name": "Docs", "propertyName": "docs", diff --git a/Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-001-switching-branches-changing-active-branch.json b/Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-001-switching-branches-changing-active-branch.json new file mode 100644 index 000000000..f7e156ef7 --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-001-switching-branches-changing-active-branch.json @@ -0,0 +1,14 @@ +{ + "topic": "Branches Management Messages", + "pageNumber": "1", + "type": "Switching Branches - Changing Current Branch", + "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/branches-management-messages-002-switching-branches-active-branch-changed.json b/Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-002-switching-branches-active-branch-changed.json new file mode 100644 index 000000000..c3a73e05b --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-002-switching-branches-active-branch-changed.json @@ -0,0 +1,14 @@ +{ + "topic": "Branches Management Messages", + "pageNumber": "2", + "type": "Switching Branches - Current Branch Changed", + "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/branches-management-messages-003-switching-branches-contributions-branch-changed.json b/Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-003-switching-branches-contributions-branch-changed.json new file mode 100644 index 000000000..0e61c965d --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-003-switching-branches-contributions-branch-changed.json @@ -0,0 +1,14 @@ +{ + "topic": "Branches Management Messages", + "pageNumber": "3", + "type": "Switching Branches - Contributions Branch Changed", + "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/branches-management-messages-004-switching-branches-active-branch-not-changed.json b/Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-004-switching-branches-active-branch-not-changed.json new file mode 100644 index 000000000..23ad5bb16 --- /dev/null +++ b/Projects/Superalgos/Schemas/Docs-Topics/branches-management-messages-004-switching-branches-active-branch-not-changed.json @@ -0,0 +1,14 @@ +{ + "topic": "Branches Management Messages", + "pageNumber": "4", + "type": "Switching Branches - Current Branch Not Changed", + "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/UI/Globals/Docs.js b/Projects/Superalgos/UI/Globals/Docs.js index 0fff2b481..63b869099 100644 --- a/Projects/Superalgos/UI/Globals/Docs.js +++ b/Projects/Superalgos/UI/Globals/Docs.js @@ -2,6 +2,8 @@ function newSuperalgosGlobalsDocs() { thisObject = { NEW_PARAGRAPH_TEXT: "Left click and Edit to enter edit mode and change this text. ENTER to write new paragraphs. ESC to exit edit mode.", DEFAULT_LANGUAGE: 'EN', + DEFAULT_ACTIVE_BRANCH: 'master', + DEFAULT_CONTRIBUTIONS_BRANCH: 'develop', DOCS_SPACE_WIDTH: 900 } return thisObject diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js b/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js index f0c57fa66..4f5b7a9cb 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js @@ -62,7 +62,16 @@ function newSuperalgosDocsCommmandInterface() { return } - httpRequest(undefined, 'App/Contribute/' + message + '/' + config.username + '/' + config.token, onResponse) + httpRequest( + undefined, + 'App/Contribute/' + + message + '/' + + config.username + '/' + + config.token + '/' + + UI.projects.superalgos.spaces.docsSpace.currentBranch + '/' + + UI.projects.superalgos.spaces.docsSpace.contributionBranch + , onResponse) + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Message - Creating Pull Request') return @@ -112,7 +121,7 @@ function newSuperalgosDocsCommmandInterface() { return } - httpRequest(undefined, 'App/Update/' + message + '/' + config.username + '/' + config.token, onResponse) + httpRequest(undefined, 'App/Update/' + UI.projects.superalgos.spaces.docsSpace.currentBranch, onResponse) UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Message - Updating Your Local App') return diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index f0a85ed6c..22298ad47 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -12,6 +12,8 @@ function newSuperalgosDocSpace() { commandInterface: undefined, contextMenu: undefined, language: undefined, + currentBranch: undefined, + contributionsBranch: undefined, menuLabelsMap: undefined, currentDocumentBeingRendered: undefined, previousDocumentBeingRendered: undefined, @@ -20,6 +22,8 @@ function newSuperalgosDocSpace() { textArea: undefined, setUpWorkspaceSchemas: setUpWorkspaceSchemas, changeLanguage: changeLanguage, + changeActiveBranch: changeActiveBranch, + changeContributionsBranch: changeContributionsBranch, enterEditMode: enterEditMode, exitEditMode: exitEditMode, openSpaceAreaAndNavigateTo: openSpaceAreaAndNavigateTo, @@ -57,6 +61,8 @@ function newSuperalgosDocSpace() { setupSidePanelTab() setUpMenuItemsMap() setupUserLanguage() + setupActiveBranch() + setupContributionsBranch() thisObject.searchEngine = newSuperalgosDocsSearchEngine() thisObject.mainSearchPage = newSuperalgosDocsMainSearchPage() @@ -76,6 +82,30 @@ function newSuperalgosDocSpace() { isInitialized = true + function setupActiveBranch() { + /* + Getting the used preferred languague + */ + if (window.localStorage.getItem('Current Branch') !== null && window.localStorage.getItem('Current Branch') !== undefined && window.localStorage.getItem('Current Branch') !== 'undefined') { + UI.projects.superalgos.spaces.docsSpace.currentBranch = window.localStorage.getItem('Current Branch') + } else { + window.localStorage.setItem('Current Branch', UI.projects.superalgos.globals.docs.DEFAULT_ACTIVE_BRANCH) + UI.projects.superalgos.spaces.docsSpace.currentBranch = UI.projects.superalgos.globals.docs.DEFAULT_ACTIVE_BRANCH + } + } + + function setupContributionsBranch() { + /* + Getting the used preferred languague + */ + if (window.localStorage.getItem('Contributions Branch') !== null && window.localStorage.getItem('Contributions Branch') !== undefined && window.localStorage.getItem('Contributions Branch') !== 'undefined') { + UI.projects.superalgos.spaces.docsSpace.contributionsBranch = window.localStorage.getItem('Contributions Branch') + } else { + window.localStorage.setItem('Contributions Branch', UI.projects.superalgos.globals.docs.DEFAULT_CONTRIBUTIONS_BRANCH) + UI.projects.superalgos.spaces.docsSpace.contributionsBranch = UI.projects.superalgos.globals.docs.DEFAULT_CONTRIBUTIONS_BRANCH + } + } + function setupUserLanguage() { /* Getting the used preferred languague @@ -86,7 +116,6 @@ function newSuperalgosDocSpace() { window.localStorage.setItem('Docs Language', UI.projects.superalgos.globals.docs.DEFAULT_LANGUAGE) UI.projects.superalgos.spaces.docsSpace.language = UI.projects.superalgos.globals.docs.DEFAULT_LANGUAGE } - } function setupSidePanelTab() { @@ -155,6 +184,29 @@ function newSuperalgosDocSpace() { initialize() } + function changeActiveBranch(branch) { + window.localStorage.setItem('Current Branch', UI.projects.superalgos.spaces.docsSpace.currentBranch) + httpRequest(undefined, 'App/Checkout/' + branch, onResponse) + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Switching Branches - Changing Current Branch') + + 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.DEFAULT_OK_RESPONSE.result) { + UI.projects.superalgos.spaces.docsSpace.currentBranch = branch + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Switching Branches - Current Branch Changed') + } else { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Switching Branches - Current Branch Not Changed') + } + } + } + + function changeContributionsBranch(branch) { + UI.projects.superalgos.spaces.docsSpace.contributionsBranch = branch + window.localStorage.setItem('Contributions Branch', UI.projects.superalgos.spaces.docsSpace.contributionsBranch) + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Switching Branches - Contributions Branch Changed') + } + function changeLanguage(pLanguage) { UI.projects.superalgos.spaces.docsSpace.language = pLanguage window.localStorage.setItem('Docs Language', UI.projects.superalgos.spaces.docsSpace.language) diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/Footer.js b/Projects/Superalgos/UI/Spaces/Docs-Space/Footer.js index b1b942071..a568c2074 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/Footer.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/Footer.js @@ -1,6 +1,6 @@ function newSuperalgosDocsFooter() { let thisObject = { - addFooter: addFooter, + addFooter: addFooter, initialize: initialize, finalize: finalize } @@ -16,7 +16,6 @@ function newSuperalgosDocsFooter() { } function addFooter() { - let languageLabel = UI.projects.superalgos.utilities.languages.getLaguageLabel(UI.projects.superalgos.spaces.docsSpace.language) let HTML = '' @@ -33,11 +32,11 @@ function newSuperalgosDocsFooter() { HTML = HTML + '

' @@ -54,7 +53,7 @@ function newSuperalgosDocsFooter() { HTML = HTML + '' diff --git a/Projects/Superalgos/UI/Utilities/GitBranches.js b/Projects/Superalgos/UI/Utilities/GitBranches.js new file mode 100644 index 000000000..de134c51b --- /dev/null +++ b/Projects/Superalgos/UI/Utilities/GitBranches.js @@ -0,0 +1,26 @@ +function newSuperalgosUtilitiesGitBranches() { + thisObject = { + getBranchLabel: getBranchLabel + } + + return thisObject + + function getBranchLabel(branch) { + let branchLabel + switch (branch) { + case 'master': { + branchLabel = 'Master' + break + } + case 'develop': { + branchLabel = 'Develop' + break + } + case 'bug-fixes': { + branchLabel = 'Bug Fixes' + break + } + } + return branchLabel + } +} \ No newline at end of file