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 { actionTypes } from './SoftwareProductProcessesConstants.js';
17 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
18 import Configuration from 'sdc-app/config/Configuration.js';
19 import i18n from 'nfvo-utils/i18n/i18n.js';
21 actionTypes as modalActionTypes,
23 } from 'nfvo-components/modal/GlobalModalConstants.js';
24 import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
26 function baseUrl(vspId, version) {
27 let { id: versionId } = version;
28 const restPrefix = Configuration.get('restPrefix');
29 return `${restPrefix}/v1.0/vendor-software-products/${vspId}/versions/${versionId}/processes`;
32 function putProcess(softwareProductId, version, process) {
33 return RestAPIUtil.put(
34 `${baseUrl(softwareProductId, version)}/${process.id}`,
37 description: process.description,
38 type: process.type === '' ? null : process.type
43 function postProcess(softwareProductId, version, process) {
44 return RestAPIUtil.post(`${baseUrl(softwareProductId, version)}`, {
46 description: process.description,
47 type: process.type === '' ? null : process.type
51 function deleteProcess(softwareProductId, version, processId) {
52 return RestAPIUtil.destroy(
53 `${baseUrl(softwareProductId, version)}/${processId}`
57 function uploadFileToProcess(softwareProductId, version, processId, formData) {
58 return RestAPIUtil.post(
59 `${baseUrl(softwareProductId, version)}/${processId}/upload`,
64 function fetchProcesses(softwareProductId, version) {
65 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}`);
68 const SoftwareProductActionHelper = {
69 fetchProcessesList(dispatch, { softwareProductId, version }) {
71 type: actionTypes.FETCH_SOFTWARE_PRODUCT_PROCESSES,
75 return fetchProcesses(softwareProductId, version).then(response => {
77 type: actionTypes.FETCH_SOFTWARE_PRODUCT_PROCESSES,
78 processesList: response.results
84 { process, softwareProductId, version, isReadOnlyMode }
87 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_EDITOR_OPEN,
88 process: process ? process : {}
91 type: modalActionTypes.GLOBAL_MODAL_SHOW,
93 modalComponentName: modalContentMapper.PROCESS_EDITOR,
94 modalComponentProps: {
98 size: modalSizes.LARGE
100 bodyClassName: 'edit-process-modal',
102 ? i18n('Edit Process Details')
103 : i18n('Create New Process Details')
108 deleteProcess(dispatch, { process, softwareProductId, version }) {
109 return deleteProcess(softwareProductId, version, process.id).then(
112 type: actionTypes.DELETE_SOFTWARE_PRODUCT_PROCESS,
113 processId: process.id
119 closeEditor(dispatch) {
121 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_EDITOR_CLOSE
124 type: modalActionTypes.GLOBAL_MODAL_CLOSE
130 { softwareProductId, version, previousProcess, process }
132 if (previousProcess) {
133 return putProcess(softwareProductId, version, process).then(() => {
134 if (process.formData) {
143 type: actionTypes.EDIT_SOFTWARE_PRODUCT_PROCESS,
148 return postProcess(softwareProductId, version, process).then(
150 if (process.formData) {
159 type: actionTypes.ADD_SOFTWARE_PRODUCT_PROCESS,
170 hideDeleteConfirm(dispatch) {
172 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_CONFIRM,
173 processToDelete: false
177 openDeleteProcessesConfirm(dispatch, { process }) {
179 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_CONFIRM,
180 processToDelete: process
185 export default SoftwareProductActionHelper;