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"]) {
55 // className="monitoring_params_component"
56 // key={prop + '-' + prop.name+ '-' + count}
57 // mp={node["mp-id"]}>
58 // <div>{node.name}</div>
59 // <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'] || ''} />
65 var backendValue
= node
[valueProperty
] || 0;
66 if (node
['units'] == 'KB') {
67 displayValue
= Utils
.getByteDataWithUnitPrefix(backendValue
* 1024, 4);
68 } else if (node
['units'] == 'bytes') {
69 displayValue
= Utils
.getByteDataWithUnitPrefix(backendValue
, 4);
70 } else if (node
['units'] == 'packets') {
71 displayValue
= Utils
.getPacketDataWithUnitPrefix(backendValue
, 4);
73 displayValue
= [backendValue
, node
['units']];
77 key
={prop
+ '-' + prop
.name
+ '-' + count
}
78 className
="monitoring_params_component"
80 <div
>{node
.name
}</div
>
81 <div style
={{fontSize
: '3rem'}}>{displayValue
[0]}</div
>
82 <div style
={{fontSize
: '1.5rem'}}>{displayValue
[1]}</div
>
85 default : return(<div
>{node
["widget-type"]} Widget Type Not Yet Supported
</div
>)
89 export default function parseCardObj(obj_list
, type
) {
92 if (typeof obj_list
!= 'undefined') {
93 for (var i
= 0; i
< obj_list
.length
; i
++) {
94 var node
= obj_list
[i
];
95 var key
= node
[type
] || node
["group-tag"];
103 for (var prop
in hash
) {
105 var vnfrID
= hash
[prop
][0]['vnfr-id'];
106 var vnfrSubstr
= vnfrID
? hash
[prop
][0]['vnfr-id'].substr(hash
[prop
][0]['vnfr-id'].length
- 4) : ''
107 var GroupName
= hash
[prop
][0]["group-tag"];
108 html
.title
= GroupName
? GroupName
: '';
109 if (hash
[prop
].length
== 1) {
110 html
.component
= Component
.call(this, hash
[prop
][0], prop
, 1);
113 for (var i
= 0; i
< hash
[prop
].length
; i
++) {
114 list
.push(Component
.call(this,hash
[prop
][i
], prop
, i
, hash
[prop
].length
));
116 html
.component
= list
;
120 return ret
.sort(function(a
,b
) {
121 var titleA
= a
.title
&& a
.title
.toUpperCase();
122 var titleB
= b
.title
&& b
.title
.toUpperCase();
123 return (titleA
< titleB
) ? -1 : (titleA
> titleB
) ? 1 : 0;