Merge pull request #1118 from Luis-Fernando-Molina/develop
Contribution: Install Asset procedure implemented
This commit is contained in:
9 files changed
+183
-95
No files matched your search
+18
-4
@@ -1085,12 +1085,25 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
|||||||
|
|
||||||
case 'DirContent':
|
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
|
const folder = global.env.PATH_TO_PROJECTS + '/' + folderPath
|
||||||
|
|
||||||
getAllFilesInDirectoryAndSubdirectories(folder, onFilesReady)
|
getAllFilesInDirectoryAndSubdirectories(folder, onFilesReady)
|
||||||
|
|
||||||
function onFilesReady(files) {
|
function onFilesReady(files) {
|
||||||
|
console.log(files)
|
||||||
respondWithContent(JSON.stringify(files), httpResponse)
|
respondWithContent(JSON.stringify(files), httpResponse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1805,11 +1818,12 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
|||||||
let pathAndNames = []
|
let pathAndNames = []
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
let file = files[i]
|
let file = files[i]
|
||||||
let filesSplitted = file.split(lastFolder)
|
console.log('file', file)
|
||||||
let pathName = filesSplitted[1]
|
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)
|
pathName = pathName.substring(1, pathName.length)
|
||||||
pathAndNames.push(pathName)
|
pathAndNames.push(pathName)
|
||||||
console.log(pathName)
|
|
||||||
}
|
}
|
||||||
callback(pathAndNames)
|
callback(pathAndNames)
|
||||||
})
|
})
|
||||||
|
|||||||
File renamed without changes.
@@ -8,6 +8,16 @@
|
|||||||
"iconPathOn": "configuration",
|
"iconPathOn": "configuration",
|
||||||
"iconPathOff": "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",
|
"action": "Add UI Object",
|
||||||
"actionFunction": "payload.executeAction",
|
"actionFunction": "payload.executeAction",
|
||||||
@@ -34,7 +44,7 @@
|
|||||||
"config": true
|
"config": true
|
||||||
},
|
},
|
||||||
"initialValues": {
|
"initialValues": {
|
||||||
"config": "{}"
|
"config": "{\n\"folderPath\": \"\"\n}"
|
||||||
},
|
},
|
||||||
"addLeftIcons": true,
|
"addLeftIcons": true,
|
||||||
"level": 2,
|
"level": 2,
|
||||||
|
|||||||
@@ -1,6 +1,23 @@
|
|||||||
{
|
{
|
||||||
"type": "Assets",
|
"type": "Assets",
|
||||||
"menuItems": [
|
"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",
|
"action": "Add UI Object",
|
||||||
"actionFunction": "payload.executeAction",
|
"actionFunction": "payload.executeAction",
|
||||||
@@ -26,6 +43,12 @@
|
|||||||
"isHierarchyHead": true,
|
"isHierarchyHead": true,
|
||||||
"addLeftIcons": true,
|
"addLeftIcons": true,
|
||||||
"level": 0,
|
"level": 0,
|
||||||
|
"editors": {
|
||||||
|
"config": true
|
||||||
|
},
|
||||||
|
"initialValues": {
|
||||||
|
"config": "{\n\"folderPath\": \"\"\n}"
|
||||||
|
},
|
||||||
"childrenNodesProperties": [
|
"childrenNodesProperties": [
|
||||||
{
|
{
|
||||||
"name": "assetClasses",
|
"name": "assetClasses",
|
||||||
|
|||||||
@@ -18,9 +18,11 @@ function newGovernanceActionSwitch() {
|
|||||||
|
|
||||||
async function executeAction(action) {
|
async function executeAction(action) {
|
||||||
switch (action.name) {
|
switch (action.name) {
|
||||||
case 'Create Wallet Account': {
|
case 'Install Assets': {
|
||||||
UI.projects.ethereum.functionLibraries.accounts.createWalletAccount(action.node)
|
{
|
||||||
break
|
UI.projects.governance.functionLibraries.assets.installAssets(action.node, action.rootNodes)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -969,7 +969,7 @@
|
|||||||
"spaces": []
|
"spaces": []
|
||||||
},
|
},
|
||||||
"TS": {
|
"TS": {
|
||||||
"globals":[],
|
"globals": [],
|
||||||
"functionLibraries": [],
|
"functionLibraries": [],
|
||||||
"utilities": [],
|
"utilities": [],
|
||||||
"botModules": [
|
"botModules": [
|
||||||
@@ -987,14 +987,13 @@
|
|||||||
"name": "Governance",
|
"name": "Governance",
|
||||||
"propertyName": "governance",
|
"propertyName": "governance",
|
||||||
"UI": {
|
"UI": {
|
||||||
"globals": [
|
"globals": [],
|
||||||
{
|
|
||||||
"name": "ChainIds",
|
|
||||||
"propertyName": "chainIds",
|
|
||||||
"functionName": "newEthereumGlobalsChainIds"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"functionLibraries": [
|
"functionLibraries": [
|
||||||
|
{
|
||||||
|
"name": "Assets",
|
||||||
|
"propertyName": "assets",
|
||||||
|
"functionName": "newGovernanceFunctionLibraryAssets"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Votes",
|
"name": "Votes",
|
||||||
"propertyName": "votes",
|
"propertyName": "votes",
|
||||||
@@ -1021,13 +1020,7 @@
|
|||||||
"functionName": "newGovernanceFunctionLibraryDistributionProcess"
|
"functionName": "newGovernanceFunctionLibraryDistributionProcess"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"utilities": [
|
"utilities": [],
|
||||||
{
|
|
||||||
"name": "Route To Client",
|
|
||||||
"propertyName": "routeToClient",
|
|
||||||
"functionName": "newEthereumUtilitiesRouteToClient"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"spaces": [
|
"spaces": [
|
||||||
{
|
{
|
||||||
"name": "User Profile Space",
|
"name": "User Profile Space",
|
||||||
@@ -1099,4 +1092,4 @@
|
|||||||
"TS": {},
|
"TS": {},
|
||||||
"CL": {}
|
"CL": {}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
Reference in new issue
Block a user