/* * * 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 {Tab, Tabs, TabList, TabPanel} from 'react-tabs'; import RecordViewStore from '../recordViewer/recordViewStore.js'; import Button from 'widgets/button/rw.button.js'; import './vnfrConfigPrimitives.scss'; import TextInput from 'widgets/form_controls/textInput.jsx'; import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx'; class VnfrConfigPrimitives extends React.Component { constructor(props) { super(props); this.state = { vnfrs: [] }; this.state.execPrimitive = {}; } handleExecuteClick = (configPrimitiveIndex, vnfrIndex, e) => { let execute = RecordViewStore.constructAndTriggerVnfConfigPrimitive({ vnfrs: this.state.vnfrs, configPrimitiveIndex: configPrimitiveIndex, vnfrIndex: vnfrIndex }); if (!execute) { this.props.actions.showNotification('Could not execute service config. Please review your parameters'); } } handleParamChange = (paramIndex, configPrimitiveIndex, vnfrIndex, e) => { let vnfrs = this.state.vnfrs; vnfrs[vnfrIndex]["vnf-configuration"]["config-primitive"][configPrimitiveIndex]["parameter"][paramIndex].value = e.target.value this.setState({ vnfrs: vnfrs }) } componentWillReceiveProps(props) { if (this.state.vnfrs.length == 0) { this.setState({ vnfrs: props.data }) } } constructConfigPrimitiveTabs = (tabList, tabPanels) => { let mandatoryFieldValue = 'true'; this.state.vnfrs && this.state.vnfrs.map((vnfr, vnfrIndex) => { if (vnfr['vnf-configuration'] && vnfr['vnf-configuration']['config-primitive'] && vnfr['vnf-configuration']['config-primitive'].length > 0) { vnfr['vnf-configuration']['config-primitive'].map((configPrimitive, configPrimitiveIndex) => { let params = []; if (configPrimitive['parameter'] && configPrimitive['parameter'].length > 0) { configPrimitive['parameter'].map((param, paramIndex) => { let optionalField = ''; let displayField = ''; let defaultValue = param['default-value'] || ''; let isFieldHidden = (param['hidden'] && param['hidden'] == 'true') || false; let isFieldReadOnly = (param['read-only'] && param['read-only'] == 'true') || false; if (param.mandatory == mandatoryFieldValue) { optionalField = * } if (isFieldReadOnly) { displayField =
{param.value || defaultValue}
} else { displayField = } params.push(
  • {displayField}
  • ); }); } tabList.push( {configPrimitive.name} ); tabPanels.push(

    {configPrimitive.name}

    * required
      {params}
    ) }); } }); } render() { let tabList = []; let tabPanels = []; let isConfiguring = (this.props.data['config-status'] && this.props.data['config-status'] != 'configured') || false; let displayConfigStatus = isConfiguring ? '(Disabled - Configuring)': ''; this.constructConfigPrimitiveTabs(tabList, tabPanels); return (
    CONFIG-PRIMITIVES {displayConfigStatus}
    {tabList} {tabPanels}
    ); } } export default SkyquakeComponent(VnfrConfigPrimitives);