update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try
[osm/UI.git] / skyquake / plugins / composer / src / src / components / ComposerAppToolbar.js
1
2 /*
3 *
4 * Copyright 2016 RIFT.IO Inc
5 *
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 *
18 */
19 'use strict';
20
21 import React from 'react'
22 import messages from './messages'
23 import ClassNames from 'classnames'
24 import PureRenderMixin from 'react-addons-pure-render-mixin'
25 import Button from './Button'
26 import CatalogItemsActions from '../actions/CatalogItemsActions'
27 import CanvasEditorActions from '../actions/CanvasEditorActions'
28 import ComposerAppActions from '../actions/ComposerAppActions'
29 import SelectionManager from '../libraries/SelectionManager'
30 import DeletionManager from '../libraries/DeletionManager'
31
32 import '../styles/ComposerAppToolbar.scss'
33
34 import imgSave from '../../../node_modules/open-iconic/svg/data-transfer-upload.svg'
35 import imgCancel from '../../../node_modules/open-iconic/svg/circle-x.svg'
36 import imgLayout from '../../../node_modules/open-iconic/svg/grid-three-up.svg'
37 import imgVLD from '../../../node_modules/open-iconic/svg/link-intact.svg'
38 import imgJSONViewer from '../../../node_modules/open-iconic/svg/code.svg'
39 import imgFG from '../../../node_modules/open-iconic/svg/infinity.svg'
40 import imgDelete from '../../../node_modules/open-iconic/svg/trash.svg'
41 import imgVDU from '../../../node_modules/open-iconic/svg/laptop.svg'
42
43 const ComposerAppToolbar = React.createClass({
44 mixins: [PureRenderMixin],
45 getInitialState() {
46 return {};
47 },
48 getDefaultProps() {
49 return {
50 disabled: true,
51 showMore: false,
52 layout: {left: 300},
53 isModified: false,
54 isEditingNSD: false,
55 isEditingVNFD: false,
56 showJSONViewer: false,
57 isNew: false
58 };
59 },
60 componentWillMount() {
61 },
62 componentDidMount() {
63 },
64 componentDidUpdate() {
65 },
66 componentWillUnmount() {
67 },
68 onClickSave(event) {
69 event.preventDefault();
70 event.stopPropagation();
71 CatalogItemsActions.saveCatalogItem();
72 },
73 onClickCancel(event) {
74 event.preventDefault();
75 event.stopPropagation();
76 CatalogItemsActions.cancelCatalogItemChanges();
77 },
78 onClickToggleShowMoreInfo(event) {
79 event.preventDefault();
80 event.stopPropagation();
81 CanvasEditorActions.toggleShowMoreInfo();
82 },
83 onClickAutoLayout(event) {
84 event.preventDefault();
85 event.stopPropagation();
86 CanvasEditorActions.applyDefaultLayout();
87 },
88 onClickAddVld(event) {
89 event.preventDefault();
90 event.stopPropagation();
91 CanvasEditorActions.addVirtualLinkDescriptor();
92 },
93 onClickAddVnffg(event) {
94 event.preventDefault();
95 event.stopPropagation();
96 CanvasEditorActions.addForwardingGraphDescriptor();
97 },
98 onClickAddVdu(event) {
99 event.preventDefault();
100 event.stopPropagation();
101 CanvasEditorActions.addVirtualDeploymentDescriptor();
102 },
103 onDragStartAddVdu(event) {
104 const data = {type: 'action', action: 'add-vdu'};
105 event.dataTransfer.effectAllowed = 'copy';
106 event.dataTransfer.setData('text', JSON.stringify(data));
107 ComposerAppActions.setDragState(data);
108 },
109 onDragStartAddVld(event) {
110 const data = {type: 'action', action: 'add-vld'};
111 event.dataTransfer.effectAllowed = 'copy';
112 event.dataTransfer.setData('text', JSON.stringify(data));
113 ComposerAppActions.setDragState(data);
114 },
115 onDragStartAddVnffg(event) {
116 const data = {type: 'action', action: 'add-vnffgd'};
117 event.dataTransfer.effectAllowed = 'copy';
118 event.dataTransfer.setData('text', JSON.stringify(data));
119 ComposerAppActions.setDragState(data);
120 },
121 onClickDeleteSelected(event) {
122 event.preventDefault();
123 event.stopPropagation();
124 DeletionManager.deleteSelected(event);
125 },
126 toggleJSONViewer(event) {
127 event.preventDefault();
128 if (this.props.showJSONViewer) {
129 ComposerAppActions.closeJsonViewer();
130 } else {
131 ComposerAppActions.closeJsonViewer();
132 ComposerAppActions.showJsonViewer.defer();
133 }
134 },
135 render() {
136 const style = {left: this.props.layout.left};
137 const saveClasses = ClassNames('ComposerAppSave', {'primary-action': this.props.isModified || this.props.isNew});
138 const cancelClasses = ClassNames('ComposerAppCancel', {'secondary-action': this.props.isModified});
139 let isDisabled = this.props.disabled;
140 // console.log('rbacDisabled', isDisabled )
141 const hasSelection = SelectionManager.getSelections().length > 0;
142 if(this.props.panelTabShown != 'descriptor') {
143 style.pointerEvents = 'none';
144 }
145 return (
146 <div className="ComposerAppToolbar" style={style}>
147 {
148 (this.props.panelTabShown != 'descriptor') ?
149 <div className="disableOverlay"></div>
150 : null
151 }
152 {(()=>{
153 if (this.props.isEditingNSD || this.props.isEditingVNFD) {
154 return (
155 <div className="FileActions">
156 <Button className={saveClasses} onClick={this.onClickSave} label={messages.getSaveActionLabel(this.props.isNew)} src={imgSave} disabled={isDisabled} />
157 <Button className={cancelClasses} onClick={this.onClickCancel} label="Cancel" src={imgCancel} disabled={isDisabled} />
158 <Button className="ComposerAppToggleJSONViewerAction" onClick={this.toggleJSONViewer} label="YAML Viewer" src={imgJSONViewer} disabled={isDisabled} />
159 </div>
160 );
161 }
162 })()}
163 <div className="LayoutActions">
164 <Button className="action-auto-layout" onClick={this.onClickAutoLayout} label="Auto Layout" src={imgLayout} disabled={isDisabled} />
165 {this.props.isEditingNSD ||
166 this.props.isEditingVNFD ? <Button className="action-add-vld"
167 disabled={isDisabled}
168 draggable="true"
169 label={this.props.isEditingNSD ? 'Add VLD' : 'Add IVLD'}
170 src={imgVLD}
171 onDragStart={this.onDragStartAddVld}
172 onClick={this.onClickAddVld} /> : null}
173 {this.props.isEditingNSD ? <Button className="action-add-vnffg"
174 disabled={isDisabled}
175 draggable="true"
176 label="Add VNFFG"
177 src={imgFG}
178 onDragStart={this.onDragStartAddVnffg}
179 onClick={this.onClickAddVnffg} /> : null}
180 {this.props.isEditingVNFD ? <Button className="action-add-vdu"
181 disabled={isDisabled}
182 draggable="true"
183 label="Add VDU"
184 src={imgVDU}
185 onDragStart={this.onDragStartAddVdu}
186 onClick={this.onClickAddVdu} /> : null}
187 <Button type="image" title="Delete selected items" className="action-delete-selected-items" disabled={!hasSelection || isDisabled} onClick = {this.onClickDeleteSelected} src={imgDelete} label="Delete" />
188 </div>
189 </div>
190 );
191 }
192 });
193
194 export default ComposerAppToolbar;