/* * * 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 Utils from 'utils/utils.js'; import _ from 'lodash'; import './nsVirtualLinks.scss'; import NSVirtualLinkCreateStore from './nsVirtualLinkCreateStore.js'; import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx'; import TextInput from 'widgets/form_controls/textInput.jsx'; import ScreenLoader from 'widgets/screen-loader/screenLoader.jsx'; import Button from 'widgets/button/rw.button.js'; import SelectOption from 'widgets/form_controls/selectOption.jsx'; class NsVirtualLinkCreate 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.Store.getState(); this.Store.listen(this.handleUpdate); } componentWillMount() { (!this.state.nsrId && this.props.nsrId) && this.Store.saveNSRId(this.props.nsrId); this.Store.saveMode(this.props.mode); this.Store.saveOnSuccess(this.props.onSuccess); switch (this.props.mode) { case 'creating': if (!this.state.vld) { this.Store.saveVld({}); } break; case 'editing': this.Store.saveVld(this.props.vld); break; } if (this.props.nsd && this.props.nsd['constituent-vnfd']) { let memberVnfIndexRefs = []; let vnfdIdRefs = []; this.props.nsd['constituent-vnfd'].map((cVNFD, cVNFDI) => { memberVnfIndexRefs.push({ label: cVNFD['member-vnf-index'], value: cVNFD['member-vnf-index'] }); vnfdIdRefs.push({ label: cVNFD['vnfd-id-ref'], value: cVNFD['vnfd-id-ref'] }); }); let ipProfileNames = []; this.props.nsd['ip-profiles'] && this.props.nsd['ip-profiles'].map((ipProfile, ipProfileIndex) => { ipProfileNames.push({ label: ipProfile['name'], value: ipProfile['name'] }); }) this.Store.saveMemberVnfIndexRefs(memberVnfIndexRefs); this.Store.saveVnfdIdRefs(vnfdIdRefs); this.Store.saveIpProfileNames(ipProfileNames); } } componentWillReceiveProps(nextProps) { if (nextProps != this.props) { if (nextProps.mode != this.props.mode) { // mode change this.Store.saveMode(nextProps.mode); switch (nextProps.mode) { case 'creating': // switching from editing to creating this.Store.saveVld({}); break; case 'editing': // switching from creating to editing this.Store.saveVld(nextProps.vld); break; } } else { // no mode change, but props changed switch (nextProps.mode) { case 'creating': // switching from creating to creating // TODO: can't figure out how to empty out without affecting create being erased break; case 'editing': // switching from editing to editing if ((nextProps.vld && nextProps.vld.id) != (this.props.vld && this.props.vld.id)) { this.Store.saveVld(nextProps.vld); } break; } } } } componentWillUnmount() { this.Store.saveVld({}); this.Store.unlisten(this.handleUpdate); } handleUpdate = (storeState) => { this.setState(storeState); } handleSubmit = (mode, e) => { e.preventDefault(); this.Store.persistVirtualLink(mode); } handleCancel = (e) => { e.preventDefault(); this.props.onCancel && this.props.onCancel(); } transformValue(field, value) { let transformedValue = (field.transform && field.transform(value)) || value; if (typeof transformedValue == 'object') { transformedValue = JSON.stringify(transformedValue); } return transformedValue; } handleFirstLevelKeyChange = (key, e) => { this.Store.updateFirstLevelKey(key, e); } handleSecondLevelKeyChange = (firstLevelKey, secondLevelKey, e) => { this.Store.updateSecondLevelKey(firstLevelKey, secondLevelKey, e); } handleFirstLevelListKeyChange = (listName, index, keyName, e) => { this.Store.updateFirstLevelListKeyChange(listName, index, keyName, e); } handleAddConnectionPointRef = () => { this.Store.addConnectionPointRef(); } handleRemoveConnectionPoint = (vCPRI, e) => { this.Store.removeConnectionPointRef(vCPRI); } updateVLDInitParamsType = (type) => { this.Store.updateVLDInitParamsType(type); } updateVLDInitParamsValue = (currentVLDInitParamsType, e) => { this.Store.updateVLDInitParamsValue(currentVLDInitParamsType, e); } render() { let self = this; let typeOptions = this.state.typeOptions; let overlayTypeOptions = this.state.overlayTypeOptions; let currentVLDInitParamsType = this.state.currentVLDInitParamsType; let memberVnfIndexRefs = this.state.memberVnfIndexRefs; let vnfdIdRefs = this.state.vnfdIdRefs; let vnfdConnectionPointRefs = this.state.vnfdConnectionPointRefs; let ipProfileNames = this.state.ipProfileNames; let connectionPointsHtml = []; this.state.vld && this.state.vld['vnfd-connection-point-ref'] && this.state.vld['vnfd-connection-point-ref'].map((vCPR, vCPRI) => { connectionPointsHtml.push(
  • VNFD CONNECTION POINT REF - {vCPRI}
  • ); }); let vldHTML = this.state.vld && (

    DETAILS

    PROVIDER NETWORK

    VNF CONNECTION POINTS

      {connectionPointsHtml}

    INIT PARAMS

    { (currentVLDInitParamsType == 'unknown') ? null : (currentVLDInitParamsType == 'vim-network-name') ? : }
    ); return (
    {vldHTML}
    ); } } export default SkyquakeComponent(NsVirtualLinkCreate);