2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
22 import Configuration from 'sdc-app/config/Configuration.js';
24 import {actionTypes} from './SoftwareProductComponentsNetworkConstants.js';
26 function baseUrl(softwareProductId, componentId) {
27 const restPrefix = Configuration.get('restPrefix');
28 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/nics`;
32 function fetchNICQuestionnaire({softwareProductId, componentId, nicId, version}) {
33 let versionQuery = version ? `?version=${version}` : '';
34 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, componentId)}/${nicId}/questionnaire${versionQuery}`);
37 function fetchNIC({softwareProductId, componentId, nicId, version}) {
38 let versionQuery = version ? `?version=${version}` : '';
39 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, componentId)}/${nicId}${versionQuery}`);
42 function fetchNICsList({softwareProductId, componentId, version}) {
43 let versionQuery = version ? `?version=${version}` : '';
44 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, componentId)}${versionQuery}`);
47 function saveNIC({softwareProductId, componentId, nic: {id, name, description, networkId}}) {
48 return RestAPIUtil.save(`${baseUrl(softwareProductId, componentId)}/${id}`,{
55 function saveNICQuestionnaire({softwareProductId, componentId, nicId, qdata}) {
56 return RestAPIUtil.save(`${baseUrl(softwareProductId, componentId)}/${nicId}/questionnaire`, qdata);
59 const SoftwareProductComponentNetworkActionHelper = {
61 fetchNICsList(dispatch, {softwareProductId, componentId, version}) {
62 return fetchNICsList({softwareProductId, componentId, version}).then((response) => {
64 type: actionTypes.NIC_LIST_UPDATE,
65 response: response.results
70 openNICEditor(dispatch, {nic = {}, data = {}}) {
72 type: actionTypes.NICEditor.OPEN,
73 nic: {...data, id: nic.id}
77 closeNICEditor(dispatch) {
79 type: actionTypes.NICEditor.CLOSE
83 loadNICData({softwareProductId, componentId, nicId, version}) {
84 return fetchNIC({softwareProductId, componentId, nicId, version});
87 loadNICQuestionnaire(dispatch, {softwareProductId, componentId, nicId, version}) {
88 return fetchNICQuestionnaire({softwareProductId, componentId, nicId, version}).then((response) => {
90 type: actionTypes.NICEditor.NIC_QUESTIONNAIRE_UPDATE,
92 qdata: response.data ? JSON.parse(response.data) : {},
93 qschema: JSON.parse(response.schema)
99 updateNICData(dispatch, {deltaData}) {
101 type: actionTypes.NICEditor.DATA_CHANGED,
106 updateNICQuestionnaire(dispatch, {data}) {
108 type: actionTypes.NICEditor.NIC_QUESTIONNAIRE_UPDATE,
115 saveNICDataAndQuestionnaire(dispatch, {softwareProductId, componentId, data, qdata}) {
116 SoftwareProductComponentNetworkActionHelper.closeNICEditor(dispatch);
118 saveNICQuestionnaire({softwareProductId, componentId, nicId: data.id, qdata}),
119 saveNIC({softwareProductId, componentId, nic: data}).then(() => {
121 type: actionTypes.NIC_LIST_EDIT,
129 export default SoftwareProductComponentNetworkActionHelper;