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';
19 import { actionTypes } from './computeComponents/computeFlavor/ComputeFlavorConstants.js';
20 import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
22 actionTypes as globalModalActionTypes,
24 } from 'nfvo-components/modal/GlobalModalConstants.js';
25 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
26 import { COMPONENTS_COMPUTE_QUESTIONNAIRE } from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsConstants.js';
28 function baseUrl(softwareProductId, componentId, version) {
29 const versionId = version.id;
30 const restPrefix = Configuration.get('restPrefix');
31 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/components/${componentId}/compute-flavors`;
34 function baseUrlVSPLevel(softwareProductId, version) {
35 const versionId = version.id;
36 const restPrefix = Configuration.get('restPrefix');
37 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/compute-flavors`;
40 function fetchComputesList(softwareProductId, componentId, version) {
41 return RestAPIUtil.fetch(
42 `${baseUrl(softwareProductId, componentId, version)}`
46 function fetchComputesListForVSP(softwareProductId, version) {
47 return RestAPIUtil.fetch(`${baseUrlVSPLevel(softwareProductId, version)}`);
50 function fetchCompute(softwareProductId, componentId, computeId, version) {
51 return RestAPIUtil.fetch(
52 `${baseUrl(softwareProductId, componentId, version)}/${computeId}`
56 function fetchComputeQuestionnaire({
62 return RestAPIUtil.fetch(
67 )}/${computeId}/questionnaire`
71 function postCompute({ softwareProductId, componentId, compute, version }) {
72 return RestAPIUtil.post(
73 baseUrl(softwareProductId, componentId, version),
78 function putCompute({ softwareProductId, componentId, compute, version }) {
81 description: compute.description
83 return RestAPIUtil.put(
84 `${baseUrl(softwareProductId, componentId, version)}/${compute.id}`,
89 function putComputeQuestionnaire({
96 return RestAPIUtil.put(
101 )}/${computeId}/questionnaire`,
106 function deleteCompute({ softwareProductId, componentId, computeId, version }) {
107 return RestAPIUtil.destroy(
108 `${baseUrl(softwareProductId, componentId, version)}/${computeId}`
112 const ComputeFlavorActionHelper = {
113 openComputeEditor(dispatch, { props }) {
115 type: actionTypes.computeEditor.LOAD_EDITOR_DATA,
116 compute: props.compute || {}
119 type: globalModalActionTypes.GLOBAL_MODAL_SHOW,
122 modalContentMapper.COMPONENT_COMPUTE_FLAVOR_EDITOR,
123 modalComponentProps: {
125 size: props.compute ? modalSizes.XLARGE : undefined,
126 dialogClassName: 'compute-flavor-editor-modal'
130 ? i18n('Edit Compute Flavor')
131 : i18n('Create New Compute Flavor')
137 closeComputeEditor(dispatch) {
139 type: globalModalActionTypes.GLOBAL_MODAL_CLOSE
142 type: actionTypes.computeEditor.CLEAR_DATA
146 fetchComputesList(dispatch, { softwareProductId, componentId, version }) {
147 return fetchComputesList(softwareProductId, componentId, version).then(
150 type: actionTypes.COMPUTE_FLAVORS_LIST_LOADED,
156 fetchComputesListForVSP(dispatch, { softwareProductId, version }) {
157 return fetchComputesListForVSP(softwareProductId, version).then(
160 type: actionTypes.COMPUTE_FLAVORS_LIST_LOADED,
166 loadComputeData({ softwareProductId, componentId, computeId, version }) {
167 return fetchCompute(softwareProductId, componentId, computeId, version);
170 loadComputeQuestionnaire(
172 { softwareProductId, componentId, computeId, version }
174 return fetchComputeQuestionnaire({
180 ValidationHelper.qDataLoaded(dispatch, {
181 qName: COMPONENTS_COMPUTE_QUESTIONNAIRE,
183 qdata: response.data ? JSON.parse(response.data) : {},
184 qschema: JSON.parse(response.schema)
192 { softwareProductId, componentId, version, computeId, isReadOnlyMode }
194 return ComputeFlavorActionHelper.loadComputeData({
199 }).then(({ data }) =>
200 ComputeFlavorActionHelper.loadComputeQuestionnaire(dispatch, {
206 ComputeFlavorActionHelper.openComputeEditor(dispatch, {
212 compute: { id: computeId, ...data }
219 saveComputeDataAndQuestionnaire(
221 { softwareProductId, componentId, data: compute, qdata, version }
223 ComputeFlavorActionHelper.closeComputeEditor(dispatch);
226 putComputeQuestionnaire({
229 computeId: compute.id,
240 type: actionTypes.COMPUTE_LIST_EDIT,
253 type: actionTypes.ADD_COMPUTE,
266 { softwareProductId, componentId, computeId, version }
268 return deleteCompute({
275 type: actionTypes.DELETE_COMPUTE,
282 export default ComputeFlavorActionHelper;