RIFT-14828: object Top level choice statements supported in composer 96/596/1
authorLaurence Maultsby <laurence.maultsby@riftio.com>
Thu, 3 Nov 2016 14:57:18 +0000 (10:57 -0400)
committerLaurence Maultsby <laurence.maultsby@riftio.com>
Thu, 3 Nov 2016 14:57:18 +0000 (10:57 -0400)
Signed-off-by: Laurence Maultsby <laurence.maultsby@riftio.com>
skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js
skyquake/plugins/composer/src/src/libraries/model/DescriptorModelSerializer.js

index a2373e6..2c4b71c 100644 (file)
@@ -342,6 +342,14 @@ export default function EditDescriptorModelProperties(props) {
                                        }
                                });
                                selectedOptionValue = utils.resolvePath(container.model, ['uiState.choice', selectName, 'selected'].join('.'));
                                        }
                                });
                                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.
                        }
                }
                //If selectedOptionValue is present, take first item in string which represents the case name.
@@ -358,7 +366,7 @@ export default function EditDescriptorModelProperties(props) {
                                        {build(container, d, childPath, childValue, props)}
                                </div>
                        );
                                        {build(container, d, childPath, childValue, props)}
                                </div>
                        );
-               }) : (!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);
 
                // end magic
                const onFocus = onFocusPropertyFormInputElement.bind(container, property, path, value);
 
@@ -510,6 +518,14 @@ export default function EditDescriptorModelProperties(props) {
 
                if (property.type === 'choice') {
                        value = utils.resolvePath(container.model, ['uiState.choice'].concat(path, 'selected').join('.'));
 
                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;
                }
 
                let displayValue = typeof value === 'object' ? '' : value;
index 4e6b792..cebb946 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
 
 /*
- * 
+ *
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
@@ -145,8 +145,11 @@ const DescriptorModelSerializer = {
                                if (confd.hasOwnProperty(key) && confd[key] === '') {
                                        delete confd[key];
                                }
                                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);
                        }
 
                        }
 
+
                        const deepProperty = 'provider-network';
                        for (var key in confd[deepProperty]) {
                                if (confd[deepProperty].hasOwnProperty(key) && confd[deepProperty][key] === '') {
                        const deepProperty = 'provider-network';
                        for (var key in confd[deepProperty]) {
                                if (confd[deepProperty].hasOwnProperty(key) && confd[deepProperty][key] === '') {
@@ -186,10 +189,29 @@ const DescriptorModelSerializer = {
        },
        vdu: {
                serialize(vduModel) {
        },
        vdu: {
                serialize(vduModel) {
-                       const confd = _.omit(vduModel, ['uiState']);
+                       const copy = _.clone(vduModel);
+                       for (let k in copy) {
+                               checkForChoiceAndRemove(k, copy, vduModel)
+                       }
+                       const confd = _.omit(copy, ['uiState']);
                        return confd;
                }
        }
 };
 
                        return confd;
                }
        }
 };
 
+
+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];
+                                       }
+                               }
+                               return confd;
+                       }
+
 export default DescriptorModelSerializer;
 export default DescriptorModelSerializer;