From 6fbb82272ebe42757bb18cc2a7c1e8a8945faee6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 14 May 2020 16:34:08 +0200 Subject: [PATCH] Loading Workspace Working --- Canvas.js | 2 +- DesignSpace/Workspace/Workspace.js | 34 ++++++++++++++++++++++++++---- SideSpace/ListItem.js | 6 +++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Canvas.js b/Canvas.js index db6104f40..af920101a 100644 --- a/Canvas.js +++ b/Canvas.js @@ -711,7 +711,7 @@ function newCanvas () { let container /* We check if the mouse is over an element of the Side Space / */ - container = thisObject.sideSpace.getContainer(point) + container = thisObject.sideSpace.getContainer(point, GET_CONTAINER_PURPOSE.MOUSE_CLICK) if (container !== undefined && container.isClickeable === true) { container.eventHandler.raiseEvent('onMouseClick', point) diff --git a/DesignSpace/Workspace/Workspace.js b/DesignSpace/Workspace/Workspace.js index 710f90310..6c7274bf0 100644 --- a/DesignSpace/Workspace/Workspace.js +++ b/DesignSpace/Workspace/Workspace.js @@ -11,6 +11,7 @@ function newWorkspace () { enabled: false, nodeChildren: undefined, eventsServerClients: new Map(), + replaceWorkspaceByLoadingOne: replaceWorkspaceByLoadingOne, save: saveWorkspace, getHierarchyHeads: getHierarchyHeads, getNodeThatIsOnFocus: getNodeThatIsOnFocus, @@ -68,7 +69,7 @@ function newWorkspace () { let workingAtTask = 0 let circularProgressBar = newBusyProgressBar() circularProgressBar.fitFunction = canvas.floatingSpace.fitIntoVisibleArea - let droppedNode + let loadedWorkspaceNode let sessionTimestamp = (new Date()).valueOf() window.localStorage.setItem('Session Timestamp', sessionTimestamp) @@ -238,8 +239,8 @@ function newWorkspace () { workingAtTask++ break case 3: - thisObject.workspaceNode = droppedNode - droppedNode = undefined + thisObject.workspaceNode = loadedWorkspaceNode + loadedWorkspaceNode = undefined workingAtTask++ break case 4: @@ -339,6 +340,30 @@ function newWorkspace () { return nodes } + function replaceWorkspaceByLoadingOne (name) { + let blobService = newFileStorage() + blobService.getFileFromHost('LoadWorkspace' + '/' + name, onFileReceived, true) + function onFileReceived (err, text, response) { + if (err && err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + canvas.cockpitSpace.setStatus('Could not load the Workspace called "' + name + '". ', 500, canvas.cockpitSpace.statusTypes.WARNING) + return + } + + loadedWorkspaceNode = JSON.parse(text) + + canvas.cockpitSpace.toTop() + + let position = { + x: browserCanvas.width / 2, + y: browserCanvas.height / 2 + } + + circularProgressBar.initialize(position) + circularProgressBar.visible = true + workingAtTask = 1 + } + } + function spawn (nodeText, mousePointer) { try { let point = { @@ -349,9 +374,10 @@ function newWorkspace () { spawnPosition.x = point.x spawnPosition.y = point.y - droppedNode = JSON.parse(nodeText) + let droppedNode = JSON.parse(nodeText) if (droppedNode.type === 'Workspace') { + loadedWorkspaceNode = droppedNode circularProgressBar.initialize(mousePointer) circularProgressBar.visible = true workingAtTask = 1 diff --git a/SideSpace/ListItem.js b/SideSpace/ListItem.js index d1aefc3dc..59e982979 100644 --- a/SideSpace/ListItem.js +++ b/SideSpace/ListItem.js @@ -19,6 +19,7 @@ function newListItem () { thisObject.container.isDraggeable = false thisObject.container.isWheelable = false thisObject.container.detectMouseOver = true + thisObject.container.isClickeable = true thisObject.container.frame.width = SIDE_PANEL_WIDTH * 0.75 thisObject.container.frame.height = SIDE_PANEL_WIDTH * 0.75 @@ -27,6 +28,7 @@ function newListItem () { let onMouseOverEventSubscriptionId let onMouseNotOverEventSubscriptionId + let onMouseClickEventSubscriptionId let isMouseOver = false return thisObject @@ -34,6 +36,7 @@ function newListItem () { function finalize () { thisObject.container.eventHandler.stopListening(onMouseOverEventSubscriptionId) thisObject.container.eventHandler.stopListening(onMouseNotOverEventSubscriptionId) + thisObject.container.eventHandler.stopListening(onMouseClickEventSubscriptionId) thisObject.container.finalize() thisObject.container = undefined @@ -46,6 +49,7 @@ function newListItem () { onMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver) onMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver) + onMouseClickEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick) } function getContainer (point) { @@ -63,7 +67,7 @@ function newListItem () { } function onMouseClick (event) { - + canvas.designSpace.workspace.replaceWorkspaceByLoadingOne(name) } function physics () {