X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FUI.git;a=blobdiff_plain;f=skyquake%2Fplugins%2Fcomposer%2Fsrc%2Fsrc%2Fcomponents%2FEditConfigParameterMap.js;h=f89b14a1beb3dd8eab8368bd2976b49ce26b1bbf;hp=1add58c4dd472be24b5a2e0119c20eba51833251;hb=98ee84ae45e88a9e2197914e7613a2fc3d3a7915;hpb=424cf2934aa45de562199ad01ab51fd76dbedba5 diff --git a/skyquake/plugins/composer/src/src/components/EditConfigParameterMap.js b/skyquake/plugins/composer/src/src/components/EditConfigParameterMap.js index 1add58c4d..f89b14a1b 100644 --- a/skyquake/plugins/composer/src/src/components/EditConfigParameterMap.js +++ b/skyquake/plugins/composer/src/src/components/EditConfigParameterMap.js @@ -45,7 +45,7 @@ import imgAdd from '../../../node_modules/open-iconic/svg/plus.svg' import imgRemove from '../../../node_modules/open-iconic/svg/trash.svg' import '../styles/EditDescriptorModelProperties.scss' - +import '../styles/EditConfigParameterMap.scss'; function getDescriptorMetaBasicForType(type) { @@ -160,13 +160,14 @@ function startEditing() { if (DescriptorModelFactory.isContainer(this)) { event.preventDefault(); const name = event.target.name; - const value = event.target.value; - utils.assignPathValue(this.model, name, value); + const value = JSON.parse(event.target.value); + utils.assignPathValue(this.model, 'config-parameter-source.config-parameter-source-ref', value.value); + utils.assignPathValue(this.model, 'config-parameter-source.member-vnf-index-ref', value.index); CatalogItemsActions.catalogItemDescriptorChanged(this.getRoot()); } } - function buildField(container, property, path, value, fieldKey) { + function buildField(container, property, path, value, fieldKey, vnfdIndex) { let cds = CatalogDataStore; let catalogs = cds.getTransientCatalogs(); @@ -180,67 +181,53 @@ function startEditing() { const placeholder = changeCase.title(property.name); const className = ClassNames(property.name + '-input', {'-is-guid': isGuid}); const fieldValue = value ? (value.constructor.name != "Object") ? value : '' : undefined; - if (isEnumeration) { - const enumeration = Property.getEnumeration(property, value); - const options = enumeration.map((d, i) => { - // note yangforge generates values for enums but the system does not use them - // so we categorically ignore them - // https://trello.com/c/uzEwVx6W/230-bug-enum-should-not-use-index-only-name - //return ; - return ; - }); - const isValueSet = enumeration.filter(d => d.isSelected).length > 0; - if (!isValueSet || property.cardinality === '0..1') { - const noValueDisplayText = changeCase.title(property.name); - options.unshift(); - } - return ; - } - - if (isLeafRef) { + // if (isEnumeration) { + // const enumeration = Property.getEnumeration(property, value); + // const options = enumeration.map((d, i) => { + // // note yangforge generates values for enums but the system does not use them + // // so we categorically ignore them + // // https://trello.com/c/uzEwVx6W/230-bug-enum-should-not-use-index-only-name + // //return ; + // return ; + // }); + // const isValueSet = enumeration.filter(d => d.isSelected).length > 0; + // if (!isValueSet || property.cardinality === '0..1') { + // const noValueDisplayText = changeCase.title(property.name); + // options.unshift(); + // } + // return ; + // } + + if (isLeafRef && (path.indexOf("config-parameter-source-ref") > -1)) { let fullFieldKey = _.isArray(fieldKey) ? fieldKey.join(':') : fieldKey; let containerRef = container; + let vnfdName = null; + let options = []; + let leafRefPathValues = []; while (containerRef.parent) { fullFieldKey = containerRef.parent.key + ':' + fullFieldKey; containerRef = containerRef.parent; } - const leafRefPathValues = Property.getLeafRef(property, path, value, fullFieldKey, catalogs, container); + let parentProperty = container.parent.constituentVnfd; + parentProperty.map((v, i) => { + let somevalues = Property.getConfigParamRef(property, path, value, fullFieldKey, catalogs, container, v.vnfdId); + options = somevalues && options.concat(somevalues.map((d, i) => { + return ; + })) + leafRefPathValues = leafRefPathValues.concat(somevalues); - const options = leafRefPathValues && leafRefPathValues.map((d, i) => { - return ; }); + const isValueSet = leafRefPathValues.filter(d => d.isSelected).length > 0; - if (!isValueSet || property.cardinality === '0..1') { + if (!isValueSet) { const noValueDisplayText = changeCase.title(property.name); options.unshift(); } - return ; - } - - if (property['preserve-line-breaks']) { - return ; + return ; } - - return ; - } - function buildElement(container, property, valuePath, value) { + function buildElement(container, property, valuePath, value, vnfdIndex) { return property.properties.map((property, index) => { let childValue; const childPath = valuePath.slice(); @@ -250,169 +237,11 @@ function startEditing() { if(property.type != 'choice'){ childPath.push(property.name); } - return build(container, property, childPath, childValue); + return build(container, property, childPath, childValue, {}, vnfdIndex); }); } - function buildChoice(container, property, path, value, key, props={}) { - - function onFormFieldValueChanged(event) { - if (DescriptorModelFactory.isContainer(this)) { - - event.preventDefault(); - - let name = event.target.name; - const value = event.target.value; - - - /* - Transient State is stored for convenience in the uiState field. - The choice yang type uses case elements to describe the "options". - A choice can only ever have one option selected which allows - the system to determine which type is selected by the name of - the element contained within the field. - */ - /* - const stateExample = { - uiState: { - choice: { - 'conf-config': { - selected: 'rest', - 'case': { - rest: {}, - netconf: {}, - script: {} - } - } - } - } - }; - */ - const statePath = ['uiState.choice'].concat(name); - const stateObject = utils.resolvePath(this.model, statePath.join('.')) || {}; - const selected = stateObject.selected ? stateObject.selected.split('.')[1] : undefined; - // write state back to the model so the new state objects are captured - utils.assignPathValue(this.model, statePath.join('.'), stateObject); - - // write the current choice value into the state - let choiceObject = utils.resolvePath(this.model, [name, selected].join('.')); - let isTopCase = false; - if (!choiceObject) { - isTopCase = true; - choiceObject = utils.resolvePath(this.model, [selected].join('.')); - } - utils.assignPathValue(stateObject, [selected].join('.'), _.cloneDeep(choiceObject)); - - if(selected) { - if(this.model.uiState.choice.hasOwnProperty(name)) { - delete this.model[selected]; - utils.removePathValue(this.model, [name, selected].join('.'), isTopCase); - } else { - // remove the current choice value from the model - utils.removePathValue(this.model, [name, selected].join('.'), isTopCase); - } - } - - // get any state for the new selected choice - const newChoiceObject = utils.resolvePath(stateObject, [value].join('.')) || {}; - - // assign new choice value to the model - if (isTopCase) { - utils.assignPathValue(this.model, [name, value].join('.'), newChoiceObject); - } else { - utils.assignPathValue(this.model, [value].join('.'), newChoiceObject) - } - - - // update the selected name - utils.assignPathValue(this.model, statePath.concat('selected').join('.'), value); - - CatalogItemsActions.catalogItemDescriptorChanged(this.getRoot()); - } - } - - const caseByNameMap = {}; - - const onChange = onFormFieldValueChanged.bind(container); - - const cases = property.properties.map(d => { - if (d.type === 'case') { - caseByNameMap[d.name] = d.properties[0]; - return { - optionName: d.name, - optionTitle: d.description, - //represents case name and case element name - optionValue: [d.name, d.properties[0].name].join('.') - }; - } - caseByNameMap[d.name] = d; - return {optionName: d.name}; - }); - - const options = [{optionName: '', optionValue: false}].concat(cases).map((d, i) => { - return ( - - ); - }); - - const selectName = path.join('.'); - let selectedOptionPath = ['uiState.choice', selectName, 'selected'].join('.'); - //Currently selected choice/case statement on UI model - let selectedOptionValue = utils.resolvePath(container.model, selectedOptionPath); - //If first time loaded, and none is selected, check if there is a value corresponding to a case statement in the container model - if(!selectedOptionValue) { - //get field properties for choice on container model - let fieldProperties = utils.resolvePath(container.model, selectName); - if(fieldProperties) { - //Check each case statement in model and see if it is present in container model. - cases.map(function(c){ - if(fieldProperties.hasOwnProperty(c.optionValue.split('.')[1])) { - utils.assignPathValue(container.model, ['uiState.choice', selectName, 'selected'].join('.'), c.optionValue); - } - }); - selectedOptionValue = utils.resolvePath(container.model, ['uiState.choice', selectName, 'selected'].join('.')); - } else { - property.properties.map(function(p) { - let pname = p.properties[0].name; - if(container.model.hasOwnProperty(pname)) { - utils.assignPathValue(container.model, ['uiState.choice', selectName, 'selected'].join('.'), [p.name, pname].join('.')); - } - }) - selectedOptionValue = utils.resolvePath(container.model, ['uiState.choice', selectName, 'selected'].join('.')); - } - } - //If selectedOptionValue is present, take first item in string which represents the case name. - const valueProperty = caseByNameMap[selectedOptionValue ? selectedOptionValue.split('.')[0] : undefined] || {properties: []}; - const isLeaf = Property.isLeaf(valueProperty); - const hasProperties = _.isArray(valueProperty.properties) && valueProperty.properties.length; - const isMissingDescriptorMeta = !hasProperties && !Property.isLeaf(valueProperty); - //Some magic that prevents errors for arising - const valueResponse = valueProperty.properties.length ? valueProperty.properties.map((d, i) => { - const childPath = path.concat(valueProperty.name, d.name); - const childValue = utils.resolvePath(container.model, childPath.join('.')); - return ( -