RIFT-15726 - optimize download size -> lodash usage in UI
[osm/UI.git] / skyquake / plugins / launchpad / src / launchpad.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 import LaunchpadCard from './launchpad_card/launchpadCard.jsx';
21 import Loader from 'widgets/loading-indicator/loadingIndicator.jsx';
22 import ScreenLoader from 'widgets/screen-loader/screenLoader.jsx';
23 import MPFilter from './monitoring-params-filter.jsx'
24 import NsCardPanel from './nsCardPanel/nsCardPanel.jsx';
25 import NsListPanel from './nsListPanel/nsListPanel.jsx';
26 import Crouton from 'react-crouton'
27 import AppHeader from 'widgets/header/header.jsx';
28 import './launchpad.scss';
29 let ReactCSSTransitionGroup = require('react-addons-css-transition-group');
30 var LaunchpadFleetActions = require('./launchpadFleetActions.js');
31 var LaunchpadFleetStore = require('./launchpadFleetStore.js');
32
33 export default class LaunchpadApp extends React.Component {
34   constructor(props) {
35     super(props);
36     var self = this;
37     this.state = LaunchpadFleetStore.getState();
38     this.state.slideno = 0;
39     this.handleUpdate = this.handleUpdate.bind(this);
40
41   }
42   componentDidMount() {
43     LaunchpadFleetStore.getCatalog();
44     LaunchpadFleetStore.listen(this.handleUpdate);
45
46     // Can not put a dispatch here it causes errors
47     // LaunchpadFleetActions.validateReset();
48     setTimeout(function() {
49       LaunchpadFleetStore.openNSRSocket();
50     },100);
51   /*
52   setTimeout(function() {
53     consoleo.log("launchpad.componentDidMount openNsrListSocket");
54     LaunchpadFleetStore.openNsrListSocket();
55   },100);
56     */
57
58   }
59   change(e) {
60
61   }
62   handleUpdate(data){
63     this.setState(data);
64   }
65   closeError() {
66     LaunchpadFleetActions.validateReset()
67   }
68   componentWillUnmount() {
69     LaunchpadFleetStore.closeSocket();
70     LaunchpadFleetStore.unlisten(this.handleUpdate);
71   }
72
73   handleOpenNsCard(nsr) {
74     LaunchpadFleetActions.openNSRCard(nsr);
75   }
76
77   handleCloseNsCard(id) {
78     LaunchpadFleetActions.closeNSRCard(id);
79   }
80
81   handleShowHideNsListPanelToggle() {
82     this.setState({
83       showNsListPanel: !this.state.showNsListPanel
84     })
85   }
86
87   openNsrs() {
88     return this.state.nsrs;
89   }
90
91   render () {
92     var self = this;
93     let mgmtDomainName = window.location.hash.split('/')[2];
94     let navItems = [];
95     if(!mgmtDomainName) {
96       mgmtDomainName = 'dashboard';
97     }
98     if(mgmtDomainName.toUpperCase() == 'DASHBOARD' || mgmtDomainName.toUpperCase() == 'UNDEFINED') {
99       mgmtDomainName = '';
100     } else {
101       mgmtDomainName = ' : ' + mgmtDomainName;
102     }
103     let nav = <AppHeader title={'LAUNCHPAD' + mgmtDomainName} nav={navItems} />
104
105     return (
106       <div className="app-body">
107         <div className="lp_dashboard">
108           <NsListPanel nsrs={self.state.nsrs}
109             openedNsrIDs={self.state.openedNsrIDs}
110             isVisible={self.state.isNsListPanelVisible}
111             />
112           <NsCardPanel nsrs={self.state.nsrs}
113             openedNsrIDs={self.state.openedNsrIDs} />
114         </div>
115       </div>
116     );
117     }
118 }
119 LaunchpadApp.contextTypes = {
120     router: React.PropTypes.object
121 };
122 LaunchpadApp.defaultProps = {
123   // name: 'Loading...',
124   // data: []
125   openedNsrIDs: []
126 };