/* * * Copyright 2016 RIFT.IO Inc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import React from 'react'; import UpTime from 'widgets/uptime/uptime.jsx'; import launchpadFleetStore from '../launchpadFleetStore.js'; import launchpadFleetActions from '../launchpadFleetActions'; import LaunchpadOperationalStatus from 'widgets/operational-status/launchpadOperationalStatus.jsx'; import LaunchpadCardMgmtInterfaces from './launchpadCardMgmtInterfaces.jsx'; import LaunchpadCardCloudAccount from './launchpadCardCloudAccount.jsx'; import { Link } from 'react-router'; class LaunchpadHeader extends React.Component { constructor(props) { super(props); this.state = {}; this.state.displayStatus = false; this.state.isLoading = this.isLoading(props); this.state.displayInterfacePanel = false; this.state.displayCloudAccount = false; this.state.failed = false; this.deleteLaunchpad = this.deleteLaunchpad.bind(this); this.openDashboard = this.openDashboard.bind(this); this.openConsole = this.openConsole.bind(this); this.setStatus = this.setStatus.bind(this); } componentWillReceiveProps(props) { this.setState({ failed: (props['operational-status'] == 'failed' || props['config-status'] == 'failed') }) } //TODO Do not setState within nested component like this. Find a way to use props. doneLoading = (failed) => { this.setState({ isLoading: false }); } //TODO instead of calling the store method, an action should be emitted and the store should respond. deleteLaunchpad(e) { if (window.confirm("Preparing to delete "+ this.props.name + ". Are you sure you want to delete this NSR?")) { launchpadFleetStore.deleteNsrInstance(this.props.id); launchpadFleetActions.deletingNSR(this.props.id); } } isLoading(props) { return !((props.nsr['operational-status'] == 'running')) } openDashboard(nsr_id) { window.location.href = '//' + window.location.hostname + ':' + window.location.port + '/index.html' + window.location.search + window.location.hash + '/' + nsr_id + '/detail'; launchpadFleetStore.closeSocket(); } openConsole() { console.log('open console clicked'); } setStatus() { var status; if(this.props.isActive) { status = "DISABLED" } else { status = "ENABLED" } launchpadFleetStore.setNSRStatus(this.props.nsr["id"], status); } openInterfacePanel = () => { this.setState({ displayStatus: false, displayInterfacePanel: !this.state.displayInterfacePanel, displayCloudAccount: false }) // this.closeHeaderViews(); } openStatus = () => { this.setState({ displayInterfacePanel: false, displayStatus: !this.state.displayStatus, displayCloudAccount: false }); // this.closeHeaderViews(); } openCloudAccountPanel = () => { let nsrCloudAccount = this.props.nsr['cloud-account']; this.setState({ displayStatus: false, displayInterfacePanel: false, displayCloudAccount: !this.state.displayCloudAccount }) } render() { let self = this; let failed = this.state.failed || (this.props.nsr['operational-status'] == 'failed'); let nsrCreateTime = this.props.nsr['create-time']; //let nsrUpDuration = (nsrCreateTime) // ? Math.floor((new Date() / 1000)) - nsrCreateTime // : null; let isLoading = failed || this.state.isLoading; let toggleStatus = isLoading ? '' : (

); let headerClassName = "launchpadCard_header"; // debugger; headerClassName += (failed ? ' failed' : ''); let sdnpresent = this.props.nsr['sdn-account'] ? true: false; return (

{ isLoading ? {this.props.name} : {this.props.name} }

{isLoading ? this.props.nsr["operational-status"] : this.props.nsr['config-status'] == 'configuring' ? 'Configuring' : this.props.nsr['config-status'] == 'configured' ? 'Active' :'Configuration Failed'}

{toggleStatus}

) } }; LaunchpadHeader.propTypes = { name: React.PropTypes.string }; LaunchpadHeader.defaultProps = { name: 'Loading...Some Name' }; export default LaunchpadHeader;