4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 import React
from 'react';
21 import * as Components
from 'widgets/components.js';
22 import Utils
from 'utils/utils.js';
24 function Component(node
, prop
, count
, length
) {
26 var numericConstraintsMinPresent
= false;
27 var numericConstraintsMaxPresent
= false;
28 if ("value-type" in node
) {
29 switch(node
["value-type"]) {
31 valueProperty
= 'value-integer';
32 if (node
['numeric-constraints']) {
33 numericConstraintsMinPresent
= node
['numeric-constraints']['min-value'] ? true : false;
34 numericConstraintsMaxPresent
= node
['numeric-constraints']['max-value'] ? true : false;
38 valueProperty
= 'value-decimal';
39 if (node
['numeric-constraints']) {
40 numericConstraintsMinPresent
= node
['numeric-constraints']['min-value'] ? true : false;
41 numericConstraintsMaxPresent
= node
['numeric-constraints']['max-value'] ? true : false;
44 case 'STRING' : valueProperty
= 'value-string'; break;
47 valueProperty
= 'value-integer';
49 //' + String((100/length) - 5) + '%'
50 switch(node
["widget-type"]) {
54 className
="monitoring_params_component"
55 key
={prop
+ '-' + prop
.name
+ '-' + count
}
57 <div
>{node
.name
}</div
>
58 <Components
.default.Gauge value
={node
[valueProperty
] || 0} min
={numericConstraintsMinPresent
? node
['numeric-constraints']['min-value'] : 0} max
={numericConstraintsMaxPresent
? node
['numeric-constraints']['max-value'] : 100} units
={node
['units'] || ''} />
64 var backendValue
= node
[valueProperty
] || 0;
65 if (node
['units'] == 'KB') {
66 displayValue
= Utils
.getByteDataWithUnitPrefix(backendValue
* 1024, 4);
67 } else if (node
['units'] == 'bytes') {
68 displayValue
= Utils
.getByteDataWithUnitPrefix(backendValue
, 4);
69 } else if (node
['units'] == 'packets') {
70 displayValue
= Utils
.getPacketDataWithUnitPrefix(backendValue
, 4);
72 displayValue
= [backendValue
, node
['units']];
76 key
={prop
+ '-' + prop
.name
+ '-' + count
}
77 className
="monitoring_params_component"
79 <div
>{node
.name
}</div
>
80 <div style
={{fontSize
: '3rem'}}>{displayValue
[0]}</div
>
81 <div style
={{fontSize
: '1.5rem'}}>{displayValue
[1]}</div
>
84 default : return(<div
>{node
["widget-type"]} Widget Type Not Yet Supported
</div
>)
88 export default function parseCardObj(obj_list
, type
) {
91 if (typeof obj_list
!= 'undefined') {
92 for (var i
= 0; i
< obj_list
.length
; i
++) {
93 var node
= obj_list
[i
];
94 var key
= node
[type
] || node
["group-tag"];
102 for (var prop
in hash
) {
104 var vnfrID
= hash
[prop
][0]['vnfr-id'];
105 var vnfrSubstr
= vnfrID
? hash
[prop
][0]['vnfr-id'].substr(hash
[prop
][0]['vnfr-id'].length
- 4) : ''
106 var GroupName
= hash
[prop
][0]["group-tag"];
107 html
.title
= GroupName
? GroupName
: '';
108 if (hash
[prop
].length
== 1) {
109 html
.component
= Component
.call(this, hash
[prop
][0], prop
, 1);
112 for (var i
= 0; i
< hash
[prop
].length
; i
++) {
113 list
.push(Component
.call(this,hash
[prop
][i
], prop
, i
, hash
[prop
].length
));
115 html
.component
= list
;
119 return ret
.sort(function(a
, b
){
120 return (a
.title
> b
.title
) ? -1 : 1;