From fee1b6e85ac33ab3781a718b64678525ddfc2c9f Mon Sep 17 00:00:00 2001 From: Laurence Maultsby Date: Thu, 3 Nov 2016 10:57:18 -0400 Subject: [PATCH] RIFT-14828: object Top level choice statements supported in composer Signed-off-by: Laurence Maultsby --- .../EditDescriptorModelProperties.js | 18 ++++++++++++- .../model/DescriptorModelSerializer.js | 26 +++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js b/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js index a2373e646..2c4b71c1d 100644 --- a/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js +++ b/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js @@ -342,6 +342,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 +366,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 +518,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; diff --git a/skyquake/plugins/composer/src/src/libraries/model/DescriptorModelSerializer.js b/skyquake/plugins/composer/src/src/libraries/model/DescriptorModelSerializer.js index 4e6b79264..cebb946ac 100644 --- a/skyquake/plugins/composer/src/src/libraries/model/DescriptorModelSerializer.js +++ b/skyquake/plugins/composer/src/src/libraries/model/DescriptorModelSerializer.js @@ -1,6 +1,6 @@ /* - * + * * 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]; } + //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] === '') { @@ -186,10 +189,29 @@ const DescriptorModelSerializer = { }, 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; } } }; + +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; -- 2.25.1