2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
17 import Configuration from 'sdc-app/config/Configuration.js';
18 import i18n from 'nfvo-utils/i18n/i18n.js';
20 import { actionTypes } from './SoftwareProductComponentsNetworkConstants.js';
21 import { actionTypes as GlobalModalActions } from 'nfvo-components/modal/GlobalModalConstants.js';
22 import { modalContentMapper as modalPagesMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
23 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
24 import { NIC_QUESTIONNAIRE } from 'sdc-app/onboarding/softwareProduct/components/network/SoftwareProductComponentsNetworkConstants.js';
26 function baseUrl(softwareProductId, version, componentId) {
27 const versionId = version.id;
28 const restPrefix = Configuration.get('restPrefix');
29 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/components/${componentId}/nics`;
32 function createNIC({ nic, vspId, componentId, version }) {
33 return RestAPIUtil.post(baseUrl(vspId, version, componentId), {
35 description: nic.description,
36 networkDescription: nic.networkDescription,
37 networkType: nic.networkType
41 function fetchNICQuestionnaire({
47 return RestAPIUtil.fetch(
52 )}/${nicId}/questionnaire`
56 function fetchNIC({ softwareProductId, version, componentId, nicId }) {
57 return RestAPIUtil.fetch(
58 `${baseUrl(softwareProductId, version, componentId)}/${nicId}`
62 function fetchNICsList({ softwareProductId, version, componentId }) {
63 return RestAPIUtil.fetch(
64 `${baseUrl(softwareProductId, version, componentId)}`
68 function deleteNIC({ softwareProductId, componentId, nicId, version }) {
69 return RestAPIUtil.destroy(
70 `${baseUrl(softwareProductId, version, componentId)}/${nicId}`
77 nic: { id, name, description, networkId, networkType, networkDescription }
79 return RestAPIUtil.put(
80 `${baseUrl(softwareProductId, version, componentId)}/${id}`,
91 function saveNICQuestionnaire({
98 return RestAPIUtil.put(
103 )}/${nicId}/questionnaire`,
108 const SoftwareProductComponentNetworkActionHelper = {
109 fetchNICsList(dispatch, { softwareProductId, version, componentId }) {
110 return fetchNICsList({ softwareProductId, version, componentId }).then(
113 type: actionTypes.NIC_LIST_UPDATE,
114 response: response.results
133 type: actionTypes.NICEditor.FILL_DATA,
134 nic: { ...data, id: nic.id }
137 type: GlobalModalActions.GLOBAL_MODAL_SHOW,
140 modalComponentProps: {
146 modalComponentName: modalPagesMapper.NIC_EDITOR,
147 title: i18n('Edit NIC')
152 closeNICEditor(dispatch) {
154 type: GlobalModalActions.GLOBAL_MODAL_CLOSE
157 type: actionTypes.NICEditor.CLEAR_DATA
161 createNIC(dispatch, { nic, softwareProductId, componentId, version }) {
164 vspId: softwareProductId,
168 return SoftwareProductComponentNetworkActionHelper.fetchNICsList(
170 { softwareProductId, componentId, version }
174 loadNICData({ softwareProductId, version, componentId, nicId }) {
175 return fetchNIC({ softwareProductId, version, componentId, nicId });
178 deleteNIC(dispatch, { softwareProductId, componentId, nicId, version }) {
185 return SoftwareProductComponentNetworkActionHelper.fetchNICsList(
187 { softwareProductId, componentId, version }
191 loadNICQuestionnaire(
193 { softwareProductId, version, componentId, nicId }
195 return fetchNICQuestionnaire({
200 }).then(response => {
201 ValidationHelper.qDataLoaded(dispatch, {
202 qName: NIC_QUESTIONNAIRE,
204 qdata: response.data ? JSON.parse(response.data) : {},
205 qschema: JSON.parse(response.schema)
211 saveNICDataAndQuestionnaire(
213 { softwareProductId, version, componentId, data, qdata }
215 SoftwareProductComponentNetworkActionHelper.closeNICEditor(dispatch);
217 saveNICQuestionnaire({
231 type: actionTypes.NIC_LIST_EDIT,
239 export default SoftwareProductComponentNetworkActionHelper;