3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 import React from 'react';
20 import AppHeader from 'widgets/header/header.jsx';
21 import InstantiateStore from './instantiateStore.js';
22 import NetworkServiceActions from './launchNetworkServiceActions.js';
23 import InstantiateSelectDescriptorPanel from './instantiateSelectDescriptorPanel.jsx';
24 import CatalogDescriptorRaw from './catalogDescriptorRaw.jsx'
25 import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx';
26 import {Panel, PanelWrapper} from 'widgets/panel/panel';
27 import Button from 'widgets/button/rw.button.js';
28 import {SkyquakeRBAC, isRBACValid} from 'widgets/skyquake_rbac/skyquakeRBAC.jsx';
29 import ROLES from 'utils/roleConstants.js';
30 import 'style/layout.scss';
31 import './instantiateDashboard.scss';
33 const PROJECT_ROLES = ROLES.PROJECT;
34 const PLATFORM = ROLES.PLATFORM;
36 class InstantiateDashboard extends React.Component {
39 this.Store = this.props.flux.stores.hasOwnProperty('InstantiateStore') ? this.props.flux.stores.InstantiateStore : this.props.flux.createStore(InstantiateStore, 'InstantiateStore');
40 this.state = this.Store.getState();
44 let asyncOperations = []
45 asyncOperations.push(this.Store.getCatalog());
46 asyncOperations.push(this.Store.getResourceOrchestratorAccounts(function() {
47 asyncOperations.push(self.Store.getSshKey());
48 asyncOperations.push(self.Store.getConfigAgent());
50 Promise.all(asyncOperations).then(function(resolve, reject) {
51 if(self.props.params.nsd) {
52 self.Store.descriptorSelected(self.state.nsdDict[self.props.params.nsd]);
56 componentWillMount() {
57 this.Store.listen(this.updateState);
59 componentWillUnmount() {
60 this.Store.unlisten(this.updateState);
62 handleCancel = (e) => {
64 this.props.router.push({pathname:''});
68 this.props.router.goBack();
70 handleSave = (launch, e) => {
73 if (this.state.name == "") {
74 self.props.actions.showNotification('Please name the network service');
77 if (!this.state.name.match(/^[a-zA-Z0-9_]*$/g)) {
78 self.props.actions.showNotification('Spaces and special characters except underscores are not supported in the network service name at this time');
81 if (this.state.isOpenMano && (this.state.dataCenterID == "" || !this.state.dataCenterID)) {
82 self.props.actions.showNotification("Please enter the Data Center ID");
85 // LaunchNetworkServiceStore.resetView();
86 this.Store.saveNetworkServiceRecord(this.state.name, launch);
88 isSelectPage = () => {
89 //If an NSD id is present in the route then this evalauates to false;
90 return !this.props.location.pathname.split('/')[2];
93 return this.state.ro['account-type'] == 'openmano';
95 openDescriptor = (descriptor) => {
97 if(descriptor.hasOwnProperty('target')) {
98 NSD = this.state.selectedNSD;
100 this.Store.descriptorSelected(NSD);
101 this.props.router.push({pathname:'/instantiate/' + NSD.id});
103 updateState = (state) => {
104 this.setState(state);
109 let selectedNSDid = self.state.selectedNSDid;
110 let isPreviewing = self.state.isPreviewing;
111 const hasAccess = isRBACValid(this.context.userProfile, [PROJECT_ROLES.LCM_ADMIN, PROJECT_ROLES.PROJECT_ADMIN]);
112 let descriptorPreview = (
113 <Panel title={(self.state.selectedNSD['short-name'] || self.state.selectedNSD.name ) + ' Descriptor Preview'} className="CatalogDescriptorPreview">
114 <span className="oi CatalogDescriptorPreview-button" data-glyph={"circle-x"} onClick={self.Store.deselectDescriptor}></span>
115 <CatalogDescriptorRaw descriptor={self.state.selectedNSD} />
117 html = this.props.children ?
118 React.cloneElement(this.props.children, {store: self.Store, nsd: self.state.nsd[0], ...self.Store, ...self.state})
121 <InstantiateSelectDescriptorPanel
122 catalog={self.state.nsd[0]}
123 onSelectDescriptor={self.Store.descriptorSelected}
124 onPreviewDescriptor={self.Store.previewDescriptor}
125 selectedDescriptorID={selectedNSDid}
126 isPreviewing={isPreviewing}
127 closeCard={self.Store.deselectDescriptor}
128 openDescriptor={this.openDescriptor}
130 {isPreviewing ? descriptorPreview : null}
135 <div className="InstantiateDashboard">
137 <div className="ButtonGroup">
139 <Button label="Cancel" onClick={this.handleCancel}/>
140 {this.isSelectPage() ?
141 <Button label="Next" isLoading={this.state.isSaving} onClick={this.state.selectedNSD && self.openDescriptor} className="dark" type="submit"/>
143 <Button label="Back" onClick={this.handleBack}/>
144 { hasAccess ? <Button label="Launch" isLoading={this.state.isSaving} onClick={self.handleSave.bind(self, true)} className="dark" type="submit"
153 InstantiateDashboard.contextTypes = {
154 router: React.PropTypes.object,
155 userProfile: React.PropTypes.object
157 export default SkyquakeComponent(InstantiateDashboard);