3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * Created by onvelocity on 1/27/16.
21 * This class provides utility methods for interrogating an instance of model uiState object.
25 isString(property
= {}) {
26 return (typeof(property
['data-type']) == 'string') && (property
['data-type'].toLowerCase() == 'string')
28 isBoolean(property
= {}) {
29 return (typeof(property
['data-type']) == 'string') && (property
['data-type'].toLowerCase() == 'boolean')
31 isLeafEmpty(property
= {}) {
32 return (typeof(property
['data-type']) == 'string') && (property
['data-type'].toLowerCase() == 'empty')
34 isLeaf(property
= {}) {
35 return property
.type
=== 'leaf';
37 isLeafOrLeafList(property
= {}) {
38 return property
.type
=== 'leaf' || property
.type
=== 'leaf_list';
40 isLeafList(property
= {}) {
41 return property
.type
=== 'leaf_list';
43 isList(property
= {}) {
44 return property
.type
=== 'list';
46 isLeafRef(property
= {}) {
47 const type
= property
['data-type'] || {};
48 return type
.hasOwnProperty('leafref');
50 isEnumeration(property
= {}) {
51 const type
= property
['data-type'] || {};
52 return type
.hasOwnProperty('enumeration');
54 isRequired(property
= {}) {
55 return property
.mandatory
=== 'true';
57 isKey(property
= {}) {
58 return property
['is-key'] === 'true';
60 isJSON(property
= {}) {
61 property
.name
.match(/(vnfd|nsd):meta$/)
63 getDefaultValue(property
= {}) {
64 if (property
['default-value']) {
65 return property
['default-value'];
69 getEnumeration(property
= {}, value
) {
70 const enumeration
= property
['data-type'].enumeration
.enum;
71 if (typeof enumeration
=== 'string') {
72 return [{name
: enumeration
, value
: enumeration
, isSelected
: String(value
) === enumeration
}];
74 return Object
.keys(enumeration
).map(enumName
=> {
75 let enumValue
= enumName
;
76 // warn we only support named enums and systematically ignore enum values
77 //const enumObj = enumeration[enumName];
79 // enumValue = enumObj.value || enumName;
81 return {name
: enumName
, value
: enumValue
, isSelected
: String(enumValue
) === String(value
)};
84 getDisplayValue(property
= {}, rawValue
) {
85 if (this.isLeafEmpty(property
) && rawValue
!== undefined && rawValue
!== null) {
87 } if (this.isLeafList(property
) && Array
.isArray(rawValue
)) {
88 return rawValue
.join(", ");
93 isValueSet(property
= {}, rawValue
) {
95 (typeof rawValue
=== 'undefined')
97 || (typeof rawValue
=== 'string' && rawValue
.length
=== 0)