2 * Copyright © 2016-2018 European Support Limited
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 or implied.
13 * See the License for the specific language governing permissions and
14 * 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';
22 actionTypes as GlobalModalActions,
24 } from 'nfvo-components/modal/GlobalModalConstants.js';
25 import { modalContentMapper as modalPagesMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
26 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
27 import { NIC_QUESTIONNAIRE } from 'sdc-app/onboarding/softwareProduct/components/network/SoftwareProductComponentsNetworkConstants.js';
29 function baseUrl(softwareProductId, version, componentId) {
30 const versionId = version.id;
31 const restPrefix = Configuration.get('restPrefix');
32 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/components/${componentId}/nics`;
35 function createNIC({ nic, vspId, componentId, version }) {
36 return RestAPIUtil.post(baseUrl(vspId, version, componentId), {
38 description: nic.description,
39 networkDescription: nic.networkDescription,
40 networkType: nic.networkType
44 function fetchNICQuestionnaire({
50 return RestAPIUtil.fetch(
55 )}/${nicId}/questionnaire`
59 function fetchNIC({ softwareProductId, version, componentId, nicId }) {
60 return RestAPIUtil.fetch(
61 `${baseUrl(softwareProductId, version, componentId)}/${nicId}`
65 function fetchNICsList({ softwareProductId, version, componentId }) {
66 return RestAPIUtil.fetch(
67 `${baseUrl(softwareProductId, version, componentId)}`
71 function deleteNIC({ softwareProductId, componentId, nicId, version }) {
72 return RestAPIUtil.destroy(
73 `${baseUrl(softwareProductId, version, componentId)}/${nicId}`
80 nic: { id, name, description, networkId, networkType, networkDescription }
82 return RestAPIUtil.put(
83 `${baseUrl(softwareProductId, version, componentId)}/${id}`,
94 function saveNICQuestionnaire({
101 return RestAPIUtil.put(
106 )}/${nicId}/questionnaire`,
111 const SoftwareProductComponentNetworkActionHelper = {
112 fetchNICsList(dispatch, { softwareProductId, version, componentId }) {
113 return fetchNICsList({ softwareProductId, version, componentId }).then(
116 type: actionTypes.NIC_LIST_UPDATE,
117 response: response.results
135 type: actionTypes.NICEditor.FILL_DATA,
136 nic: { ...data, id: nic.id }
139 type: GlobalModalActions.GLOBAL_MODAL_SHOW,
141 modalComponentProps: {
146 size: modalSizes.LARGE
148 modalComponentName: modalPagesMapper.NIC_EDITOR,
149 title: i18n('Edit NIC')
154 closeNICEditor(dispatch) {
156 type: GlobalModalActions.GLOBAL_MODAL_CLOSE
159 type: actionTypes.NICEditor.CLEAR_DATA
163 createNIC(dispatch, { nic, softwareProductId, componentId, version }) {
166 vspId: softwareProductId,
170 return SoftwareProductComponentNetworkActionHelper.fetchNICsList(
172 { softwareProductId, componentId, version }
176 loadNICData({ softwareProductId, version, componentId, nicId }) {
177 return fetchNIC({ softwareProductId, version, componentId, nicId });
180 deleteNIC(dispatch, { softwareProductId, componentId, nicId, version }) {
187 return SoftwareProductComponentNetworkActionHelper.fetchNICsList(
189 { softwareProductId, componentId, version }
193 loadNICQuestionnaire(
195 { softwareProductId, version, componentId, nicId }
197 return fetchNICQuestionnaire({
202 }).then(response => {
203 ValidationHelper.qDataLoaded(dispatch, {
204 qName: NIC_QUESTIONNAIRE,
206 qdata: response.data ? JSON.parse(response.data) : {},
207 qschema: JSON.parse(response.schema)
213 saveNICDataAndQuestionnaire(
215 { softwareProductId, version, componentId, data, qdata }
217 SoftwareProductComponentNetworkActionHelper.closeNICEditor(dispatch);
219 saveNICQuestionnaire({
233 type: actionTypes.NIC_LIST_EDIT,
241 export default SoftwareProductComponentNetworkActionHelper;