From 43628bfa29533b798cd781b64b4d8a357dbad43a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 29 Jan 2020 12:28:51 +0100 Subject: [PATCH] IMplementing savePropertyAtNodeConfig --- ChartsSpace/TimeMachine.js | 4 ++-- Panels/Layer.js | 36 +++++++----------------------------- Panels/LayersPanel.js | 2 +- Spaces/PanelsSpace.js | 13 +++++++------ Utilities.js | 18 ++++++++++++++++++ 5 files changed, 35 insertions(+), 38 deletions(-) diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index 72e23cbf1..f484a5cd3 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -340,9 +340,9 @@ function newTimeMachine () { function panelPhysics () { if (thisObject.container.frame.isInViewPort()) { - canvas.panelsSpace.makeVisible(thisObject.payload.node.id) + canvas.panelsSpace.makeVisible(thisObject.payload.node.id, 'Layers Panel') } else { - canvas.panelsSpace.makeInvisible(thisObject.payload.node.id) + canvas.panelsSpace.makeInvisible(thisObject.payload.node.id, 'Layers Panel') } } diff --git a/Panels/Layer.js b/Panels/Layer.js index babf7ded3..85300f606 100644 --- a/Panels/Layer.js +++ b/Panels/Layer.js @@ -316,17 +316,11 @@ function newLayer () { if (thisObject.panels.length > 0) { panelsVisibleButton = newPanelsVisibleButton() - try { - let code = JSON.parse(thisObject.payload.node.code) - if (code.showPanels !== undefined) { - if (code.showPanels === true || code.showPanels === false) { - panelsVisibleButton.showPanels = code.showPanels - } + let storedValue = loadPropertyFromNodeConfig(thisObject.payload, 'showPanels') + if (storedValue !== undefined) { + if (storedValue === true || storedValue === false) { + panelsVisibleButton.showPanels = storedValue } - - thisObject.payload.node.code = JSON.stringify(code) - } catch (err) { - // we ignore errors here since most likely they will be parsing errors. } panelsVisibleButton.initialize(thisObject.panels) @@ -334,14 +328,7 @@ function newLayer () { } } } else { - /* Saving the new status at the node config */ - try { - let code = JSON.parse(thisObject.payload.node.code) - code.showPanels = panelsVisibleButton.showPanels - thisObject.payload.node.code = JSON.stringify(code) - } catch (err) { - // we ignore errors here since most likely they will be parsing errors. - } + savePropertyAtNodeConfig(thisObject.payload, 'showPanels', panelsVisibleButton.showPanels) } } } @@ -349,8 +336,7 @@ function newLayer () { function statusPhysics () { /* We retrieve the stored status at the config. */ try { - let code = JSON.parse(thisObject.payload.node.code) - let storedValue = code.status + let storedValue = loadPropertyFromNodeConfig(thisObject.payload, 'status') if (storedValue !== undefined) { if (storedValue !== thisObject.status) { @@ -392,15 +378,7 @@ function newLayer () { } } - /* Saving the new status at the node config */ - try { - let code = JSON.parse(thisObject.payload.node.code) - code.status = thisObject.status - thisObject.payload.node.code = JSON.stringify(code) - } catch (err) { - // we ignore errors here since most likely they will be parsing errors. - } - + savePropertyAtNodeConfig(thisObject.payload, 'status', thisObject.status) let eventData = thisObject thisObject.container.eventHandler.raiseEvent('Status Changed', eventData) } diff --git a/Panels/LayersPanel.js b/Panels/LayersPanel.js index 2b0fc501e..34c4d5711 100644 --- a/Panels/LayersPanel.js +++ b/Panels/LayersPanel.js @@ -1,4 +1,4 @@ -function newProductsPanel () { +function newLayersPanel () { let thisObject = { name: 'Layers Panel', fitFunction: undefined, diff --git a/Spaces/PanelsSpace.js b/Spaces/PanelsSpace.js index eef432453..30b1b2b0e 100644 --- a/Spaces/PanelsSpace.js +++ b/Spaces/PanelsSpace.js @@ -42,9 +42,10 @@ function newPanelsSpace () { case 'Layers Panel': { - panel = newProductsPanel() + panel = newLayersPanel() panel.fitFunction = canvas.chartSpace.fitFunction panel.container.isVisibleFunction = canvas.chartSpace.isThisPointVisible + panel.type = 'Layers Panel' break } case 'Plotter Panel': @@ -62,7 +63,7 @@ function newPanelsSpace () { panel.session = pSession panel.initialize() } - + panel.type = 'Plotter Panel' break } } @@ -75,19 +76,19 @@ function newPanelsSpace () { return panel.handle } - function makeVisible (owner) { + function makeVisible (owner, type) { for (let i = 0; i < thisObject.panels.length; i++) { let panel = thisObject.panels[i] - if (panel.owner === owner) { + if (panel.owner === owner && panel.type === type) { panel.isVisible = true } } } - function makeInvisible (owner) { + function makeInvisible (owner, type) { for (let i = 0; i < thisObject.panels.length; i++) { let panel = thisObject.panels[i] - if (panel.owner === owner) { + if (panel.owner === owner && panel.type === type) { panel.isVisible = false } } diff --git a/Utilities.js b/Utilities.js index 7b68ea56f..46ae2b890 100644 --- a/Utilities.js +++ b/Utilities.js @@ -1,3 +1,21 @@ +function savePropertyAtNodeConfig (payload, propertyName, value) { + try { + let code = JSON.parse(payload.node.code) + code[propertyName] = value + payload.node.code = JSON.stringify(code) + } catch (err) { + // we ignore errors here since most likely they will be parsing errors. + } +} + +function loadPropertyFromNodeConfig (payload, propertyName) { + try { + let code = JSON.parse(payload.node.code) + return code[propertyName] + } catch (err) { + // we ignore errors here since most likely they will be parsing errors. + } +} function saveFrame (payload, frame) { payload.frame = {