RIFT-14803: UI Composer: References should be dropdowns https://osm.etsi.org/gerrit...
[osm/UI.git] / skyquake / plugins / composer / src / src / libraries / model / DescriptorModelMetaProperty.js
index efd06c0..8ba295a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 
+ *
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,16 +29,21 @@ import changeCase from 'change-case'
 import InstanceCounter from './../InstanceCounter'
 import DescriptorModelFields from './DescriptorModelFields'
 import DescriptorTemplateFactory from './DescriptorTemplateFactory'
+import utils from '../utils'
 
 export default {
        isLeaf(property = {}) {
                return /leaf|choice/.test(property.type);
        },
        isList(property = {}) {
-               return /list|leaf-list/.test(property.type);
+        return /list|leaf_list/.test(property.type);
        },
        isLeafList(property = {}) {
-               return property.type === 'leaf-list';
+        return property.type === 'leaf_list';
+       },
+       isLeafRef(property = {}) {
+               const type = property['data-type'] || {};
+               return type.hasOwnProperty('leafref');
        },
        isArray(property = {}) {
                // give '1' or '0..N' or '0..1' or '0..5' determine if represents an array
@@ -58,7 +63,7 @@ export default {
                return /^1/.test(property.cardinality);
        },
        isObject(property = {}) {
-               return !/^(leaf|leaf-list)$/.test(property.type);
+        return !/^(leaf|leaf_list)$/.test(property.type);
        },
        isSimpleList(property = {}) {
                return _.contains(DescriptorModelFields.simpleList, property.name);
@@ -107,6 +112,30 @@ export default {
                        return {name: enumName, value: enumValue, isSelected: String(enumValue) === String(value)};
                });
        },
+       getLeafRef(property = {}, path, value, fullFieldKey, transientCatalogs, container) {
+               const leafRefPath = property['data-type']['leafref']['path'];
+
+               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,
+                               isSelected: String(leafRefPathValue) === String(value)
+                       });
+               });
+
+               return leafRefObjects;
+       },
        isGuid(property = {}) {
                const type = property['data-type'];
                if (typeof type === 'object' && type.leafref && type.leafref.path) {