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