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
,
88 saveOnSuccess
: this.saveOnSuccess
101 saveOnSuccess
= (onSuccess
) => {
107 saveMode
= (mode
) => {
113 saveVnfdIdRefs
= (vnfdIdRefs
) => {
115 vnfdIdRefs
: vnfdIdRefs
119 saveMemberVnfIndexRefs
= (memberVnfIndexRefs
) => {
121 memberVnfIndexRefs
: memberVnfIndexRefs
125 saveIpProfileNames
= (ipProfileNames
) => {
127 ipProfileNames
: ipProfileNames
131 saveNSRId
= (nsrId
) => {
143 updateFirstLevelKey
= (key
, e
) => {
144 let vld
= _
.cloneDeep(this.vld
);
145 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
152 updateSecondLevelKey
= (firstLevelKey
, secondLevelKey
, e
) => {
153 let vld
= _
.cloneDeep(this.vld
);
154 if (!vld
[firstLevelKey
]) {
155 vld
[firstLevelKey
] = {};
157 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
158 vld
[firstLevelKey
][secondLevelKey
] = value
;
164 updateVLDInitParamsType
= (value
) => {
167 // Reset init param types
168 this.vldInitParamsTypes
.map((vldInitParamType
) => {
169 vld
[vldInitParamType
] && delete vld
[vldInitParamType
];
173 currentVLDInitParamsType
: value
,
178 updateVLDInitParamsValue
= (currentVLDInitParamsType
, e
) => {
179 let vld
= _
.cloneDeep(this.vld
);
180 this.vldInitParamsTypes
.map((vldInitParamType
) => {
181 if (currentVLDInitParamsType
== vldInitParamType
) {
182 let value
= e
.target
.nodeName
== "SELECT" ? JSON
.parse(e
.target
.value
) : e
.target
.value
;
183 vld
[currentVLDInitParamsType
] = value
;
185 vld
[vldInitParamType
] && delete vld
[vldInitParamType
];
194 updateFirstLevelListKeyChange
= (listName
, index
, keyName
, e
) => {
195 let vld
= _
.cloneDeep(this.vld
);
198 !vld
[listName
] && (vld
[listName
] = []);
199 !vld
[listName
][index
] && (vld
[listName
][index
] = {});
200 vld
[listName
][index
][keyName
] = e
.target
.value
;
207 addConnectionPointRef
= () => {
210 vld
= _
.cloneDeep(this.vld
);
211 if (!vld
['vnfd-connection-point-ref']) {
212 vld
['vnfd-connection-point-ref'] = [];
214 vld
['vnfd-connection-point-ref'].push({
215 'member-vnf-index-ref': '',
217 'vnfd-connection-point-ref': ''
226 removeConnectionPointRef
= (vnfdConnectionPointRefIndex
) => {
227 let vld
= _
.cloneDeep(this.vld
);
228 vld
['vnfd-connection-point-ref'].splice(vnfdConnectionPointRefIndex
, 1);
234 createVirtualLinkError(data
) {
235 this.alt
.actions
.global
.showError
.defer('Something went wrong while trying to create the virtual link. Check the error logs for more information');
238 editVirtualLinkError(data
) {
239 this.alt
.actions
.global
.showError
.defer('Something went wrong while trying to save the virtual link. Check the error logs for more information');
242 deleteVirtualLinkError(data
) {
243 this.alt
.actions
.global
.showError
.defer('Something went wrong while trying to delete the virtual link. Check the error logs for more information');
249 createVirtualLinkSuccess(data
) {
252 editVirtualLinkSuccess(data
) {
255 deleteVirtualLinkSuccess(data
) {
259 cleanupPayload
= (mode
, vld
) => {
260 // Do necessary cleanup here
261 let cleanVld
= _
.pickBy(vld
, _
.identity
);
265 setLoadingState
= (state
= false) => {
272 this.setLoadingState(true);
275 persistVirtualLink
= (mode
) => {
278 let payload
= this.cleanupPayload(mode
, this.vld
);
280 if (mode
== 'creating') {
281 this.getInstance().createVirtualLink(this.nsrId
, payload
);
283 this.getInstance().editVirtualLink(this.nsrId
, this.vld
.id
, payload
);
287 removeVirtualLink
= (nsrId
, vldId
) => {
288 this.getInstance().deleteVirtualLink(nsrId
, vldId
);
293 export default NSVirtualLinkCreateStore
;