Rift.IO OSM R1 Initial Submission
[osm/UI.git] / skyquake / plugins / launchpad / src / monitoring-params-filter.jsx
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 import React from 'react';
20
21 let ReactCSSTransitionGroup = require('react-addons-css-transition-group');
22 var LaunchpadFleetActions = require('./launchpadFleetActions.js');
23 var LaunchpadFleetStore = require('./launchpadFleetStore.js');
24
25 class MPFilter extends React.Component {
26   constructor(props) {
27     super(props);
28     var self = this;
29     this.state = LaunchpadFleetStore.getState();
30     this.state.slideno = 0;
31
32   }
33   componentDidMount() {
34 }
35 change(e) {
36   var pane = JSON.parse(e.target.value);
37   var ret = {no: pane[1], pane:pane, slideChange:this.props.nsrs.length}
38   this.setState({slideno:pane[1], dropdownSlide:pane, slideChange: this.state.nsrs.length});
39   LaunchpadFleetActions.slideNoStateChange(ret);
40 }
41
42 render () {
43     var self = this;
44     /////////
45     // This code shouldn't be in here. It needs to be placed in an isolated component.
46     var drop_down = [];
47     var key = [];
48     if (self.props.nsrs
49         && self.props.nsrs.length > 0
50         && self.props.nsrs[0]
51          && self.props.nsrs[0]["monitoring-param"]) {
52       drop_down.push(<option key={'default'} value={JSON.stringify(['default', -1])}>Monitoring Params</option>)
53       for (var j = 0; j < self.props.nsrs.length; j++) {
54         var monitoring_params = self.props.nsrs[j]["monitoring-param"];
55         checkAndAddKey(monitoring_params);
56         for (var i = 0; i < monitoring_params.length; i++) {
57           if (key.indexOf(monitoring_params[i]["group-tag"]) == -1) {
58             var same = false;
59             for (var k = 0; k < drop_down.length; k++) {
60               if (monitoring_params[i]["mp-id"] == drop_down[k].key) {
61                 same = true;
62               }
63             }
64             if (!same) {
65               drop_down.push(<option key={monitoring_params[i]["mp-id"]} value={JSON.stringify([monitoring_params[i]["mp-id"], monitoring_params[i]['group-tag'][6] - 1])}>{monitoring_params[i].name}</option>)
66               key.push(monitoring_params[i]);
67             }
68           }
69         }
70       }
71     }
72     //
73     /////////
74
75     return (
76       <div>
77           <div
78             style={{
79               display:'flex',
80               justifyContent: 'start',
81               flexWrap:'wrap'
82             }}
83           >
84           <h4>CHANGE METRICS</h4>
85             <select style={{margin:'0px 0px 14px 15px'}} onChange={this.change.bind(this)} value={JSON.stringify(['default',0])}>{drop_down}</select>
86           </div>
87         </div>
88             )
89   }
90 }
91 function checkAndAddKey (monitoring_params) {
92   monitoring_params.forEach(function(v, i) {
93     if(v["mp-id"] == "") {
94       v["mp-id"] = v["group-tag"] + "-" + i;
95     }
96   })
97 }
98
99 export default MPFilter