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({softwareProductId, version, componentId, nicId}) {
42 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version, componentId)}/${nicId}/questionnaire`);
45 function fetchNIC({softwareProductId, version, componentId, nicId}) {
46 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version, componentId)}/${nicId}`);
49 function fetchNICsList({softwareProductId, version, componentId}) {
50 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version, componentId)}`);
53 function deleteNIC({softwareProductId, componentId, nicId, version}) {
54 return RestAPIUtil.destroy(`${baseUrl(softwareProductId, version, componentId)}/${nicId}`);
56 function saveNIC({softwareProductId, version, componentId, nic: {id, name, description, networkId, networkType, networkDescription}}) {
57 return RestAPIUtil.put(`${baseUrl(softwareProductId, version, componentId)}/${id}`,{
66 function saveNICQuestionnaire({softwareProductId, version, componentId, nicId, qdata}) {
67 return RestAPIUtil.put(`${baseUrl(softwareProductId, version, componentId)}/${nicId}/questionnaire`, qdata);
70 const SoftwareProductComponentNetworkActionHelper = {
72 fetchNICsList(dispatch, {softwareProductId, version, componentId}) {
73 return fetchNICsList({softwareProductId, version, componentId}).then((response) => {
75 type: actionTypes.NIC_LIST_UPDATE,
76 response: response.results
81 openNICEditor(dispatch, {nic = {}, data = {}, softwareProductId, componentId, isReadOnlyMode, modalClassName}) {
83 type: actionTypes.NICEditor.FILL_DATA,
84 nic: {...data, id: nic.id}
87 type: GlobalModalActions.GLOBAL_MODAL_SHOW,
90 modalComponentProps: {softwareProductId, componentId, isReadOnlyMode},
91 modalComponentName: modalPagesMapper.NIC_EDITOR,
92 title: i18n('Edit NIC')
97 closeNICEditor(dispatch) {
99 type: GlobalModalActions.GLOBAL_MODAL_CLOSE
102 type: actionTypes.NICEditor.CLEAR_DATA
106 createNIC(dispatch, {nic, softwareProductId, componentId, version}){
107 return createNIC({nic, vspId: softwareProductId, componentId, version}).then(() => {
108 return SoftwareProductComponentNetworkActionHelper.fetchNICsList(dispatch, {softwareProductId, componentId, version});
111 loadNICData({softwareProductId, version, componentId, nicId}) {
112 return fetchNIC({softwareProductId, version, componentId, nicId});
115 deleteNIC(dispatch, {softwareProductId, componentId, nicId, version}) {
116 return deleteNIC({softwareProductId, componentId, nicId, version}).then(() => {
117 return SoftwareProductComponentNetworkActionHelper.fetchNICsList(dispatch, {softwareProductId, componentId, version});
120 loadNICQuestionnaire(dispatch, {softwareProductId, version, componentId, nicId}) {
121 return fetchNICQuestionnaire({softwareProductId, version, componentId, nicId}).then((response) => {
122 ValidationHelper.qDataLoaded(dispatch, {qName: NIC_QUESTIONNAIRE ,response: {
123 qdata: response.data ? JSON.parse(response.data) : {},
124 qschema: JSON.parse(response.schema)
129 saveNICDataAndQuestionnaire(dispatch, {softwareProductId, version, componentId, data, qdata}) {
130 SoftwareProductComponentNetworkActionHelper.closeNICEditor(dispatch);
132 saveNICQuestionnaire({softwareProductId, version, componentId, nicId: data.id, qdata}),
133 saveNIC({softwareProductId, version, componentId, nic: data}).then(() => {
135 type: actionTypes.NIC_LIST_EDIT,
143 export default SoftwareProductComponentNetworkActionHelper;