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.
18 import NSVirtualLinkCreateActions
from './nsVirtualLinkCreateActions.js';
19 import NSVirtualLinkCreateSource
from './nsVirtualLinkCreateSource.js';
20 import Alt
from '../alt';
21 import _
from 'lodash';
23 class NSVirtualLinkCreateStore
{
31 this.overlayTypeOptions
= [{
48 /* TODO: Move this to be populated from props */
49 this.vnfdConnectionPointRefs
= [{
50 label
: 'ping_vnfd/cp0',
51 value
: 'ping_vnfd/cp0'
53 label
: 'pong_vnfd/cp0',
54 value
: 'pong_vnfd/cp0'
59 this.vldInitParamsTypes
= [
65 this.currentVLDInitParamsType
= 'unknown';
66 this.registerAsync(NSVirtualLinkCreateSource
);
67 this.bindAction(NSVirtualLinkCreateActions
.EDIT_VIRTUAL_LINK_ERROR
, this.editVirtualLinkError
);
68 this.bindAction(NSVirtualLinkCreateActions
.DELETE_VIRTUAL_LINK_ERROR
, this.deleteVirtualLinkError
);
69 this.bindAction(NSVirtualLinkCreateActions
.CREATE_VIRTUAL_LINK_SUCCESS
, this.createVirtualLinkSuccess
);
70 this.bindAction(NSVirtualLinkCreateActions
.EDIT_VIRTUAL_LINK_SUCCESS
, this.editVirtualLinkSuccess
);
71 this.bindAction(NSVirtualLinkCreateActions
.DELETE_VIRTUAL_LINK_SUCCESS
, this.deleteVirtualLinkSuccess
);
72 this.exportPublicMethods({
73 persistVirtualLink
: this.persistVirtualLink
,
74 updateFirstLevelKey
: this.updateFirstLevelKey
,
75 updateSecondLevelKey
: this.updateSecondLevelKey
,
76 updateVLDInitParamsType
: this.updateVLDInitParamsType
,
77 updateVLDInitParamsValue
: this.updateVLDInitParamsValue
,
78 saveNSRId
: this.saveNSRId
,
79 saveVld
: this.saveVld
,
80 addConnectionPointRef
: this.addConnectionPointRef
,
81 removeConnectionPointRef
: this.removeConnectionPointRef
,
82 updateFirstLevelListKeyChange
: this.updateFirstLevelListKeyChange
,
83 saveMemberVnfIndexRefs
: this.saveMemberVnfIndexRefs
,
84 saveVnfdIdRefs
: this.saveVnfdIdRefs
,
85 saveIpProfileNames
: this.saveIpProfileNames
,
86 removeVirtualLink
: this.removeVirtualLink
,
87 saveMode
: this.saveMode
100 saveMode
= (mode
) => {
106 saveVnfdIdRefs
= (vnfdIdRefs
) => {
108 vnfdIdRefs
: vnfdIdRefs
112 saveMemberVnfIndexRefs
= (memberVnfIndexRefs
) => {
114 memberVnfIndexRefs
: memberVnfIndexRefs
118 saveIpProfileNames
= (ipProfileNames
) => {
120 ipProfileNames
: ipProfileNames
124 saveNSRId
= (nsrId
) => {
136 updateFirstLevelKey
= (key
, e
) => {
137 let vld
= _
.cloneDeep(this.vld
);
138 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
145 updateSecondLevelKey
= (firstLevelKey
, secondLevelKey
, e
) => {
146 let vld
= _
.cloneDeep(this.vld
);
147 if (!vld
[firstLevelKey
]) {
148 vld
[firstLevelKey
] = {};
150 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
151 vld
[firstLevelKey
][secondLevelKey
] = value
;
157 updateVLDInitParamsType
= (value
) => {
160 // Reset init param types
161 this.vldInitParamsTypes
.map((vldInitParamType
) => {
162 vld
[vldInitParamType
] && delete vld
[vldInitParamType
];
166 currentVLDInitParamsType
: value
,
171 updateVLDInitParamsValue
= (currentVLDInitParamsType
, e
) => {
172 let vld
= _
.cloneDeep(this.vld
);
173 this.vldInitParamsTypes
.map((vldInitParamType
) => {
174 if (currentVLDInitParamsType
== vldInitParamType
) {
175 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
176 vld
[currentVLDInitParamsType
] = value
;
178 vld
[vldInitParamType
] && delete vld
[vldInitParamType
];
187 updateFirstLevelListKeyChange
= (listName
, index
, keyName
, e
) => {
188 let vld
= _
.cloneDeep(this.vld
);
191 !vld
[listName
] && (vld
[listName
] = []);
192 !vld
[listName
][index
] && (vld
[listName
][index
] = {});
193 vld
[listName
][index
][keyName
] = e
.target
.value
;
200 addConnectionPointRef
= () => {
203 vld
= _
.cloneDeep(this.vld
);
204 if (!vld
['vnfd-connection-point-ref']) {
205 vld
['vnfd-connection-point-ref'] = [];
207 vld
['vnfd-connection-point-ref'].push({
208 'member-vnf-index-ref': '',
210 'vnfd-connection-point-ref': ''
219 removeConnectionPointRef
= (vnfdConnectionPointRefIndex
) => {
220 let vld
= _
.cloneDeep(this.vld
);
221 vld
['vnfd-connection-point-ref'].splice(vnfdConnectionPointRefIndex
, 1);
227 createVirtualLinkError(data
) {
228 this.alt
.actions
.global
.showError
.defer('Something went wrong while trying to create the virtual link. Check the error logs for more information');
231 editVirtualLinkError(data
) {
232 this.alt
.actions
.global
.showError
.defer('Something went wrong while trying to save the virtual link. Check the error logs for more information');
235 deleteVirtualLinkError(data
) {
236 this.alt
.actions
.global
.showError
.defer('Something went wrong while trying to delete the virtual link. Check the error logs for more information');
242 createVirtualLinkSuccess(data
) {
249 editVirtualLinkSuccess(data
) {
255 deleteVirtualLinkSuccess(data
) {
257 deleteState
: 'success'
261 cleanupPayload
= (mode
, vld
) => {
262 // Do necessary cleanup here
263 let cleanVld
= _
.pickBy(vld
, _
.identity
);
267 setLoadingState
= (state
= false) => {
274 this.setLoadingState(true);
277 persistVirtualLink
= (mode
) => {
280 let payload
= this.cleanupPayload(mode
, this.vld
);
282 if (mode
== 'creating') {
283 this.getInstance().createVirtualLink(this.nsrId
, payload
);
285 this.getInstance().editVirtualLink(this.nsrId
, this.vld
.id
, payload
);
289 removeVirtualLink
= (nsrId
, vldId
) => {
290 this.getInstance().deleteVirtualLink(nsrId
, vldId
);
295 export default NSVirtualLinkCreateStore
;