Commissioning Failure
Updated Template Failed to Upload
Status code: { await response.status }: { response.statusText }
Response Text: { await response.text() }
);
}
};
const renderJsonEditor = async (template, commonProps) => {
const fullTemplate = await template.json()
setFullToscaTemplate(fullTemplate)
const allNodeTemplates = fullTemplate.topology_template.node_templates
const shortenedNodeTemplatesObjectStartValues = {}
// Get the common properties to construct a schema
// Get valid start values at the same time
const commonNodeTemplatesJson = await commonProps.json().then(data => {
const nodeTemplatesArray = Object.entries(data)
const shortenedNodeTemplatesObject = {}
nodeTemplatesArray.forEach(([key, temp]) => {
const currentNodeTemplate = allNodeTemplates[key]
const propertiesObject = {
properties: temp.properties
}
shortenedNodeTemplatesObject[key] = propertiesObject
const propertiesStartValues = {}
// Get all the existing start values to populate the properties in the schema
Object.entries(propertiesObject.properties).forEach(([propKey, prop]) => {
propertiesStartValues[propKey] = currentNodeTemplate.properties[propKey]
})
shortenedNodeTemplatesObjectStartValues[key] = propertiesStartValues
})
setToscaInitialValues(shortenedNodeTemplatesObjectStartValues)
return shortenedNodeTemplatesObject;
})
const propertySchema = makeSchemaForCommonProperties(commonNodeTemplatesJson)
setToscaJsonSchema(propertySchema)
editorTemp = createJsonEditor(propertySchema, shortenedNodeTemplatesObjectStartValues);
setJsonEditor(editorTemp)
}
const updateTemplate = (userAddedCommonPropValues) => {
const nodeTemplates = fullToscaTemplate.topology_template.node_templates
const commonPropertyDataEntries = Object.entries(userAddedCommonPropValues)
// This replaces the values for properties in the full tosca template
// that will be sent up to the api with the entries the user provided.
commonPropertyDataEntries.forEach(([templateKey, values]) => {
Object.entries(values).forEach(([propKey, propVal]) => {
nodeTemplates[templateKey].properties[propKey] = propVal
})
})
fullToscaTemplate.topology_template.node_templates = nodeTemplates
setFullToscaTemplate(fullToscaTemplate)
alert('Changes saved. Commission When Ready...')
}
const makeSchemaForCommonProperties = (commonProps) => {
const commonPropsArr = Object.entries(commonProps)
const newSchemaObject = {}
newSchemaObject.title = "CommonProperties"
newSchemaObject.type = "object"
newSchemaObject.properties = {}
commonPropsArr.forEach(([templateKey, template]) => {
const propertiesObject = {}
Object.entries(template.properties).forEach(([propKey, prop]) => {
propertiesObject[propKey] = {
type: getType(prop.type)
}
})
newSchemaObject.properties[templateKey] = {
options: {
"collapsed": true
},
properties: propertiesObject
}
})
return newSchemaObject
}
const getType = (propertyType) => {
switch (propertyType)
{
case "string":
return "string"
case "integer":
return "integer"
case "list":
return "array"
case "object":
return "object"
default:
return "object"
}
}
const createJsonEditor = (toscaModel, editorData) => {
JSONEditor.defaults.options.collapse = false;
return new JSONEditor(document.getElementById("editor"),
{
schema: toscaModel,
startval: editorData,
theme: 'bootstrap4',
iconlib: 'fontawesome5',
object_layout: 'normal',
disable_properties: false,
disable_edit_json: true,
disable_array_reorder: true,
disable_array_delete_last_row: true,
disable_array_delete_all_rows: false,
array_controls_top: true,
keep_oneof_values: false,
collapsed: false,
show_errors: 'always',
display_required_only: false,
show_opt_in: false,
prompt_before_delete: true,
required_by_default: false,
})
}
return (