From 33cd8dc2627c6af0718521b8ec47a20397107d6e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 30 Jun 2021 21:15:13 +0200 Subject: [PATCH] Saving Individual Plugins Working --- .../UI/Function-Libraries/PluginsFunctions.js | 2 +- .../UI/Spaces/Design-Space/Workspace.js | 43 +---------------- Projects/Foundations/UI/Utilities/Plugins.js | 47 ++++++++++++++++++- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/Projects/Foundations/UI/Function-Libraries/PluginsFunctions.js b/Projects/Foundations/UI/Function-Libraries/PluginsFunctions.js index d14991d3b..b762f8bde 100644 --- a/Projects/Foundations/UI/Function-Libraries/PluginsFunctions.js +++ b/Projects/Foundations/UI/Function-Libraries/PluginsFunctions.js @@ -203,6 +203,6 @@ function newFoundationsFunctionLibraryPluginsFunctions() { } function savePlugin(node, rootNodes) { - + UI.projects.foundations.utilities.plugins.savePluginFile(node) } } diff --git a/Projects/Foundations/UI/Spaces/Design-Space/Workspace.js b/Projects/Foundations/UI/Spaces/Design-Space/Workspace.js index 8a3023f96..ffba5e592 100644 --- a/Projects/Foundations/UI/Spaces/Design-Space/Workspace.js +++ b/Projects/Foundations/UI/Spaces/Design-Space/Workspace.js @@ -239,47 +239,8 @@ function newWorkspace() { for (let k = 0; k < childNode.pluginFiles.length; k++) { let pluginFile = childNode.pluginFiles[k] - let project = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(pluginFile.payload, 'project') - let fileName = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(pluginFile.payload, 'fileName') - let folderName = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(pluginFile.payload, 'folderName') - let nodeType = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(pluginFile.payload, 'nodeType') - - if ( - project === undefined || - fileName === undefined || - folderName === undefined || - nodeType === undefined - ) { - pluginFile.payload.uiObject.setWarningMessage('This Plugin could not be saved because some Config Properties were missing.', 500) - continue - } - /* - Next thing to do is to find the Plugin Hierarchy at the Workspace, and send - a request to the Client to save it. - */ - let pluginToSave = getHierarchyHeadsByCodeNameAndNodeType(fileName, nodeType) - - if (pluginToSave === undefined) { - pluginFile.payload.uiObject.setWarningMessage('This Plugin could not be saved because it could not be found at the workspace.', 500) - continue - } - let fileContent = JSON.stringify( - UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(pluginToSave, false, false, true, true, true), - undefined, - 4) - - httpRequest(fileContent, 'SavePlugin' + '/' + project + '/' + folderName + '/' + fileName, onResponse) - - 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) { - pluginFile.payload.uiObject.setInfoMessage('Plugin Saved.', 250) - return - } - console.log('[ERROR] Saving Plugin File: ' + JSON.stringify(data)) - pluginFile.payload.uiObject.setErrorMessage('This Plugin Could not be Saved. ' + JSON.stringify(data), 500) - } + let saveWithWorkspace = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(pluginFile.payload, 'saveWithWorkspace') + UI.projects.foundations.utilities.plugins.savePluginFile(pluginFile) } } break diff --git a/Projects/Foundations/UI/Utilities/Plugins.js b/Projects/Foundations/UI/Utilities/Plugins.js index b4cb3e1a0..1bc44b3f8 100644 --- a/Projects/Foundations/UI/Utilities/Plugins.js +++ b/Projects/Foundations/UI/Utilities/Plugins.js @@ -2,7 +2,8 @@ function newFoundationsUtilitiesPlugins() { let thisObject = { getPluginFileNames: getPluginFileNames, addPluginFileIfNeeded: addPluginFileIfNeeded, - getProjectName: getProjectName + getProjectName: getProjectName, + savePluginFile: savePluginFile } return thisObject @@ -56,4 +57,48 @@ function newFoundationsUtilitiesPlugins() { return config.codeName } + + function savePluginFile(pluginFile) { + let project = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(pluginFile.payload, 'project') + let fileName = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(pluginFile.payload, 'fileName') + let folderName = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(pluginFile.payload, 'folderName') + let nodeType = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(pluginFile.payload, 'nodeType') + + if ( + project === undefined || + fileName === undefined || + folderName === undefined || + nodeType === undefined + ) { + pluginFile.payload.uiObject.setWarningMessage('This Plugin could not be saved because some Config Properties were missing.', 500) + return + } + /* + Next thing to do is to find the Plugin Hierarchy at the Workspace, and send + a request to the Client to save it. + */ + let pluginToSave = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByCodeNameAndNodeType(fileName, nodeType) + + if (pluginToSave === undefined) { + pluginFile.payload.uiObject.setWarningMessage('This Plugin could not be saved because it could not be found at the workspace.', 500) + return + } + let fileContent = JSON.stringify( + UI.projects.foundations.functionLibraries.protocolNode.getProtocolNode(pluginToSave, false, false, true, true, true), + undefined, + 4) + + httpRequest(fileContent, 'SavePlugin' + '/' + project + '/' + folderName + '/' + fileName, onResponse) + + 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) { + pluginFile.payload.uiObject.setInfoMessage('Plugin Saved.', 250) + return + } + console.log('[ERROR] Saving Plugin File: ' + JSON.stringify(data)) + pluginFile.payload.uiObject.setErrorMessage('This Plugin Could not be Saved. ' + JSON.stringify(data), 500) + } + } } \ No newline at end of file