diff --git a/Client/httpInterface.js b/Client/httpInterface.js index 93418c86a..de7aed21e 100644 --- a/Client/httpInterface.js +++ b/Client/httpInterface.js @@ -1085,12 +1085,25 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE case 'DirContent': { - const folderPath = unescape(requestParameters[2]) + let folderPath = unescape(requestParameters[2]) + if (requestParameters[3] !== undefined) { + folderPath = folderPath + '/' + requestParameters[3] + } + + if (requestParameters[4] !== undefined) { + folderPath = folderPath + '/' + requestParameters[4] + } + + if (requestParameters[5] !== undefined) { + folderPath = folderPath + '/' + requestParameters[5] + } + const folder = global.env.PATH_TO_PROJECTS + '/' + folderPath getAllFilesInDirectoryAndSubdirectories(folder, onFilesReady) function onFilesReady(files) { + console.log(files) respondWithContent(JSON.stringify(files), httpResponse) } } @@ -1805,11 +1818,12 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE let pathAndNames = [] for (let i = 0; i < files.length; i++) { let file = files[i] - let filesSplitted = file.split(lastFolder) - let pathName = filesSplitted[1] + console.log('file', file) + console.log('lastFolder', lastFolder) + let pathName = file.substring(file.indexOf(lastFolder) + lastFolder.length, file.length) + console.log('pathName', pathName) pathName = pathName.substring(1, pathName.length) pathAndNames.push(pathName) - console.log(pathName) } callback(pathAndNames) }) diff --git a/Projects/Governance/Plugins/Workspaces/Governance Demo.json b/Projects/Governance/Plugins/Workspaces/Governance-Demo.json similarity index 100% rename from Projects/Governance/Plugins/Workspaces/Governance Demo.json rename to Projects/Governance/Plugins/Workspaces/Governance-Demo.json diff --git a/Projects/Governance/Schemas/App-Schema/asset-class.json b/Projects/Governance/Schemas/App-Schema/asset-class.json index 8b55d8671..c78f45a7b 100644 --- a/Projects/Governance/Schemas/App-Schema/asset-class.json +++ b/Projects/Governance/Schemas/App-Schema/asset-class.json @@ -8,6 +8,16 @@ "iconPathOn": "configuration", "iconPathOff": "configuration" }, + { + "action": "Install Assets", + "actionProject": "Governance", + "label": "Install Assets", + "askConfirmation": true, + "confirmationLabel": "Confirm to Proceed", + "workDoneLabel": "Done", + "relatedUiObject": "Asset", + "actionFunction": "payload.executeAction" + }, { "action": "Add UI Object", "actionFunction": "payload.executeAction", @@ -34,7 +44,7 @@ "config": true }, "initialValues": { - "config": "{}" + "config": "{\n\"folderPath\": \"\"\n}" }, "addLeftIcons": true, "level": 2, diff --git a/Projects/Governance/Schemas/App-Schema/assets.json b/Projects/Governance/Schemas/App-Schema/assets.json index ca65263ba..8da4de500 100644 --- a/Projects/Governance/Schemas/App-Schema/assets.json +++ b/Projects/Governance/Schemas/App-Schema/assets.json @@ -1,6 +1,23 @@ { "type": "Assets", "menuItems": [ + { + "action": "Configure", + "actionFunction": "uiObject.configEditor.activate", + "label": "Configure", + "iconPathOn": "configuration", + "iconPathOff": "configuration" + }, + { + "action": "Install Assets", + "actionProject": "Governance", + "label": "Install Assets", + "askConfirmation": true, + "confirmationLabel": "Confirm to Proceed", + "workDoneLabel": "Done", + "relatedUiObject": "Asset", + "actionFunction": "payload.executeAction" + }, { "action": "Add UI Object", "actionFunction": "payload.executeAction", @@ -26,6 +43,12 @@ "isHierarchyHead": true, "addLeftIcons": true, "level": 0, + "editors": { + "config": true + }, + "initialValues": { + "config": "{\n\"folderPath\": \"\"\n}" + }, "childrenNodesProperties": [ { "name": "assetClasses", diff --git a/Projects/Governance/UI/Function-Libraries/ActionSwitch.js b/Projects/Governance/UI/Function-Libraries/ActionSwitch.js index 54865bda6..183067e05 100644 --- a/Projects/Governance/UI/Function-Libraries/ActionSwitch.js +++ b/Projects/Governance/UI/Function-Libraries/ActionSwitch.js @@ -18,9 +18,11 @@ function newGovernanceActionSwitch() { async function executeAction(action) { switch (action.name) { - case 'Create Wallet Account': { - UI.projects.ethereum.functionLibraries.accounts.createWalletAccount(action.node) - break + case 'Install Assets': { + { + UI.projects.governance.functionLibraries.assets.installAssets(action.node, action.rootNodes) + break + } } } } diff --git a/Projects/Governance/UI/Function-Libraries/Assets.js b/Projects/Governance/UI/Function-Libraries/Assets.js new file mode 100644 index 000000000..caadee10b --- /dev/null +++ b/Projects/Governance/UI/Function-Libraries/Assets.js @@ -0,0 +1,117 @@ +function newGovernanceFunctionLibraryAssets() { + let thisObject = { + installAssets: installAssets + } + + return thisObject + + function installAssets( + node, + rootNodes + ) { + let folderPath = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(node.payload, 'folderPath') + + if (folderPath === undefined || folderPath === "") { + node.payload.uiObject.setErrorMessage("folderPath Config Property undefined.") + return + } + + httpRequest(undefined, 'DirContent' + '/' + folderPath, onResponse) + + function onResponse(err, data) { + if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + console.log('Failed to get Directory Content from the Client') + return + } + let filePathArray = JSON.parse(data) + for (let i = 0; i < filePathArray.length; i++) { + let filePath = filePathArray[i] + let foldersArray = removeFirstFromArray(filePath.split('\\')) + createNodesFromPath(node, foldersArray) + } + } + + function removeFirstFromArray(array) { + /* + Don't want to use splice here because this will be used + recursivelly and can have problems because we will be + passing a pointer to the array at several branches. + */ + let newArray = [] + for (let i = 1; i < array.length; i++) { + newArray.push(array[i]) + } + return newArray + } + + function createNodesFromPath(node, pathArray) { + if (node === undefined) { return } + if (node.payload === undefined) { return } + if (pathArray.length === 0) { return } + + let nextItem = pathArray[0] + pathArray = removeFirstFromArray(pathArray) + + let schemaDocument = getSchemaDocument(node) + if (schemaDocument === undefined) { return } + + /* + Here we will check that the node corersponding to the next item does not already exist. + */ + let exist = false + if (schemaDocument.childrenNodesProperties !== undefined) { + for (let i = 0; i < schemaDocument.childrenNodesProperties.length; i++) { + let property = schemaDocument.childrenNodesProperties[i] + + switch (property.type) { + case 'node': { + let childNode = node[property.name] + if (childNode !== undefined) { + let codeName = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(childNode.payload, 'codeName') + if (nextItem === codeName) { + exist = true + createNodesFromPath(childNode, pathArray) + } + } + } + break + case 'array': { + let propertyArray = node[property.name] + if (propertyArray !== undefined) { + for (let m = 0; m < propertyArray.length; m++) { + let childNode = propertyArray[m] + if (childNode !== undefined) { + let codeName = UI.projects.superalgos.utilities.nodeConfig.loadPropertyFromNodeConfig(childNode.payload, 'codeName') + if (nextItem === codeName) { + exist = true + createNodesFromPath(childNode, pathArray) + } + } + } + } + break + } + } + } + } + if (exist === true) { return } + if (pathArray.length === 0) { + /* + The last element of the path is an Asset. + */ + let childNode = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Asset') + childNode.config = JSON.stringify({ codeName: nextItem }) + childNode.name = nextItem + + } else { + /* + All previous elements are an Asset Class. + */ + let childNode = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Asset Class') + childNode.config = JSON.stringify({ codeName: nextItem }) + childNode.name = nextItem + createNodesFromPath(childNode, pathArray) + } + } + } +} diff --git a/Projects/Governance/UI/Globals/ChainIds.js b/Projects/Governance/UI/Globals/ChainIds.js deleted file mode 100644 index e17cf4226..000000000 --- a/Projects/Governance/UI/Globals/ChainIds.js +++ /dev/null @@ -1,18 +0,0 @@ -function newEthereumGlobalsChainIds() { - let thisObject = { - chainNameById: chainNameById - } - return thisObject - - function chainNameById(chainId) { - switch(chainId) { - case 1: return 'Ethereum Mainnet' - case 3: return 'Ethereum Ropsten' - case 4: return 'Ethereum Rinkeby' - case 42: return 'Ethereum Kovan' - case 61: return 'Ethereum Classic Mainnet' - case 62: return 'Ethereum Classic Morden' - default: return 'Unknown Network' - } - } -} \ No newline at end of file diff --git a/Projects/Governance/UI/Utilities/RouteToClient.js b/Projects/Governance/UI/Utilities/RouteToClient.js deleted file mode 100644 index a371b08b9..000000000 --- a/Projects/Governance/UI/Utilities/RouteToClient.js +++ /dev/null @@ -1,53 +0,0 @@ -function newEthereumUtilitiesRouteToClient() { - let thisObject = { - buildRouteToClient: buildRouteToClient - } - - return thisObject - - function buildRouteToClient(networkClient) { - let config = JSON.parse(networkClient.config) - if (config.host === undefined) { - networkClient.payload.uiObject.setErrorMessage('Property host not defined at node config.') - return - } - if (config.httpPort === undefined && config.webSocketsPort === undefined) { - networkClient.payload.uiObject.setErrorMessage('Property httpPort or webSocketsPort must be defined at node config.') - return - } - - /* Web Sockets would be the default protocol */ - let clientPort - let clientInterface - if (config.webSocketsPort !== undefined) { - clientInterface = 'ws' - clientPort = config.webSocketsPort - } else { - clientInterface = 'http' - clientPort = config.httpPort - } - - let params = { - host: config.host, - port: clientPort, - interface: clientInterface - } - - /* - Next, we will check which Superalgos Network Node we need as a gateway - to the Ethereum Client. We will use the current node reference parent for that. - */ - if (networkClient.payload.referenceParent === undefined) { - networkClient.payload.uiObject.setErrorMessage('You need to reference a Superalgos Network Node so that it acts as a gateway to the Ethereum Client.') - return - } - - let networkNodeConfig = JSON.parse(networkClient.payload.referenceParent.config) - let url = 'http://' + networkNodeConfig.host + ':' + networkNodeConfig.webPort + '/' + 'WEB3' - - return { - params: params, - url: url - } - } -} \ No newline at end of file diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 35c56119d..b51491d4f 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -969,7 +969,7 @@ "spaces": [] }, "TS": { - "globals":[], + "globals": [], "functionLibraries": [], "utilities": [], "botModules": [ @@ -987,14 +987,13 @@ "name": "Governance", "propertyName": "governance", "UI": { - "globals": [ - { - "name": "ChainIds", - "propertyName": "chainIds", - "functionName": "newEthereumGlobalsChainIds" - } - ], + "globals": [], "functionLibraries": [ + { + "name": "Assets", + "propertyName": "assets", + "functionName": "newGovernanceFunctionLibraryAssets" + }, { "name": "Votes", "propertyName": "votes", @@ -1021,13 +1020,7 @@ "functionName": "newGovernanceFunctionLibraryDistributionProcess" } ], - "utilities": [ - { - "name": "Route To Client", - "propertyName": "routeToClient", - "functionName": "newEthereumUtilitiesRouteToClient" - } - ], + "utilities": [], "spaces": [ { "name": "User Profile Space", @@ -1099,4 +1092,4 @@ "TS": {}, "CL": {} } -] +] \ No newline at end of file