RIFT-15495: Boolean dropdowns for composer 55/1055/1
authorLaurence Maultsby <laurence.maultsby@riftio.com>
Tue, 31 Jan 2017 18:12:53 +0000 (13:12 -0500)
committerLaurence Maultsby <laurence.maultsby@riftio.com>
Tue, 31 Jan 2017 18:12:53 +0000 (13:12 -0500)
Signed-off-by: Laurence Maultsby <laurence.maultsby@riftio.com>
skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js
skyquake/plugins/composer/src/src/libraries/model/DescriptorModelMetaProperty.js

index 4ee4345..a69f3bb 100644 (file)
@@ -180,6 +180,7 @@ export default function EditDescriptorModelProperties(props) {
                const name = path.join('.');
                const isEditable = true;
                const isGuid = Property.isGuid(property);
+               const isBoolean = Property.isBoolean(property);
                const onChange = onFormFieldValueChanged.bind(container);
                const isEnumeration = Property.isEnumeration(property);
                const isLeafRef = Property.isLeafRef(property);
@@ -224,6 +225,31 @@ export default function EditDescriptorModelProperties(props) {
                        return <select key={fieldKey.toString()} id={fieldKey.toString()} className={ClassNames({'-value-not-set': !isValueSet})} name={name} value={value} title={name} onChange={onChange} onFocus={onFocus} onBlur={endEditing} onMouseDown={startEditing} onMouseOver={startEditing} readOnly={!isEditable}>{options}</select>;
                }
 
+               if (isBoolean) {
+                       let fullFieldKey = _.isArray(fieldKey) ? fieldKey.join(':') : fieldKey;
+                       let containerRef = container;
+                       while (containerRef.parent) {
+                               fullFieldKey = containerRef.parent.key + ':' + fullFieldKey;
+                               containerRef = containerRef.parent;
+                       }
+
+                       const options = [
+                               <option key={fieldKey.toString() + '-true'} value="TRUE">TRUE</option>,
+                               <option key={fieldKey.toString() + '-false'} value="FALSE">FALSE</option>
+                       ]
+
+                       // if (!isValueSet) {
+                               const noValueDisplayText = changeCase.title(property.name);
+                               options.unshift(<option key={'(value-not-in-leafref)' + fieldKey.toString()} value="" placeholder={placeholder}></option>);
+                       // }
+                       let val = value;
+                       if(typeof(val) == 'number') {
+                               val = value ? "TRUE" : "FALSE"
+                       }
+                       const isValueSet = (val != '' && val)
+                       return <select key={fieldKey.toString()} id={fieldKey.toString()} className={ClassNames({'-value-not-set': !isValueSet})} name={name} value={val && val.toUpperCase()} title={name} onChange={onChange} onFocus={onFocus} onBlur={endEditing} onMouseDown={startEditing} onMouseOver={startEditing} readOnly={!isEditable}>{options}</select>;
+               }
+
                if (property['preserve-line-breaks']) {
                        return <textarea key={fieldKey.toString()} cols="5" id={fieldKey.toString()} name={name} value={value} placeholder={placeholder} onChange={onChange} onFocus={onFocus} onBlur={endEditing} onMouseDown={startEditing} onMouseOver={startEditing} onMouseOut={endEditing} onMouseLeave={endEditing} readOnly={!isEditable} />;
                }
index 89d1fe9..8fe51d9 100644 (file)
@@ -32,6 +32,9 @@ import DescriptorTemplateFactory from './DescriptorTemplateFactory'
 import utils from '../utils'
 
 export default {
+       isBoolean(property = {}) {
+               return (typeof(property['data-type']) == 'string') && (property['data-type'].toLowerCase() == 'boolean')
+       },
        isLeaf(property = {}) {
                return /leaf|choice/.test(property.type);
        },