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