Revert "BUG-410 -- update RIFT platform"
[osm/UI.git] / skyquake / plugins / launchpad / src / virtual_links / nsVirtualLinkCreateStore.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 */
18 import NSVirtualLinkCreateActions from './nsVirtualLinkCreateActions.js';
19 import NSVirtualLinkCreateSource from './nsVirtualLinkCreateSource.js';
20 import Alt from '../alt';
21 import _cloneDeep from 'lodash/cloneDeep';
22 import _pickBy from 'lodash/pickBy';
23 import _identity from 'lodash/identity';
24
25 class NSVirtualLinkCreateStore {
26 constructor() {
27
28 this.vld = null;
29 this.typeOptions = [{
30 label: 'ELAN',
31 value: 'ELAN'
32 }];
33 this.overlayTypeOptions = [{
34 label: 'LOCAL',
35 value: 'LOCAL'
36 }, {
37 label: 'FLAT',
38 value: 'FLAT'
39 }, {
40 label: 'VLAN',
41 value: 'VLAN'
42 }, {
43 label: 'VXLAN',
44 value: 'VXLAN'
45 }, {
46 label: 'GRE',
47 value: 'GRE'
48 }];
49
50 /* TODO: Move this to be populated from props */
51 this.vnfdConnectionPointRefs = [{
52 label: 'ping_vnfd/cp0',
53 value: 'ping_vnfd/cp0'
54 }, {
55 label: 'pong_vnfd/cp0',
56 value: 'pong_vnfd/cp0'
57 }];
58
59 /* end TODO */
60
61 this.vldInitParamsTypes = [
62 'vim-network-name',
63 'ip-profile-ref',
64 'unknown'
65 ];
66
67 this.currentVLDInitParamsType = 'unknown';
68 this.registerAsync(NSVirtualLinkCreateSource);
69 this.bindAction(NSVirtualLinkCreateActions.EDIT_VIRTUAL_LINK_ERROR, this.editVirtualLinkError);
70 this.bindAction(NSVirtualLinkCreateActions.DELETE_VIRTUAL_LINK_ERROR, this.deleteVirtualLinkError);
71 this.bindAction(NSVirtualLinkCreateActions.CREATE_VIRTUAL_LINK_SUCCESS, this.createVirtualLinkSuccess);
72 this.bindAction(NSVirtualLinkCreateActions.EDIT_VIRTUAL_LINK_SUCCESS, this.editVirtualLinkSuccess);
73 this.bindAction(NSVirtualLinkCreateActions.DELETE_VIRTUAL_LINK_SUCCESS, this.deleteVirtualLinkSuccess);
74 this.exportPublicMethods({
75 persistVirtualLink: this.persistVirtualLink,
76 updateFirstLevelKey: this.updateFirstLevelKey,
77 updateSecondLevelKey: this.updateSecondLevelKey,
78 updateVLDInitParamsType: this.updateVLDInitParamsType,
79 updateVLDInitParamsValue: this.updateVLDInitParamsValue,
80 saveNSRId: this.saveNSRId,
81 saveVld: this.saveVld,
82 addConnectionPointRef: this.addConnectionPointRef,
83 removeConnectionPointRef: this.removeConnectionPointRef,
84 updateFirstLevelListKeyChange: this.updateFirstLevelListKeyChange,
85 saveMemberVnfIndexRefs: this.saveMemberVnfIndexRefs,
86 saveVnfdIdRefs: this.saveVnfdIdRefs,
87 saveIpProfileNames: this.saveIpProfileNames,
88 removeVirtualLink: this.removeVirtualLink,
89 saveMode: this.saveMode,
90 saveOnSuccess: this.saveOnSuccess
91 });
92 }
93
94 resetState = () => {
95 delete this.vld;
96 let vld = {};
97
98 this.setState({
99
100 });
101 }
102
103 saveOnSuccess = (onSuccess) => {
104 this.setState({
105 onSuccess: onSuccess
106 })
107 }
108
109 saveMode = (mode) => {
110 this.setState({
111 mode: mode
112 })
113 }
114
115 saveVnfdIdRefs = (vnfdIdRefs) => {
116 this.setState({
117 vnfdIdRefs: vnfdIdRefs
118 });
119 }
120
121 saveMemberVnfIndexRefs = (memberVnfIndexRefs) => {
122 this.setState({
123 memberVnfIndexRefs: memberVnfIndexRefs
124 });
125 }
126
127 saveIpProfileNames = (ipProfileNames) => {
128 this.setState({
129 ipProfileNames: ipProfileNames
130 });
131 }
132
133 saveNSRId = (nsrId) => {
134 this.setState({
135 nsrId: nsrId
136 })
137 }
138
139 saveVld = (vld) => {
140 this.setState({
141 vld:vld
142 })
143 }
144
145 updateFirstLevelKey = (key, e) => {
146 let vld = _cloneDeep(this.vld);
147 let value = e.target.nodeName == "SELECT" ? JSON.parse(e.target.value) : e.target.value;
148 vld[key] = value;
149 this.setState({
150 vld: vld
151 });
152 }
153
154 updateSecondLevelKey = (firstLevelKey, secondLevelKey, e) => {
155 let vld = _cloneDeep(this.vld);
156 if (!vld[firstLevelKey]) {
157 vld[firstLevelKey] = {};
158 }
159 let value = e.target.nodeName == "SELECT" ? JSON.parse(e.target.value) : e.target.value;
160 vld[firstLevelKey][secondLevelKey] = value;
161 this.setState({
162 vld: vld
163 });
164 }
165
166 updateVLDInitParamsType = (value) => {
167 let vld = this.vld;
168
169 // Reset init param types
170 this.vldInitParamsTypes.map((vldInitParamType) => {
171 vld[vldInitParamType] && delete vld[vldInitParamType];
172 });
173
174 this.setState({
175 currentVLDInitParamsType: value,
176 vld: vld
177 })
178 }
179
180 updateVLDInitParamsValue = (currentVLDInitParamsType, e) => {
181 let vld = _cloneDeep(this.vld);
182 this.vldInitParamsTypes.map((vldInitParamType) => {
183 if (currentVLDInitParamsType == vldInitParamType) {
184 let value = e.target.nodeName == "SELECT" ? JSON.parse(e.target.value) : e.target.value;
185 vld[currentVLDInitParamsType] = value;
186 } else {
187 vld[vldInitParamType] && delete vld[vldInitParamType];
188 }
189 });
190
191 this.setState({
192 vld: vld
193 })
194 }
195
196 updateFirstLevelListKeyChange = (listName, index, keyName, e) => {
197 let vld = _cloneDeep(this.vld);
198
199
200 !vld[listName] && (vld[listName] = []);
201 !vld[listName][index] && (vld[listName][index] = {});
202 vld[listName][index][keyName] = e.target.value;
203
204 this.setState({
205 vld: vld
206 })
207 }
208
209 addConnectionPointRef = () => {
210 let vld = {};
211 if (this.vld) {
212 vld = _cloneDeep(this.vld);
213 if (!vld['vnfd-connection-point-ref']) {
214 vld['vnfd-connection-point-ref'] = [];
215 }
216 vld['vnfd-connection-point-ref'].push({
217 'member-vnf-index-ref': '',
218 'vnfd-id-ref': '',
219 'vnfd-connection-point-ref': ''
220 });
221
222 this.setState({
223 vld: vld
224 });
225 }
226 }
227
228 removeConnectionPointRef = (vnfdConnectionPointRefIndex) => {
229 let vld = _cloneDeep(this.vld);
230 vld['vnfd-connection-point-ref'].splice(vnfdConnectionPointRefIndex, 1);
231 this.setState({
232 vld: vld
233 });
234 }
235
236 createVirtualLinkError(data) {
237 this.alt.actions.global.showError.defer('Something went wrong while trying to create the virtual link. Check the error logs for more information');
238 }
239
240 editVirtualLinkError(data) {
241 this.alt.actions.global.showError.defer('Something went wrong while trying to save the virtual link. Check the error logs for more information');
242 }
243
244 deleteVirtualLinkError(data) {
245 this.alt.actions.global.showError.defer('Something went wrong while trying to delete the virtual link. Check the error logs for more information');
246 this.setState({
247 deleteState: 'error'
248 })
249 }
250
251 createVirtualLinkSuccess(data) {
252 this.onSuccess();
253 }
254 editVirtualLinkSuccess(data) {
255 this.onSuccess();
256 }
257 deleteVirtualLinkSuccess(data) {
258 this.onSuccess();
259 }
260
261 cleanupPayload = (mode, vld) => {
262 // Do necessary cleanup here
263 let cleanVld = _pickBy(vld, _identity);
264 return cleanVld;
265 }
266
267 setLoadingState = (state = false) => {
268 this.setState({
269 isLoading: state
270 })
271 }
272
273 setLoaded = () => {
274 this.setLoadingState(true);
275 }
276
277 persistVirtualLink = (mode) => {
278 let self = this;
279
280 let payload = this.cleanupPayload(mode, this.vld);
281
282 if (mode == 'creating') {
283 this.getInstance().createVirtualLink(this.nsrId, payload);
284 } else {
285 this.getInstance().editVirtualLink(this.nsrId, this.vld.id, payload);
286 }
287 }
288
289 removeVirtualLink = (nsrId, vldId) => {
290 this.getInstance().deleteVirtualLink(nsrId, vldId);
291 }
292
293 }
294
295 export default NSVirtualLinkCreateStore;