Merging master to master_vca_intg
authorKiran Kashalkar <kiran.kashalkar@riftio.com>
Thu, 23 Feb 2017 10:48:18 +0000 (10:48 +0000)
committerKiran Kashalkar <kiran.kashalkar@riftio.com>
Thu, 23 Feb 2017 10:48:18 +0000 (10:48 +0000)
Signed-off-by: Kiran Kashalkar <kiran.kashalkar@riftio.com>
1  2 
skyquake/plugins/composer/api/composer.js
skyquake/plugins/composer/src/src/components/CanvasPanel.js
skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js
skyquake/plugins/composer/src/src/libraries/model/DescriptorModelMetaProperty.js
skyquake/plugins/composer/src/src/libraries/utils.js

@@@ -312,7 -312,7 +312,7 @@@ Composer.update = function(req) 
      var download_host = req.query['dev_download_server'];
  
      if (!download_host) {
-         download_host = api_server + ':' + utils.getPortForProtocol(req.protocol);
+         download_host = req.protocol + '://' + req.get('host');//api_server + ':' + utils.getPortForProtocol(req.protocol);
      }
      var input = {
          'external-url': download_host + '/composer/update/' + req.file.filename,
@@@ -368,7 -368,7 +368,7 @@@ Composer.upload = function(req) 
      var download_host = req.query['dev_download_server'];
  
      if (!download_host) {
-         download_host = api_server + ':' + utils.getPortForProtocol(req.protocol);
+         download_host = req.protocol + '://' + req.get('host');//req.api_server + ':' + utils.getPortForProtocol(req.protocol);
      }
  
      return new Promise(function(resolve, reject) {
@@@ -425,9 -425,14 +425,14 @@@ Composer.addFile = function(req) 
      var package_type = req.query['package_type'].toUpperCase();
      var package_path = req.query['package_path'];
      if (!download_host) {
-         download_host = api_server + ':' + utils.getPortForProtocol(req.protocol);
+         download_host = req.protocol + '://' + req.get('host');//api_server + ':' + utils.getPortForProtocol(req.protocol);
+     }
+     var input = {
+         'external-url': download_host + '/composer/upload/' + req.query['package_id'] + '/' + req.file.filename,
+         'package-type': package_type,
+         'package-id': package_id,
+         'package-path': package_path + '/' + req.file.filename
      }
      return new Promise(function(resolve, reject) {
          Promise.all([
              rp({
                  resolveWithFullResponse: true,
                  json: true,
                  body: {
-                     input: {
-                         'external-url': download_host + '/composer/upload/' + req.query['package_id'] + '/' + req.file.filename,
-                         'package-type': package_type,
-                         'package-id': package_id,
-                         'package-path': package_path + '/' + req.file.filename
-                     }
+                     input: input
                  }
              })
          ]).then(function(result) {
@@@ -636,7 -636,7 +636,7 @@@ FileManager.job = function(req) 
              forever: constants.FOREVER_ON,
              rejectUnauthorized: false,
          }, function(error, response, body) {
 -            if (utils.validateResponse('restconfAPI.streams', error, response, body, resolve, reject)) {
 +            if (utils.validateResponse('FileManager.job', error, response, body, resolve, reject)) {
                  var data = JSON.parse(response.body)['rw-pkg-mgmt:download-jobs'];
                  var returnData = [];
                  data && data.job.map(function(d) {
@@@ -34,9 -34,9 +34,9 @@@ import CanvasPanelTray from './CanvasPa
  import EditForwardingGraphPaths from './EditorForwardingGraph/EditForwardingGraphPaths'
  import SelectionManager from '../libraries/SelectionManager'
  import DescriptorModelIconFactory from '../libraries/model/IconFactory'
 -
  import FileManager from './filemanager/FileManager.jsx';
  
 +import ConfigPrimitiveParameters from './ConfigPrimitiveParameters/ConfigPrimitiveParameters'
  import '../styles/CanvasPanel.scss'
  
  const CanvasPanel = React.createClass({
                                        </div>
                                </div>
                        )
 +        //CanvasPanelTray panel to display
 +        let displayedPanel = null;
 +        switch (this.props.displayedPanel) {
 +            case 'forwarding' : displayedPanel = (<EditForwardingGraphPaths containers={this.props.containers} />); break;
 +            case 'parameter' : displayedPanel = (<ConfigPrimitiveParameters  containers={this.props.containers} />); break;
 +            default: displayedPanel = (<div><p className="welcome-message">Please select a tab</p></div>); break;
 +        }
                return (
                        <div id="canvasPanelDiv" className="CanvasPanel" style={style} onDragOver={this.onDragOver} onDrop={this.onDrop}>
                                <div onDoubleClick={this.onDblClickOpenFullScreen}  className="CanvasPanelHeader panel-header" data-resizable="limit_bottom">
                                </div>
                                {viewButtonTabs}
                                <div className="CanvasPanelBody panel-body" style={{marginRight: this.props.layout.right, bottom: this.props.layout.bottom}} >
-                                       {hasNoCatalogs ? null : viewFiles ? <FileManager files={this.props.files} type={this.props.type} item={this.props.item} filesState={this.props.filesState} /> : bodyComponent}
+                                       {hasNoCatalogs ? null : viewFiles ? <FileManager files={this.props.files} type={this.props.type} item={this.props.item} filesState={this.props.filesState} newPathName={this.props.newPathName} /> : bodyComponent}
                                </div>
                                {
                                        isDescriptorView ?
                                                <CanvasZoom zoom={this.props.zoom} style={{bottom: this.props.layout.bottom + 20}}/>
                                                : null
                                }
 -                              <CanvasPanelTray layout={this.props.layout} show={isEditingNSD && isDescriptorView}>
 -                                      <EditForwardingGraphPaths containers={this.props.containers} />
 +                              <CanvasPanelTray layout={this.props.layout} displayedPanel={this.props.displayedPanel} show={isEditingNSD && isDescriptorView}>
 +                                      {displayedPanel}
                                </CanvasPanelTray>
                        </div>
                );
@@@ -46,8 -46,6 +46,8 @@@ import imgRemove from '../../../node_mo
  
  import '../styles/EditDescriptorModelProperties.scss'
  
 +
 +
  function getDescriptorMetaBasicForType(type) {
        const basicPropertiesFilter = d => _.includes(DESCRIPTOR_MODEL_FIELDS[type], d.name);
        return DescriptorModelMetaFactory.getModelMetaForType(type, basicPropertiesFilter) || {properties: []};
@@@ -72,7 -70,16 +72,7 @@@ function getTitle(model = {}) 
                return model.id;
        }
  }
 -
 -export default function EditDescriptorModelProperties(props) {
 -
 -      const container = props.container;
 -
 -      if (!(DescriptorModelFactory.isContainer(container))) {
 -              return
 -      }
 -
 -      function startEditing() {
 +function startEditing() {
                DeletionManager.removeEventListeners();
        }
  
                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);
                        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} />;
                }
                });
        }
  
 -      function buildChoice(container, property, path, value, key) {
 +    function buildChoice(container, property, path, value, key, props={}) {
  
                function onFormFieldValueChanged(event) {
                        if (DescriptorModelFactory.isContainer(this)) {
                        if (isMissingDescriptorMeta) {
                                field = <span key={key.concat('warning').join(':')} className="warning">No Descriptor Meta for {property.name}</span>;
                        } else if (property.type === 'choice') {
 -                              field = buildChoice(container, property, valuePath, value, key.join(':'));
 +                field = buildChoice(container, property, valuePath, value, key.join(':'), props);
                        } else if (isSimpleListView) {
 -                              field = buildSimpleListItem(container, property, valuePath, value, key, index);
 +                field = buildSimpleListItem(container, property, valuePath, value, key, index, props);
                        } else if (isLeafList) {
 -                              field = buildLeafListItem(container, property, valuePath, value, key, index);
 +                field = buildLeafListItem(container, property, valuePath, value, key, index, props);
                        } else if (hasProperties) {
 -                              field = buildElement(container, property, valuePath, value, key.join(':'))
 +                field = buildElement(container, property, valuePath, value, key.join(':'), props)
                        } else {
 -                              field = buildField(container, property, valuePath, value, key.join(':'));
 +                field = buildField(container, property, valuePath, value, key.join(':'), props);
                        }
  
                        function onClickLeaf(property, path, value, event) {
                );
  
        }
 +export default function EditDescriptorModelProperties(props, type) {
 +
 +    const container = props.container;
 +
 +    if (!(DescriptorModelFactory.isContainer(container))) {
 +        return
 +    }
 +
 +
  
 -      const containerType = container.uiState['qualified-type'] || container.uiState.type;
 +    const containerType = (_.isEmpty(type) ? false : type)|| container.uiState['qualified-type'] || container.uiState.type;
        const basicProperties = getDescriptorMetaBasicForType(containerType).properties;
  
        function buildBasicGroup() {
                                        {properties.map(property => {
                                                const path = [property.name];
                                                const value = container.model[property.name];
 -                                              return build(container, property, path, value, {toggle: true, width: props.width});
 +                        return build(container, property, path, value, _.assign({toggle: true, width: props.width}, props));
                                        })}
                                </div>
                                <div className="toggle-bottom-spacer" style={{visibility: 'hidden', 'height': '50%', position: 'absolute'}}>We need this so when the user closes the panel it won't shift away and scare the bj out of them!</div>
        );
  
  }
 +export {build}
 +// export buildElement;
 +// export buildChoice;
@@@ -32,6 -32,9 +32,9 @@@ import DescriptorTemplateFactory from '
  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);
        },
                let leafRefObjects = [];
  
                leafRefPathValues && leafRefPathValues.map((leafRefPathValue) => {
 +                      leafRefObjects.push({
 +                              name: leafRefPathValue,
 +                              value: leafRefPathValue,
 +                              isSelected: String(leafRefPathValue) === String(value)
 +                      });
 +              });
 +
 +              return leafRefObjects;
 +      },
 +
 +      getConfigParamRef(property = {}, path, value, fullFieldKey, transientCatalogs, container, vnfdId) {
 +              // const leafRefPath = property['data-type']['leafref']['path'];
 +              const leafRefPath = "/vnfd:vnfd-catalog/vnfd:vnfd[vnfd:id = " + vnfdId + "]/vnfd:config-parameter/vnfd:config-parameter-source/vnfd:name"
 +              const transientCatalogHash = {};
 +
 +              transientCatalogs.map((catalog) => {
 +                      transientCatalogHash[catalog.type + '-catalog'] = {};
 +                      transientCatalogHash[catalog.type + '-catalog'][catalog.type] = catalog['descriptors'];
 +              });
 +
 +              let leafRefPathValues = utils.resolveLeafRefPath(transientCatalogHash, leafRefPath, fullFieldKey, path, container);
 +
 +              let leafRefObjects = [];
 +
 +              leafRefPathValues && leafRefPathValues.map((leafRefPathValue) => {
                        leafRefObjects.push({
                                name: leafRefPathValue,
                                value: leafRefPathValue,
@@@ -212,9 -212,27 +212,27 @@@ export default 
                                                let key = fragment.split('[')[0];
                                                let searchObject = {};
                                                searchObject[predicateKey] = predicateValue;
-                                               objectCopy = _.find(objectCopy[key], searchObject);
-                                               if (!objectCopy) {
-                                                       return [];
+                                               let found = _.find(objectCopy[key], searchObject);
+                                               if (found) {
+                                                       objectCopy = found;
+                                               } else {
+                                                       // check for numerical value
+                                                       if (predicateValue != "" &&
+                                                               predicateValue != null &&
+                                                               predicateValue != NaN &&
+                                                               predicateValue != Infinity &&
+                                                               predicateValue != -Infinity) {
+                                                               let numericalPredicateValue = _.toNumber(predicateValue);
+                                                               if (_.isNumber(numericalPredicateValue)) {
+                                                                       searchObject[predicateKey] = numericalPredicateValue;
+                                                                       found = _.find(objectCopy[key], searchObject);
+                                                               }
+                                                       }
+                                                       if (found) {
+                                                               objectCopy = found;
+                                                       } else {
+                                                               return [];
+                                                       }
                                                }
                                        } else {
                                                // contains no predicate
  
                // Check if relative path or not
                // TODO: Below works but
 -              // better to convert the pathCopy to absolute/rooted path 
 +              // better to convert the pathCopy to absolute/rooted path
                // and use the absolute module instead
                if (this.isRelativePath(leafRefPathCopy)) {
                        let i = pathArray.length;
 -                      while (pathArray[pathArray.length - i] == '..') {
 +                      while ((pathArray[pathArray.length - i] == '..') && fieldKeyArray.length > 1) {
                                fieldKeyArray.splice(-1, 1);
                                if (!isNaN(Number(fieldKeyArray[fieldKeyArray.length - 1]))) {
                                        // found a number, so an index. strip it
                                                }
                                        }
                                }
 -                      } else {
 +                      }  else {
                                // not supported - too many levels deep ... maybe some day
                                console.log('The relative path is from a node too many levels deep from root. This is not supported at the time');
                        }