4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import React from 'react';
20 import RWslider from 'widgets/input-range-slider/input-range-slider.jsx';
21 import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
22 import CardActions from './launchpadCardActions.js';
24 let currentID, lastSelected;
26 function isTabNode(node) {
27 return node.nodeName === 'LI' && node.getAttribute('role') === 'tab';
29 class launchpadControls extends React.Component {
30 constructor(props, context) {
31 super(props, context);
33 controlSets: this.props.controlSets,
37 this.handleInputUpdate = this.handleInputUpdate.bind(this);
38 this.handleSelected = this.handleSelected.bind(this);
39 this.handleSameTab = this.handleSameTab.bind(this);
41 handleSelected(index,last) {
42 this.state.selectedIndex = index;
44 //If same Tab is clicked, default to empty tab contents
46 var node = e.target.parentNode;
47 var isTab = isTabNode(node);
49 if(node.id == currentID) {
50 this.state.selectedIndex = 0;
58 componentWillReceiveProps(nextProps) {
59 if((!this.state.controlSets && nextProps.controlSets) || this.state.controlSets && !nextProps.controlSets) {
60 this.state.controlSets = nextProps.controlSets;
64 shouldComponentUpdate(nextProps, nextState) {
65 // console.log(this.props, nextProps);
66 // console.log(this.state, nextState)
69 handleInputUpdate(gIndex, groupID, cIndex, options, value) {
70 this.state.controlSets[gIndex][groupID]['control-param'][cIndex].value = value;
71 CardActions.updateControlInput(options, value)
75 if(!this.state.controlSets) {
79 <div className="launchpadCard_controls" onClick={self.handleSameTab}>
81 this.state.controlSets.map(function(group, gIndex) {
82 for(let id in group) {
84 <Tabs key={gIndex} selectedIndex={self.state.selectedIndex} onSelect={self.handleSelected}>
89 group[id]['action-param'].map(function(action, aIndex) {
91 <button key={aIndex} className="light small" title={action.name}>{action.name}</button>
97 group[id]['control-param'].map(function(control, cIndex) {
100 <span title={control.name}>
101 {control.name} : {control.value || control["current-value"]} {control.units}
108 <TabPanel actionplaceholder>
111 group[id]['control-param'].map(function(control, cIndex) {
113 <TabPanel key={cIndex}>
114 <RWslider {...control} handleInputUpdate={self.handleInputUpdate.bind(self, gIndex, id, cIndex, {operation:control.operation,
132 export default launchpadControls;
137 * grouping control-param {
140 "List of control parameters to manage and
141 update the running configuration of the VNF";
157 description "A simple tag to group control parameters";
163 "Minimum value for the parameter";
169 "Maxium value for the parameter";
175 "Step value for the parameter";
184 type manotypes:widget-type;