/* * * 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 NSVirtualLinkCreateStore from './nsVirtualLinkCreateStore.js'; import Button from 'widgets/button/rw.button.js'; import Utils from 'utils/utils.js'; import _ from 'lodash'; import './nsVirtualLinks.scss'; import UpTime from 'widgets/uptime/uptime.jsx'; import NSVirtualLinkDetails from './nsVirtualLinkDetails.jsx'; import NSVirtualLinkCreate from './nsVirtualLinkCreate.jsx'; import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx'; class NsVirtualLinks extends React.Component { constructor(props) { super(props); this.Store = this.props.flux.stores.hasOwnProperty('NSVirtualLinkCreateStore') ? this.props.flux.stores.NSVirtualLinkCreateStore : this.props.flux.createStore(NSVirtualLinkCreateStore, 'NSVirtualLinkCreateStore'); this.state = {}; this.state.mode = 'viewing'; // Can be 'viewing'/'creating'/'editing'/'deleting'. Default is 'viewing' this.selectedVirtualLink = null; this.editingVirtualLink = null; this.Store.listen(this.handleUpdate); } handleUpdate = (storeState) => { // all we care about is if delete succeeded if (storeState.deleteState == 'success') { this.setState({ mode: 'viewing', selectedVirtualLink: this.props.data && this.props.data['decorated-vlrs'] && this.props.data['decorated-vlrs'][0], editingVirtualLink: null }); } } componentWillMount() { if (this.state.mode == 'viewing' && !this.state.selectedVirtualLink) { this.setState({ selectedVirtualLink: this.props.data && this.props.data['decorated-vlrs'] && this.props.data['decorated-vlrs'][0] }); } if (!this.state.nsd) { this.setState({ nsd: this.props.data.nsd }); } if (!this.state.nsrId) { this.setState({ nsrId: this.props.data.id }); } } componentWillUnmount() { this.Store.unlisten(this.handleUpdate) } componentWillReceiveProps(nextProps) { if (!this.state.nsd) { this.setState({ nsd: nextProps.data.nsd }); } if (!this.state.nsrId) { this.setState({ nsrId: nextProps.data.id }); } } handleCreateVirtualLinkClick = (nsrId, event) => { this.setState({ mode: 'creating' }); } resetState = () => { let self = this; this.setState({ mode: 'viewing', selectedVirtualLink: self.props.data && self.props.data['decorated-vlrs'] && self.props.data['decorated-vlrs'][0], editingVirtualLink: null }) } handleDeleteVirtualLinkClick = (nsrId, virtualLinkId, event) => { let self = this; event.preventDefault(); event.stopPropagation(); this.Store.removeVirtualLink(nsrId, virtualLinkId); } handleSelectVirtualLinkClick = (virtualLinkId, event) => { this.setState({ mode: 'viewing', selectedVirtualLink: this.props.data && this.props.data['decorated-vlrs'] && _.find(this.props.data['decorated-vlrs'], {id: virtualLinkId}), editingVirtualLink: null }); } handleEditVirtualLinkClick = (nsrId, vlrId, vldId, event) => { event.stopPropagation(); this.setState({ mode: 'editing', editingVirtualLink: this.props.data && this.props.data['nsd'] && this.props.data['nsd']['vld'] && _.find(this.props.data['nsd']['vld'], {id: vldId}), selectedVirtualLink: this.props.data && this.props.data['decorated-vlrs'] && _.find(this.props.data['decorated-vlrs'], {id: vlrId}) }); } handleCancelCreate = () => { this.resetState(); } createVirtualLinksTable = () => { let trows = []; let nsr = this.props.data && this.props.data; let nsd = nsr.nsd && nsr.nsd; nsr['decorated-vlrs'] && nsr['decorated-vlrs'].map((vlr, vlrIndex) => { let name = vlr.name || 'Undergoing virtual link operation'; let operationalStatus = vlr['operational-status']; let vlrId = vlr['id']; let vldId = vlr['vld-ref']; let selectedClassName = (!(this.state.mode == 'creating') && ((this.state.selectedVirtualLink && this.state.selectedVirtualLink.id) == vlrId)) ? 'selectedVirtualLink' : '' trows.push( {name} {operationalStatus} ); }); let tbody = ( {trows} ); return ( {tbody}
Name Status
); return (
{JSON.stringify(nsd)}
); } render() { let nsVirtualLinksTable = this.createVirtualLinksTable(); let nsVirtualLinkCreateButton = (