update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try
[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 // Disabked fir OSM
53 // return (
54 // <div
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'] || ''} />
60 // </div>);
61 // break;
62 case 'TEXTBOX':
63 case 'COUNTER':
64 var displayValue = 0;
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);
72 } else {
73 displayValue = [backendValue, node['units']];
74 }
75 return (
76 <div
77 key={prop + '-' + prop.name + '-' + count}
78 className="monitoring_params_component"
79 mp={node["mp-id"]}>
80 <div>{node.name}</div>
81 <div style={{fontSize: '3rem'}}>{displayValue[0]}</div>
82 <div style={{fontSize: '1.5rem'}}>{displayValue[1]}</div>
83 </div>);
84 break;
85 default : return(<div>{node["widget-type"]} Widget Type Not Yet Supported</div>)
86 }
87 }
88
89 export default function parseCardObj(obj_list, type) {
90 var ret = [];
91 var hash = {};
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"];
96 if (key in hash) {
97 hash[key].push(node);
98 } else {
99 hash[key] = [node];
100 }
101 }
102 }
103 for (var prop in hash) {
104 var html = {};
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);
111 } else {
112 var list = []
113 for (var i = 0; i < hash[prop].length; i++) {
114 list.push(Component.call(this,hash[prop][i], prop, i, hash[prop].length));
115 }
116 html.component = list;
117 }
118 ret.push(html)
119 }
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;
124 });
125 }