Can add an UI object defined at the App Schema

This commit is contained in:
Luis Fernando Molina committed 2019-12-07 16:42:26 +01:00
1 parent 09416fc474
commit c65545e879
5 files changed
+92 -10

No files matched your search

@@ -2,6 +2,7 @@ function newUiObjectsFromNodes () {
thisObject = {
recreateWorkspace: recreateWorkspace,
createUiObjectFromNode: createUiObjectFromNode,
addUIObject: addUIObject,
addTeam: addTeam,
addSensorBot: addSensorBot,
addIndicatorBot: addIndicatorBot,
@@ -1078,6 +1079,34 @@ function newUiObjectsFromNodes () {
}
}
function addUIObject (parent, type) {
let object = {
name: 'New ' + type,
type: type
}
createUiObject(true, object.type, object.name, object, parent, parent)
let nodeDefinition = APP_SCHEMA_MAP.get(parent.type)
if (nodeDefinition !== undefined) {
for (i = 0; i < nodeDefinition.properties.length; i++) {
let property = nodeDefinition.properties[i]
if (property.childType === type) {
switch (property.type) {
case 'node': {
parent[property.name] = object
}
break
case 'array': {
parent[property.name].push(object)
}
break
}
}
}
}
return object
}
function addTeam (node) {
let team = {
name: 'New Team',
+6 -1
View File
@@ -248,8 +248,13 @@ function newWorkspace () {
}
}
async function onMenuItemClick (payload, action, callBackFunction) {
async function onMenuItemClick (payload, action, relatedUiObject, callBackFunction) {
switch (action) {
case 'Add UI Object':
{
functionLibraryUiObjectsFromNodes.addUIObject(payload.node, relatedUiObject)
}
break
case 'Share Workspace':
{
let text = stringifyWorkspace(true)
+3 -3
View File
@@ -229,7 +229,7 @@ function newCircularMenuItem () {
if (thisObject.label === undefined) {
/* This is what we have in the case of menu items that are only Icons. In this situation there is no complex logic, just execute the specified action. */
thisObject.actionFunction(thisObject.payload, thisObject.action)
thisObject.actionFunction(thisObject.payload, thisObject.action, thisObject.relatedUiObject)
return
}
@@ -261,7 +261,7 @@ function newCircularMenuItem () {
}
/* Execute the action and wait for callbacks to update our statuus. */
thisObject.actionFunction(thisObject.payload, thisObject.action, onPrimaryCallBack)
thisObject.actionFunction(thisObject.payload, thisObject.action, thisObject.relatedUiObject, onPrimaryCallBack)
return
}
if (temporaryStatus === STATUS_PRIMARY_WORK_DONE && thisObject.secondaryAction !== undefined) {
@@ -271,7 +271,7 @@ function newCircularMenuItem () {
}
/* Execute the action and wait for callbacks to update our statuus. */
thisObject.actionFunction(thisObject.payload, thisObject.secondaryAction, onSecondaryCallBack)
thisObject.actionFunction(thisObject.payload, thisObject.secondaryAction, thisObject.relatedUiObject, onSecondaryCallBack)
return
}
+49 -4
View File
@@ -1621,7 +1621,7 @@ function newUiObjectConstructor () {
rawRadius: 8,
targetRadius: 0,
currentRadius: 0,
angle: -50,
angle: -60,
dontShowAtFullscreen: true
}
)
@@ -1642,7 +1642,9 @@ function newUiObjectConstructor () {
)
menuItemsInitialValues.push(
{
action: 'Add Shapes',
action: 'Add UI Object',
disableIfPropertyIsDefined: true,
propertyToCheckFor: 'shapes',
actionFunction: payload.onMenuItemClick,
label: 'Add Shapes',
visible: true,
@@ -1693,7 +1695,7 @@ function newUiObjectConstructor () {
rawRadius: 8,
targetRadius: 0,
currentRadius: 0,
angle: 50
angle: 60
}
)
break
@@ -4708,7 +4710,21 @@ function newUiObjectConstructor () {
break
}
default: {
if (ERROR_LOG === true) { logger.write('[ERROR] getMenuItemsInitialValues -> UI Object Type not Recognized -> type = ' + payload.node.type) }
let nodeDefinition = APP_SCHEMA_MAP.get(payload.node.type)
if (nodeDefinition !== undefined) {
for (i = 0; i < nodeDefinition.menuItems.length; i++) {
let menutItemDefinition = nodeDefinition.menuItems[i]
let newMenuItem = JSON.parse(JSON.stringify(menutItemDefinition))
/* We need to reference the real function based on its name */
if (menutItemDefinition.actionFunction !== undefined) {
newMenuItem.actionFunction = eval(menutItemDefinition.actionFunction)
}
menuItemsInitialValues.push(newMenuItem)
}
} else {
if (ERROR_LOG === true) { logger.write('[ERROR] getMenuItemsInitialValues -> UI Object Type not Recognized -> type = ' + payload.node.type) }
}
}
}
@@ -5021,6 +5037,35 @@ function newUiObjectConstructor () {
break
}
default: {
let nodeDefinition = APP_SCHEMA_MAP.get(payload.node.type)
if (nodeDefinition !== undefined) {
switch (nodeDefinition.level) {
case 0: {
level_0()
return
}
case 1: {
level_1()
return
}
case 2: {
level_2()
return
}
case 3: {
level_3()
return
}
case 4: {
level_4()
return
}
case 5: {
level_5()
return
}
}
}
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> UI Object Type not Recognized -> type = ' + payload.node.type) }
return
}
+5 -2
View File
@@ -122,8 +122,11 @@ function newDesignerSpace () {
/* Take types-icons relationships defined at the schema */
for (let i = 0; i < APP_SCHEMA_ARRAY.length; i++) {
let nodeDefinition = APP_SCHEMA_ARRAY[i]
let icon = thisObject.iconCollection.get(nodeDefinition.icon)
thisObject.iconByUiObjectType.set(nodeDefinition.type, icon)
let iconName = nodeDefinition.icon
if (iconName !== undefined) {
let icon = thisObject.iconCollection.get(iconName)
thisObject.iconByUiObjectType.set(nodeDefinition.type, icon)
}
}
}