9d52bb82111bad0d4d60e39aa2b1fc0926342d4e
[osm/UI.git] / skyquake / plugins / launchpad / src / monitoring_params / monitoringParamComponents.js
1 /*
2
3 *
4 * Copyright 2016 RIFT.IO Inc
5 *
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 *
18
19 */
20 import React from 'react';
21 import * as Components from 'widgets/components.js';
22 import Utils from 'utils/utils.js';
23
24 function Component(node, prop, count, length) {
25 var valueProperty;
26 var numericConstraintsMinPresent = false;
27 var numericConstraintsMaxPresent = false;
28 if ("value-type" in node) {
29 switch(node["value-type"]) {
30 case 'INT' :
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;
35 }
36 break;
37 case 'DECIMAL' :
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;
42 }
43 break;
44 case 'STRING' : valueProperty = 'value-string'; break;
45 }
46 } else {
47 valueProperty = 'value-integer';
48 }
49 //' + String((100/length) - 5) + '%'
50 switch(node["widget-type"]) {
51 case 'GAUGE':
52 return (
53 <div
54 className="monitoring_params_component"
55 key={prop + '-' + prop.name+ '-' + count}
56 mp={node["mp-id"]}>
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'] || ''} />
59 </div>);
60 break;
61 case 'TEXTBOX':
62 case 'COUNTER':
63 var displayValue = 0;
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);
71 } else {
72 displayValue = [backendValue, node['units']];
73 }
74 return (
75 <div
76 key={prop + '-' + prop.name + '-' + count}
77 className="monitoring_params_component"
78 mp={node["mp-id"]}>
79 <div>{node.name}</div>
80 <div style={{fontSize: '3rem'}}>{displayValue[0]}</div>
81 <div style={{fontSize: '1.5rem'}}>{displayValue[1]}</div>
82 </div>);
83 break;
84 default : return(<div>{node["widget-type"]} Widget Type Not Yet Supported</div>)
85 }
86 }
87
88 export default function parseCardObj(obj_list, type) {
89 var ret = [];
90 var hash = {};
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"];
95 if (key in hash) {
96 hash[key].push(node);
97 } else {
98 hash[key] = [node];
99 }
100 }
101 }
102 for (var prop in hash) {
103 var html = {};
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);
110 } else {
111 var list = []
112 for (var i = 0; i < hash[prop].length; i++) {
113 list.push(Component.call(this,hash[prop][i], prop, i, hash[prop].length));
114 }
115 html.component = list;
116 }
117 ret.push(html)
118 }
119 return ret.sort(function(a, b){
120 return (a.title > b.title) ? -1 : 1;
121 });
122 }