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".
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;
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);
/*
- *
+ *
* Copyright 2016 RIFT.IO Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
nsd: common.concat(['constituent-vnfd', 'vnffgd', 'vld']),
vld: common.concat([]),
vnfd: common.concat(['vdu', 'internal-vld']),
- 'vnfd.vdu': common.concat(['image', 'external-interface', 'vm-flavor', 'cloud-init']),
+ 'vnfd.vdu': common.concat(['image', 'external-interface', 'vm-flavor', 'cloud-init', 'filename']),
// white-list valid fields to send in the meta field
meta: ['containerPositionMap']
};
// resolve paths like 'nsd' or 'vnfd.vdu' or 'nsd.constituent-vnfd'
const found = utils.resolvePath(modelMetaByPropertyNameMap, getPathForType(typeOrPath));
if (found) {
- return found[':meta'].properties.map(p => p.name);
+ let result = [];
+ found[':meta'].properties.map((p) => {
+ // if(false) {
+ if(p.type == 'choice') {
+ result.push(p.name)
+ return p.properties.map(function(q){
+ result.push(q.properties[0].name);
+ })
+
+ } else {
+ return result.push(p.name);
+ }
+ })
+ return result;
}
console.warn('no model uiState found for type', typeOrPath);
}
return constituentVNFD;
});
-
+ for (var key in confd) {
+ checkForChoiceAndRemove(key, confd, nsdModel);
+ }
// serialize the VLD instances
confd.vld = confd.vld.map(d => {
return DescriptorModelSerializer.serialize(d);
// once that is fixed, remove this piece of code.
// fix-start
for (var key in confd) {
- if (confd.hasOwnProperty(key) && confd[key] === '') {
- delete confd[key];
- }
- //removes choice properties from top level object and copies immediate children onto it.
- checkForChoiceAndRemove(key, confd, vldModel);
+ if (confd.hasOwnProperty(key) && confd[key] === '') {
+ delete confd[key];
+ } else {
+ //removes choice properties from top level object and copies immediate children onto it.
+ checkForChoiceAndRemove(key, confd, vldModel);
+ }
}
}
}
// fix-end
-
-
confd[property] = confd[property].map(d => DescriptorModelSerializer[property].serialize(d));
return confd;
}
},
vdu: {
serialize(vduModel) {
- const copy = _.clone(vduModel);
+ const copy = _.cloneDeep(vduModel);
for (let k in copy) {
checkForChoiceAndRemove(k, copy, vduModel)
}
function checkForChoiceAndRemove(k, confd, model) {
- let state = model.uiState;
- if (state.choice) {
- let choice = state.choice[k]
- if(choice) {
- for (let key in confd[k]) {
- confd[key] = confd[k][key]
- };
- delete confd[k];
- }
+ let state = model.uiState;
+ if (state.choice) {
+ let choice = state.choice[k]
+ if(choice) {
+ for (let key in confd[k]) {
+ if(choice && (choice.selected.indexOf(key) > -1)) {
+ confd[key] = confd[k][key]
}
- return confd;
- }
+ };
+ delete confd[k];
+ }
+ }
+ return confd;
+}
export default DescriptorModelSerializer;
/*
- *
+ *
* Copyright 2016 RIFT.IO Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
}, obj);
resolvedObj[name] = value;
},
- updatePathValue(obj, path, value) {
+ updatePathValue(obj, path, value, isCase) {
// todo: replace implementation of assignPathValue with this impl and
// remove updatePathValue (only need one function, not both)
// same as assignPathValue except removes property if value is undefined
if (isArray) {
r[p] = r[p].filter((d, i) => i !== index);
} else {
- delete r[p][name];
+ if(isCase) {
+ delete r[name];
+ } else {
+ delete r[p][name];
+ }
}
}
- return r[p];
+ if(isCase) {
+ return r;
+ } else {
+ return r[p];
+ }
+
}, obj);
if (!isRemove) {
resolvedObj[name] = value;
}
},
- removePathValue(obj, path) {
+ removePathValue(obj, path, isCase) {
// note updatePathValue removes value if third argument is undefined
- return this.updatePathValue(obj, path);
+ return this.updatePathValue(obj, path, undefined, isCase);
},
suffixAsInteger: (field) => {