[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / attachments / setup / HeatSetupActionHelper.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 import {actionTypes} from './HeatSetupConstants.js';
17 import isEqual from 'lodash/isEqual.js';
18 import cloneDeep from 'lodash/cloneDeep.js';
19 import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
20 import i18n from 'nfvo-utils/i18n/i18n.js';
21 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
22
23 export default {
24
25         addModule(dispatch, isBase){
26                 dispatch({type: actionTypes.ADD_MODULE, data: {isBase}});
27         },
28
29         deleteModule(dispatch, moduleName){
30                 dispatch({type: actionTypes.REMOVE_MODULE, data: {moduleName}});
31         },
32
33         renameModule(dispatch, {oldName, newName}){
34                 dispatch({type: actionTypes.RENAME_MODULE, data: {oldName, newName}});
35         },
36
37         changeModuleFileType(dispatch, {module, value, type}){
38                 if (!value) {
39                         value = {value: ''};
40                 }
41                 dispatch({type: actionTypes.FILE_ASSIGN_CHANGED, data: {module, value, type}});
42         },
43
44         changeArtifactList(dispatch, artifacts){
45                 dispatch({type: actionTypes.ARTIFACT_LIST_CHANGE, data: {artifacts: artifacts.map(artifact => artifact.value)}});
46         },
47
48         processAndValidateHeat(dispatch, {softwareProductId, heatData, heatDataCache, isReadOnlyMode, version}){                
49                 return (isEqual({...heatData, softwareProductId}, heatDataCache) || isReadOnlyMode) ? Promise.resolve() :
50                 SoftwareProductActionHelper.updateSoftwareProductHeatCandidate(dispatch, {softwareProductId, heatCandidate: heatData, version})
51                         .then(() => SoftwareProductActionHelper.processAndValidateHeatCandidate(dispatch, {softwareProductId, version}))
52                         .then(() => dispatch({type: actionTypes.FILL_HEAT_SETUP_CACHE, payload: {...cloneDeep(heatData), softwareProductId}}));
53         },
54
55         addAllUnassignedFilesToArtifacts(dispatch){
56                 dispatch({type: actionTypes.ADD_ALL_UNASSIGNED_TO_ARTIFACTS});
57         },
58
59         heatSetupLeaveConfirmation(dispatch, {softwareProductId, heatSetup, heatSetupCache}) {
60                 return new Promise((resolve, reject) => {
61                         if (isEqual({...heatSetup, softwareProductId}, heatSetupCache)) {
62                                 resolve();
63                         } else {
64                                 dispatch({
65                                         type: modalActionTypes.GLOBAL_MODAL_WARNING,
66                                         data:{
67                                                 msg: i18n(`You have uploaded a new HEAT. If you navigate away or Check-in without proceeding to validation, 
68                                                         Old HEAT zip file will be in use. new HEAT will be ignored. Do you want to continue?`),
69                                                 confirmationButtonText: i18n('Continue'),
70                                                 onConfirmed: () => resolve(),
71                                                 onDeclined: () => reject()
72                                         }
73                                 });
74                         }
75                 });
76         }
77 };