Saving and Loading Workspace from Backend

This commit is contained in:
Luis Fernando Molina committed 2020-05-11 20:21:55 +02:00
1 parent 99e233cd3f
commit 7b540068c0
5 files changed
+52 -31

No files matched your search

+4 -8
View File
@@ -109,12 +109,12 @@ function newCanvas () {
thisObject.topSpace = newTopSpace()
thisObject.topSpace.initialize()
thisObject.designSpace = newDesignSpace()
thisObject.designSpace.initialize()
thisObject.cockpitSpace = newCockpitSpace()
thisObject.cockpitSpace.initialize()
thisObject.designSpace = newDesignSpace()
thisObject.designSpace.initialize()
thisObject.panelsSpace = newPanelsSpace()
thisObject.panelsSpace.initialize()
@@ -295,11 +295,7 @@ function newCanvas () {
}
if (event.shiftKey === true && (event.ctrlKey === true || event.metaKey === true) && (event.key === 'S' || event.key === 's')) {
let saved = canvas.designSpace.workspace.save()
if (saved === true) {
canvas.cockpitSpace.setStatus('Workspace Saved.', 50, canvas.cockpitSpace.statusTypes.ALL_GOOD)
}
canvas.designSpace.workspace.save()
event.preventDefault()
return
}
@@ -22,7 +22,7 @@ function newUiObjectsFromNodes () {
addIncludedNodes()
function addIncludedNodes () {
blobService = newFileStorage()
let blobService = newFileStorage()
// if (node.code === undefined) {
node.code = '{ \n"includeDataMines": ["Masters", "Sparta", "TradingEngines"],\n"includeTradingSystems": ["Sparta-WHB-BTC-USDT", "Example-ETH-USDT", "Sparta-BRR-BTC-USDT"],\n"includeSuperScripts": ["Masters"]\n }'
+29 -12
View File
@@ -85,19 +85,34 @@ function newWorkspace () {
function initialize () {
try {
let reset = window.localStorage.getItem('Reset')
let savedWorkspace = window.localStorage.getItem(CANVAS_APP_NAME + '.' + 'Workspace')
let lastUsedWorkspace = window.localStorage.getItem('Last Used Workspace')
if (savedWorkspace === null || reset !== null) {
thisObject.workspaceNode = getWorkspace()
if (lastUsedWorkspace !== 'undefined' && lastUsedWorkspace !== null && lastUsedWorkspace !== undefined) {
let blobService = newFileStorage()
blobService.getFileFromHost('LoadWorkspace' + '/' + lastUsedWorkspace, onFileReceived, true)
function onFileReceived (err, text, response) {
if (err && err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
canvas.cockpitSpace.setStatus('Could not load the last Workspace used, called "' + lastUsedWorkspace + '". Will switch to the default Workspace instead.', 500, canvas.cockpitSpace.statusTypes.WARNING)
thisObject.workspaceNode = getWorkspace() // This is the default workspace that comes with the system.
finishInitialization()
return
}
thisObject.workspaceNode = JSON.parse(text)
finishInitialization()
}
} else {
thisObject.workspaceNode = JSON.parse(savedWorkspace)
thisObject.workspaceNode = getWorkspace() // This is the default workspace that comes with the system.
finishInitialization()
}
functionLibraryUiObjectsFromNodes.recreateWorkspace(thisObject.workspaceNode)
setupEventsServerClients()
thisObject.enabled = true
setInterval(saveWorkspace, 60000)
function finishInitialization () {
functionLibraryUiObjectsFromNodes.recreateWorkspace(thisObject.workspaceNode)
setupEventsServerClients()
thisObject.enabled = true
canvas.cockpitSpace.initializePosition()
setInterval(saveWorkspace, 60000)
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err.stack) }
}
@@ -171,14 +186,16 @@ function newWorkspace () {
window.localStorage.setItem(CANVAS_APP_NAME + '.' + 'Workspace', textToSave)
window.localStorage.setItem('Session Timestamp', sessionTimestamp)
let url = 'SaveWorkspace/' + workspace.name
callServer(textToSave, url, onResponse)
if (workspace.name !== undefined) {
let url = 'SaveWorkspace/' + workspace.name
callServer(textToSave, url, onResponse)
}
function onResponse (err) {
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
window.localStorage.setItem('Last Used Workspace', workspace.name)
window.localStorage.setItem('Session Timestamp', sessionTimestamp)
canvas.cockpitSpace.setStatus('Workspace Auto-Saved.', 50, canvas.cockpitSpace.statusTypes.ALL_GOOD)
canvas.cockpitSpace.setStatus(workspace.name + ' Saved.', 50, canvas.cockpitSpace.statusTypes.ALL_GOOD)
} else {
canvas.cockpitSpace.setStatus('Could not save the Workspace at the Backend. Please check the Backend Console for more information.', 150, canvas.cockpitSpace.statusTypes.WARNING)
}
+4 -2
View File
@@ -96,8 +96,10 @@ function newChartingSpace () {
let rootNodes = canvas.designSpace.workspace.workspaceNode.rootNodes
for (let i = 0; i < rootNodes.length; i++) {
let rootNode = rootNodes[i]
if (rootNode.type === 'Charting Space') {
thisObject.payload = rootNode.payload
if (rootNode !== null) {
if (rootNode.type === 'Charting Space') {
thisObject.payload = rootNode.payload
}
}
}
+14 -8
View File
@@ -20,7 +20,8 @@
physics: physics,
getContainer: getContainer,
finalize: finalize,
initialize: initialize
initialize: initialize,
initializePosition: initializePosition
}
thisObject.container = newContainer()
@@ -39,6 +40,7 @@
let statusCounter = 0
let statusText
let statusType
let isInitilized = false
return thisObject
@@ -52,6 +54,15 @@
}
function initialize () {
canvasBrowserResizedEventSubscriptionId = canvas.eventHandler.listenToEvent('Browser Resized', resize)
selfMouseClickEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick)
thisObject.fullscreen = newFullScreen()
thisObject.fullscreen.container.connectToParent(thisObject.container)
thisObject.fullscreen.initialize()
}
function initializePosition () {
thisObject.container.frame.position.x = 0
let INITIAL_POSITION
@@ -68,13 +79,7 @@
INITIAL_POSITION = 100
thisObject.container.frame.position.y = browserCanvas.height * INITIAL_POSITION / 100 - COCKPIT_SPACE_HEIGHT
}
canvasBrowserResizedEventSubscriptionId = canvas.eventHandler.listenToEvent('Browser Resized', resize)
selfMouseClickEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick)
thisObject.fullscreen = newFullScreen()
thisObject.fullscreen.container.connectToParent(thisObject.container)
thisObject.fullscreen.initialize()
isInitilized = true
}
function onMouseClick (event) {
@@ -148,6 +153,7 @@
thisObject.fullscreen.physics()
}
function thisObjectPhysics () {
if (isInitilized === false) { return }
/* Check the limits */
thisObject.status = 'MIDDLE'