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';
19 import {actionTypes} from './computeComponents/computeFlavor/ComputeFlavorConstants.js';
20 import {modalContentMapper} from 'sdc-app/common/modal/ModalContentMapper.js';
21 import {actionTypes as globalModalActionTypes, modalSizes} from 'nfvo-components/modal/GlobalModalConstants.js';
22 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
23 import {COMPONENTS_COMPUTE_QUESTIONNAIRE} from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsConstants.js';
25 function baseUrl(softwareProductId, componentId, version) {
26 const versionId = version.id;
27 const restPrefix = Configuration.get('restPrefix');
28 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/components/${componentId}/compute-flavors`;
31 function baseUrlVSPLevel(softwareProductId, version){
32 const versionId = version.id;
33 const restPrefix = Configuration.get('restPrefix');
34 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/compute-flavors`;
37 function fetchComputesList(softwareProductId, componentId, version){
38 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, componentId, version)}`);
41 function fetchComputesListForVSP(softwareProductId, version){
42 return RestAPIUtil.fetch(`${baseUrlVSPLevel(softwareProductId, version)}`);
45 function fetchCompute(softwareProductId, componentId, computeId, version) {
46 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, componentId, version)}/${computeId}`);
49 function fetchComputeQuestionnaire({softwareProductId, componentId, computeId, version}) {
50 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, componentId, version)}/${computeId}/questionnaire`);
53 function postCompute({softwareProductId, componentId, compute, version}) {
54 return RestAPIUtil.post(baseUrl(softwareProductId, componentId, version), compute);
57 function putCompute({softwareProductId, componentId, compute, version}) {
60 description: compute.description
62 return RestAPIUtil.put(`${baseUrl(softwareProductId, componentId, version)}/${compute.id}`, computeData);
65 function putComputeQuestionnaire({softwareProductId, componentId, computeId, qdata, version}) {
66 return RestAPIUtil.put(`${baseUrl(softwareProductId, componentId, version)}/${computeId}/questionnaire`, qdata);
69 function deleteCompute({softwareProductId, componentId, computeId, version}) {
70 return RestAPIUtil.destroy(`${baseUrl(softwareProductId, componentId, version)}/${computeId}`);
74 const ComputeFlavorActionHelper = {
75 openComputeEditor(dispatch, {props}) {
77 type: actionTypes.computeEditor.LOAD_EDITOR_DATA,
78 compute: props.compute || {}
81 type: globalModalActionTypes.GLOBAL_MODAL_SHOW,
83 modalComponentName: modalContentMapper.COMPONENT_COMPUTE_FLAVOR_EDITOR,
84 modalClassName: `compute-flavor-editor-modal-${props.compute ? 'edit' : 'create'}`,
85 modalComponentProps: {...props, size: props.compute ? modalSizes.LARGE : undefined, dialogClassName:'compute-flavor-editor-modal'},
86 title: `${props.compute ? i18n('Edit Compute Flavor') : i18n('Create New Compute Flavor')}`
91 closeComputeEditor(dispatch){
93 type: globalModalActionTypes.GLOBAL_MODAL_CLOSE
96 type: actionTypes.computeEditor.CLEAR_DATA
100 fetchComputesList(dispatch, {softwareProductId, componentId, version}) {
101 return fetchComputesList(softwareProductId, componentId, version).then(response => dispatch({
102 type: actionTypes.COMPUTE_FLAVORS_LIST_LOADED,
107 fetchComputesListForVSP(dispatch, {softwareProductId, version}) {
108 return fetchComputesListForVSP(softwareProductId, version).then(response => dispatch({
109 type: actionTypes.COMPUTE_FLAVORS_LIST_LOADED,
114 loadComputeData({softwareProductId, componentId, computeId, version}) {
115 return fetchCompute(softwareProductId, componentId, computeId, version);
118 loadComputeQuestionnaire(dispatch, {softwareProductId, componentId, computeId, version}) {
119 return fetchComputeQuestionnaire({softwareProductId, componentId, computeId, version}).then(response =>
120 ValidationHelper.qDataLoaded(dispatch, {qName: COMPONENTS_COMPUTE_QUESTIONNAIRE ,response: {
121 qdata: response.data ? JSON.parse(response.data) : {},
122 qschema: JSON.parse(response.schema)
127 loadCompute(dispatch, {softwareProductId, componentId, version, computeId, isReadOnlyMode}){
128 return ComputeFlavorActionHelper.loadComputeData({softwareProductId, componentId, computeId, version}).then(({data}) =>
129 ComputeFlavorActionHelper.loadComputeQuestionnaire(dispatch, {softwareProductId, componentId, computeId, version}).then(() =>
130 ComputeFlavorActionHelper.openComputeEditor(dispatch, {props: {softwareProductId, componentId, version, isReadOnlyMode, compute: {id: computeId, ...data}}})
134 saveComputeDataAndQuestionnaire(dispatch, {softwareProductId, componentId, data: compute, qdata, version}) {
135 ComputeFlavorActionHelper.closeComputeEditor(dispatch);
138 putComputeQuestionnaire({softwareProductId, componentId, computeId: compute.id, qdata, version}),
139 putCompute({softwareProductId, componentId, compute, version}).then(() => {
141 type: actionTypes.COMPUTE_LIST_EDIT,
148 return postCompute({softwareProductId, componentId, compute, version}).then(response =>
150 type: actionTypes.ADD_COMPUTE,
161 deleteCompute(dispatch, {softwareProductId, componentId, computeId, version}) {
162 return deleteCompute({softwareProductId, componentId, computeId, version}).then(() => dispatch({
163 type: actionTypes.DELETE_COMPUTE,
169 export default ComputeFlavorActionHelper;