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