1533a702dea6784ddfd0f74ea7cdf8f6c63c8521
[osm/riftware.git] /
1 /*
2  *    Copyright 2016 RIFT.IO Inc
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 /*
18  * 
19  *
20  */
21 import React from 'react';
22 import UpTime from '../../../components/uptime/uptime.jsx';
23 import LaunchpadOperationalStatus from '../../../components/operational-status/launchpadOperationalStatus.jsx';
24 import MissionControlStore from '../../missionControlStore.js';
25 import ManagementDomainStore from '../managementDomainStore.js';
26 class ManagementDomainCardHeader extends React.Component {
27   constructor(props) {
28     super(props);
29     this.state = {};
30     this.state.displayStatus = false;
31     this.state.isLoading = true;
32     this.openDashboard = this.openDashboard.bind(this);
33     this.openConsole = this.openConsole.bind(this);
34     this.setStatus = this.setStatus.bind(this);
35     this.toggleStatus = this.toggleStatus.bind(this);
36   }
37
38   componentWillReceiveProps(nextProps) {
39     let lpState = nextProps.data.launchpad.state;
40     if(lpState == 'stopped' || lpState == 'started') {
41       this.setState({
42         isLoading: false
43       })
44     } else {
45       this.setState({
46         isLoading: true
47       })
48     }
49   }
50   deleteLaunchpad(name) {
51     if (confirm("Do you really want to delete management domain '" + name + "'?")) {
52             ManagementDomainStore.delete(name);
53     }
54   }
55   doneLoading() {
56     console.log('Done loading')
57     this.setState({
58       isLoading: false
59     });
60   }
61   //TODO instead of calling the store method, an action should be emitted and the store should respond.
62
63   openDashboard() {
64     if(this.props.isActive) {
65           window.open('http://' + this.props.data.launchpad.ip_address + ':8000/index.html?api_server=http://localhost#/launchpad/' + this.props.data.name);
66         }
67   }
68   openConsole() {
69     console.log('open console clicked');
70   }
71   setStatus(name) {
72     console.log('setting status for ', name)
73     this.props.isActive ? MissionControlStore.stopLaunchpad(name) : MissionControlStore.startLaunchpad(name)
74   }
75   editMgmtDomain(mgmtDomainName) {
76     window.location.href = '#/management-domain/' + mgmtDomainName + '/edit'
77   }
78   toggleStatus() {
79   }
80   render() {
81     let self = this;
82     let isLoading = this.state.isLoading;
83     let isActive = this.props.isActive;
84     let opStatusHack = [];
85     let d = new Date();
86     let currentTime = (d.getTime() / 1000);
87     let startTime = currentTime - this.props.data.launchpad["create-time"];
88     opStatusHack.push({
89       id:this.props.data.launchpad.state,
90       description:this.props.data.launchpad.state
91     })
92     console.log(this.props.data.launchpad['state-details'])
93     return (
94       <header className="launchpadCard_header">
95         <div className={"launchpadCard_header-title " + (this.props.isActive ? '' : 'launchpadCard_header-title-off')}>
96           <a role="button"
97             className="fleet-card-pwr-btn"
98             style={{'color':this.props.isActive?'#93cb43':'white'}}
99             onClick={this.setStatus.bind(this, this.props.name)}
100             title={this.props.isActive ? 'Turn Off' : 'Turn On'}
101             >
102           <span className="oi" data-glyph="power-standby" aria-hidden="true"></span>
103           </a>
104           <h3 className="managementDomainCard_header-link" onClick={this.openDashboard} style={{cursor: this.props.isActive ? 'pointer' : 'default', 'text-overflow':'ellipsis', 'max-width':'150px', 'overflow':'hidden'}}>
105             {this.props.name}
106           </h3>
107           <h3 className="managementDomainCard_header-link" style={{display: this.props.isActive ? 'inherit' : 'none'}}>
108             <a onClick={this.openDashboard} title="Open Launchpad">
109               <span className="oi" data-glyph="external-link" aria-hidden="true"></span>
110             </a>
111           </h3>
112           <div className="managementDomainCard_header-actions">
113             <h3>
114               {isLoading || !isActive ? '' : 'Active' }
115             </h3>
116             <h3 style={{display: (isLoading || !isActive) ? 'none' : 'inherit'}}>
117                 <UpTime initialtime={startTime} run={true} />
118             </h3>
119             <h3 style={{display: isLoading ? 'none' : 'inherit'}}>
120             </h3>
121             <h3 className="launchpadCard_header-link">
122                 <a onClick={this.editMgmtDomain.bind(this, this.props.name)} title="Edit">
123                   <span className="oi" data-glyph="pencil" aria-hidden="true">
124                   </span>
125                 </a>
126             </h3>
127             <h3 className="launchpadCard_header-link" style={{display:'none'}}>
128                 <a onClick={this.openConsole} title="Open Console">
129                   <span className="oi" data-glyph="monitor" aria-hidden="true">
130                   </span>
131                 </a>
132             </h3>
133             <h3 className="launchpadCard_header-link" style={{display: this.props.isActive ? 'none' : 'inherit'}}>
134               <a onClick={this.deleteLaunchpad.bind(this, this.props.name)} title="Delete">
135                 <span className="oi" data-glyph="trash" aria-hidden="true"></span>
136               </a>
137             </h3>
138           </div>
139         </div>
140         <div className="managementDomainCard_header-status">
141         </div>
142         <LaunchpadOperationalStatus className="managementDomainCard_header-operational-status" loading={this.state.isLoading} doneLoading={this.doneLoading.bind(this)} display={this.state.displayStatus} currentStatus={this.props.data.launchpad.state} currentStatusDetails={this.props.data.launchpad['state-details']} />
143       </header>
144     )
145   }
146 };
147 ManagementDomainCardHeader.propTypes = {
148   name: React.PropTypes.string
149  };
150 ManagementDomainCardHeader.defaultProps = {
151   name: 'Loading...Some Name',
152   isActive: false,
153   data: {}
154 };
155
156
157 // <LaunchpadOperationalStatus className="managementDomainCard_header-operational-status" loading={isLoading} doneLoading={this.doneLoading.bind(this)} display={this.state.displayStatus} currentStatus={this.props.nsr["operational-status"]} status={this.props.nsr["rw-nsr:operational-events"]} />
158
159
160 export default ManagementDomainCardHeader;