X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=skyquake%2Fplugins%2Fcomposer%2Fsrc%2Fsrc%2Fcomponents%2FEditDescriptorModelProperties.js;h=20c84dac58559a518cdff195ca658afc029d6f5a;hb=refs%2Fchanges%2F52%2F652%2F1;hp=a2373e6466a3ea03771614a482ea113d925eed97;hpb=9a546bd5bcb6db7488f6a4059a356d8beb9b5b11;p=osm%2FUI.git diff --git a/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js b/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js index a2373e646..20c84dac5 100644 --- a/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js +++ b/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js @@ -245,9 +245,10 @@ export default function EditDescriptorModelProperties(props) { event.preventDefault(); - const name = event.target.name; + 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". @@ -255,22 +256,22 @@ export default function EditDescriptorModelProperties(props) { 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 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; @@ -278,19 +279,34 @@ export default function EditDescriptorModelProperties(props) { utils.assignPathValue(this.model, statePath.join('.'), stateObject); // write the current choice value into the state - const choiceObject = utils.resolvePath(this.model, [name, selected].join('.')); - if (choiceObject) { - utils.assignPathValue(stateObject, ['case', selected].join('.'), _.cloneDeep(choiceObject)); + 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(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); + } + - // remove the current choice value from the model - utils.removePathValue(this.model, [name, selected].join('.')); // get any state for the new selected choice - const newChoiceObject = utils.resolvePath(stateObject, ['case', value].join('.')) || {}; + const newChoiceObject = utils.resolvePath(stateObject, [value].join('.')) || {}; // assign new choice value to the model - utils.assignPathValue(this.model, [name, value].join('.'), newChoiceObject); + 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); @@ -342,6 +358,14 @@ export default function EditDescriptorModelProperties(props) { } }); 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. @@ -358,7 +382,7 @@ export default function EditDescriptorModelProperties(props) { {build(container, d, childPath, childValue, props)} ); - }) : (!isMissingDescriptorMeta) ? build(container, valueProperty, path.concat(valueProperty.name), utils.resolvePath(container.model, path.concat(valueProperty.name).join('.'))) : null + }) : (!isMissingDescriptorMeta) ? build(container, valueProperty, path.concat(valueProperty.name), utils.resolvePath(container.model, path.concat(valueProperty.name).join('.')) || container.model[valueProperty.name]) : null // end magic const onFocus = onFocusPropertyFormInputElement.bind(container, property, path, value); @@ -510,6 +534,14 @@ export default function EditDescriptorModelProperties(props) { if (property.type === 'choice') { value = utils.resolvePath(container.model, ['uiState.choice'].concat(path, 'selected').join('.')); + if(!value) { + property.properties.map(function(p) { + let pname = p.properties[0].name; + if(container.model.hasOwnProperty(pname)) { + value = container.model[pname]; + } + }) + } } let displayValue = typeof value === 'object' ? '' : value;