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 _cloneDeep
from 'lodash/cloneDeep';
22 import _pickBy
from 'lodash/pickBy';
23 import _identity
from 'lodash/identity';
25 class NSVirtualLinkCreateStore
{
33 this.overlayTypeOptions
= [{
50 /* TODO: Move this to be populated from props */
51 this.vnfdConnectionPointRefs
= [{
52 label
: 'ping_vnfd/cp0',
53 value
: 'ping_vnfd/cp0'
55 label
: 'pong_vnfd/cp0',
56 value
: 'pong_vnfd/cp0'
61 this.vldInitParamsTypes
= [
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
103 saveOnSuccess
= (onSuccess
) => {
109 saveMode
= (mode
) => {
115 saveVnfdIdRefs
= (vnfdIdRefs
) => {
117 vnfdIdRefs
: vnfdIdRefs
121 saveMemberVnfIndexRefs
= (memberVnfIndexRefs
) => {
123 memberVnfIndexRefs
: memberVnfIndexRefs
127 saveIpProfileNames
= (ipProfileNames
) => {
129 ipProfileNames
: ipProfileNames
133 saveNSRId
= (nsrId
) => {
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
;
154 updateSecondLevelKey
= (firstLevelKey
, secondLevelKey
, e
) => {
155 let vld
= _cloneDeep(this.vld
);
156 if (!vld
[firstLevelKey
]) {
157 vld
[firstLevelKey
] = {};
159 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
160 vld
[firstLevelKey
][secondLevelKey
] = value
;
166 updateVLDInitParamsType
= (value
) => {
169 // Reset init param types
170 this.vldInitParamsTypes
.map((vldInitParamType
) => {
171 vld
[vldInitParamType
] && delete vld
[vldInitParamType
];
175 currentVLDInitParamsType
: value
,
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
;
187 vld
[vldInitParamType
] && delete vld
[vldInitParamType
];
196 updateFirstLevelListKeyChange
= (listName
, index
, keyName
, e
) => {
197 let vld
= _cloneDeep(this.vld
);
200 !vld
[listName
] && (vld
[listName
] = []);
201 !vld
[listName
][index
] && (vld
[listName
][index
] = {});
202 vld
[listName
][index
][keyName
] = e
.target
.value
;
209 addConnectionPointRef
= () => {
212 vld
= _cloneDeep(this.vld
);
213 if (!vld
['vnfd-connection-point-ref']) {
214 vld
['vnfd-connection-point-ref'] = [];
216 vld
['vnfd-connection-point-ref'].push({
217 'member-vnf-index-ref': '',
219 'vnfd-connection-point-ref': ''
228 removeConnectionPointRef
= (vnfdConnectionPointRefIndex
) => {
229 let vld
= _cloneDeep(this.vld
);
230 vld
['vnfd-connection-point-ref'].splice(vnfdConnectionPointRefIndex
, 1);
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');
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');
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');
251 createVirtualLinkSuccess(data
) {
254 editVirtualLinkSuccess(data
) {
257 deleteVirtualLinkSuccess(data
) {
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
;