diff --git a/Desktop/httpInterface.js b/Desktop/Client/httpInterface.js similarity index 95% rename from Desktop/httpInterface.js rename to Desktop/Client/httpInterface.js index ddbddda7e..22a202645 100644 --- a/Desktop/httpInterface.js +++ b/Desktop/Client/httpInterface.js @@ -37,7 +37,7 @@ exports.newHttpInterface = function newHttpInterface() { switch (endpointOrFile) { case 'Images': // This means the Images folder. { - let path = global.env.PATH_TO_CLIENT + '/WebServer/Images/' + requestPath[2] + let path = global.env.PATH_TO_DESKTOP + '/WebServer/Images/' + requestPath[2] if (requestPath[3] !== undefined) { path = path + '/' + requestPath[3] diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index d2bb686db..e04a0ddad 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -19,8 +19,8 @@ exports.newDesktopApp = function newDesktopApp() { //await DK.webSocketsClient.initialize() /* These are the Network Interfaces by which the UI interacts with the Desktop App.*/ - //let WEB_SOCKETS_INTERFACE = require('./webSocketsInterface.js') - let HTTP_INTERFACE = require('./httpInterface.js') + //let WEB_SOCKETS_INTERFACE = require('./Client/webSocketsInterface.js') + let HTTP_INTERFACE = require('./Client/httpInterface.js') /* WEB_SOCKETS_INTERFACE = WEB_SOCKETS_INTERFACE.newWebSocketsInterface() diff --git a/Desktop/UI/AppPostLoader.js b/Desktop/UI/AppPostLoader.js new file mode 100644 index 000000000..b73803e3c --- /dev/null +++ b/Desktop/UI/AppPostLoader.js @@ -0,0 +1,232 @@ + + +function newAppPostLoader() { + const MODULE_NAME = 'Post Loader' + const ERROR_LOG = true + const logger = newWebDebugLog() + + + let thisObject = { + start: start + } + + return thisObject + + function start() { + try { + + // autoSaveWhenClosingTheBrowser() + setupProjectsSchema() + + function setupProjectsSchema() { + httpRequest(undefined, 'ProjectsSchema', onResponse) + + function onResponse(err, file) { + PROJECTS_SCHEMA = JSON.parse(file) + setupSchemas() + } + } + + function setupSchemas() { + + let totalWebServerCalls = 0 + let webServerResponses = 0 + + for (let i = 0; i < PROJECTS_SCHEMA.length; i++) { + let project = PROJECTS_SCHEMA[i].name + let schemas = { + array: { + appSchema: [], + docsNodeSchema: [], + docsConceptSchema: [], + docsTopicSchema: [], + docsTutorialSchema: [], + docsReviewSchema: [], + docsBookSchema: [] + }, + map: { + appSchema: new Map(), + docsNodeSchema: new Map(), + docsConceptSchema: new Map(), + docsTopicSchema: new Map(), + docsTutorialSchema: new Map(), + docsReviewSchema: new Map(), + docsBookSchema: new Map() + } + } + SCHEMAS_BY_PROJECT.set(project, schemas) + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/AppSchema', onResponseAppSchema) + + function onResponseAppSchema(err, schema) { + try { + schemas.array.appSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.appSchema.length; j++) { + let schemaDocument = schemas.array.appSchema[j] + let key = schemaDocument.type + schemas.map.appSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { startCanvas() } + } + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/DocsNodeSchema', onResponseDocSchema) + + function onResponseDocSchema(err, schema) { + try { + schemas.array.docsNodeSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docsNodeSchema.length; j++) { + let schemaDocument = schemas.array.docsNodeSchema[j] + let key = schemaDocument.type + schemas.map.docsNodeSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { startCanvas() } + } + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/DocsConceptSchema', onResponseConceptSchema) + + function onResponseConceptSchema(err, schema) { + try { + schemas.array.docsConceptSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docsConceptSchema.length; j++) { + let schemaDocument = schemas.array.docsConceptSchema[j] + let key = schemaDocument.type + schemas.map.docsConceptSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { startCanvas() } + } + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/DocsTopicSchema', onResponseTopicSchema) + + function onResponseTopicSchema(err, schema) { + try { + schemas.array.docsTopicSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docsTopicSchema.length; j++) { + let schemaDocument = schemas.array.docsTopicSchema[j] + let key = schemaDocument.type + schemas.map.docsTopicSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { startCanvas() } + } + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/DocsTutorialSchema', onResponseTutorialSchema) + + function onResponseTutorialSchema(err, schema) { + try { + schemas.array.docsTutorialSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docsTutorialSchema.length; j++) { + let schemaDocument = schemas.array.docsTutorialSchema[j] + let key = schemaDocument.type + schemas.map.docsTutorialSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + webServerResponses++ + if (webServerResponses === totalWebServerCalls) { startCanvas() } + } + + totalWebServerCalls++ + httpRequest(undefined, 'Schema/' + project + '/DocsReviewSchema', onResponseReviewSchema) + + function onResponseReviewSchema(err, schema) { + try { + schemas.array.docsReviewSchema = JSON.parse(schema) + + for (let j = 0; j < schemas.array.docsReviewSchema.length; j++) { + let schemaDocument = schemas.array.docsReviewSchema[j] + let key = schemaDocument.type + schemas.map.docsReviewSchema.set(key, schemaDocument) + } + } catch (err) { + console.log(err.stack) + } + + 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() } + } + } + } + + function startCanvas() { + /* If this method is executed for a second time, it should finalize the current execution structure */ + if (canvas !== undefined) { canvas.finalize() } + + canvas = newCanvas() + canvas.initialize() + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] start -> err = ' + err.stack) } + } + } + + function autoSaveWhenClosingTheBrowser() { + window.onbeforeunload = saveWorkspace + + /* handles backspace and refresh(F5) from keyboard */ + window.manageBackRefresh = function (event) { + var tag = event.target.tagName.toLowerCase() + if (event.keyCode === 8 && tag !== 'input' && tag !== 'textarea') { // Backbutton pressed + saveWorkspace() + } else if (event.keyCode === 116) { // F5 pressed + saveWorkspace() + } + } + + window.addEventListener('keydown', window.manageBackRefresh) + + function saveWorkspace() { + UI.projects.foundations.spaces.designSpace.workspace.save() + } + } +} diff --git a/Desktop/UI/AppPreLoader.js b/Desktop/UI/AppPreLoader.js new file mode 100644 index 000000000..09002d258 --- /dev/null +++ b/Desktop/UI/AppPreLoader.js @@ -0,0 +1,181 @@ + +/* Callbacks default responses. */ + +let GLOBAL = {} + +GLOBAL.DEFAULT_OK_RESPONSE = { + result: "Ok", + message: "Operation Succeeded" +} + +GLOBAL.DEFAULT_FAIL_RESPONSE = { + result: "Fail", + message: "Operation Failed" +} + +GLOBAL.DEFAULT_RETRY_RESPONSE = { + result: "Retry", + message: "Retry Later" +} + +GLOBAL.CUSTOM_OK_RESPONSE = { + result: "Ok, but check Message", + message: "Custom Message" +} + +GLOBAL.CUSTOM_FAIL_RESPONSE = { + result: "Fail Because", + message: "Custom Message" +} + +let browserCanvas // This is the canvas object of the browser. + +function spacePad(str, max) { + str = str.toString() + return str.length < max ? spacePad(" " + str, max) : str +} + +function loadSuperalgos() { + + const MODULE_NAME = "App Pre-Loader" + const INFO_LOG = false + + let browser = checkBrowserVersion() + setupHTMLTextArea() + setupHTMLInput() + setupHTMLCanvas() + loadDebugModule() + + if ((browser.name !== "Chrome" && browser.name!=="Safari") || (browser.name === "Chrome" && parseInt(browser.version) < 85) || (browser.name === "Safari" && parseInt(browser.version) < 13)) { + alert("Superalgos is officially supported on Google Chrome 85 or Safari 13.1 and above. Your browser version has been detected as potentially beneath this. If you continue you may experience some functionaility issues.\n\nDetected Browser: " + browser.name + "\nVersion: " + browser.version) + } + + function checkBrowserVersion () { + + let ua=navigator.userAgent,tem,M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [] + if(/trident/i.test(M[1])){ + tem=/\brv[ :]+(\d+)/g.exec(ua) || [] + return {name:'IE',version:(tem[1]||'')} + } + if(M[1]==='Chrome'){ + tem=ua.match(/\bOPR|Edge\/(\d+)/) + if(tem!=null) {return {name:'Opera', version:tem[1]}} + } + M=M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'] + if((tem=ua.match(/version\/(\d+)/i))!=null) {M.splice(1,1,tem[1])} + return { + name: M[0], + version: M[1] + } + } + + function setupHTMLTextArea() { + let textArea = document.createElement('textarea') + textArea.id = "textArea" + textArea.spellcheck = false + textArea.style = 'resize: none;' + + ' border: none;' + + ' outline: none;' + + 'box-shadow: none;' + + 'overflow:hidden;' + + 'font-family: ' + 'Saira' + ';' + + 'font-size: 12px;' + + 'background-color: rgb(255, 255, 255);' + + 'color:rgb(255, 255, 255);' + + 'width: ' + 600 + 'px;' + + 'height: ' + 400 + 'px' + + let textAreaDiv = document.getElementById('textAreaDiv') + textAreaDiv.appendChild(textArea) + textAreaDiv.style = 'position:fixed; top:' + -1500 + 'px; left:' + 500 + 'px; z-index:10; ' + } + + function setupHTMLInput() { + let input = document.createElement('input') + input.id = "input" + input.spellcheck = false + input.style = "border: none; outline: none; box-shadow: none; overflow:hidden; width: 0px; height: 0px;" + + let inputDiv = document.getElementById('inputDiv') + inputDiv.appendChild(input) + } + + function setupHTMLCanvas() { + let canvas = document.createElement('canvas') + + canvas.id = "canvas" + canvas.width = 1400 + canvas.height = 600 + canvas.style.border = "0" + canvas.style = "position:absolute; top:0px; left:0px; z-index:1" + + let canvasApp = document.getElementById('canvasApp') + canvasApp.appendChild(canvas) + + browserCanvas = document.getElementById('canvas') + + browserCanvas.width = window.innerWidth + browserCanvas.height = window.innerHeight + browserCanvas.style.border = "none" + + browserCanvas.style.top = 0 + 'px' + } + + function loadDebugModule() { + let path = "WebDebugLog.js" + REQUIREJS([path], onRequired) + + function onRequired(pModule) { + if (INFO_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[INFO] " + path + " downloaded.") } + loadModules() + } + } + + /* And Finally, we start loading all the scripts we will inmediatelly need. */ + function loadModules() { + let path = "AppLoader.js" + REQUIREJS([path], onRequired) + + function onRequired(pModule) { + if (INFO_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[INFO] " + path + " downloaded.") } + let APP_LOADER_MODULE = newAppLoader() + APP_LOADER_MODULE.loadModules() + } + } +} + +function httpRequest(pContentToSend, pPath, callBackFunction) { + let xmlHttpRequest = new XMLHttpRequest() + xmlHttpRequest.onreadystatechange = function () { + if (this.readyState === 4 && this.status === 200) { + try { + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, xmlHttpRequest.responseText) + } catch(err) { + console.log('[ERROR] httpRequest -> httpRequest -> err.stack = '+ err.stack) + console.log('[ERROR] httpRequest -> httpRequest -> pContentToSend = '+ pContentToSend) + console.log('[ERROR] httpRequest -> httpRequest -> pPath = '+ pPath) + console.log('[ERROR] httpRequest -> httpRequest -> xmlHttpRequest.responseText = '+ xmlHttpRequest.responseText) + console.log('[ERROR] httpRequest -> httpRequest -> callBackFunction = '+ callBackFunction) + + } + return + } else if (this.readyState === 4 && this.status === 404) { + callBackFunction({ result: "Fail", message: xmlHttpRequest.responseText.trim(), code: xmlHttpRequest.responseText.trim() }) + return + } + } + + if (pContentToSend === undefined) { + xmlHttpRequest.open("GET", pPath, true) + xmlHttpRequest.send() + } else { + try { + let blob = new Blob([pContentToSend], { type: 'text/plain' }) + xmlHttpRequest.open("POST", pPath, true) + xmlHttpRequest.send(blob) + } catch (err) { + if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] callServer -> err.message = " & err.message) } + callBackFunction({ result: "Fail", message: err.message }) + } + } +} diff --git a/Platform/UI/AppLoader.js b/Platform/UI/AppLoader.js index b17587624..eb8f87864 100644 --- a/Platform/UI/AppLoader.js +++ b/Platform/UI/AppLoader.js @@ -5,7 +5,7 @@ function newAppLoader() { const INFO_LOG = false const ERROR_LOG = true const logger = newWebDebugLog() - + let thisObject = { loadModules: loadModules @@ -64,16 +64,16 @@ function newAppLoader() { let fileArray = JSON.parse(fileList) for (let i = 0; i < fileArray.length; i++) { let item = fileArray[i] - + project = item[0] fileName = item[1] - urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Function-Libraries' + '/' + fileName) + urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Function-Libraries' + '/' + fileName) } modulesArray = modulesArray.concat(urlArray) utilities() } - } + } function utilities() { let url = 'ListUtilitiesFiles' @@ -84,16 +84,16 @@ function newAppLoader() { let fileArray = JSON.parse(fileList) for (let i = 0; i < fileArray.length; i++) { let item = fileArray[i] - + project = item[0] fileName = item[1] - urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Utilities' + '/' + fileName) + urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Utilities' + '/' + fileName) } modulesArray = modulesArray.concat(urlArray) globals() } - } + } function globals() { let url = 'ListGlobalFiles' @@ -104,16 +104,16 @@ function newAppLoader() { let fileArray = JSON.parse(fileList) for (let i = 0; i < fileArray.length; i++) { let item = fileArray[i] - + project = item[0] fileName = item[1] - urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Globals' + '/' + fileName) + urlArray.push('Projects' + '/' + project + '/' + 'UI' + '/' + 'Globals' + '/' + fileName) } modulesArray = modulesArray.concat(urlArray) spaces() } - } + } function spaces() { let url = 'ListSpaceFiles' @@ -138,7 +138,7 @@ function newAppLoader() { for (let i = 0; i < modulesArray.length; i++) { let path = modulesArray[i] - + console.log(path) REQUIREJS([path], onRequired) if (INFO_LOG === true) { logger.write('[INFO] loadModules -> Module Requested.') }