Plugins Saved everytime the Workspace is saved.

This commit is contained in:
Luis Fernando Molina committed 2021-06-30 12:28:16 +02:00
1 parent 3a1f99ff86
commit 22ef87ad80
6 files changed
+158 -23

No files matched your search

+29
View File
@@ -1183,6 +1183,35 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
}
break
case 'SavePlugin':
getBody(processRequest)
async function processRequest(body) {
try {
let plugin = JSON.parse(body)
let project = requestParameters[2]
let folder = requestParameters[3]
let fileName = requestParameters[4]
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Plugins/' + folder
createNewDir(filePath)
let fileContent = JSON.stringify(plugin, undefined, 4)
const fs = require('fs')
fs.writeFileSync(filePath + '/' + fileName + '.json', fileContent)
} catch (err) {
console.log('[ERROR] httpInterface -> SavePlugin -> Method call produced an error.')
console.log('[ERROR] httpInterface -> SavePlugin -> err.stack = ' + err.stack)
console.log('[ERROR] httpInterface -> SavePlugin -> Params Received = ' + body)
let error = {
result: 'Fail Because',
message: err.message,
stack: err.stack
}
respondWithContent(JSON.stringify(error), httpResponse)
}
}
break
case 'Workspace.js':
{
let fs = require('fs')
@@ -57,7 +57,7 @@ function newFoundationsFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'Data-Mines', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'Data-Mines', 'Data Mine')
}
}
@@ -73,7 +73,7 @@ function newFoundationsFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'Trading-Mines', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'Trading-Mines', 'Trading Mine')
}
}
@@ -89,7 +89,7 @@ function newFoundationsFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'Trading-Systems', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'Trading-Systems', 'Trading System')
}
}
@@ -105,7 +105,7 @@ function newFoundationsFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'Trading-Engines', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'Trading-Engines', 'Trading Engine')
}
}
@@ -121,7 +121,7 @@ function newFoundationsFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'Learning-Mines', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'Learning-Mines', 'Learning Mine')
}
}
@@ -137,7 +137,7 @@ function newFoundationsFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'Learning-Systems', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'Learning-Systems', 'Learning System')
}
}
@@ -153,7 +153,7 @@ function newFoundationsFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'Learning-Engines', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'Learning-Engines', 'Learning Engine')
}
}
@@ -169,7 +169,7 @@ function newFoundationsFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'Tutorials', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'Tutorials', 'Tutorial')
}
}
@@ -185,7 +185,7 @@ function newFoundationsFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'API-Maps', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'API-Maps', 'API Map')
}
}
}
@@ -138,10 +138,11 @@ function newFoundationsFunctionLibraryUiObjectsFromNodes() {
addUserDefinedNodes()
}
function pluginAllTheseFiles(pluginFiles, pluginType) {
function pluginAllTheseFiles(pluginFiles, pluginFolder) {
for (let i = 0; i < pluginFiles.length; i++) {
let pluginFile = pluginFiles[i]
let name = pluginFile.name
let folder = pluginFolder
let project = "Foundations"
try {
let config = JSON.parse(pluginFile.config)
@@ -151,14 +152,17 @@ function newFoundationsFunctionLibraryUiObjectsFromNodes() {
if (config.fileName !== undefined) {
name = config.fileName
}
if (config.folderName !== undefined) {
folder = config.fileName
}
} catch (err) { }
httpRequest(undefined, 'LoadPlugin' + '/' + project + '/' + pluginType + '/' + name + '.json', onFileReceived)
httpRequest(undefined, 'LoadPlugin' + '/' + project + '/' + folder + '/' + name + '.json', onFileReceived)
function onFileReceived(err, text, response) {
if (err && err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
console.log('[WARN] Cannot load plugin ' + pluginType + ' ' + name + '. The Workspace will be loaded with this plugin file missing.')
console.log('[WARN] Cannot load plugin ' + pluginFolder + ' ' + name + '. The Workspace will be loaded with this plugin file missing.')
} else {
let receivedNode = JSON.parse(text)
/*
@@ -173,6 +177,12 @@ function newFoundationsFunctionLibraryUiObjectsFromNodes() {
}
}
receivedNode.isPlugin = true
/*
We will force the Plugin codeName to the same to the fileName.
*/
let config = JSON.parse(receivedNode.config)
config.codeName = name
receivedNode.config = JSON.stringify(config)
if (pluginFile.pluginFilePosition !== undefined) {
let positionOffset = {
@@ -19,6 +19,7 @@ function newWorkspace() {
getProjectsHeads: getProjectsHeads,
getHierarchyHeads: getHierarchyHeads,
getHierarchyHeadsById: getHierarchyHeadsById,
getHierarchyHeadsByCodeNameAndNodeType: getHierarchyHeadsByCodeNameAndNodeType,
getHierarchyHeadByNodeType: getHierarchyHeadByNodeType,
getHierarchyHeadsByNodeType: getHierarchyHeadsByNodeType,
getNodeThatIsOnFocus: getNodeThatIsOnFocus,
@@ -191,6 +192,7 @@ function newWorkspace() {
return
}
httpRequest(textToSave, url, onResponse)
savePlugins()
return true
function onResponse(err) {
@@ -209,6 +211,85 @@ function newWorkspace() {
}
}
function savePlugins() {
/*
Here we will scan the workspace for all Plugins and we will try to save them.
The first thing to do is to find the Plugins hierarchy.
*/
let plugins = getHierarchyHeadByNodeType('Plugins')
if (plugins === undefined) { return }
for (let i = 0; i < plugins.pluginsProjects.length; i++) {
let pluginProject = plugins.pluginsProjects.length[i]
/*
Here we are inside the Voting Program, so we will crawl all it's children.
*/
let schemaDocument = getSchemaDocument('Plugin Project')
if (schemaDocument === undefined) { return }
if (schemaDocument.childrenNodesProperties !== undefined) {
for (let j = 0; j < schemaDocument.childrenNodesProperties.length; j++) {
let property = schemaDocument.childrenNodesProperties[j]
switch (property.type) {
case 'node': {
let childNode = node[property.name]
if (childNode === undefined) { continue }
if (childNode.pluginFiles === undefined) { continue }
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.')
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.')
continue
}
let fileContent = JSON.stringify(pluginToSave, 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.')
return
}
console.log('[ERROR] Saving Plugin File: ' + data)
pluginFile.payload.uiObject.setErrorMessage('This Plugin Could not be Saved. ' + data)
}
}
}
break
case 'array': {
/*Nothing to do here*/
break
}
}
}
}
}
}
async function backupWorkspace(action) {
let text = await stringifyWorkspace(false)
let fileName = 'Backup - ' + action.node.type + ' - ' + action.node.name + '.json'
@@ -366,7 +447,7 @@ function newWorkspace() {
workingAtTask = 0
UI.projects.foundations.spaces.floatingSpace.inMapMode = false
thisObject.isInitialized = true
await UI.projects.education.spaces.docsSpace.reset()
await UI.projects.education.spaces.tutorialSpace.reset()
@@ -499,6 +580,18 @@ function newWorkspace() {
}
}
function getHierarchyHeadsByCodeNameAndNodeType(codeName, nodeType) {
let hierarchyHeads = getHierarchyHeads()
if (hierarchyHeads === undefined) { return }
for (let i = 0; i < hierarchyHeads.length; i++) {
let hierarchyHead = hierarchyHeads[i]
let hierarchyHeadCodeName = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(hierarchyHead.payload, 'codeName')
if (hierarchyHeadCodeName === codeName && hierarchyHead.type === nodeType) {
return hierarchyHead
}
}
}
function getHierarchyHeadByNodeType(nodeType) {
let hierarchyHeads = getHierarchyHeads()
if (hierarchyHeads === undefined) { return }
@@ -523,6 +616,7 @@ function newWorkspace() {
return resultArray
}
function replaceWorkspaceByLoadingOne(project, name) {
let webCommand
+7 -5
View File
@@ -7,12 +7,12 @@ function newFoundationsUtilitiesPlugins() {
return thisObject
function getPluginFileNames(projectName, pluginType, callBack) {
httpRequest(undefined, 'PluginFileNames/' + projectName + '/' + pluginType, onResponse)
function getPluginFileNames(projectName, pluginFolder, callBack) {
httpRequest(undefined, 'PluginFileNames/' + projectName + '/' + pluginFolder, onResponse)
function onResponse(err, data) {
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
console.log('Failed to Fetch Plugin ' + pluginType + ' from the Client')
console.log('Failed to Fetch Plugin ' + pluginFolder + ' from the Client')
return
}
@@ -21,7 +21,7 @@ function newFoundationsUtilitiesPlugins() {
}
}
function addPluginFileIfNeeded(node, fileNames) {
function addPluginFileIfNeeded(node, fileNames, pluginFolder, nodeType) {
for (let i = 0; i < fileNames.length; i++) {
let fileName = fileNames[i]
fileName = fileName.replace('.json', '')
@@ -30,7 +30,9 @@ function newFoundationsUtilitiesPlugins() {
child.name = fileName
child.config = JSON.stringify({
project: node.project,
fileName: fileName
fileName: fileName,
folderName: pluginFolder,
nodeType: nodeType
})
}
}
@@ -20,7 +20,7 @@ function newGovernanceFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'User-Profiles', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'User-Profiles', 'User Profile')
}
}
@@ -36,7 +36,7 @@ function newGovernanceFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'Pools', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'Pools', 'Pools')
}
}
@@ -52,7 +52,7 @@ function newGovernanceFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'Assets', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'Assets', 'Assets')
}
}
@@ -68,7 +68,7 @@ function newGovernanceFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'Features', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'Features', 'Features')
}
}
@@ -84,7 +84,7 @@ function newGovernanceFunctionLibraryPluginsFunctions() {
UI.projects.foundations.utilities.plugins.getPluginFileNames(projectName, 'Positions', onNamesArrived)
function onNamesArrived(fileNames) {
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames)
UI.projects.foundations.utilities.plugins.addPluginFileIfNeeded(node, fileNames, 'Positions', 'Positions')
}
}
}